Skip to content

Commit 863fc17

Browse files
committed
Standardize initialization of variables and order of $component functions
1 parent d6e0f7b commit 863fc17

File tree

4 files changed

+167
-172
lines changed

4 files changed

+167
-172
lines changed

src/wizard/wizard-review-page.component.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,30 +23,36 @@ angular.module('patternfly.wizard').component('pfWizardReviewPage', {
2323
'use strict';
2424
var ctrl = this;
2525

26+
ctrl.$onInit = function () {
27+
ctrl.reviewSteps = [];
28+
};
29+
30+
ctrl.$onChanges = function (changesObj) {
31+
if (changesObj.shown) {
32+
if (changesObj.shown.currentValue) {
33+
ctrl.updateReviewSteps();
34+
}
35+
}
36+
};
37+
2638
ctrl.toggleShowReviewDetails = function (step) {
2739
if (step.showReviewDetails === true) {
2840
step.showReviewDetails = false;
2941
} else {
3042
step.showReviewDetails = true;
3143
}
3244
};
45+
3346
ctrl.getSubStepNumber = function (step, substep) {
3447
return step.getStepDisplayNumber(substep);
3548
};
49+
3650
ctrl.getReviewSubSteps = function (reviewStep) {
3751
return reviewStep.getReviewSteps();
3852
};
39-
ctrl.reviewSteps = [];
53+
4054
ctrl.updateReviewSteps = function () {
4155
ctrl.reviewSteps = ctrl.wizard.getReviewSteps();
4256
};
43-
44-
ctrl.$onChanges = function (changesObj) {
45-
if (changesObj.shown) {
46-
if (changesObj.shown.currentValue) {
47-
ctrl.updateReviewSteps();
48-
}
49-
}
50-
};
5157
}
5258
});

src/wizard/wizard-step.component.js

