-
Notifications
You must be signed in to change notification settings - Fork 231
/
Copy pathfromFileDialog.js
102 lines (90 loc) · 2.78 KB
/
fromFileDialog.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
'use strict';
(function() {
angular.module('openshiftConsole').component('fromFileDialog', {
controller: [
'$scope',
'$timeout',
'$routeParams',
'$filter',
'DataService',
FromFileDialog
],
controllerAs: '$ctrl',
bindings: {
project: '<', //handle create project optionally
context: '<',
onDialogClosed: '&'
},
templateUrl: 'views/directives/from-file-dialog.html'
});
function FromFileDialog($scope, $timeout, $routeParams, $filter, DataService) {
var ctrl = this;
ctrl.$onInit = function() {
ctrl.alerts = {};
ctrl.loginBaseUrl = DataService.openshiftAPIBaseUrl();
// if on the landing page, show the project name in next-steps
if (!$routeParams.project) {
ctrl.showProjectName = true;
}
};
function getIconClass() {
var icon = _.get(ctrl, 'template.metadata.annotations.iconClass', 'fa fa-clone');
return (icon.indexOf('icon-') !== -1) ? 'font-icon ' + icon : icon;
}
ctrl.importFile = function() {
$scope.$broadcast('importFileFromYAMLOrJSON');
};
ctrl.instantiateTemplate = function() {
$scope.$broadcast('instantiateTemplate');
};
$scope.$on('fileImportedFromYAMLOrJSON', function(event, message) {
ctrl.selectedProject = message.project;
ctrl.template = message.template;
ctrl.iconClass = getIconClass();
ctrl.name = "YAML / JSON";
// Need to let the current digest loop finish so the template config step becomes visible or the wizard will throw an error
// from the change to currentStep
$timeout(function() {
ctrl.currentStep = ctrl.template ? "Template Configuration" : "Results";
},0);
});
$scope.$on('templateInstantiated', function(event, message) {
ctrl.selectedProject = message.project;
ctrl.name = $filter('displayName')(ctrl.template);
ctrl.currentStep = "Results";
});
ctrl.close = function() {
ctrl.template = null;
var cb = ctrl.onDialogClosed();
if (_.isFunction(cb)) {
cb();
}
ctrl.wizardDone = false;
return true;
};
ctrl.stepChanged = function(step) {
if (step.stepId === 'results') {
ctrl.nextButtonTitle = "Close";
ctrl.wizardDone = true;
} else {
ctrl.nextButtonTitle = "Create";
}
};
ctrl.currentStep = "YAML / JSON";
ctrl.nextCallback = function (step) {
if (step.stepId === 'file') {
ctrl.importFile();
return false; // don't actually navigate yet
}
else if (step.stepId === 'template') {
ctrl.instantiateTemplate();
return false;
}
else if (step.stepId === 'results') {
ctrl.close();
return false;
}
return true;
};
}
})();