Skip to content

Commit 51fa4de

Browse files
committed
improve label selector
1 parent 4db8cf3 commit 51fa4de

4 files changed

Lines changed: 55 additions & 9 deletions

File tree

OpenFlow/src/Messages/Message.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,7 +1017,9 @@ export class Message {
10171017
if (NoderedUtil.IsNullEmpty(Config.stripe_api_secret)) {
10181018
if (user.nodered.resources.limits) {
10191019
resources.limits.memory = user.nodered.resources.limits.memory;
1020-
resources.limits.cpu = user.nodered.resources.limits.cpu;
1020+
resources.limits.cpu = user.nodered.resources.limits.memory;
1021+
resources.requests.memory = user.nodered.resources.limits.memory;
1022+
resources.requests.cpu = user.nodered.resources.limits.memory;
10211023
}
10221024
if (user.nodered.resources.requests) {
10231025
resources.requests.memory = user.nodered.resources.requests.memory;
@@ -1028,6 +1030,7 @@ export class Message {
10281030
if (billings.length > 0) {
10291031
const billing: Billing = billings[0];
10301032
resources.limits.memory = billing.memory;
1033+
resources.requests.memory = billing.memory;
10311034
if (!NoderedUtil.IsNullEmpty(billing.openflowuserplan)) {
10321035
hasbilling = true;
10331036
}
@@ -1401,7 +1404,9 @@ export class Message {
14011404
if (node.metadata && node.metadata.labels) {
14021405
const keys = Object.keys(node.metadata.labels);
14031406
keys.forEach(key => {
1404-
result[key] = node.metadata.labels[key];
1407+
let value = node.metadata.labels[key];
1408+
if (result[key] == null) result[key] = [];
1409+
if (result[key].indexOf(value) == -1) result[key].push(value);
14051410
});
14061411
}
14071412
});

OpenFlow/src/public/Controllers.ts

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2646,9 +2646,12 @@ export class NoderedCtrl {
26462646
public user: NoderedUser = null;
26472647
public limitsmemory: string = "";
26482648
public loading: boolean = false;
2649-
public labels: any[] = [];
2649+
public labels: any = {};
26502650
public keys: string[] = [];
2651+
public labelkeys: string[] = [];
26512652
public label: any = null;
2653+
public newkey: string = "";
2654+
public newvalue: string = "";
26522655
constructor(
26532656
public $scope: ng.IScope,
26542657
public $location: ng.ILocationService,
@@ -2689,7 +2692,10 @@ export class NoderedCtrl {
26892692
this.limitsmemory = this.user.nodered.resources.limits.memory;
26902693
}
26912694
if (this.user.nodered != null && (this.user.nodered as any).nodeselector != null) {
2692-
this.label = JSON.stringify((this.user.nodered as any).nodeselector);
2695+
// this.label = JSON.stringify((this.user.nodered as any).nodeselector);
2696+
this.label = (this.user.nodered as any).nodeselector;
2697+
this.labelkeys = Object.keys(this.label);
2698+
26932699
}
26942700
this.name = this.name.split("@").join("").split(".").join("");
26952701
this.name = this.name.toLowerCase();
@@ -2723,8 +2729,15 @@ export class NoderedCtrl {
27232729
}
27242730
}
27252731
if (this.label) {
2732+
const keys = Object.keys(this.label);
2733+
if (keys.length == 0) this.label = null;
2734+
}
2735+
if (this.label) {
2736+
if (this.user.nodered == null) this.user.nodered = new NoderedConfig();
2737+
(this.user.nodered as any).nodeselector = this.label;
2738+
} else {
27262739
if (this.user.nodered == null) this.user.nodered = new NoderedConfig();
2727-
(this.user.nodered as any).nodeselector = JSON.parse(this.label);
2740+
delete (this.user.nodered as any).nodeselector;
27282741
}
27292742
this.loading = true;
27302743
this.messages = 'Updating ' + this.user.name + "\n" + this.messages;
@@ -2877,6 +2890,24 @@ export class NoderedCtrl {
28772890
}
28782891
if (!this.$scope.$$phase) { this.$scope.$apply(); }
28792892
}
2893+
addkey() {
2894+
if (this.label == null) this.label = {};
2895+
var _label: any[] = this.labels[this.newkey];
2896+
this.label[this.newkey] = _label[0];
2897+
if (this.newvalue != null) this.label[this.newkey] = this.newvalue;
2898+
this.labelkeys = Object.keys(this.label);
2899+
}
2900+
removekey(key) {
2901+
if (key == null) key = this.newkey;
2902+
if (this.label == null) this.label = {};
2903+
var _label: any[] = this.labels[key];
2904+
delete this.label[key];
2905+
this.labelkeys = Object.keys(this.label);
2906+
}
2907+
newkeyselected() {
2908+
if (this.label == null || this.label[this.newkey] == null) this.newvalue = this.labels[this.newkey][0];
2909+
if (this.label != null && this.label[this.newkey] != null) this.newvalue = this.label[this.newkey];
2910+
}
28802911
}
28812912
export class hdrobotsCtrl extends entitiesCtrl<unattendedclient> {
28822913
constructor(

OpenFlow/src/public/Nodered.html

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,21 @@ <h1 translate lib="web">nodered</h1>
108108
<section>
109109
<div class="form-group" ng-show="menuctrl.hasrole('admins') && ctrl.labels && ctrl.keys && ctrl.keys.length > 0">
110110
<label class="col-sm-3 control-label"><span translate lib="web">label</span>: </label>
111-
<div class="col-sm-9">
112-
<select class="form-control" ng-model="ctrl.label">
111+
<div class="col-sm-15">
112+
<!-- <select class="form-control" ng-model="ctrl.label">
113113
<option value="">No label</option>
114114
<option ng-repeat="key in ctrl.keys">{{ '{"' + key + '":"' + ctrl.labels[key] + '"}'}}</option>
115-
</select>
115+
</select> -->
116+
<span class="border mr-2" ng-repeat="key in ctrl.labelkeys"
117+
ng-click="ctrl.removekey(key)">{{key + '=' + ctrl.label[key]}}</span>
118+
<br>
119+
<select ng-model="ctrl.newkey" ng-options="item as item for item in ctrl.keys"
120+
ng-change="ctrl.newkeyselected()"></select>
121+
<select ng-model="ctrl.newvalue" ng-options="item as item for item in ctrl.labels[ctrl.newkey]"></select>
122+
<button type="button" ng-disabled="ctrl.loading==true" class="btn" translate lib="web"
123+
ng-click="ctrl.addkey()">add</button>
124+
<button type="button" ng-disabled="ctrl.loading==true" class="btn" translate lib="web"
125+
ng-click="ctrl.removekey()">remove</button>
116126
</div>
117127
</div>
118128
</section>

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.1.116
1+
1.1.117

0 commit comments

Comments
 (0)