Skip to content

Commit 3619536

Browse files
author
OpenShift Bot
authored
Merge pull request #1492 from spadgett/template-dialog
Merged by openshift-bot
2 parents be96ed8 + 63254d7 commit 3619536

20 files changed

+715
-285
lines changed

app/index.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ <h1>JavaScript Required</h1>
282282
<script src="scripts/controllers/modals/deleteModal.js"></script>
283283
<script src="scripts/controllers/modals/debugTerminal.js"></script>
284284
<script src="scripts/controllers/modals/confirmReplaceModal.js"></script>
285-
<script src="scripts/controllers/modals/processTemplateModal.js"></script>
285+
<script src="scripts/controllers/modals/processOrSaveTemplateModal.js"></script>
286286
<script src="scripts/controllers/modals/linkService.js"></script>
287287
<script src="scripts/controllers/modals/jenkinsfileExamplesModal.js"></script>
288288
<script src="scripts/controllers/modals/aboutComputeUnitsModal.js"></script>
@@ -345,6 +345,7 @@ <h1>JavaScript Required</h1>
345345
<script src="scripts/directives/routeServiceBarChart.js"></script>
346346
<script src="scripts/directives/bindService.js"></script>
347347
<script src="scripts/directives/processTemplate.js"></script>
348+
<script src="scripts/directives/processTemplateDialog.js"></script>
348349
<script src="scripts/directives/create/nextSteps.js"></script>
349350

350351
<!-- Old Overview, TODO: remove -->

app/scripts/controllers/landingPage.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,16 @@ angular.module('openshiftConsole')
1818
// Once all pages show notifications this should be removed.
1919
NotificationsService.clearNotifications();
2020

