I’m trying to design a flexible notification system for our app. The functional goal is to notify users when certain [server] actions have completed or error-ed and allow the user to navigate or trigger a response action. I’m not worried with queuing multiple message. Last in wins. I cut out some of the mockups to help illustrate it.
Imagine a header, and depending on the scenario, one of the 5 messages above would be rendered. In some cases the message would contain an action that needs triggered (e.g. Undo), and in other cases it would render a {{link-to}} (e.g. Interview Sorting). And it’s conceivable as the app grows we will continue to add different messages.
So I’m looking for feedback on my technical design. I spent a few hours and tried a few different things. I didn’t really love any of the designs, but this is minified version of where I landed.
Edit: Made a JSBin: JS Bin - Collaborative JavaScript Debugging
//# app/routes/application.js
export default Ember.Route.extend({
actions: {
showNotification: function(name, msg) {
// We prepend notifications with "/notifications" to keep them organized
if(name.indexOf("notifications") === -1) {
name = "notifications" + name.capitalize();
}
this.render(name, {
into: 'application',
outlet: 'notification'
});
this.controllerFor(name).set('msg', msg);
},
hideNotification: function() {
return this.disconnectOutlet({
outlet: 'notification',
parentView: 'application'
});
}
}
});
–
//# app/controllers/wall.js
export Ember.Controller.extend({
actions: {
doCopyItems: function() {
var copyPromise = this.doCopyItemsStuff();
copyPromise.then(function(result) {
this.send('showNotification', 'copyWallItems', {
copyCount: result.copyCount
destWall: this.get('wall'),
undoCallback: function() {
this.triggerUndo();
}.bind(this)
});
}.bind(this));
}
}
});
–
//# app/templates/notificationsCopyWallItems.hbs
{{msg.copyCount}} copies sent to {{#link-to 'wall' msg.destWall}} {{msg.destWall.name}} {{/link-to}}.
<a {{action "triggerUndoCallback"}}>Undo</a>
<a class="close-x" {{action "hideNotification"}}>X</a>
So in this design, the application route simple renders the provided template/controller and passes along a message. Each template/controller would handle their layout and actions accordingly. The different notification types would share no code between them.
Does this make sense? Is there a better way to structure it? ~
Thanks!