Lines changed: 60 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ angular.module('patternfly.wizard').component('pfWizardStep', {
5252
controller: function ($timeout) {
5353
'use strict';
5454

55-
var firstRun = true,
56-
ctrl = this;
55+
var ctrl = this,
56+
firstRun;
5757

5858
var stepIdx = function (step) {
5959
var idx = 0;
@@ -86,32 +86,59 @@ angular.module('patternfly.wizard').component('pfWizardStep', {
8686
return foundStep;
8787
};
8888

89-
ctrl.steps = [];
90-
ctrl.context = {};
91-
92-
if (angular.isUndefined(ctrl.nextEnabled)) {
93-
ctrl.nextEnabled = true;
94-
}
95-
if (angular.isUndefined(ctrl.prevEnabled)) {
96-
ctrl.prevEnabled = true;
97-
}
98-
if (angular.isUndefined(ctrl.showReview)) {
99-
ctrl.showReview = false;
100-
}
101-
if (angular.isUndefined(ctrl.showReviewDetails)) {
102-
ctrl.showReviewDetails = false;
103-
}
104-
if (angular.isUndefined(ctrl.stepPriority)) {
105-
ctrl.stepPriority = 999;
106-
} else {
107-
ctrl.stepPriority = parseInt(ctrl.stepPriority);
108-
}
109-
if (angular.isUndefined(ctrl.okToNavAway)) {
110-
ctrl.okToNavAway = true;
111-
}
112-
if (angular.isUndefined(ctrl.allowClickNav)) {
113-
ctrl.allowClickNav = true;
114-
}
89+
ctrl.$onInit = function () {
90+
firstRun = true;
91+
ctrl.steps = [];
92+
ctrl.context = {};
93+
ctrl.title = ctrl.stepTitle;
94+
ctrl.contentStyle = ctrl.wizard.contentStyle;
95+
ctrl.wizard.addStep(ctrl);
96+
ctrl.pageNumber = ctrl.wizard.getStepNumber(ctrl);
97+
98+
if (angular.isUndefined(ctrl.nextEnabled)) {
99+
ctrl.nextEnabled = true;
100+
}
101+
if (angular.isUndefined(ctrl.prevEnabled)) {
102+
ctrl.prevEnabled = true;
103+
}
104+
if (angular.isUndefined(ctrl.showReview)) {
105+
ctrl.showReview = false;
106+
}
107+
if (angular.isUndefined(ctrl.showReviewDetails)) {
108+
ctrl.showReviewDetails = false;
109+
}
110+
if (angular.isUndefined(ctrl.stepPriority)) {
111+
ctrl.stepPriority = 999;
112+
} else {
113+
ctrl.stepPriority = parseInt(ctrl.stepPriority);
114+
}
115+
if (angular.isUndefined(ctrl.okToNavAway)) {
116+
ctrl.okToNavAway = true;
117+
}
118+
if (angular.isUndefined(ctrl.allowClickNav)) {
119+
ctrl.allowClickNav = true;
120+
}
121+
122+
if (ctrl.substeps && !ctrl.onShow) {
123+
ctrl.onShow = function () {
124+
$timeout(function () {
125+
if (!ctrl.selectedStep) {
126+
ctrl.goTo(ctrl.getEnabledSteps()[0]);
127+
}
128+
}, 10);
129+
};
130+
}
131+
};
132+
133+
ctrl.$onChanges = function (changesObj) {
134+
if (changesObj.nextTooltip) {
135+
ctrl.wizard.nextTooltip = changesObj.nextTooltip.currentValue;
136+
}
137+
138+
if (changesObj.prevTooltip) {
139+
ctrl.wizard.prevTooltip = changesObj.prevTooltip.currentValue;
140+
}
141+
};
115142

116143
ctrl.getEnabledSteps = function () {
117144
return ctrl.steps.filter(function (step) {
@@ -204,7 +231,7 @@ angular.module('patternfly.wizard').component('pfWizardStep', {
204231
}
205232
};
206233

207-
this.addStep = function (step) {
234+
ctrl.addStep = function (step) {
208235
// Insert the step into step array
209236
var insertBefore = _.find(ctrl.steps, function (nextStep) {
210237
return nextStep.stepPriority > step.stepPriority;
@@ -216,36 +243,22 @@ angular.module('patternfly.wizard').component('pfWizardStep', {
216243
}
217244
};
218245

219-
this.currentStepTitle = function () {
246+
ctrl.currentStepTitle = function () {
220247
return ctrl.selectedStep.stepTitle;
221248
};
222249

223-
this.currentStepDescription = function () {
250+
ctrl.currentStepDescription = function () {
224251
return ctrl.selectedStep.description;
225252
};
226253

227-
this.currentStep = function () {
254+
ctrl.currentStep = function () {
228255
return ctrl.selectedStep;
229256
};
230257

231-
this.totalStepCount = function () {
258+
ctrl.totalStepCount = function () {
232259
return ctrl.getEnabledSteps().length;
233260
};
234261

235-
// Allow access to any step
236-
this._goTo = function (step) {
237-
var enabledSteps = ctrl.getEnabledSteps();
238-
var stepTo;
239-
240-
if (angular.isNumber(step)) {
241-
stepTo = enabledSteps[step];
242-
} else {
243-
stepTo = stepByTitle(step);
244-
}
245-
246-
ctrl.goTo(stepTo);
247-
};
248-
249262
// Method used for next button within step
250263
ctrl.next = function (callback) {
251264
var enabledSteps = ctrl.getEnabledSteps();
@@ -291,35 +304,7 @@ angular.module('patternfly.wizard').component('pfWizardStep', {
291304
}
292305
}
293306
}
294-
295307
return goPrev;
296308
};
297-
298-
if (ctrl.substeps && !ctrl.onShow) {
299-
ctrl.onShow = function () {
300-
$timeout(function () {
301-
if (!ctrl.selectedStep) {
302-
ctrl.goTo(ctrl.getEnabledSteps()[0]);
303-
}
304-
}, 10);
305-
};
306-
}
307-
308-
ctrl.$onInit = function () {
309-
ctrl.title = ctrl.stepTitle;
310-
ctrl.contentStyle = ctrl.wizard.contentStyle;
311-
ctrl.wizard.addStep(ctrl);
312-
ctrl.pageNumber = ctrl.wizard.getStepNumber(ctrl);
313-
};
314-
315-
ctrl.$onChanges = function (changesObj) {
316-
if (changesObj.nextTooltip) {
317-
ctrl.wizard.nextTooltip = changesObj.nextTooltip.currentValue;
318-
}
319-
320-
if (changesObj.prevTooltip) {
321-
ctrl.wizard.prevTooltip = changesObj.prevTooltip.currentValue;
322-
}
323-
};
324309
}
325310
});

src/wizard/wizard-substep.component.js

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -44,37 +44,28 @@ angular.module('patternfly.wizard').component('pfWizardSubstep', {
4444
'use strict';
4545
var ctrl = this;
4646

47-
if (angular.isUndefined(ctrl.nextEnabled)) {
48-
ctrl.nextEnabled = true;
49-
}
50-
if (angular.isUndefined(ctrl.prevEnabled)) {
51-
ctrl.prevEnabled = true;
52-
}
53-
if (angular.isUndefined(ctrl.showReviewDetails)) {
54-
ctrl.showReviewDetails = false;
55-
}
56-
if (angular.isUndefined(ctrl.stepPriority)) {
57-
ctrl.stepPriority = 999;
58-
} else {
59-
ctrl.stepPriority = parseInt(ctrl.stepPriority);
60-
}
61-
if (angular.isUndefined(ctrl.okToNavAway)) {
62-
ctrl.okToNavAway = true;
63-
}
64-
if (angular.isUndefined(ctrl.allowClickNav)) {
65-
ctrl.allowClickNav = true;
66-
}
67-
68-
ctrl.isPrevEnabled = function () {
69-
var enabled = angular.isUndefined(ctrl.prevEnabled) || ctrl.prevEnabled;
70-
if (ctrl.substeps) {
71-
angular.forEach(ctrl.getEnabledSteps(), function (step) {
72-
enabled = enabled && step.prevEnabled;
73-
});
74-
}
75-
return enabled;
76-
};
7747
ctrl.$onInit = function () {
48+
if (angular.isUndefined(ctrl.nextEnabled)) {
49+
ctrl.nextEnabled = true;
50+
}
51+
if (angular.isUndefined(ctrl.prevEnabled)) {
52+
ctrl.prevEnabled = true;
53+
}
54+
if (angular.isUndefined(ctrl.showReviewDetails)) {
55+
ctrl.showReviewDetails = false;
56+
}
57+
if (angular.isUndefined(ctrl.stepPriority)) {
58+
ctrl.stepPriority = 999;
59+
} else {
60+
ctrl.stepPriority = parseInt(ctrl.stepPriority);
61+
}
62+
if (angular.isUndefined(ctrl.okToNavAway)) {
63+
ctrl.okToNavAway = true;
64+
}
65+
if (angular.isUndefined(ctrl.allowClickNav)) {
66+
ctrl.allowClickNav = true;
67+
}
68+
7869
ctrl.title = ctrl.stepTitle;
7970
ctrl.step.addStep(ctrl);
8071
};
@@ -96,5 +87,15 @@ angular.module('patternfly.wizard').component('pfWizardSubstep', {
9687
ctrl.step.allowClickNav = changesObj.allowClickNav.currentValue;
9788
}
9889
};
90+
91+
ctrl.isPrevEnabled = function () {
92+
var enabled = angular.isUndefined(ctrl.prevEnabled) || ctrl.prevEnabled;
93+
if (ctrl.substeps) {
94+
angular.forEach(ctrl.getEnabledSteps(), function (step) {
95+
enabled = enabled && step.prevEnabled;
96+
});
97+
}
98+
return enabled;
99+
};
99100
}
100101
});

0 commit comments

Comments
 (0)