Merge lp:~allenap/maas/notifications-warn-info-ui into lp:~maas-committers/maas/trunk

Proposed by Gavin Panella
Status: Merged
Approved by: Gavin Panella
Approved revision: no longer in the source branch.
Merged at revision: 5695
Proposed branch: lp:~allenap/maas/notifications-warn-info-ui
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 177 lines (+50/-15)
5 files modified
Makefile (+4/-6)
src/maasserver/static/js/angular/directives/notifications.js (+7/-2)
src/maasserver/static/js/angular/directives/tests/test_notifications.js (+23/-1)
src/maasserver/testing/factory.py (+6/-2)
src/maasserver/testing/sampledata.py (+10/-4)
To merge this branch: bzr merge lp:~allenap/maas/notifications-warn-info-ui
Reviewer Review Type Date Requested Status
Blake Rouse (community) Approve
Review via email: mp+316353@code.launchpad.net

Commit message

Display UI notifications with styling according to its category (i.e. info, success, warning, error).

To post a comment you must log in.
Revision history for this message
Blake Rouse (blake-rouse) wrote :

Looks good.

review: Approve
Revision history for this message
MAAS Lander (maas-lander) wrote :
Download full text (1.2 MiB)

The attempt to merge lp:~allenap/maas/notifications-warn-info-ui into lp:maas failed. Below is the output from the failed tests.

Get:1 http://security.ubuntu.com/ubuntu xenial-security InRelease [102 kB]
Hit:2 http://prodstack-zone-2.clouds.archive.ubuntu.com/ubuntu xenial InRelease
Get:3 http://prodstack-zone-2.clouds.archive.ubuntu.com/ubuntu xenial-updates InRelease [102 kB]
Get:4 http://prodstack-zone-2.clouds.archive.ubuntu.com/ubuntu xenial-backports InRelease [102 kB]
Fetched 306 kB in 0s (642 kB/s)
Reading package lists...
sudo DEBIAN_FRONTEND=noninteractive apt-get -y \
    --no-install-recommends install apache2 archdetect-deb authbind avahi-utils bash bind9 bind9utils build-essential bzr bzr-builddeb chromium-browser chromium-chromedriver curl daemontools debhelper dh-apport dh-systemd distro-info dnsutils firefox freeipmi-tools git gjs ipython isc-dhcp-common isc-dhcp-server libjs-angularjs libjs-jquery libjs-jquery-hotkeys libjs-yui3-full libjs-yui3-min libnss-wrapper libpq-dev make nodejs-legacy npm postgresql pxelinux python3-all python3-apt python3-attr python3-bson python3-convoy python3-crochet python3-cssselect python3-curtin python3-dev python3-distro-info python3-django python3-django-nose python3-django-piston3 python3-dnspython python3-docutils python3-formencode python3-hivex python3-httplib2 python3-jinja2 python3-jsonschema python3-lxml python3-netaddr python3-netifaces python3-novaclient python3-oauth python3-oauthlib python3-openssl python3-paramiko python3-petname python3-pexpect python3-psycopg2 python3-pyinotify python3-pyparsing python3-pyvmomi python3-requests python3-seamicroclient python3-setuptools python3-simplestreams python3-sphinx python3-tempita python3-twisted python3-txtftp python3-tz python3-yaml python3-zope.interface python-bson python-crochet python-django python-django-piston python-djorm-ext-pgarray python-formencode python-lxml python-netaddr python-netifaces python-pocket-lint python-psycopg2 python-simplejson python-tempita python-twisted python-yaml socat syslinux-common tgt ubuntu-cloudimage-keyring wget xvfb
