mirror of
https://github.com/YunoHost/yunohost-admin.git
synced 2024-09-03 20:06:15 +02:00
[enh] Display messages IN REAL TIME 👏
This commit is contained in:
parent
25f60b6d40
commit
9215420093
1 changed files with 25 additions and 13 deletions
38
js/app.js
38
js/app.js
|
@ -67,21 +67,30 @@ app = Sammy('#main', function (sam) {
|
||||||
|
|
||||||
// Flash helper to diplay instant notifications
|
// Flash helper to diplay instant notifications
|
||||||
flash: function (level, message) {
|
flash: function (level, message) {
|
||||||
flashs = store.get('flash');
|
if (!store.get('flash')) {
|
||||||
if (!flashs) { flashs = {'info': [], 'fail': [], 'warning': [], 'success': [] } }
|
store.set('flash', true);
|
||||||
flashs[level].push(message);
|
}
|
||||||
store.set('flash', flashs);
|
if (level == 'fail') { alertClass = 'alert-danger'; }
|
||||||
|
else { alertClass = 'alert-'+ level; }
|
||||||
html = '';
|
if ($('#flash .alert').last().hasClass(alertClass)) {
|
||||||
for(lvl in flashs) {
|
if (level == 'log') {
|
||||||
flashs[lvl].forEach( function(msg) {
|
$('#flash .alert').last().append('<p style="display: none">'+ message +'</p>');
|
||||||
if (lvl == 'fail') { alertClass = 'alert-danger'; }
|
} else {
|
||||||
else { alertClass = 'alert-'+ lvl; }
|
$('#flash .alert').last().append('<p>'+ message +'</p>');
|
||||||
html += '<div class="alert '+ alertClass +'">'+ msg +'</div>';
|
}
|
||||||
});
|
} else {
|
||||||
|
if (level == 'log') {
|
||||||
|
$('#flash').append('<pre style="display:none" class="alert '+ alertClass +'"><div><button type="button" class="btn btn-default btn-small">'+ y18n.t('log') +'</button></div><p style="display: none">'+ message +'</p></pre>').show();
|
||||||
|
} else {
|
||||||
|
$('#flash').append('<div style="display:none" class="alert '+ alertClass +'"><p>'+ message +'</p></div>').show();
|
||||||
|
}
|
||||||
|
$('#flash .alert').last().fadeIn();
|
||||||
}
|
}
|
||||||
$('#flash').html(html).fadeIn();
|
|
||||||
document.body.scrollTop = document.documentElement.scrollTop = 0;
|
document.body.scrollTop = document.documentElement.scrollTop = 0;
|
||||||
|
$('#flash .alert-log button').on('click', function() {
|
||||||
|
$('#flash .alert-log p:hidden').fadeIn();
|
||||||
|
$('#flash .alert-log div').hide();
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
// Websocket connection
|
// Websocket connection
|
||||||
|
@ -91,6 +100,9 @@ app = Sammy('#main', function (sam) {
|
||||||
c.ws = new WebSocket('wss://'+ store.get('url') +'/messages');
|
c.ws = new WebSocket('wss://'+ store.get('url') +'/messages');
|
||||||
c.ws.onmessage = function(evt) {
|
c.ws.onmessage = function(evt) {
|
||||||
console.log(evt.data);
|
console.log(evt.data);
|
||||||
|
$.each($.parseJSON(evt.data), function(k, v) {
|
||||||
|
c.flash(k, v);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
c.ws.onopen = function() {
|
c.ws.onopen = function() {
|
||||||
if (typeof callback === 'function') {
|
if (typeof callback === 'function') {
|
||||||
|
|
Loading…
Add table
Reference in a new issue