21+
$scope.templateSelected = function(template) {
22+
$scope.template = template;
23+
};
24+
25+
$scope.templateDialogClosed = function() {
26+
$scope.template = null;
27+
};
28+
2129
AuthService.withUser().then(function() {
22-
Catalog.getCatalogItems().then(function(items) {
30+
Catalog.getCatalogItems(true).then(function(items) {
2331
$scope.catalogItems = items;
2432
});
2533
});

app/scripts/controllers/modals/processTemplateModal.js renamed to app/scripts/controllers/modals/processOrSaveTemplateModal.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
/**
44
* @ngdoc function
5-
* @name openshiftConsole.controller:ProcessTemplateModalController
5+
* @name openshiftConsole.controller:ProcessOrSaveTemplateModalController
66
* @description
7-
* # ProcessTemplateModalController
7+
* # ProcessOrSaveTemplateModalController
88
* Controller of the openshiftConsole
99
*/
1010
angular.module('openshiftConsole')
11-
.controller('ProcessTemplateModalController', function ($scope, $uibModalInstance) {
11+
.controller('ProcessOrSaveTemplateModalController', function ($scope, $uibModalInstance) {
1212
$scope.continue = function() {
1313
$uibModalInstance.close('create');
1414
};

app/scripts/directives/fromFile.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,8 @@ angular.module("openshiftConsole")
216216
function openTemplateProcessModal() {
217217
var modalInstance = $uibModal.open({
218218
animation: true,
219-
templateUrl: 'views/modals/process-template.html',
220-
controller: 'ProcessTemplateModalController',
219+
templateUrl: 'views/modals/process-or-save-template.html',
220+
controller: 'ProcessOrSaveTemplateModalController',
221221
scope: $scope
222222
});
223223
modalInstance.result.then(function() {

app/scripts/directives/processTemplate.js

+85-38
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ angular.module('openshiftConsole').component('processTemplate', {
2121
template: '<',
2222
project: '<',
2323
alerts: '<',
24-
prefillParameters: '<'
24+
prefillParameters: '<',
25+
isDialog: '<'
2526
},
2627
templateUrl: 'views/directives/process-template.html'
2728
});
@@ -41,7 +42,6 @@ function ProcessTemplate($filter,
4142
var ctrl = this;
4243

4344
var context;
44-
var projectDisplayName;
4545

4646
var dcContainers = $parse('spec.template.spec.containers');
4747
var builderImage = $parse('spec.strategy.sourceStrategy.from || spec.strategy.dockerStrategy.from || spec.strategy.customStrategy.from');
@@ -129,16 +129,17 @@ function ProcessTemplate($filter,
129129
images = [];
130130
var dcImages = [];
131131
var outputImages = {};
132+
var namespace = _.get(ctrl, 'selectedProject.metadata.name');
132133
angular.forEach(data.objects, function(item) {
133134
if (item.kind === "BuildConfig") {
134-
var builder = imageObjectRef(builderImage(item), ctrl.project.metadata.name);
135+
var builder = imageObjectRef(builderImage(item), namespace);
135136
if(builder) {
136137
images.push({
137138
name: builder,
138139
usesParameters: getParametersInImage(builder)
139140
});
140141
}
141-
var output = imageObjectRef(outputImage(item), ctrl.project.metadata.name);
142+
var output = imageObjectRef(outputImage(item), namespace);
142143
if (output) {
143144
outputImages[output] = true;
144145
}
@@ -185,23 +186,20 @@ function ProcessTemplate($filter,
185186
ctrl.$onInit = function() {
186187
ctrl.labels = [];
187188
ctrl.templateDisplayName = displayName(ctrl.template);
188-
context = {
189-
namespace: ctrl.project.metadata.name
190-
};
191-
projectDisplayName = displayName(ctrl.project);
189+
ctrl.selectedProject = ctrl.project;
192190
setTemplateParams();
193191
};
194192

195193
var processedResources;
196194
var createResources = function() {
197195
var titles = {
198-
started: "Creating " + ctrl.templateDisplayName + " in project " + projectDisplayName,
199-
success: "Created " + ctrl.templateDisplayName + " in project " + projectDisplayName,
200-
failure: "Failed to create " + ctrl.templateDisplayName + " in project " + projectDisplayName
196+
started: "Creating " + ctrl.templateDisplayName + " in project " + displayName(ctrl.selectedProject),
197+
success: "Created " + ctrl.templateDisplayName + " in project " + displayName(ctrl.selectedProject),
198+
failure: "Failed to create " + ctrl.templateDisplayName + " in project " + displayName(ctrl.selectedProject)
201199
};
202200
var helpLinks = getHelpLinks(ctrl.template);
203201
TaskList.clear();
204-
TaskList.add(titles, helpLinks, ctrl.project.metadata.name, function() {
202+
TaskList.add(titles, helpLinks, ctrl.selectedProject.metadata.name, function() {
205203
var d = $q.defer();
206204
DataService.batch(processedResources, context).then(
207205
function(result) {
@@ -235,7 +233,15 @@ function ProcessTemplate($filter,
235233
);
236234
return d.promise;
237235
});
238-
Navigate.toNextSteps(ctrl.templateDisplayName, ctrl.project.metadata.name);
236+
237+
if (ctrl.isDialog) {
238+
$scope.$emit('templateInstantiated', {
239+
project: ctrl.selectedProject,
240+
template: ctrl.template
241+
});
242+
} else {
243+
Navigate.toNextSteps(ctrl.templateDisplayName, ctrl.selectedProject.metadata.name);
244+
}
239245
};
240246

241247
var launchConfirmationDialog = function(alerts) {
@@ -260,7 +266,7 @@ function ProcessTemplate($filter,
260266
};
261267

262268
var showWarningsOrCreate = function(result) {
263-
var alerts = SecurityCheckService.getSecurityAlerts(processedResources, ctrl.project.metadata.name);
269+
var alerts = SecurityCheckService.getSecurityAlerts(processedResources, ctrl.selectedProject.metadata.name);
264270

265271
// Now that all checks are completed, show any Alerts if we need to
266272
var quotaAlerts = result.quotaAlerts || [];
@@ -279,36 +285,77 @@ function ProcessTemplate($filter,
279285
}
280286
};
281287

282-
ctrl.createFromTemplate = function() {
283-
ctrl.disableInputs = true;
284-
var userLabels = keyValueEditorUtils.mapEntries(keyValueEditorUtils.compactEntries(ctrl.labels));
285-
var systemLabels = keyValueEditorUtils.mapEntries(keyValueEditorUtils.compactEntries(ctrl.systemLabels));
286-
ctrl.template.labels = _.extend(systemLabels, userLabels);
287-
288-
DataService.create("processedtemplates", null, ctrl.template, context).then(
289-
function(config) { // success
290-
// Cache template parameters and message so they can be displayed in the nexSteps page
291-
ProcessedTemplateService.setTemplateData(config.parameters, ctrl.template.parameters, config.message);
292-
processedResources = config.objects;
288+
var createProjectIfNecessary = function() {
289+
if (_.has(ctrl.selectedProject, 'metadata.uid')) {
290+
return $q.when();
291+
}
293292

294-
QuotaService.getLatestQuotaAlerts(processedResources, context).then(showWarningsOrCreate);
293+
var newProjName = ctrl.selectedProject.metadata.name;
294+
var newProjDisplayName = ctrl.selectedProject.metadata.annotations['new-display-name'];
295+
var newProjDesc = $filter('description')(ctrl.selectedProject);
296+
var projReqObj = {
297+
apiVersion: "v1",
298+
kind: "ProjectRequest",
299+
metadata: {
300+
name: newProjName
295301
},
296-
function(result) { // failure
297-
ctrl.disableInputs = false;
298-
var details;
299-
if (result.data && result.data.message) {
300-
details = result.data.message;
302+
displayName: newProjDisplayName,
303+
description: newProjDesc
304+
};
305+
return DataService.create('projectrequests', null, projReqObj, $scope);
306+
};
307+
308+
ctrl.createFromTemplate = function() {
309+
ctrl.disableInputs = true;
310+
createProjectIfNecessary().then(function() {
311+
context = {
312+
namespace: ctrl.selectedProject.metadata.name
313+
};
314+
var userLabels = keyValueEditorUtils.mapEntries(keyValueEditorUtils.compactEntries(ctrl.labels));
315+
var systemLabels = keyValueEditorUtils.mapEntries(keyValueEditorUtils.compactEntries(ctrl.systemLabels));
316+
ctrl.template.labels = _.extend(systemLabels, userLabels);
317+
318+
DataService.create("processedtemplates", null, ctrl.template, context).then(
319+
function(config) { // success
320+
// Cache template parameters and message so they can be displayed in the nexSteps page
321+
ProcessedTemplateService.setTemplateData(config.parameters, ctrl.template.parameters, config.message);
322+
processedResources = config.objects;
323+
324+
QuotaService.getLatestQuotaAlerts(processedResources, context).then(showWarningsOrCreate);
325+
},
326+
function(result) { // failure
327+
ctrl.disableInputs = false;
328+
var details;
329+
if (result.data && result.data.message) {
330+
details = result.data.message;
331+
}
332+
ctrl.alerts["process"] =
333+
{
334+
type: "error",
335+
message: "An error occurred processing the template.",
336+
details: details
337+
};
301338
}
302-
ctrl.alerts["process"] =
303-
{
304-
type: "error",
305-
message: "An error occurred processing the template.",
306-
details: details
307-
};
339+
);
340+
}, function(result) {
341+
ctrl.disableInputs = false;
342+
var details;
343+
if (result.data && result.data.message) {
344+
details = result.data.message;
308345
}
309-
);
346+
ctrl.alerts["create-project"] = {
347+
type: "error",
348+
message: "An error occurred creating the project.",
349+
details: details
350+
};
351+
});
310352
};
311353

354+
// When the process-template component is displayed in a dialog, the create
355+
// button is outside the component since it is in the wizard footer. Listen
356+
// for an event for when the button is clicked.
357+
$scope.$on('instantiateTemplate', ctrl.createFromTemplate);
358+
312359
var shouldAddAppLabel = function() {
313360
// If the template defines its own app label, we don't need to add one at all
314361
if (_.get(ctrl.template, 'labels.app')) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
'use strict';
2+
3+
angular.module('openshiftConsole').component('processTemplateDialog', {
4+
controller: [
5+
'$scope',
6+
'DataService',
7+
ProcessTemplateDialog
8+
],
9+
controllerAs: '$ctrl',
10+
bindings: {
11+
template: '<',
12+
onDialogClosed: '&'
13+
},
14+
templateUrl: 'views/directives/process-template-dialog.html'
15+
});
16+
17+
function ProcessTemplateDialog($scope, DataService) {
18+
var ctrl = this;
19+
20+
var initializeSteps = function() {
21+
ctrl.steps = [{
22+
id: 'configuration',
23+
label: 'Configuration',
24+
selected: true,
25+
visited: true
26+
}, {
27+
id: 'results',
28+
label: 'Results'
29+
}];
30+
ctrl.currentStep = ctrl.steps[0];
31+
};
32+
33+
ctrl.$onInit = function() {
34+
ctrl.alerts = {};
35+
ctrl.loginBaseUrl = DataService.openshiftAPIBaseUrl();
36+
};
37+
38+
var getIconClass = function() {
39+
var icon = _.get(ctrl, 'template.metadata.annotations.iconClass', 'fa fa-cubes');
40+
return (icon.indexOf('icon-') !== -1) ? 'font-icon ' + icon : icon;
41+
};
42+
43+
ctrl.$onChanges = function(changes) {
44+
if (changes.template) {
45+
initializeSteps();
46+
ctrl.iconClass = getIconClass();
47+
}
48+
};
49+
50+
var showResults = function() {
51+
ctrl.steps[0].selected = false;
52+
ctrl.currentStep = ctrl.steps[1];
53+
ctrl.currentStep.selected = true;
54+
ctrl.currentStep.visited = true;
55+
};
56+
57+
ctrl.instantiateTemplate = function() {
58+
$scope.$broadcast('instantiateTemplate');
59+
};
60+
61+
$scope.$on('templateInstantiated', function(event, message) {
62+
ctrl.selectedProject = message.project;
63+
showResults();
64+
});
65+
66+
ctrl.close = function() {
67+
var cb = ctrl.onDialogClosed();
68+
if (_.isFunction(cb)) {
69+
cb();
70+
}
71+
};
72+
}

app/scripts/directives/templateopt.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ angular.module('openshiftConsole')
66
return {
77
restrict: 'E',
88
templateUrl: 'views/_templateopt.html',
9+
transclude: true,
910
scope: {
1011
parameters: "=",
1112
expand: "=?",
12-
canToggle: "=?"
13+
canToggle: "=?",
14+
isDialog: "=?"
1315
},
1416
link: function(scope, element, attrs) {
1517
if (!angular.isDefined(attrs.canToggle)) {
@@ -23,6 +25,17 @@ angular.module('openshiftConsole')
2325
scope.focus = function(id) {
2426
angular.element('#' + id).focus();
2527
};
28+
29+
if (!scope.isDialog) {
30+
scope.visibleParameters = scope.parameters;
31+
} else {
32+
scope.$watch('parameters', function(parameters) {
33+
// Only show parameters that the user has to fill in a value when in a dialog.
34+
scope.visibleParameters = _.reject(parameters, function(parameter) {
35+
return !parameter.required || parameter.value || parameter.generate;
36+
});
37+
});
38+
}
2639
}
2740
};
2841
});

app/styles/_core.less

+5-6
Original file line numberDiff line numberDiff line change
@@ -597,8 +597,6 @@ label.checkbox {
597597
}
598598
}
599599
.form-group {
600-
width: 100%;
601-
602600
.parameter-input-wrapper {
603601
position: relative;
604602

@@ -611,10 +609,11 @@ label.checkbox {
611609
transform: rotate(90deg);
612610
}
613611
}
614-
615-
input, textarea {
616-
padding-right: 20px;
617-
}
612+
}
613+
}
614+
&.form-horizontal .form-group .parameter-input-wrapper {
615+
.resize-input {
616+
right: 26px;
618617
}
619618
}
620619
.help-block {

0 commit comments

Comments
 (0)