Merge lp:~blake-rouse/maas/fix-1509476 into lp:~maas-committers/maas/trunk

Proposed by Blake Rouse
Status: Merged
Approved by: Blake Rouse
Approved revision: no longer in the source branch.
Merged at revision: 4420
Proposed branch: lp:~blake-rouse/maas/fix-1509476
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 334 lines (+163/-111)
3 files modified
src/maasserver/static/js/angular/controllers/node_details_networking.js (+54/-31)
src/maasserver/static/js/angular/controllers/tests/test_node_details_networking.js (+107/-78)
src/maasserver/static/partials/node-details.html (+2/-2)
To merge this branch: bzr merge lp:~blake-rouse/maas/fix-1509476
Reviewer Review Type Date Requested Status
Mike Pontillo (community) Approve
Review via email: mp+275874@code.launchpad.net

Commit message

 Fix angular $digest loop error for version of angular on vivid and above.

To post a comment you must log in.
Revision history for this message
Mike Pontillo (mpontillo) wrote :

Looks good to me.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/maasserver/static/js/angular/controllers/node_details_networking.js'
2--- src/maasserver/static/js/angular/controllers/node_details_networking.js 2015-10-26 18:42:48 +0000
3+++ src/maasserver/static/js/angular/controllers/node_details_networking.js 2015-10-27 16:02:26 +0000
4@@ -81,6 +81,42 @@
5 });
6
7
8+// Filter that is specific to the NodeNetworkingController. Only provide the
9+// available modes for that interface type.
10+angular.module('MAAS').filter('filterLinkModes', function() {
11+ return function(modes, nic) {
12+ if(!angular.isObject(nic)) {
13+ return modes;
14+ }
15+ var filtered = [];
16+ if(!angular.isObject(nic.subnet)) {
17+ // No subnet is configure so the only allowed mode
18+ // is 'link_up'.
19+ angular.forEach(modes, function(mode) {
20+ if(mode.mode === "link_up") {
21+ filtered.push(mode);
22+ }
23+ });
24+ } else {
25+ // Don't add LINK_UP or DHCP if more than one link exists or
26+ // if the interface is an alias.
27+ var allowLinkUpAndDHCP = (
28+ (angular.isObject(nic.links) && nic.links.length > 1) ||
29+ (nic.type === "alias"));
30+ angular.forEach(modes, function(mode) {
31+ if(allowLinkUpAndDHCP && (
32+ mode.mode === "link_up" ||
33+ mode.mode === "dhcp")) {
34+ return;
35+ }
36+ filtered.push(mode);
37+ });
38+ }
39+ return filtered;
40+ };
41+});
42+
43+
44 angular.module('MAAS').controller('NodeNetworkingController', [
45 '$scope', '$filter', 'FabricsManager', 'VLANsManager', 'SubnetsManager',
46 'NodesManager', 'GeneralManager', 'UsersManager', 'ManagerHelperService',
47@@ -146,6 +182,24 @@
48 $scope.newInterface = {};
49 $scope.newBondInterface = {};
50 $scope.bondOptions = GeneralManager.getData("bond_options");
51+ $scope.modes = [
52+ {
53+ mode: LINK_MODE.AUTO,
54+ text: LINK_MODE_TEXTS[LINK_MODE.AUTO]
55+ },
56+ {
57+ mode: LINK_MODE.STATIC,
58+ text: LINK_MODE_TEXTS[LINK_MODE.STATIC]
59+ },
60+ {
61+ mode: LINK_MODE.DHCP,
62+ text: LINK_MODE_TEXTS[LINK_MODE.DHCP]
63+ },
64+ {
65+ mode: LINK_MODE.LINK_UP,
66+ text: LINK_MODE_TEXTS[LINK_MODE.LINK_UP]
67+ }
68+ ];
69
70 // Give $parent which is the NodeDetailsController access to this scope
71 // it will call `nodeLoaded` once the node has been fully loaded.
72@@ -577,37 +631,6 @@
73 return !angular.isObject(nic.subnet);
74 };
75
76- // Get the available link modes for an interface.
77- $scope.getLinkModes = function(nic) {
78- modes = [];
79- if(!angular.isObject(nic.subnet)) {
80- // No subnet is configure so the only allowed mode
81- // is 'link_up'.
82- modes.push({
83- "mode": LINK_MODE.LINK_UP,
84- "text": LINK_MODE_TEXTS[LINK_MODE.LINK_UP]
85- });
86- } else {
87- // Don't add LINK_UP or DHCP if more than one link exists or
88- // if the interface is an alias.
89- var allowLinkUpAndDHCP = (
90- (angular.isObject(nic.links) && nic.links.length > 1) ||
91- (nic.type === INTERFACE_TYPE.ALIAS));
92- angular.forEach(LINK_MODE_TEXTS, function(text, mode) {
93- if(allowLinkUpAndDHCP && (
94- mode === LINK_MODE.LINK_UP ||
95- mode === LINK_MODE.DHCP)) {
96- return;
97- }
98- modes.push({
99- "mode": mode,
100- "text": text
101- });
102- });
103- }
104- return modes;
105- };
106-
107 // Called when the link mode for this interface and link has been
108 // changed.
109 $scope.saveInterfaceLink = function(nic) {
110
111=== modified file 'src/maasserver/static/js/angular/controllers/tests/test_node_details_networking.js'
112--- src/maasserver/static/js/angular/controllers/tests/test_node_details_networking.js 2015-10-26 11:43:54 +0000
113+++ src/maasserver/static/js/angular/controllers/tests/test_node_details_networking.js 2015-10-27 16:02:26 +0000
114@@ -167,6 +167,113 @@
115 });
116
117
118+describe("filterLinkModes", function() {
119+
120+ // Load the MAAS module.
121+ beforeEach(module("MAAS"));
122+
123+ // Load the filterLinkModes.
124+ var filterLinkModes;
125+ beforeEach(inject(function($filter) {
126+ filterLinkModes = $filter("filterLinkModes");
127+ }));
128+
129+ // Load the modes before each test.
130+ var modes;
131+ beforeEach(function() {
132+ modes = [
133+ {
134+ mode: "auto",
135+ text: "Auto assign"
136+ },
137+ {
138+ mode: "static",
139+ text: "Static assign"
140+ },
141+ {
142+ mode: "dhcp",
143+ text: "DHCP"
144+ },
145+ {
146+ mode: "link_up",
147+ text: "Unconfigured"
148+ }
149+ ];
150+ });
151+
152+ it("only link_up when no subnet", function() {
153+ var nic = {
154+ subnet : null
155+ };
156+ expect(filterLinkModes(modes, nic)).toEqual([
157+ {
158+ "mode": "link_up",
159+ "text": "Unconfigured"
160+ }
161+ ]);
162+ });
163+
164+ it("all modes if only one link", function() {
165+ var nic = {
166+ subnet : {},
167+ links: [{}]
168+ };
169+ expect(filterLinkModes(modes, nic)).toEqual([
170+ {
171+ "mode": "auto",
172+ "text": "Auto assign"
173+ },
174+ {
175+ "mode": "static",
176+ "text": "Static assign"
177+ },
178+ {
179+ "mode": "dhcp",
180+ "text": "DHCP"
181+ },
182+ {
183+ "mode": "link_up",
184+ "text": "Unconfigured"
185+ }
186+ ]);
187+ });
188+
189+ it("auto and static modes if more than one link", function() {
190+ var nic = {
191+ subnet : {},
192+ links: [{}, {}]
193+ };
194+ expect(filterLinkModes(modes, nic)).toEqual([
195+ {
196+ "mode": "auto",
197+ "text": "Auto assign"
198+ },
199+ {
200+ "mode": "static",
201+ "text": "Static assign"
202+ }
203+ ]);
204+ });
205+
206+ it("auto and static modes if interface is alias", function() {
207+ var nic = {
208+ type: "alias",
209+ subnet : {}
210+ };
211+ expect(filterLinkModes(modes, nic)).toEqual([
212+ {
213+ "mode": "auto",
214+ "text": "Auto assign"
215+ },
216+ {
217+ "mode": "static",
218+ "text": "Static assign"
219+ }
220+ ]);
221+ });
222+});
223+
224+
225 describe("NodeNetworkingController", function() {
226 // Load the MAAS module.
227 beforeEach(module("MAAS"));
228@@ -1225,84 +1332,6 @@
229 });
230 });
231
232- describe("getLinkModes", function() {
233-
234- it("only link_up when no subnet", function() {
235- var controller = makeController();
236- var nic = {
237- subnet : null
238- };
239- expect($scope.getLinkModes(nic)).toEqual([
240- {
241- "mode": "link_up",
242- "text": "Unconfigured"
243- }
244- ]);
245- });
246-
247- it("all modes if only one link", function() {
248- var controller = makeController();
249- var nic = {
250- subnet : {},
251- links: [{}]
252- };
253- expect($scope.getLinkModes(nic)).toEqual([
254- {
255- "mode": "auto",
256- "text": "Auto assign"
257- },
258- {
259- "mode": "static",
260- "text": "Static assign"
261- },
262- {
263- "mode": "dhcp",
264- "text": "DHCP"
265- },
266- {
267- "mode": "link_up",
268- "text": "Unconfigured"
269- }
270- ]);
271- });
272-
273- it("auto and static modes if more than one link", function() {
274- var controller = makeController();
275- var nic = {
276- subnet : {},
277- links: [{}, {}]
278- };
279- expect($scope.getLinkModes(nic)).toEqual([
280- {
281- "mode": "auto",
282- "text": "Auto assign"
283- },
284- {
285- "mode": "static",
286- "text": "Static assign"
287- }
288- ]);
289- });
290-
291- it("auto and static modes if interface is alias", function() {
292- var controller = makeController();
293- var nic = {
294- type: "alias",
295- subnet : {}
296- };
297- expect($scope.getLinkModes(nic)).toEqual([
298- {
299- "mode": "auto",
300- "text": "Auto assign"
301- },
302- {
303- "mode": "static",
304- "text": "Static assign"
305- }
306- ]);
307- });
308- });
309-
310 describe("saveInterfaceLink", function() {
311
312 it("calls NodesManager.linkSubnet with params", function() {
313
314=== modified file 'src/maasserver/static/partials/node-details.html'
315--- src/maasserver/static/partials/node-details.html 2015-10-26 11:46:36 +0000
316+++ src/maasserver/static/partials/node-details.html 2015-10-27 16:02:26 +0000
317@@ -416,7 +416,7 @@
318 data-ng-model="interface.mode"
319 data-ng-change="saveInterfaceLink(interface)"
320 data-ng-disabled="isLinkModeDisabled(interface)"
321- data-ng-options="mode.mode as mode.text for mode in getLinkModes(interface)">
322+ data-ng-options="mode.mode as mode.text for mode in modes | filterLinkModes:interface">
323 </select>
324 </li>
325 <li class="margin-top--ten" data-ng-show="shouldShowIPAddress(interface)">
326@@ -490,7 +490,7 @@
327 <select class="table__input" name="link-mode" id="link-mode"
328 data-ng-model="newInterface.mode"
329 data-ng-disabled="isLinkModeDisabled(newInterface)"
330- data-ng-options="mode.mode as mode.text for mode in getLinkModes(newInterface)">
331+ data-ng-options="mode.mode as mode.text for mode in modes | filterLinkModes:newInterface">
332 </select>
333 </div>
334 <div class="table__data table_column--13"></div>