Skip to content

Commit 44d587b

Browse files
author
OpenShift Bot
authored
Merge pull request #2094 from spadgett/add-config-map-to-application
Merged by openshift-bot
2 parents 690def0 + 6d67cc0 commit 44d587b

File tree

12 files changed

+262
-165
lines changed

12 files changed

+262
-165
lines changed

app/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ <h1>JavaScript Required</h1>
328328
<script src="scripts/directives/labels.js"></script>
329329
<script src="scripts/directives/lifecycleHook.js"></script>
330330
<script src="scripts/directives/actionChip.js"></script>
331-
<script src="scripts/directives/addSecretToApplication.js"></script>
331+
<script src="scripts/directives/addConfigToApplication.js"></script>
332332
<script src="scripts/directives/templateopt.js"></script>
333333
<script src="scripts/directives/tasks.js"></script>
334334
<script src="scripts/directives/catalog.js"></script>

app/scripts/controllers/configMap.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,20 @@ angular.module('openshiftConsole')
3737
}
3838
};
3939

40+
$scope.addToApplicationVisible = false;
41+
42+
$scope.addToApplication = function() {
43+
$scope.addToApplicationVisible = true;
44+
};
45+
46+
$scope.closeAddToApplication = function() {
47+
$scope.addToApplicationVisible = false;
48+
};
49+
4050
ProjectsService
4151
.get($routeParams.project)
4252
.then(_.spread(function(project, context) {
53+
$scope.project = project;
4354
DataService
4455
.get("configmaps", $routeParams.configMap, context, { errorNotification: false })
4556
.then(function(configMap) {

app/scripts/directives/addSecretToApplication.js renamed to app/scripts/directives/addConfigToApplication.js

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use strict";
22
(function() {
3-
angular.module("openshiftConsole").component('addSecretToApplication', {
3+
angular.module("openshiftConsole").component('addConfigToApplication', {
44
controller: [
55
'$filter',
66
'$scope',
@@ -10,19 +10,19 @@
1010
'Navigate',
1111
'NotificationsService',
1212
'StorageService',
13-
AddSecretToApplication
13+
AddConfigToApplication
1414
],
1515
controllerAs: 'ctrl',
1616
bindings: {
1717
project: '<',
18-
secret: '<',
18+
apiObject: '<',
1919
onComplete: '<',
2020
onCancel: '<'
2121
},
22-
templateUrl: 'views/directives/add-secret-to-application.html'
22+
templateUrl: 'views/directives/add-config-to-application.html'
2323
});
2424

25-
function AddSecretToApplication($filter, $scope, APIService, ApplicationsService, DataService, Navigate, NotificationsService, StorageService) {
25+
function AddConfigToApplication($filter, $scope, APIService, ApplicationsService, DataService, Navigate, NotificationsService, StorageService) {
2626
var ctrl = this;
2727

2828
var getApplications = function() {
@@ -41,8 +41,8 @@
4141

4242
getApplications();
4343

44-
var keyValidator = new RegExp("^[A-Za-z_]{1}[A-Za-z0-9_]*$");
45-
ctrl.hasInvalidEnvVars = _.some(ctrl.secret.data, function(value, key) {
44+
var keyValidator = new RegExp("^[A-Za-z_][A-Za-z0-9_]*$");
45+
ctrl.hasInvalidEnvVars = _.some(ctrl.apiObject.data, function(value, key) {
4646
return !keyValidator.test(key);
4747
});
4848
};
@@ -70,11 +70,19 @@
7070
ctrl.disableInputs = true;
7171

7272
if (ctrl.addType === 'env') {
73-
var newEnvFrom = {
74-
secretRef: {
75-
name: ctrl.secret.metadata.name
76-
}
77-
};
73+
var newEnvFrom = {};
74+
switch (ctrl.apiObject.kind) {
75+
case 'Secret':
76+
newEnvFrom.secretRef = {
77+
name: ctrl.apiObject.metadata.name
78+
};
79+
break;
80+
case 'ConfigMap':
81+
newEnvFrom.configMapRef = {
82+
name: ctrl.apiObject.metadata.name
83+
};
84+
break;
85+
}
7886

7987
// For each container, add the new volume mount.
8088
_.each(podTemplate.spec.containers, function(container) {
@@ -85,7 +93,7 @@
8593
});
8694
} else {
8795
var generateName = $filter('generateName');
88-
var name = generateName(ctrl.secret.metadata.name + '-');
96+
var name = generateName(ctrl.apiObject.metadata.name + '-');
8997
var newVolumeMount = {
9098
name: name,
9199
mountPath: ctrl.mountVolume,
@@ -101,18 +109,28 @@
101109
});
102110

103111
var newVolume = {
104-
name: name,
105-
secret: {
106-
secretName: ctrl.secret.metadata.name
107-
}
112+
name: name
108113
};
109114

115+
switch (ctrl.apiObject.kind) {
116+
case 'Secret':
117+
newVolume.secret = {
118+
secretName: ctrl.apiObject.metadata.name
119+
};
120+
break;
121+
case 'ConfigMap':
122+
newVolume.configMap = {
123+
name: ctrl.apiObject.metadata.name
124+
};
125+
break;
126+
}
127+
110128
podTemplate.spec.volumes = podTemplate.spec.volumes || [];
111129
podTemplate.spec.volumes.push(newVolume);
112130
}
113131

114132
var humanizeKind = $filter('humanizeKind');
115-
var sourceKind = humanizeKind(ctrl.secret.kind);
133+
var sourceKind = humanizeKind(ctrl.apiObject.kind);
116134
var targetKind = humanizeKind(applicationToUpdate.kind);
117135
var context = {
118136
namespace: ctrl.project.metadata.name
@@ -122,7 +140,7 @@
122140
function() {
123141
NotificationsService.addNotification({
124142
type: "success",
125-
message: "Successfully added " + sourceKind + " " + ctrl.secret.metadata.name + " to " + targetKind + " " + applicationToUpdate.metadata.name + ".",
143+
message: "Successfully added " + sourceKind + " " + ctrl.apiObject.metadata.name + " to " + targetKind + " " + applicationToUpdate.metadata.name + ".",
126144
links: [{
127145
href: Navigate.resourceURL(applicationToUpdate),
128146
label: "View " + humanizeKind(applicationToUpdate.kind, true)
@@ -137,7 +155,7 @@
137155

138156
NotificationsService.addNotification({
139157
type: "error",
140-
message: "An error occurred adding " + sourceKind + " " + ctrl.secret.metadata.name + " to " + targetKind + " " + applicationToUpdate.metadata.name + ". " +
158+
message: "An error occurred adding " + sourceKind + " " + ctrl.apiObject.metadata.name + " to " + targetKind + " " + applicationToUpdate.metadata.name + ". " +
141159
getErrorDetails(result)
142160
});
143161
}).finally(function() {
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
.add-config-to-application {
2+
.catalogs-overlay-panel {
3+
max-width: 600px;
4+
}
5+
6+
.container-options {
7+
margin-left: 20px;
8+
.select-container {
9+
max-height: 200px;
10+
overflow-y: auto;
11+
.checkbox:first-of-type {
12+
margin-top: 0;
13+
}
14+
}
15+
}
16+
17+
.dialog-title {
18+
border-bottom: 1px solid @color-pf-black-300;
19+
20+
h3 {
21+
margin: 18px 0;
22+
padding-left: 15px;
23+
}
24+
}
25+
26+
.dialog-body {
27+
padding: 20px;
28+
29+
.add-choice {
30+
margin-bottom: 10px;
31+
}
32+
.button-group {
33+
.btn {
34+
margin-left: 10px;
35+
&:first-of-type {
36+
margin-left: 0;
37+
}
38+
}
39+
}
40+
legend {
41+
border-bottom: 0;
42+
font-size: @font-size-base + 1;
43+
font-weight: 600;
44+
margin-bottom: 10px;
45+
}
46+
.radio {
47+
margin-top: 0;
48+
}
49+
}
50+
51+
.env-warning {
52+
margin-left: 20px;
53+
}
54+
55+
.updating {
56+
background-color: @color-pf-white;
57+
bottom: 55px;
58+
left: 0;
59+
padding-top: 60px;
60+
position: absolute;
61+
right: 0;
62+
top: 55px;
63+
z-index: 1000;
64+
}
65+
66+
.volume-options {
67+
margin-left: 20px;
68+
}
69+
}

app/styles/_secrets.less

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,3 @@
1-
.add-secret-to-application {
2-
.catalogs-overlay-panel {
3-
max-width: 600px;
4-
}
5-
6-
.container-options {
7-
margin-left: 20px;
8-
.select-container {
9-
max-height: 200px;
10-
overflow-y: auto;
11-
.checkbox:first-of-type {
12-
margin-top: 0;
13-
}
14-
}
15-
}
16-
17-
.dialog-title {
18-
border-bottom: 1px solid @color-pf-black-300;
19-
20-
h3 {
21-
margin: 18px 0;
22-
padding-left: 15px;
23-
}
24-
}
25-
26-
.dialog-body {
27-
padding: 20px;
28-
29-
.add-choice {
30-
margin-bottom: 10px;
31-
}
32-
.button-group {
33-
.btn {
34-
margin-left: 10px;
35-
&:first-of-type {
36-
margin-left: 0;
37-
}
38-
}
39-
}
40-
legend {
41-
border-bottom: 0;
42-
font-size: @font-size-base + 1;
43-
font-weight: 600;
44-
margin-bottom: 10px;
45-
}
46-
.radio {
47-
margin-top: 0;
48-
}
49-
}
50-
51-
.env-warning {
52-
margin-left: 20px;
53-
}
54-
55-
.updating {
56-
background-color: @color-pf-white;
57-
bottom: 55px;
58-
left: 0;
59-
padding-top: 60px;
60-
position: absolute;
61-
right: 0;
62-
top: 55px;
63-
z-index: 1000;
64-
}
65-
66-
.volume-options {
67-
margin-left: 20px;
68-
}
69-
}
70-
711
.osc-secrets-form {
722
.advanced-secrets,
733
.basic-secrets {

app/styles/main.less

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,4 @@
6565
@import "_wizard.less";
6666
@import "_builds.less";
6767
@import "_editor.less";
68+
@import "_add-config-to-application.less";

app/views/browse/config-map.html

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,31 @@ <h2>The config map could not be loaded.</h2>
1010
</div>
1111
<div ng-if="loaded && !error">
1212
<h1 class="contains-actions">
13-
<div class="pull-right dropdown" ng-if="'configmaps' | canIDoAny">
14-
<button type="button" class="dropdown-toggle btn btn-default actions-dropdown-btn hidden-xs" data-toggle="dropdown">
13+
<div class="pull-right dropdown">
14+
<!--
15+
`canIAddToProject` returns true if you can update any resource.
16+
We'll use this as a best-effort check to see if we should show the
17+
button.
18+
-->
19+
<button ng-if="project.metadata.name | canIAddToProject"
20+
type="button"
21+
class="btn btn-default hidden-xs"
22+
ng-click="addToApplication()">
23+
Add to Application
24+
</button>
25+
<button ng-if="'configmaps' | canIDoAny" type="button" class="dropdown-toggle btn btn-default actions-dropdown-btn hidden-xs" data-toggle="dropdown">
1526
Actions
1627
<span class="caret"></span>
1728
</button>
29+
<!-- Check `canIAddToProject` for the mobile menu since "Add to Application" uses it. -->
1830
<a href=""
31+
ng-if="project.metadata.name | canIAddToProject"
1932
class="dropdown-toggle actions-dropdown-kebab visible-xs-inline"
20-
data-toggle="dropdown"><i class="fa fa-ellipsis-v"></i><span class="sr-only">Actions</span></a>
33+
data-toggle="dropdown"><i class="fa fa-ellipsis-v" aria-hidden="true"></i><span class="sr-only">Actions</span></a>
2134
<ul class="dropdown-menu dropdown-menu-right actions action-button">
35+
<li ng-if="project.metadata.name | canIAddToProject" class="visible-xs">
36+
<a href="" role="button" ng-click="addToApplication()">Add to Application</a>
37+
</li>
2238
<li ng-if="'configmaps' | canI : 'update'">
2339
<a ng-href="{{configMap | editResourceURL}}" role="button">Edit</a>
2440
</li>
@@ -58,7 +74,7 @@ <h2>The config map has no items.</h2>
5874
<truncate-long-text
5975
content="value"
6076
limit="1024"
61-
newlineLimit="20"
77+
newline-limit="20"
6278
expandable="true">
6379
</truncate-long-text>
6480
</td>
@@ -70,5 +86,8 @@ <h2>The config map has no items.</h2>
7086
</div><!-- /col-* -->
7187
</div>
7288
</div>
89+
<overlay-panel class="add-config-to-application" show-panel="addToApplicationVisible" show-close="true" handle-close="closeAddToApplication">
90+
<add-config-to-application project="project" api-object="configMap" on-cancel="closeAddToApplication" on-complete="closeAddToApplication"></add-config-to-application>
91+
</overlay-panel>
7392
</div><!-- /middle-content -->
7493
</div>

0 commit comments

Comments
 (0)