Reading package lists...
Building dependency tree...
Reading state information...
authbind is already the newest version (2.1.1+nmu1).
avahi-utils is already the newest version (0.6.32~rc+dfsg-1ubuntu2).
build-essential is already the newest version (12.1ubuntu2).
debhelper is already the newest version (9.20160115ubuntu3).
distro-info is already the newest version (0.14build1).
git is already the newest version (1:2.7.4-0ubuntu1).
libjs-angularjs is already the newest version (1.2.28-1ubuntu2).
libjs-jquery is already the newest version (1.11.3+dfsg-4).
libjs-yui3-full is already the newest version (3.5.1-1ubuntu3).
libjs-yui3-min is already the newest version (3.5.1-1ubuntu3).
make is already the newest version (4.1-6).
postgresql is already the newest version (9.5+173).
pxelinux is already the newest version (3:6.03+dfsg-11ubuntu1).
python-formencode is already the newest version (1.3.0-0ubuntu5).
python-lxml is already the newest version (3.5.0-1build1).
python-netaddr is already the newest version (0.7.18-1).
python-netifaces is already the newest version (0.10.4-0.1build2).
pyt...

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Makefile'
2--- Makefile 2017-02-02 14:23:26 +0000
3+++ Makefile 2017-02-03 17:20:17 +0000
4@@ -29,10 +29,8 @@
5 # MAAS SASS stylesheets. The first input file (maas-styles.css) imports
6 # the others, so is treated specially in the target definitions.
7 scss_theme := include/nodejs/node_modules/cloud-vanilla-theme
8-scss_inputs := \
9- src/maasserver/static/scss/build.scss \
10- $(wildcard src/maasserver/static/scss/*/*.scss) \
11- $(wildcard src/maasserver/static/scss/*/*/*.scss)
12+scss_input := src/maasserver/static/scss/build.scss
13+scss_deps := $(wildcard src/maasserver/static/scss/_*.scss)
14 scss_output := src/maasserver/static/css/build.css
15
16 # Prefix commands with this when they need access to the database.
17@@ -390,9 +388,9 @@
18
19 styles: clean-styles $(scss_output)
20
21-$(scss_output): bin/sass $(scss_theme) $(scss_inputs)
22+$(scss_output): bin/sass $(scss_theme) $(scss_input) $(scss_deps)
23 bin/sass --include-path=src/maasserver/static/scss \
24- --output-style compressed $(scss_inputs) -o $(dir $@)
25+ --output-style compressed $(scss_input) -o $(dir $@)
26
27 $(scss_theme): prefix = include/nodejs
28 $(scss_theme):
29
30=== modified file 'src/maasserver/static/js/angular/directives/notifications.js'
31--- src/maasserver/static/js/angular/directives/notifications.js 2017-02-01 14:11:26 +0000
32+++ src/maasserver/static/js/angular/directives/notifications.js 2017-02-03 17:20:17 +0000
33@@ -7,8 +7,7 @@
34 angular.module('MAAS').run(['$templateCache', function ($templateCache) {
35 // Inject notifications.html into the template cache.
36 $templateCache.put('directive/templates/notifications.html', [
37- '<div class="p-notification--error" ',
38- 'ng-repeat="n in notifications">',
39+ '<div ng-repeat="n in notifications" ng-class="classes[n.category]">',
40 '<p class="p-notification__response">',
41 '<span class="p-notification__status"></span>',
42 '<span>{$ n.message $}</span> — ',
43@@ -33,6 +32,12 @@
44 $scope.notifications = NotificationsManager.getItems();
45 $scope.dismiss = angular.bind(
46 NotificationsManager, NotificationsManager.dismiss);
47+ $scope.classes = {
48+ "error": "p-notification--error",
49+ "warning": "p-notification--warning",
50+ "success": "p-notification--success",
51+ "info": "p-notification" // No suffix.
52+ };
53 }
54 };
55 }]);
56
57=== modified file 'src/maasserver/static/js/angular/directives/tests/test_notifications.js'
58--- src/maasserver/static/js/angular/directives/tests/test_notifications.js 2017-02-01 14:18:36 +0000
59+++ src/maasserver/static/js/angular/directives/tests/test_notifications.js 2017-02-03 17:20:17 +0000
60@@ -15,6 +15,7 @@
61 "id": 1,
62 "ident": null,
63 "message": "Attention admins!",
64+ "category": "error",
65 "user": null,
66 "users": false,
67 "admins": true,
68@@ -25,6 +26,7 @@
69 "id": 2,
70 "ident": null,
71 "message": "Dear users, ...",
72+ "category": "warning",
73 "user": null,
74 "users": true,
75 "admins": false,
76@@ -35,6 +37,7 @@
77 "id": 3,
78 "ident": null,
79 "message": "Greetings, Individual!",
80+ "category": "info",
81 "user": 1,
82 "users": false,
83 "admins": false,
84@@ -58,7 +61,7 @@
85 // Return the compiled directive.
86 function compileDirective() {
87 var directive;
88- var html = '<maas-notifications />';
89+ var html = '<maas-notifications></maas-notifications>';
90
91 // Compile the directive.
92 inject(function($compile) {
93@@ -93,6 +96,25 @@
94 expect(dismiss).toHaveBeenCalledWith(notification);
95 });
96
97+ it("adjusts class according to category", function() {
98+ theNotificationsManager._items = exampleNotifications;
99+ var directive = compileDirective();
100+ var classes = directive.find("div").map(
101+ function() { return $(this).attr("class"); }).get();
102+ expect(classes.length).toBe(3);
103+ var p_classes = [];
104+ angular.forEach(classes, function(cls) {
105+ // Find classes that begin with 'p-'.
106+ var matches = cls.match(/\bp-.+\b/);
107+ p_classes = p_classes.concat(matches);
108+ });
109+ expect(p_classes).toEqual([
110+ "p-notification--error",
111+ "p-notification--warning",
112+ "p-notification"
113+ ]);
114+ });
115+
116 });
117
118 });
119
120=== modified file 'src/maasserver/testing/factory.py'
121--- src/maasserver/testing/factory.py 2017-01-26 18:51:52 +0000
122+++ src/maasserver/testing/factory.py 2017-02-03 17:20:17 +0000
123@@ -2048,7 +2048,7 @@
124
125 def make_Notification(
126 self, message=None, *, ident=None, user=None, users=False,
127- admins=False, context=None):
128+ admins=False, context=None, category=None):
129
130 if context is None:
131 context_name = self.make_name("name")
132@@ -2062,9 +2062,13 @@
133 context_name = random.choice(context_names)
134 message = self.make_name("message-{%s}" % context_name)
135
136+ if category is None:
137+ category = random.choice((
138+ "error", "warning", "success", "info"))
139+
140 notification = Notification(
141 ident=ident, user=user, users=users, admins=admins,
142- message=message, context=context)
143+ message=message, context=context, category=category)
144 notification.save()
145
146 return notification
147
148=== modified file 'src/maasserver/testing/sampledata.py'
149--- src/maasserver/testing/sampledata.py 2017-01-27 13:26:00 +0000
150+++ src/maasserver/testing/sampledata.py 2017-02-03 17:20:17 +0000
151@@ -521,16 +521,22 @@
152 server-name "boot.from.me";
153 """)), node=device)
154
155- # Add notifications for admins, users, and each individual user.
156+ # Add notifications for admins, users, and each individual user, and for
157+ # each notification category.
158 factory.make_Notification(
159 "Attention admins! Core critical! Meltdown imminent! Evacuate "
160- "habitat immediately!", admins=True)
161+ "habitat immediately!", admins=True, category="error")
162 factory.make_Notification(
163 "Dear users, rumours of a core meltdown are unfounded. Please "
164- "return to your home-pods and places of business.", users=True)
165+ "return to your home-pods and places of business.", users=True,
166+ category="warning")
167+ factory.make_Notification(
168+ "FREE! For the next 2 hours get FREE blueberry and iodine pellets "
169+ "at the nutri-dispensers.", users=True, category="success")
170 for user in User.objects.all():
171 context = {"name": user.username.capitalize()}
172 factory.make_Notification(
173 "Greetings, {name}! Get away from the habitat for the weekend and "
174 "visit the Mare Nubium with MAAS Tours. Use the code METAL to "
175- "claim a special gift!", user=user, context=context)
176+ "claim a special gift!", user=user, context=context,
177+ category="info")