Skip to content

Commit 14635d5

Browse files
committed
Let users define labels when creating routes
1 parent 8bca523 commit 14635d5

File tree

4 files changed

+63
-18
lines changed

4 files changed

+63
-18
lines changed

app/scripts/controllers/createRoute.js

+26-5
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ angular.module('openshiftConsole')
1717
AuthorizationService,
1818
DataService,
1919
Navigate,
20-
ProjectsService) {
20+
ProjectsService,
21+
keyValueEditorUtils) {
2122
$scope.alerts = {};
2223
$scope.renderOptions = {
2324
hideFilterWidget: true
2425
};
2526
$scope.projectName = $routeParams.project;
2627
$scope.serviceName = $routeParams.service;
28+
$scope.labels = [];
2729

2830
// Prefill route name with the service name.
2931
$scope.routing = {
@@ -56,24 +58,43 @@ angular.module('openshiftConsole')
5658
return;
5759
}
5860

59-
var labels = {},
60-
orderByDisplayName = $filter('orderByDisplayName');
61+
var orderByDisplayName = $filter('orderByDisplayName');
6162

6263
DataService.list("services", context, function(services) {
6364
$scope.services = orderByDisplayName(services.by("metadata.name"));
6465
$scope.routing.to = {};
6566
$scope.routing.to.service = _.find($scope.services, function(service) {
6667
return !$scope.serviceName || service.metadata.name === $scope.serviceName;
6768
});
68-
$scope.$watch('routing.to.service', function() {
69-
labels = angular.copy($scope.routing.to.service.metadata.labels);
69+
$scope.$watch('routing.to.service', function(service) {
70+
var serviceLabels = _.get(service, 'metadata.labels', {});
71+
$scope.systemLabels = _.map(serviceLabels, function(value, key) {
72+
return {
73+
name: key,
74+
value: value
75+
};
76+
});
7077
});
7178
});
7279

80+
$scope.copyServiceLabels = function() {
81+
var serviceLabels = _.get($scope, 'routing.to.service.metadata.labels', {});
82+
var existing = keyValueEditorUtils.mapEntries(keyValueEditorUtils.compactEntries($scope.labels));
83+
var updated = _.assign(existing, serviceLabels);
84+
$scope.labels = _.map(updated, function(value, key) {
85+
return {
86+
name: key,
87+
value: value
88+
};
89+
});
90+
};
91+
7392
$scope.createRoute = function() {
7493
if ($scope.createRouteForm.$valid) {
7594
$scope.disableInputs = true;
7695
var serviceName = $scope.routing.to.service.metadata.name;
96+
var labels = keyValueEditorUtils.mapEntries(keyValueEditorUtils.compactEntries($scope.labels));
97+
7798
var route = ApplicationGenerator.createRoute($scope.routing, serviceName, labels);
7899
var alternateServices = _.get($scope, 'routing.alternateServices', []);
79100
if (!_.isEmpty(alternateServices)) {

app/views/create-route.html

+8-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ <h1>Create Route</h1>
1818
<div class="help-block">
1919
Routing is a way to make your application publicly visible.
2020
</div>
21-
<form name="createRouteForm" class="mar-top-xl">
21+
<form name="createRouteForm" class="mar-top-xl osc-form">
2222
<div ng-if="!services">Loading...</div>
2323
<div ng-if="services">
2424
<fieldset ng-disabled="disableInputs">
@@ -27,6 +27,13 @@ <h1>Create Route</h1>
2727
services="services"
2828
show-name-input="true">
2929
</osc-routing>
30+
<label-editor
31+
labels="labels"
32+
expand="true"
33+
can-toggle="false"
34+
help-text="Labels for this route.">
35+
</label-editor>
36+
<a href="" ng-click="copyServiceLabels()">Copy service labels</a>
3037
<div class="button-group gutter-top gutter-bottom">
3138
<button type="submit"
3239
class="btn btn-primary btn-lg"

dist/scripts/scripts.js

+25-11
Original file line numberDiff line numberDiff line change
@@ -8143,10 +8143,10 @@ details:c("getErrorDetails")(b)
81438143
}
81448144
});
81458145
}));
8146-
} ]), angular.module("openshiftConsole").controller("CreateRouteController", [ "$filter", "$routeParams", "$scope", "$window", "ApplicationGenerator", "AuthorizationService", "DataService", "Navigate", "ProjectsService", function(a, b, c, d, e, f, g, h, i) {
8146+
} ]), angular.module("openshiftConsole").controller("CreateRouteController", [ "$filter", "$routeParams", "$scope", "$window", "ApplicationGenerator", "AuthorizationService", "DataService", "Navigate", "ProjectsService", "keyValueEditorUtils", function(a, b, c, d, e, f, g, h, i, j) {
81478147
c.alerts = {}, c.renderOptions = {
81488148
hideFilterWidget:!0
8149-
}, c.projectName = b.project, c.serviceName = b.service, c.routing = {
8149+
}, c.projectName = b.project, c.serviceName = b.service, c.labels = [], c.routing = {
81508150
name:c.serviceName || ""
81518151
}, c.breadcrumbs = [ {
81528152
title:c.projectName,
@@ -8156,26 +8156,40 @@ title:"Routes",
81568156
link:"project/" + c.projectName + "/browse/routes"
81578157
}, {
81588158
title:"Create Route"
8159-
} ], i.get(b.project).then(_.spread(function(i, j) {
8159+
} ], i.get(b.project).then(_.spread(function(i, k) {
81608160
if (c.project = i, c.breadcrumbs[0].title = a("displayName")(i), !f.canI("routes", "create", b.project)) return void h.toErrorPage("You do not have authority to create routes in project " + b.project + ".", "access_denied");
8161-
var k = {}, l = a("orderByDisplayName");
8162-
g.list("services", j, function(a) {
8161+
var l = a("orderByDisplayName");
8162+
g.list("services", k, function(a) {
81638163
c.services = l(a.by("metadata.name")), c.routing.to = {}, c.routing.to.service = _.find(c.services, function(a) {
81648164
return !c.serviceName || a.metadata.name === c.serviceName;
8165-
}), c.$watch("routing.to.service", function() {
8166-
k = angular.copy(c.routing.to.service.metadata.labels);
8165+
}), c.$watch("routing.to.service", function(a) {
8166+
var b = _.get(a, "metadata.labels", {});
8167+
c.systemLabels = _.map(b, function(a, b) {
8168+
return {
8169+
name:b,
8170+
value:a
8171+
};
8172+
});
8173+
});
8174+
}), c.copyServiceLabels = function() {
8175+
var a = _.get(c, "routing.to.service.metadata.labels", {}), b = j.mapEntries(j.compactEntries(c.labels)), d = _.assign(b, a);
8176+
c.labels = _.map(d, function(a, b) {
8177+
return {
8178+
name:b,
8179+
value:a
8180+
};
81678181
});
8168-
}), c.createRoute = function() {
8182+
}, c.createRoute = function() {
81698183
if (c.createRouteForm.$valid) {
81708184
c.disableInputs = !0;
8171-
var b = c.routing.to.service.metadata.name, f = e.createRoute(c.routing, b, k), h = _.get(c, "routing.alternateServices", []);
8172-
_.isEmpty(h) || (f.spec.to.weight = _.get(c, "routing.to.weight"), f.spec.alternateBackends = _.map(h, function(a) {
8185+
var b = c.routing.to.service.metadata.name, f = j.mapEntries(j.compactEntries(c.labels)), h = e.createRoute(c.routing, b, f), i = _.get(c, "routing.alternateServices", []);
8186+
_.isEmpty(i) || (h.spec.to.weight = _.get(c, "routing.to.weight"), h.spec.alternateBackends = _.map(i, function(a) {
81738187
return {
81748188
kind:"Service",
81758189
name:_.get(a, "service.metadata.name"),
81768190
weight:a.weight
81778191
};
8178-
})), g.create("routes", null, f, j).then(function() {
8192+
})), g.create("routes", null, h, k).then(function() {
81798193
d.history.back();
81808194
}, function(b) {
81818195
c.disableInputs = !1, c.alerts["create-route"] = {

dist/scripts/templates.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -4455,12 +4455,15 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
44554455
"<div class=\"help-block\">\n" +
44564456
"Routing is a way to make your application publicly visible.\n" +
44574457
"</div>\n" +
4458-
"<form name=\"createRouteForm\" class=\"mar-top-xl\">\n" +
4458+
"<form name=\"createRouteForm\" class=\"mar-top-xl osc-form\">\n" +
44594459
"<div ng-if=\"!services\">Loading...</div>\n" +
44604460
"<div ng-if=\"services\">\n" +
44614461
"<fieldset ng-disabled=\"disableInputs\">\n" +
44624462
"<osc-routing model=\"routing\" services=\"services\" show-name-input=\"true\">\n" +
44634463
"</osc-routing>\n" +
4464+
"<label-editor labels=\"labels\" expand=\"true\" can-toggle=\"false\" help-text=\"Additional labels for this route.\">\n" +
4465+
"</label-editor>\n" +
4466+
"<a href=\"\" ng-click=\"copyServiceLabels()\">Copy service labels</a>\n" +
44644467
"<div class=\"button-group gutter-top gutter-bottom\">\n" +
44654468
"<button type=\"submit\" class=\"btn btn-primary btn-lg\" ng-click=\"createRoute()\" ng-disabled=\"createRouteForm.$invalid || disableInputs || !createRoute\" value=\"\">Create</button>\n" +
44664469
"<a class=\"btn btn-default btn-lg\" href=\"#\" back>Cancel</a>\n" +

0 commit comments

Comments
 (0)