Skip to content

Commit 32c3a25

Browse files
author
OpenShift Bot
authored
Merge pull request #1043 from jhadvig/listWithoutMeta
Merged by openshift-bot
2 parents 232ddec + 3d60d74 commit 32c3a25

File tree

4 files changed

+73
-61
lines changed

4 files changed

+73
-61
lines changed

app/scripts/directives/fromFile.js

+18-9
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,17 @@ angular.module("openshiftConsole")
114114
}
115115
}
116116

117-
// Top level resource field check.
118-
if (!validateFields(resource)) {
117+
if (!isKindValid(resource)) {
119118
return;
120119
}
121120

122121
$scope.resourceKind = resource.kind;
122+
$scope.resourceKind.endsWith("List") ? $scope.isList = true : $scope.isList = false;
123123

124-
if ($scope.resourceKind.endsWith("List")) {
125-
$scope.isList = true;
124+
if (!isMetadataValid(resource)) {
125+
return;
126+
}
127+
if ($scope.isList) {
126128
$scope.resourceList = resource.items;
127129
$scope.resourceName = '';
128130
} else {
@@ -142,7 +144,7 @@ angular.module("openshiftConsole")
142144
var resourceCheckPromises = [];
143145
$scope.errorOccured = false;
144146
_.forEach($scope.resourceList, function(item) {
145-
if (!validateFields(item)) {
147+
if (!isMetadataValid(item)) {
146148
$scope.errorOccured = true;
147149
return false;
148150
}
@@ -170,22 +172,29 @@ angular.module("openshiftConsole")
170172
});
171173
};
172174

173-
// Takes item that will be inspect for kind, metadata fields and if the item is meant to be created in current namespace
174-
function validateFields(item) {
175+
// Takes item that will be inspect kind field.
176+
function isKindValid(item) {
175177
if (!item.kind) {
176178
$scope.error = {
177179
message: "Resource is missing kind field."
178180
};
179181
return false;
180182
}
183+
return true;
184+
}
185+
186+
// Takes item that will be inspect metadata fields and if the item is meant to be created in current namespace
187+
function isMetadataValid(item) {
188+
if ($scope.isList) {
189+
return true;
190+
}
181191
if (!item.metadata) {
182192
$scope.error = {
183193
message: "Resource is missing metadata field."
184194
};
185195
return false;
186196
}
187-
// Validate if resource has 'name' field in its 'metadata', but it's not a List
188-
if (!item.metadata.name && !item.kind.endsWith("List")) {
197+
if (!item.metadata.name) {
189198
$scope.error = {
190199
message: "Resource name is missing in metadata field."
191200
};

app/views/modals/confirm-replace.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<div class="modal-resource-action">
22
<div class="modal-body">
3-
<div ng-if="resourceList.length === 1">
4-
<h1>{{resourceKind | humanizeKind}} '<strong>{{resourceName}}</strong>' already exists</h1>
3+
<div ng-if="!isList">
4+
<h1>{{resourceKind}} '<strong>{{resourceName}}</strong>' already exists</h1>
55
<p>Do you want to replace with the new content?</p>
66
</div>
77

8-
<div ng-if="resourceList.length > 1">
8+
<div ng-if="isList">
99
<h1>Some items already exist:</h1>
1010
<dl class="dl-horizontal">
1111
<dt ng-repeat-start="resource in updateResources">{{resource.kind}}</dt>

dist/scripts/scripts.js

+49-46
Original file line numberDiff line numberDiff line change
@@ -9381,56 +9381,59 @@ scope:!1,
93819381
templateUrl:"views/directives/from-file.html",
93829382
controller:[ "$scope", function(l) {
93839383
function m(a) {
9384-
return a.kind ? a.metadata ? a.metadata.name || a.kind.endsWith("List") ? !a.metadata.namespace || a.metadata.namespace === l.projectName || (l.error = {
9384+
return !!a.kind || (l.error = {
9385+
message:"Resource is missing kind field."
9386+
}, !1);
9387+
}
9388+
function n(a) {
9389+
return !!l.isList || (a.metadata ? a.metadata.name ? !a.metadata.namespace || a.metadata.namespace === l.projectName || (l.error = {
93859390
message:a.kind + " " + a.metadata.name + " can't be created in project " + a.metadata.namespace + ". Can't create resource in different projects."
93869391
}, !1) :(l.error = {
93879392
message:"Resource name is missing in metadata field."
93889393
}, !1) :(l.error = {
93899394
message:"Resource is missing metadata field."
9390-
}, !1) :(l.error = {
9391-
message:"Resource is missing kind field."
9392-
}, !1);
9395+
}, !1));
93939396
}
9394-
function n() {
9397+
function o() {
93959398
var a = b.open({
93969399
animation:!0,
93979400
templateUrl:"views/modals/process-template.html",
93989401
controller:"ProcessTemplateModalController",
93999402
scope:l
94009403
});
94019404
a.result.then(function() {
9402-
l.templateOptions.add ? p() :(e.setTemplate(l.resourceList[0]), q());
9405+
l.templateOptions.add ? q() :(e.setTemplate(l.resourceList[0]), r());
94039406
});
94049407
}
9405-
function o() {
9408+
function p() {
94069409
var a = b.open({
94079410
animation:!0,
94089411
templateUrl:"views/modals/confirm-replace.html",
94099412
controller:"ConfirmReplaceModalController",
94109413
scope:l
94119414
});
94129415
a.result.then(function() {
9413-
k.getLatestQuotaAlerts(l.createResources, l.context).then(B);
9416+
k.getLatestQuotaAlerts(l.createResources, l.context).then(C);
94149417
});
94159418
}
9416-
function p() {
9419+
function q() {
94179420
var b = l.createResources.length, c = l.updateResources.length;
94189421
if (l.resourceKind.endsWith("List")) {
94199422
var d = [];
9420-
c > 0 && d.push(u()), b > 0 && d.push(t()), a.all(d).then(q);
9421-
} else s();
9423+
c > 0 && d.push(v()), b > 0 && d.push(u()), a.all(d).then(r);
9424+
} else t();
94229425
}
9423-
function q() {
9426+
function r() {
94249427
var a;
94259428
if ("Template" === l.resourceKind && l.templateOptions.process && !l.errorOccured) {
94269429
var b = l.templateOptions.add || l.updateResources.length > 0 ? l.projectName :"";
9427-
a = g.createFromTemplateURL(z, l.projectName, {
9430+
a = g.createFromTemplateURL(A, l.projectName, {
94289431
namespace:b
94299432
});
94309433
} else a = g.projectOverviewURL(l.projectName);
94319434
c.url(a);
94329435
}
9433-
function r(a) {
9436+
function s(a) {
94349437
var b = j.objectToResourceGroupVersion(a);
94359438
return b ? j.apiInfo(b) ? i.get(b, a.metadata.name, l.context, {
94369439
errorNotification:!1
@@ -9445,7 +9448,7 @@ message:j.unsupportedObjectKindOrVersion(a)
94459448
message:j.invalidObjectKindOrVersion(a)
94469449
}));
94479450
}
9448-
function s() {
9451+
function t() {
94499452
var a;
94509453
_.isEmpty(l.createResources) ? (a = _.head(l.updateResources), i.update(j.kindToResource(a.kind), a.metadata.name, a, {
94519454
namespace:l.projectName
@@ -9456,11 +9459,11 @@ data:{
94569459
type:"success",
94579460
message:a.kind + " " + a.metadata.name + " was successfully updated."
94589461
}
9459-
}), q();
9462+
}), r();
94609463
}, function(b) {
94619464
l.alerts["update" + a.metadata.name] = {
94629465
type:"error",
9463-
message:"Unable to update the " + w(a.kind) + " '" + a.metadata.name + "'.",
9466+
message:"Unable to update the " + x(a.kind) + " '" + a.metadata.name + "'.",
94649467
details:d("getErrorDetails")(b)
94659468
};
94669469
})) :(a = _.head(l.createResources), i.create(j.kindToResource(a.kind), null, a, {
@@ -9472,16 +9475,16 @@ data:{
94729475
type:"success",
94739476
message:a.kind + " " + a.metadata.name + " was successfully created."
94749477
}
9475-
}), q();
9478+
}), r();
94769479
}, function(b) {
94779480
l.alerts["create" + a.metadata.name] = {
94789481
type:"error",
9479-
message:"Unable to create the " + w(a.kind) + " '" + a.metadata.name + "'.",
9482+
message:"Unable to create the " + x(a.kind) + " '" + a.metadata.name + "'.",
94809483
details:d("getErrorDetails")(b)
94819484
};
94829485
}));
94839486
}
9484-
function t() {
9487+
function u() {
94859488
var b = {
94869489
started:"Creating resources in project " + l.projectName,
94879490
success:"Creating resources in project " + l.projectName,
@@ -9494,17 +9497,17 @@ var c = [], d = !1;
94949497
if (a.failure.length > 0) d = !0, l.errorOccured = !0, a.failure.forEach(function(a) {
94959498
c.push({
94969499
type:"error",
9497-
message:"Cannot create " + w(a.object.kind) + ' "' + a.object.metadata.name + '". ',
9500+
message:"Cannot create " + x(a.object.kind) + ' "' + a.object.metadata.name + '". ',
94989501
details:a.data.message
94999502
});
95009503
}), a.success.forEach(function(a) {
95019504
c.push({
95029505
type:"success",
9503-
message:"Created " + w(a.kind) + ' "' + a.metadata.name + '" successfully. '
9506+
message:"Created " + x(a.kind) + ' "' + a.metadata.name + '" successfully. '
95049507
});
95059508
}); else {
95069509
var e;
9507-
e = l.isList ? "All items in list were created successfully." :w(l.resourceKind) + " " + l.resourceName + " was successfully created.", c.push({
9510+
e = l.isList ? "All items in list were created successfully." :x(l.resourceKind) + " " + l.resourceName + " was successfully created.", c.push({
95089511
type:"success",
95099512
message:e
95109513
});
@@ -9516,7 +9519,7 @@ hasErrors:d
95169519
}), b.promise;
95179520
});
95189521
}
9519-
function u() {
9522+
function v() {
95209523
var b = {
95219524
started:"Updating resources in project " + l.projectName,
95229525
success:"Updated resources in project " + l.projectName,
@@ -9529,17 +9532,17 @@ var c = [], d = !1;
95299532
if (a.failure.length > 0) d = !0, l.errorOccured = !0, a.failure.forEach(function(a) {
95309533
c.push({
95319534
type:"error",
9532-
message:"Cannot update " + w(a.object.kind) + ' "' + a.object.metadata.name + '". ',
9535+
message:"Cannot update " + x(a.object.kind) + ' "' + a.object.metadata.name + '". ',
95339536
details:a.data.message
95349537
});
95359538
}), a.success.forEach(function(a) {
95369539
c.push({
95379540
type:"success",
9538-
message:"Updated " + w(a.kind) + ' "' + a.metadata.name + '" successfully. '
9541+
message:"Updated " + x(a.kind) + ' "' + a.metadata.name + '" successfully. '
95399542
});
95409543
}); else {
95419544
var e;
9542-
e = l.isList ? "All items in list were updated successfully." :w(l.resourceKind) + " " + l.resourceName + " was successfully updated.", c.push({
9545+
e = l.isList ? "All items in list were updated successfully." :x(l.resourceKind) + " " + l.resourceName + " was successfully updated.", c.push({
95439546
type:"success",
95449547
message:e
95459548
});
@@ -9560,27 +9563,27 @@ alerts:c
95609563
}), b.promise;
95619564
});
95629565
}
9563-
var v, w = d("humanizeKind");
9566+
var w, x = d("humanizeKind");
95649567
h.clear(), l.aceLoaded = function(a) {
9565-
v = a.getSession(), v.setOption("tabSize", 2), v.setOption("useSoftTabs", !0), a.setDragDelay = 0, a.$blockScrolling = 1 / 0;
9568+
w = a.getSession(), w.setOption("tabSize", 2), w.setOption("useSoftTabs", !0), a.setDragDelay = 0, a.$blockScrolling = 1 / 0;
95669569
};
9567-
var x = function() {
9568-
var a = v.getAnnotations();
9570+
var y = function() {
9571+
var a = w.getAnnotations();
95699572
l.editorErrorAnnotation = _.some(a, {
95709573
type:"error"
95719574
});
9572-
}, y = _.debounce(function() {
9575+
}, z = _.debounce(function() {
95739576
try {
9574-
JSON.parse(l.editorContent), v.setMode("ace/mode/json");
9577+
JSON.parse(l.editorContent), w.setMode("ace/mode/json");
95759578
} catch (a) {
95769579
try {
9577-
jsyaml.safeLoad(l.editorContent), v.setMode("ace/mode/yaml");
9580+
jsyaml.safeLoad(l.editorContent), w.setMode("ace/mode/yaml");
95789581
} catch (a) {}
95799582
}
9580-
l.$apply(x);
9583+
l.$apply(y);
95819584
}, 300);
9582-
l.aceChanged = y;
9583-
var z, A = function(a) {
9585+
l.aceChanged = z;
9586+
var A, B = function(a) {
95849587
var c = b.open({
95859588
animation:!0,
95869589
templateUrl:"views/modals/confirm.html",
@@ -9597,34 +9600,34 @@ cancelButtonText:"Cancel"
95979600
}
95989601
}
95999602
});
9600-
c.result.then(p);
9601-
}, B = function(a) {
9603+
c.result.then(q);
9604+
}, C = function(a) {
96029605
var b = a.quotaAlerts || [], c = _.filter(b, {
96039606
type:"error"
96049607
});
9605-
c.length ? (l.disableInputs = !1, l.alerts = b) :b.length ? (A(b), l.disableInputs = !1) :p();
9608+
c.length ? (l.disableInputs = !1, l.alerts = b) :b.length ? (B(b), l.disableInputs = !1) :q();
96069609
};
96079610
l.create = function() {
96089611
l.alerts = {}, delete l.error;
96099612
try {
9610-
z = JSON.parse(l.editorContent);
9613+
A = JSON.parse(l.editorContent);
96119614
} catch (b) {
96129615
try {
9613-
z = jsyaml.safeLoad(l.editorContent);
9616+
A = jsyaml.safeLoad(l.editorContent);
96149617
} catch (b) {
96159618
return void (l.error = b);
96169619
}
96179620
}
9618-
if (m(z)) {
9619-
l.resourceKind = z.kind, l.resourceKind.endsWith("List") ? (l.isList = !0, l.resourceList = z.items, l.resourceName = "") :(l.resourceList = [ z ], l.resourceName = z.metadata.name, "Template" === l.resourceKind && (l.templateOptions = {
9621+
if (m(A) && (l.resourceKind = A.kind, l.resourceKind.endsWith("List") ? l.isList = !0 :l.isList = !1, n(A))) {
9622+
l.isList ? (l.resourceList = A.items, l.resourceName = "") :(l.resourceList = [ A ], l.resourceName = A.metadata.name, "Template" === l.resourceKind && (l.templateOptions = {
96209623
process:!0,
96219624
add:!1
96229625
})), l.updateResources = [], l.createResources = [];
96239626
var c = [];
96249627
l.errorOccured = !1, _.forEach(l.resourceList, function(a) {
9625-
return m(a) ? void c.push(r(a)) :(l.errorOccured = !0, !1);
9628+
return n(a) ? void c.push(s(a)) :(l.errorOccured = !0, !1);
96269629
}), a.all(c).then(function() {
9627-
l.errorOccured || (1 === l.createResources.length && "Template" === l.resourceList[0].kind ? n() :_.isEmpty(l.updateResources) ? k.getLatestQuotaAlerts(l.createResources, l.context).then(B) :(l.updateTemplate = 1 === l.updateResources.length && "Template" === l.updateResources[0].kind, l.updateTemplate ? n() :o()));
9630+
l.errorOccured || (1 === l.createResources.length && "Template" === l.resourceList[0].kind ? o() :_.isEmpty(l.updateResources) ? k.getLatestQuotaAlerts(l.createResources, l.context).then(C) :(l.updateTemplate = 1 === l.updateResources.length && "Template" === l.updateResources[0].kind, l.updateTemplate ? o() :p()));
96289631
});
96299632
}
96309633
};

dist/scripts/templates.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -9763,11 +9763,11 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
97639763
$templateCache.put('views/modals/confirm-replace.html',
97649764
"<div class=\"modal-resource-action\">\n" +
97659765
"<div class=\"modal-body\">\n" +
9766-
"<div ng-if=\"resourceList.length === 1\">\n" +
9767-
"<h1>{{resourceKind | humanizeKind}} '<strong>{{resourceName}}</strong>' already exists</h1>\n" +
9766+
"<div ng-if=\"!isList\">\n" +
9767+
"<h1>{{resourceKind}} '<strong>{{resourceName}}</strong>' already exists</h1>\n" +
97689768
"<p>Do you want to replace with the new content?</p>\n" +
97699769
"</div>\n" +
9770-
"<div ng-if=\"resourceList.length > 1\">\n" +
9770+
"<div ng-if=\"isList\">\n" +
97719771
"<h1>Some items already exist:</h1>\n" +
97729772
"<dl class=\"dl-horizontal\">\n" +
97739773
"<dt ng-repeat-start=\"resource in updateResources\">{{resource.kind}}</dt>\n" +

0 commit comments

Comments
 (0)