@@ -13,6 +13,74 @@ module openflow {
1313 }
1414 declare var jsondiffpatch : any ;
1515
16+ export class RPAWorkflowCtrl extends entityCtrl < openflow . RPAWorkflow > {
17+ public arguments : any ;
18+ public users : TokenUser [ ] ;
19+ public user : TokenUser ;
20+ public messages : string ;
21+ constructor (
22+ public $scope : ng . IScope ,
23+ public $location : ng . ILocationService ,
24+ public $routeParams : ng . route . IRouteParamsService ,
25+ public WebSocketClient : WebSocketClient ,
26+ public api : api
27+ ) {
28+ super ( $scope , $location , $routeParams , WebSocketClient , api ) ;
29+ console . debug ( "RPAWorkflowCtrl" ) ;
30+ this . collection = "openrpa" ;
31+ this . messages = "" ;
32+ WebSocketClient . onSignedin ( async ( _user : TokenUser ) => {
33+ if ( this . id !== null && this . id !== undefined ) {
34+ await api . RegisterQueue ( ) ;
35+ await this . loadData ( ) ;
36+ await this . loadUsers ( ) ;
37+ $scope . $on ( 'queuemessage' , ( event , data : QueueMessage ) => {
38+ if ( event && data ) { }
39+ // console.log("queuemessage");
40+ // console.log(event);
41+ console . log ( data ) ;
42+ this . messages += data . data . command + "\n" ;
43+ if ( data . data . command == "invokecompleted" ) {
44+ this . arguments = data . data . data ;
45+ }
46+ if ( ! this . $scope . $$phase ) { this . $scope . $apply ( ) ; }
47+ } ) ;
48+
49+ } else {
50+ console . error ( "Missing id" ) ;
51+ }
52+ } ) ;
53+ }
54+ async loadUsers ( ) : Promise < void > {
55+ this . users = await this . api . Query ( "users" , { $or : [ { _type : "user" } , { _type : "role" } ] } , null , null ) ;
56+ this . users . forEach ( user => {
57+ if ( user . _id == this . model . _createdbyid || user . _id == this . model . _createdbyid ) {
58+ this . user = user ;
59+ }
60+ } ) ;
61+ if ( ! this . $scope . $$phase ) { this . $scope . $apply ( ) ; }
62+ }
63+ async submit ( ) : Promise < void > {
64+ var rpacommand = {
65+ command : "invoke" ,
66+ workflowid : this . model . _id ,
67+ data : this . arguments
68+ }
69+ // var message = {
70+ // jwt: this.WebSocketClient.jwt,
71+ // payload: rpacommand
72+ // }
73+ console . log ( "QueueMessage" ) ;
74+ console . log ( rpacommand ) ;
75+ var result : any = await this . api . QueueMessage ( this . user . _id , rpacommand ) ;
76+ console . log ( "result:" ) ;
77+ console . log ( result ) ;
78+ try {
79+ // result = JSON.parse(result);
80+ } catch ( error ) {
81+ }
82+ }
83+ }
1684
1785 export class RPAWorkflowsCtrl extends entitiesCtrl < openflow . Base > {
1886 public message : string = "" ;
@@ -636,7 +704,7 @@ module openflow {
636704 }
637705 export class RoleCtrl extends entityCtrl < openflow . Role > {
638706 public addthis : any = "" ;
639- public users : any [ ] = null ;
707+ public users : TokenUser [ ] = null ;
640708 constructor (
641709 public $scope : ng . IScope ,
642710 public $location : ng . ILocationService ,
@@ -658,13 +726,7 @@ module openflow {
658726 } ) ;
659727 }
660728 async loadUsers ( ) : Promise < void > {
661- var q : QueryMessage = new QueryMessage ( ) ;
662- q . collectionname = this . collection ;
663- // q.query = {};
664- q . query = { $or : [ { _type : "user" } , { _type : "role" } ] } ;
665- var msg : Message = new Message ( ) ; msg . command = "query" ; msg . data = JSON . stringify ( q ) ;
666- q = await this . WebSocketClient . Send < QueryMessage > ( msg ) ;
667- this . users = q . result ;
729+ this . users = await this . api . Query ( this . collection , { $or : [ { _type : "user" } , { _type : "role" } ] } , null , null ) ;
668730 var ids : string [ ] = [ ] ;
669731 if ( this . model . members === undefined ) { this . model . members = [ ] ; }
670732 for ( var i : number = 0 ; i < this . model . members . length ; i ++ ) {
@@ -675,8 +737,7 @@ module openflow {
675737 this . users . splice ( i , 1 ) ;
676738 }
677739 }
678- this . addthis = q . result [ 0 ] . _id ;
679-
740+ this . addthis = this . users [ 0 ] . _id ;
680741 if ( ! this . $scope . $$phase ) { this . $scope . $apply ( ) ; }
681742 }
682743 async submit ( ) : Promise < void > {
0 commit comments