@@ -1091,49 +1091,49 @@ module openflow {
10911091 } ) ;
10921092 }
10931093
1094- async EnsureNoderedInstance ( name : string ) {
1094+ async EnsureNoderedInstance ( _id : string , name : string ) {
10951095 try {
1096- await this . api . EnsureNoderedInstance ( name ) ;
1096+ await this . api . EnsureNoderedInstance ( _id , name ) ;
10971097 this . messages += "EnsureNoderedInstance completed" + "\n" ;
10981098 } catch ( error ) {
10991099 this . messages += error + "\n" ;
11001100 console . error ( error ) ;
11011101 }
11021102 if ( ! this . $scope . $$phase ) { this . $scope . $apply ( ) ; }
11031103 }
1104- async DeleteNoderedInstance ( name : string ) {
1104+ async DeleteNoderedInstance ( _id : string , name : string ) {
11051105 try {
1106- await this . api . DeleteNoderedInstance ( name ) ;
1106+ await this . api . DeleteNoderedInstance ( _id , name ) ;
11071107 this . messages += "DeleteNoderedInstance completed" + "\n" ;
11081108 } catch ( error ) {
11091109 this . messages += error + "\n" ;
11101110 console . error ( error ) ;
11111111 }
11121112 if ( ! this . $scope . $$phase ) { this . $scope . $apply ( ) ; }
11131113 }
1114- async RestartNoderedInstance ( name : string ) {
1114+ async RestartNoderedInstance ( _id : string , name : string ) {
11151115 try {
1116- await this . api . RestartNoderedInstance ( name ) ;
1116+ await this . api . RestartNoderedInstance ( _id , name ) ;
11171117 this . messages += "RestartNoderedInstance completed" + "\n" ;
11181118 } catch ( error ) {
11191119 this . messages += error + "\n" ;
11201120 console . error ( error ) ;
11211121 }
11221122 if ( ! this . $scope . $$phase ) { this . $scope . $apply ( ) ; }
11231123 }
1124- async StartNoderedInstance ( name : string ) {
1124+ async StartNoderedInstance ( _id : string , name : string ) {
11251125 try {
1126- await this . api . StartNoderedInstance ( name ) ;
1126+ await this . api . StartNoderedInstance ( _id , name ) ;
11271127 this . messages += "StartNoderedInstance completed" + "\n" ;
11281128 } catch ( error ) {
11291129 this . messages += error + "\n" ;
11301130 console . error ( error ) ;
11311131 }
11321132 if ( ! this . $scope . $$phase ) { this . $scope . $apply ( ) ; }
11331133 }
1134- async StopNoderedInstance ( name : string ) {
1134+ async StopNoderedInstance ( _id : string , name : string ) {
11351135 try {
1136- await this . api . StopNoderedInstance ( name ) ;
1136+ await this . api . StopNoderedInstance ( _id , name ) ;
11371137 this . messages += "StopNoderedInstance completed" + "\n" ;
11381138 } catch ( error ) {
11391139 this . messages += error + "\n" ;
@@ -2365,6 +2365,7 @@ module openflow {
23652365 public instancestatus : string = "" ;
23662366 public instancelog : string = "" ;
23672367 public name : string = "" ;
2368+ public userid : string = "" ;
23682369 constructor (
23692370 public $scope : ng . IScope ,
23702371 public $location : ng . ILocationService ,
@@ -2375,9 +2376,17 @@ module openflow {
23752376 console . debug ( "NoderedCtrl" ) ;
23762377 WebSocketClient . onSignedin ( async ( user : TokenUser ) => {
23772378 await api . RegisterQueue ( ) ;
2378- this . name = $routeParams . id ;
2379- if ( this . name == null || this . name == undefined || this . name == "" ) {
2379+ this . userid = $routeParams . id ;
2380+ if ( this . userid == null || this . userid == undefined || this . userid == "" ) {
23802381 this . name = WebSocketClient . user . username ;
2382+ this . userid = WebSocketClient . user . _id ;
2383+ } else {
2384+ var users = await this . api . Query ( "users" , { _id : this . userid } , null , null , 1 ) ;
2385+ if ( users . length == 0 ) {
2386+ this . instancestatus = "Unknown id!" ;
2387+ return ;
2388+ }
2389+ this . name = users [ 0 ] . username ;
23812390 }
23822391 this . name = this . name . split ( "@" ) . join ( "" ) . split ( "." ) . join ( "" ) ;
23832392 this . name = this . name . toLowerCase ( ) ;
@@ -2390,7 +2399,7 @@ module openflow {
23902399 try {
23912400 this . instancestatus = "fetching status" ;
23922401
2393- this . instance = await this . api . GetNoderedInstance ( this . name ) ;
2402+ this . instance = await this . api . GetNoderedInstance ( this . userid , this . name ) ;
23942403 console . debug ( "GetNoderedInstance:" ) ;
23952404 if ( this . instance !== null && this . instance !== undefined ) {
23962405 if ( this . instance . metadata . deletionTimestamp !== undefined ) {
@@ -2414,7 +2423,7 @@ module openflow {
24142423 try {
24152424 this . instancestatus = "fetching log" ;
24162425 console . debug ( "GetNoderedInstanceLog:" ) ;
2417- this . instancelog = await this . api . GetNoderedInstanceLog ( this . name ) ;
2426+ this . instancelog = await this . api . GetNoderedInstanceLog ( this . userid , this . name ) ;
24182427 this . instancelog = this . instancelog . split ( "\n" ) . reverse ( ) . join ( "\n" ) ;
24192428 this . messages += "GetNoderedInstanceLog completed\n" ;
24202429 this . instancestatus = "" ;
@@ -2427,7 +2436,7 @@ module openflow {
24272436 }
24282437 async EnsureNoderedInstance ( ) {
24292438 try {
2430- await this . api . EnsureNoderedInstance ( this . name ) ;
2439+ await this . api . EnsureNoderedInstance ( this . userid , this . name ) ;
24312440 this . messages += "EnsureNoderedInstance completed" + "\n" ;
24322441 } catch ( error ) {
24332442 this . messages += error + "\n" ;
@@ -2438,7 +2447,7 @@ module openflow {
24382447 }
24392448 async DeleteNoderedInstance ( ) {
24402449 try {
2441- await this . api . DeleteNoderedInstance ( this . name ) ;
2450+ await this . api . DeleteNoderedInstance ( this . userid , this . name ) ;
24422451 this . messages += "DeleteNoderedInstance completed" + "\n" ;
24432452 } catch ( error ) {
24442453 this . messages += error + "\n" ;
@@ -2449,7 +2458,7 @@ module openflow {
24492458 }
24502459 async RestartNoderedInstance ( ) {
24512460 try {
2452- await this . api . RestartNoderedInstance ( this . name ) ;
2461+ await this . api . RestartNoderedInstance ( this . userid , this . name ) ;
24532462 this . messages += "RestartNoderedInstance completed" + "\n" ;
24542463 } catch ( error ) {
24552464 this . messages += error + "\n" ;
@@ -2460,7 +2469,7 @@ module openflow {
24602469 }
24612470 async StartNoderedInstance ( ) {
24622471 try {
2463- await this . api . StartNoderedInstance ( this . name ) ;
2472+ await this . api . StartNoderedInstance ( this . userid , this . name ) ;
24642473 this . messages += "StartNoderedInstance completed" + "\n" ;
24652474 } catch ( error ) {
24662475 this . messages += error + "\n" ;
@@ -2471,7 +2480,7 @@ module openflow {
24712480 }
24722481 async StopNoderedInstance ( ) {
24732482 try {
2474- await this . api . StopNoderedInstance ( this . name ) ;
2483+ await this . api . StopNoderedInstance ( this . userid , this . name ) ;
24752484 this . messages += "StopNoderedInstance completed" + "\n" ;
24762485 } catch ( error ) {
24772486 this . messages += error + "\n" ;
@@ -2606,8 +2615,18 @@ module openflow {
26062615 name = name . toLowerCase ( ) ;
26072616 var noderedurl = "https://" + this . WebSocketClient . nodered_domain_schema . replace ( "$nodered_id$" , name ) ;
26082617 window . open ( noderedurl ) ;
2609-
26102618 }
2619+ ManageNodered ( model : any ) {
2620+ this . $location . path ( "/Nodered/" + model . _id ) ;
2621+ if ( ! this . $scope . $$phase ) { this . $scope . $apply ( ) ; }
2622+ }
2623+ async Impersonate ( model : openflow . TokenUser ) : Promise < any > {
2624+ this . loading = true ;
2625+ var result = await this . api . SigninWithToken ( this . WebSocketClient . jwt , null , model . _id ) ;
2626+ this . loading = false ;
2627+ if ( ! this . $scope . $$phase ) { this . $scope . $apply ( ) ; }
2628+ }
2629+
26112630 // async DeleteOne(model: any): Promise<any> {
26122631 // this.loading = true;
26132632 // await this.api.Delete(this.collection, model);
0 commit comments