More fixes:

- Add "back to site" button on logout screen
- Add favicon to account pages
- Refactor notifications / alerts / caching
This commit is contained in:
Oliver 2021-11-04 09:59:56 +11:00
parent 4e7825df13
commit df30a85c03
10 changed files with 93 additions and 52 deletions

View File

@ -28,9 +28,8 @@
padding: 20px;
padding-bottom: 35px;
background-color: rgba(50, 50, 50, 0.75);
width: 100%;
max-width: 330px;
max-width: 550px;
margin: auto;
}

View File

@ -202,6 +202,9 @@ function inventreeDocReady() {
location.href = url;
});
// Display any cached alert messages
showCachedAlerts();
}
function isFileTransfer(transfer) {

View File

@ -1,12 +1,43 @@
/*
* Add a cached alert message to sesion storage
*/
function addCachedAlert(message, style) {
function showAlertOrCache(alertType, message, cache, timeout=5000) {
if (cache) {
sessionStorage.setItem(`inventree-${alertType}`, message);
var alerts = sessionStorage.getItem('inventree-alerts');
if (alerts) {
alerts = JSON.parse(alerts);
} else {
alerts = [];
}
else {
showMessage('#' + alertType, message, timeout);
sessionStorage.removeItem(`inventree-${alertType}`);
alerts.push({
message: message,
style: style
});
sessionStorage.setItem('inventree-alerts', JSON.stringify(alerts));
}
/*
* Remove all cached alert messages
*/
function clearCachedAlerts() {
sessionStorage.removeItem('inventree-alerts');
}
/*
* Display an alert, or cache to display on reload
*/
function showAlertOrCache(message, style, cache=false) {
if (cache) {
addCachedAlert(message, style);
} else {
showMessage(message, {style: style});
}
}
@ -16,25 +47,13 @@ function showAlertOrCache(alertType, message, cache, timeout=5000) {
*/
function showCachedAlerts() {
var styles = [
'primary',
'secondary',
'success',
'info',
'warning',
'danger',
];
var alerts = JSON.parse(sessionStorage.getItem('inventree-alerts')) || [];
styles.forEach(function(style) {
var msg = sessionStorage.getItem(`inventree-alert-${style}`);
if (msg) {
showMessage(msg, {
style: style,
});
}
alerts.forEach(function(alert) {
showMessage(alert.message, {style: alert.style});
});
clearCachedAlerts();
}

View File

@ -10,6 +10,26 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Favicon -->
<link rel="apple-touch-icon" sizes="57x57" href="{% static 'img/favicon/apple-icon-57x57.png' %}">
<link rel="apple-touch-icon" sizes="60x60" href="{% static 'img/favicon/apple-icon-60x60.png' %}">
<link rel="apple-touch-icon" sizes="72x72" href="{% static 'img/favicon/apple-icon-72x72.png' %}">
<link rel="apple-touch-icon" sizes="76x76" href="{% static 'img/favicon/apple-icon-76x76.png' %}">
<link rel="apple-touch-icon" sizes="114x114" href="{% static 'img/favicon/apple-icon-114x114.png' %}">
<link rel="apple-touch-icon" sizes="120x120" href="{% static 'img/favicon/apple-icon-120x120.png' %}">
<link rel="apple-touch-icon" sizes="144x144" href="{% static 'img/favicon/apple-icon-144x144.png' %}">
<link rel="apple-touch-icon" sizes="152x152" href="{% static 'img/favicon/apple-icon-152x152.png' %}">
<link rel="apple-touch-icon" sizes="180x180" href="{% static 'img/favicon/apple-icon-180x180.png' %}">
<link rel="icon" type="image/png" sizes="192x192" href="{% static 'img/favicon/android-icon-192x192.png' %}">
<link rel="icon" type="image/png" sizes="32x32" href="{% static 'img/favicon/favicon-32x32.png' %}">
<link rel="icon" type="image/png" sizes="96x96" href="{% static 'img/favicon/favicon-96x96.png' %}">
<link rel="icon" type="image/png" sizes="16x16" href="{% static 'img/favicon/favicon-16x16.png' %}">
<link rel="manifest" href="{% static 'img/favicon/manifest.json' %}">
<meta name="msapplication-TileColor" content="#ffffff">
<meta name="msapplication-TileImage" content="{% static 'img/favicon/ms-icon-144x144.png' %}">
<meta name="theme-color" content="#ffffff">
<!-- CSS -->
<link rel="stylesheet" href="{% static 'fontawesome/css/brands.css' %}">
<link rel="stylesheet" href="{% static 'fontawesome/css/solid.css' %}">
@ -46,9 +66,10 @@
<div class="row">
<div class='container-fluid'>
<div class='clearfix content-heading login-header'>
<div class='clearfix content-heading login-header d-flex flex-wrap'>
<img class="pull-left" src="{% static 'img/inventree.png' %}" width="60" height="60"/>
<span><h3>{% inventree_title %}</h3></span>
{% include "spacer.html" %}
<span class='float-right'><h3>{% inventree_title %}</h3></span>
</div>
<hr>
<div class='container-fluid'>{% block content %}{% endblock %}</div>
@ -90,12 +111,10 @@ $(document).ready(function () {
// notifications
{% if messages %}
{% for message in messages %}
showAlertOrCache('alert-info', '{{message}}', true);
showAlertOrCache('{{ message }}', 'info', true);
{% endfor %}
{% endif %}
showCachedAlerts();
inventreeDocReady();
});

View File

@ -32,12 +32,12 @@ for a account and sign in below:{% endblocktrans %}</p>
<input type="hidden" name="{{ redirect_field_name }}" value="{{ redirect_field_value }}" />
{% endif %}
<div class="btn-toolbar">
<button class="btn btn-primary col-md-8" type="submit">{% trans "Sign In" %}</button>
{% if mail_conf and enable_pwd_forgot %}
<a class="btn btn-primary" href="{% url 'account_reset_password' %}">{% trans "Forgot Password?" %}</a>
{% endif %}
</div>
<div class="btn-group float-right" role="group">
<button class="btn btn-success" type="submit">{% trans "Sign In" %}</button>
</div>
{% if mail_conf and enable_pwd_forgot %}
<a class="" href="{% url 'account_reset_password' %}"><small>{% trans "Forgot Password?" %}</small></a>
{% endif %}
</form>
{% if enable_sso %}

View File

@ -14,7 +14,10 @@
{% if redirect_field_value %}
<input type="hidden" name="{{ redirect_field_name }}" value="{{ redirect_field_value }}"/>
{% endif %}
<button type="submit" class="btn btn-primary btn-block">{% trans 'Sign Out' %}</button>
<div class='btn-group float-right' role='group'>
<a type='button' class='btn btn-secondary' href='{% url "index" %}'><span class='fas fa-undo-alt'></span> {% trans "Back to Site" %}</a>
<button type="submit" class="btn btn-danger btn-block">{% trans 'Sign Out' %}</button>
</div>
</form>

View File

@ -183,15 +183,13 @@ $(document).ready(function () {
inventreeDocReady();
showCachedAlerts();
{% if barcodes %}
$('#barcode-scan').click(function() {
barcodeScanDialog();
});
{% endif %}
moment.locale('{{request.LANGUAGE_CODE}}');
moment.locale('{{ request.LANGUAGE_CODE }}');
});
</script>

View File

@ -480,10 +480,10 @@ function barcodeCheckIn(location_id) {
$(modal).modal('hide');
if (status == 'success' && 'success' in response) {
showAlertOrCache('alert-success', response.success, true);
showAlertOrCache(response.success, 'success', true);
location.reload();
} else {
showAlertOrCache('alert-success', '{% trans "Error transferring stock" %}', false);
showAlertOrCache('{% trans "Error transferring stock" %}', 'danger', false);
}
}
}
@ -604,10 +604,10 @@ function scanItemsIntoLocation(item_id_list, options={}) {
$(modal).modal('hide');
if (status == 'success' && 'success' in response) {
showAlertOrCache('alert-success', response.success, true);
showAlertOrCache(response.success, 'success', true);
location.reload();
} else {
showAlertOrCache('alert-danger', '{% trans "Error transferring stock" %}', false);
showAlertOrCache('{% trans "Error transferring stock" %}', 'danger', false);
}
}
}

View File

@ -885,19 +885,19 @@ function handleFormSuccess(response, options) {
// Display any messages
if (response && response.success) {
showAlertOrCache('alert-success', response.success, cache);
showAlertOrCache(response.success, 'success', cache);
}
if (response && response.info) {
showAlertOrCache('alert-info', response.info, cache);
showAlertOrCache(response.info, 'info', cache);
}
if (response && response.warning) {
showAlertOrCache('alert-warning', response.warning, cache);
showAlertOrCache(response.warning, 'warning', cache);
}
if (response && response.danger) {
showAlertOrCache('alert-danger', response.danger, cache);
showAlertOrCache(response.danger, 'dagner', cache);
}
if (options.onSuccess) {

View File

@ -399,19 +399,19 @@ function afterForm(response, options) {
// Display any messages
if (response.success) {
showAlertOrCache('alert-success', response.success, cache);
showAlertOrCache(response.success, 'success', cache);
}
if (response.info) {
showAlertOrCache('alert-info', response.info, cache);
showAlertOrCache(response.info, 'info', cache);
}
if (response.warning) {
showAlertOrCache('alert-warning', response.warning, cache);
showAlertOrCache(response.warning, 'warning', cache);
}
if (response.danger) {
showAlertOrCache('alert-danger', response.danger, cache);
showAlertOrCache(response.danger, 'danger', cache);
}
// Was a callback provided?