Skip to content

Commit 7275cb9

Browse files
committed
add named nodered support
1 parent 3bce94f commit 7275cb9

5 files changed

Lines changed: 57 additions & 37 deletions

File tree

OpenFlow/src/public/CommonControllers.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -243,40 +243,40 @@ module openflow {
243243
}
244244
return msg;
245245
}
246-
async GetNoderedInstance(): Promise<any> {
247-
var q: GetNoderedInstanceMessage = new GetNoderedInstanceMessage();
246+
async GetNoderedInstance(name: string): Promise<any> {
247+
var q: GetNoderedInstanceMessage = new GetNoderedInstanceMessage(); q.name = name;
248248
var msg: Message = new Message(); msg.command = "getnoderedinstance"; msg.data = JSON.stringify(q);
249249
q = await this.WebSocketClient.Send<GetNoderedInstanceMessage>(msg);
250250
return q.result;
251251
}
252-
async GetNoderedInstanceLog(): Promise<string> {
253-
var q: GetNoderedInstanceLogMessage = new GetNoderedInstanceLogMessage();
252+
async GetNoderedInstanceLog(name: string): Promise<string> {
253+
var q: GetNoderedInstanceLogMessage = new GetNoderedInstanceLogMessage(); q.name = name;
254254
var msg: Message = new Message(); msg.command = "getnoderedinstancelog"; msg.data = JSON.stringify(q);
255255
q = await this.WebSocketClient.Send<GetNoderedInstanceLogMessage>(msg);
256256
return q.result;
257257
}
258-
async EnsureNoderedInstance(): Promise<void> {
259-
var q: EnsureNoderedInstanceMessage = new EnsureNoderedInstanceMessage();
258+
async EnsureNoderedInstance(name: string): Promise<void> {
259+
var q: EnsureNoderedInstanceMessage = new EnsureNoderedInstanceMessage(); q.name = name;
260260
var msg: Message = new Message(); msg.command = "ensurenoderedinstance"; msg.data = JSON.stringify(q);
261261
q = await this.WebSocketClient.Send<EnsureNoderedInstanceMessage>(msg);
262262
}
263-
async DeleteNoderedInstance(): Promise<void> {
264-
var q: DeleteNoderedInstanceMessage = new DeleteNoderedInstanceMessage();
263+
async DeleteNoderedInstance(name: string): Promise<void> {
264+
var q: DeleteNoderedInstanceMessage = new DeleteNoderedInstanceMessage(); q.name = name;
265265
var msg: Message = new Message(); msg.command = "deletenoderedinstance"; msg.data = JSON.stringify(q);
266266
q = await this.WebSocketClient.Send<DeleteNoderedInstanceMessage>(msg);
267267
}
268-
async RestartNoderedInstance(): Promise<void> {
269-
var q: RestartNoderedInstanceMessage = new RestartNoderedInstanceMessage();
268+
async RestartNoderedInstance(name: string): Promise<void> {
269+
var q: RestartNoderedInstanceMessage = new RestartNoderedInstanceMessage(); q.name = name;
270270
var msg: Message = new Message(); msg.command = "restartnoderedinstance"; msg.data = JSON.stringify(q);
271271
q = await this.WebSocketClient.Send<RestartNoderedInstanceMessage>(msg);
272272
}
273-
async StartNoderedInstance(): Promise<void> {
274-
var q: StartNoderedInstanceMessage = new StartNoderedInstanceMessage();
273+
async StartNoderedInstance(name: string): Promise<void> {
274+
var q: StartNoderedInstanceMessage = new StartNoderedInstanceMessage(); q.name = name;
275275
var msg: Message = new Message(); msg.command = "startnoderedinstance"; msg.data = JSON.stringify(q);
276276
q = await this.WebSocketClient.Send<StartNoderedInstanceMessage>(msg);
277277
}
278-
async StopNoderedInstance(): Promise<void> {
279-
var q: StopNoderedInstanceMessage = new StopNoderedInstanceMessage();
278+
async StopNoderedInstance(name: string): Promise<void> {
279+
var q: StopNoderedInstanceMessage = new StopNoderedInstanceMessage(); q.name = name;
280280
var msg: Message = new Message(); msg.command = "stopnoderedinstance"; msg.data = JSON.stringify(q);
281281
q = await this.WebSocketClient.Send<StopNoderedInstanceMessage>(msg);
282282
}

OpenFlow/src/public/Controllers.ts

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,49 +1147,49 @@ module openflow {
11471147
});
11481148
}
11491149

1150-
async EnsureNoderedInstance() {
1150+
async EnsureNoderedInstance(name: string) {
11511151
try {
1152-
await this.api.EnsureNoderedInstance();
1152+
await this.api.EnsureNoderedInstance(name);
11531153
this.messages += "EnsureNoderedInstance completed" + "\n";
11541154
} catch (error) {
11551155
this.messages += error + "\n";
11561156
console.error(error);
11571157
}
11581158
if (!this.$scope.$$phase) { this.$scope.$apply(); }
11591159
}
1160-
async DeleteNoderedInstance() {
1160+
async DeleteNoderedInstance(name: string) {
11611161
try {
1162-
await this.api.DeleteNoderedInstance();
1162+
await this.api.DeleteNoderedInstance(name);
11631163
this.messages += "DeleteNoderedInstance completed" + "\n";
11641164
} catch (error) {
11651165
this.messages += error + "\n";
11661166
console.error(error);
11671167
}
11681168
if (!this.$scope.$$phase) { this.$scope.$apply(); }
11691169
}
1170-
async RestartNoderedInstance() {
1170+
async RestartNoderedInstance(name: string) {
11711171
try {
1172-
await this.api.RestartNoderedInstance();
1172+
await this.api.RestartNoderedInstance(name);
11731173
this.messages += "RestartNoderedInstance completed" + "\n";
11741174
} catch (error) {
11751175
this.messages += error + "\n";
11761176
console.error(error);
11771177
}
11781178
if (!this.$scope.$$phase) { this.$scope.$apply(); }
11791179
}
1180-
async StartNoderedInstance() {
1180+
async StartNoderedInstance(name: string) {
11811181
try {
1182-
await this.api.StartNoderedInstance();
1182+
await this.api.StartNoderedInstance(name);
11831183
this.messages += "StartNoderedInstance completed" + "\n";
11841184
} catch (error) {
11851185
this.messages += error + "\n";
11861186
console.error(error);
11871187
}
11881188
if (!this.$scope.$$phase) { this.$scope.$apply(); }
11891189
}
1190-
async StopNoderedInstance() {
1190+
async StopNoderedInstance(name: string) {
11911191
try {
1192-
await this.api.StopNoderedInstance();
1192+
await this.api.StopNoderedInstance(name);
11931193
this.messages += "StopNoderedInstance completed" + "\n";
11941194
} catch (error) {
11951195
this.messages += error + "\n";
@@ -2400,6 +2400,7 @@ module openflow {
24002400
public instance: any = null;
24012401
public instancestatus: string = "";
24022402
public instancelog: string = "";
2403+
public name: string = "";
24032404
constructor(
24042405
public $scope: ng.IScope,
24052406
public $location: ng.ILocationService,
@@ -2410,10 +2411,13 @@ module openflow {
24102411
console.debug("NoderedCtrl");
24112412
WebSocketClient.onSignedin(async (user: TokenUser) => {
24122413
await api.RegisterQueue();
2413-
var name = WebSocketClient.user.username;
2414-
name = name.split("@").join("").split(".").join("");
2415-
name = name.toLowerCase();
2416-
this.noderedurl = "https://" + WebSocketClient.nodered_domain_schema.replace("$nodered_id$", name);
2414+
this.name = $routeParams.id;
2415+
if (this.name == null || this.name == undefined || this.name == "") {
2416+
this.name = WebSocketClient.user.username;
2417+
}
2418+
this.name = this.name.split("@").join("").split(".").join("");
2419+
this.name = this.name.toLowerCase();
2420+
this.noderedurl = "https://" + WebSocketClient.nodered_domain_schema.replace("$nodered_id$", this.name);
24172421
// // this.GetNoderedInstance();
24182422
this.GetNoderedInstance();
24192423
});
@@ -2422,7 +2426,7 @@ module openflow {
24222426
try {
24232427
this.instancestatus = "fetching status";
24242428

2425-
this.instance = await this.api.GetNoderedInstance();
2429+
this.instance = await this.api.GetNoderedInstance(this.name);
24262430
console.debug("GetNoderedInstance:");
24272431
if (this.instance !== null && this.instance !== undefined) {
24282432
if (this.instance.metadata.deletionTimestamp !== undefined) {
@@ -2446,7 +2450,7 @@ module openflow {
24462450
try {
24472451
this.instancestatus = "fetching log";
24482452
console.debug("GetNoderedInstanceLog:");
2449-
this.instancelog = await this.api.GetNoderedInstanceLog();
2453+
this.instancelog = await this.api.GetNoderedInstanceLog(this.name);
24502454
this.instancelog = this.instancelog.split("\n").reverse().join("\n");
24512455
this.messages += "GetNoderedInstanceLog completed\n";
24522456
this.instancestatus = "";
@@ -2459,7 +2463,7 @@ module openflow {
24592463
}
24602464
async EnsureNoderedInstance() {
24612465
try {
2462-
await this.api.EnsureNoderedInstance();
2466+
await this.api.EnsureNoderedInstance(this.name);
24632467
this.messages += "EnsureNoderedInstance completed" + "\n";
24642468
} catch (error) {
24652469
this.messages += error + "\n";
@@ -2470,7 +2474,7 @@ module openflow {
24702474
}
24712475
async DeleteNoderedInstance() {
24722476
try {
2473-
await this.api.DeleteNoderedInstance();
2477+
await this.api.DeleteNoderedInstance(this.name);
24742478
this.messages += "DeleteNoderedInstance completed" + "\n";
24752479
} catch (error) {
24762480
this.messages += error + "\n";
@@ -2481,7 +2485,7 @@ module openflow {
24812485
}
24822486
async RestartNoderedInstance() {
24832487
try {
2484-
await this.api.RestartNoderedInstance();
2488+
await this.api.RestartNoderedInstance(this.name);
24852489
this.messages += "RestartNoderedInstance completed" + "\n";
24862490
} catch (error) {
24872491
this.messages += error + "\n";
@@ -2492,7 +2496,7 @@ module openflow {
24922496
}
24932497
async StartNoderedInstance() {
24942498
try {
2495-
await this.api.StartNoderedInstance();
2499+
await this.api.StartNoderedInstance(this.name);
24962500
this.messages += "StartNoderedInstance completed" + "\n";
24972501
} catch (error) {
24982502
this.messages += error + "\n";
@@ -2503,7 +2507,7 @@ module openflow {
25032507
}
25042508
async StopNoderedInstance() {
25052509
try {
2506-
await this.api.StopNoderedInstance();
2510+
await this.api.StopNoderedInstance(this.name);
25072511
this.messages += "StopNoderedInstance completed" + "\n";
25082512
} catch (error) {
25092513
this.messages += error + "\n";
@@ -2590,6 +2594,7 @@ module openflow {
25902594
console.debug("RolesCtrl");
25912595
this.basequery = { _type: "user" };
25922596
this.collection = "users";
2597+
this.postloadData = this.processdata;
25932598
this.preloadData = () => {
25942599
var dt = new Date(new Date().toISOString());
25952600
if (this.showinactive) {
@@ -2610,6 +2615,20 @@ module openflow {
26102615
this.loadData();
26112616
});
26122617
}
2618+
processdata() {
2619+
for (var i = 0; i < this.models.length; i++) {
2620+
var model: any = this.models[i];
2621+
(model as any).hasnodered = false;
2622+
if (model._noderedheartbeat != undefined && model._noderedheartbeat != null) {
2623+
var dt = new Date(model._noderedheartbeat)
2624+
var now: Date = new Date(),
2625+
secondsPast: number = (now.getTime() - dt.getTime()) / 1000;
2626+
if (secondsPast < 60) (model as any).hasnodered = true;
2627+
}
2628+
}
2629+
this.loading = false;
2630+
if (!this.$scope.$$phase) { this.$scope.$apply(); }
2631+
}
26132632
ShowWorkflows(model: any) {
26142633
this.userdata.data.basequeryas = model._id;
26152634
this.$location.path("/RPAWorkflows");

OpenFlow/src/public/Robots.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ <h1 translate lib="web">robots</h1>
6161
<a href ng-click="ctrl.ShowWorkflows(model)" class="table-btn">workflows</a>
6262
</td>
6363
<td class="btn-cell">
64-
<a href ng-click="ctrl.OpenNodered(model)" class="table-btn">nodered</a>
64+
<a href ng-click="ctrl.OpenNodered(model)" ng-show="model.hasnodered==true" class="table-btn">nodered</a>
6565
</td>
6666
<td class="btn-cell">
6767
<a ng-href="#/Entity/{{ctrl.collection}}/{{model._id}}" class="table-btn"><i class="az-edit"></i></a>

OpenFlow/src/public/app.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ module openflow {
6969

7070
.when('/Socket', { templateUrl: 'Socket.html', controller: SocketCtrl, controllerAs: 'ctrl' })
7171
.when('/Nodered', { templateUrl: 'Nodered.html', controller: NoderedCtrl, controllerAs: 'ctrl' })
72+
.when('/Nodered/:id', { templateUrl: 'Nodered.html', controller: NoderedCtrl, controllerAs: 'ctrl' })
7273

7374
.when('/hdrobots', { templateUrl: 'hdrobots.html', controller: hdrobotsCtrl, controllerAs: 'ctrl' })
7475
.when('/Robots', { templateUrl: 'Robots.html', controller: RobotsCtrl, controllerAs: 'ctrl' })

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.0.454
1+
0.0.455

0 commit comments

Comments
 (0)