1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Add notification button to title bar

This commit is contained in:
Nick O'Leary 2018-01-19 10:36:57 +00:00
parent d93a92c1c8
commit fc3012ba72
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
2 changed files with 79 additions and 13 deletions

View File

@ -119,7 +119,8 @@
var options = {
type: msg.type,
fixed: msg.timeout === undefined,
timeout: msg.timeout
timeout: msg.timeout,
id: notificationId
}
if (notificationId === "runtime-state") {
if (msg.error === "missing-types") {
@ -128,8 +129,7 @@
{
text: "Close",
click: function() {
persistentNotifications[notificationId].close();
delete persistentNotifications[notificationId];
persistentNotifications[notificationId].hideNotification();
}
}
]
@ -139,8 +139,7 @@
{
text: "Setup credentials",
click: function() {
persistentNotifications[notificationId].close();
delete persistentNotifications[notificationId];
persistentNotifications[notificationId].hideNotification();
RED.projects.showCredentialsPrompt();
}
}
@ -152,8 +151,7 @@
{
text: "Setup project files",
click: function() {
persistentNotifications[notificationId].close();
delete persistentNotifications[notificationId];
persistentNotifications[notificationId].hideNotification();
RED.projects.showFilesPrompt();
}
}
@ -165,14 +163,12 @@
{
text: "No thanks",
click: function() {
persistentNotifications[notificationId].close();
delete persistentNotifications[notificationId];
persistentNotifications[notificationId].hideNotification();
}
}, {
text: "Create default project files",
click: function() {
persistentNotifications[notificationId].close();
delete persistentNotifications[notificationId];
persistentNotifications[notificationId].hideNotification();
RED.projects.createDefaultFileSet();
}
}
@ -397,6 +393,7 @@
RED.menu.init({id:"btn-sidemenu",options: menuOptions});
RED.deploy.init(RED.settings.theme("deployButton",null));
RED.notifications.init();
RED.actions.add("core:show-about", showAbout);
RED.nodes.init();

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
**/
RED.notify = (function() {
RED.notifications = (function() {
/*
// Example usage for a modal dialog with buttons
@ -39,9 +39,11 @@ RED.notify = (function() {
});
*/
var persistentNotifications = {};
var currentNotifications = [];
var c = 0;
return function(msg,type,fixed,timeout) {
function notify(msg,type,fixed,timeout) {
var options = {};
if (type !== null && typeof type === 'object') {
options = type;
@ -99,6 +101,12 @@ RED.notify = (function() {
}
nn.closed = true;
currentNotifications.splice(currentNotifications.indexOf(nn),1);
if (options.id) {
delete persistentNotifications[options.id];
if (Object.keys(persistentNotifications).length === 0) {
notificationButtonWrapper.hide();
}
}
$(nn).slideUp(300, function() {
nn.parentNode.removeChild(nn);
});
@ -107,6 +115,26 @@ RED.notify = (function() {
}
};
})();
n.hideNotification = (function() {
var nn = n;
return function() {
if (nn.closed) {
return
}
nn.hidden = true;
$(nn).slideUp(300);
}
})();
n.showNotification = (function() {
var nn = n;
return function() {
if (nn.closed || !nn.hidden) {
return
}
nn.hidden = false;
$(nn).slideDown(300);
}
})();
n.update = (function() {
var nn = n;
@ -137,6 +165,9 @@ RED.notify = (function() {
} else {
window.clearTimeout(nn.timeoutid);
}
if (nn.hidden) {
nn.showNotification();
}
}
})();
@ -152,7 +183,45 @@ RED.notify = (function() {
n.timeoutid = window.setTimeout(n.close,timeout||5000);
}
currentNotifications.push(n);
if (options.id) {
persistentNotifications[options.id] = n;
notificationButtonWrapper.show();
}
c+=1;
return n;
}
RED.notify = notify;
function hidePersistent() {
for(var i in persistentNotifications) {
if (persistentNotifications.hasOwnProperty(i)) {
persistentNotifications[i].hideNotification();
}
}
}
function showPersistent() {
for(var i in persistentNotifications) {
if (persistentNotifications.hasOwnProperty(i)) {
persistentNotifications[i].showNotification();
}
}
}
var notificationButtonWrapper;
return {
init: function() {
notificationButtonWrapper = $('<li>'+
'<a id="btn-notifications" class="button" href="#">'+
'<i class="fa fa-warning"></i>'+
'</a>'+
'</li>').prependTo(".header-toolbar").hide();
$('#btn-notifications').click(function() {
showPersistent();
})
},
notify: notify
}
})();