@@ -87,19 +87,14 @@ export class MenuCtrl {
8787 this . signedin = true ;
8888
8989 this . customers = await NoderedUtil . Query ( "users" , { _type : "customer" } , null , null , 100 , 0 , null , null , null , 2 ) ;
90- if ( this . customers . length == 1 ) this . customer = this . customers [ 0 ] ;
91- if ( this . customers . length > 1 && ( data . customerid != null || data . selectedcustomerid != null ) ) {
92- this . customer = null ;
93- if ( data . selectedcustomerid != null ) {
90+ this . customer = null ;
91+ if ( this . customers . length > 0 && ( this . user . selectedcustomerid != null ) ) {
92+ if ( this . user . selectedcustomerid != null ) {
9493 for ( let cust of this . customers )
95- if ( cust . _id == data . selectedcustomerid ) this . customer = cust ;
96- }
97- if ( this . customer == null ) {
98- for ( let cust of this . customers )
99- if ( cust . _id == data . customerid ) this . customer = cust ;
100-
94+ if ( cust . _id == this . user . selectedcustomerid ) this . customer = cust ;
10195 }
10296 }
97+ this . WebSocketClientService . customer = this . customer as any ;
10398 if ( ! this . $scope . $$phase ) { this . $scope . $apply ( ) ; }
10499 // cleanup();
105100 } ) ;
@@ -111,15 +106,11 @@ export class MenuCtrl {
111106 this . $scope . $on ( 'menurefresh' , async ( event , data ) => {
112107 if ( event && data ) { }
113108 this . customers = await NoderedUtil . Query ( "users" , { _type : "customer" } , null , null , 100 , 0 , null , null , null , 2 ) ;
114- if ( this . customers . length == 1 ) this . customer = this . customers [ 0 ] ;
115- if ( this . customers . length > 1 && data . customerid != null ) {
116- for ( let cust of this . customers )
117- if ( cust . _id == data . customerid ) this . customer = cust ;
118- }
119- if ( this . customers . length > 1 && data . selectedcustomerid != null ) {
109+ if ( this . customers . length > 0 && this . user . selectedcustomerid != null ) {
120110 for ( let cust of this . customers )
121- if ( cust . _id == data . selectedcustomerid ) this . customer = cust ;
111+ if ( cust . _id == this . user . selectedcustomerid ) this . customer = cust ;
122112 }
113+ this . WebSocketClientService . customer = this . customer as any ;
123114 if ( ! this . $scope . $$phase ) { this . $scope . $apply ( ) ; }
124115 } ) ;
125116 }
@@ -150,6 +141,27 @@ export class MenuCtrl {
150141 Search ( ) {
151142 this . $rootScope . $broadcast ( "search" , this . searchstring ) ;
152143 }
144+ SelectCustomer ( customer ) {
145+ if ( customer != null ) {
146+ if ( this . WebSocketClientService . user . customerid == customer . _id ) {
147+ this . WebSocketClientService . user . selectedcustomerid = null ;
148+ } else {
149+ this . WebSocketClientService . user . selectedcustomerid = customer . _id ;
150+ }
151+ this . WebSocketClientService . customer = customer as any ;
152+ this . $rootScope . $broadcast ( "menurefresh" ) ;
153+ this . $rootScope . $broadcast ( "search" , this . searchstring ) ;
154+ if ( this . PathIs ( "/Customer" ) ) {
155+ this . $location . path ( "/Customer/" + customer . _id ) ;
156+ if ( ! this . $scope . $$phase ) { this . $scope . $apply ( ) ; }
157+ }
158+ } else {
159+ this . WebSocketClientService . user . selectedcustomerid = null ;
160+ this . WebSocketClientService . customer = null ;
161+ this . $rootScope . $broadcast ( "menurefresh" ) ;
162+ this . $rootScope . $broadcast ( "search" , this . searchstring ) ;
163+ }
164+ }
153165}
154166export class RPAWorkflowCtrl extends entityCtrl < RPAWorkflow > {
155167 public arguments : any ;
@@ -1128,6 +1140,7 @@ export class UsersCtrl extends entitiesCtrl<TokenUser> {
11281140 this . orderby = this . userdata . data . UsersCtrl . orderby ;
11291141 this . searchstring = this . userdata . data . UsersCtrl . searchstring ;
11301142 this . basequeryas = this . userdata . data . UsersCtrl . basequeryas ;
1143+ this . skipcustomerfilter = this . userdata . data . UsersCtrl . skipcustomerfilter ;
11311144 }
11321145
11331146 WebSocketClientService . onSignedin ( ( user : TokenUser ) => {
@@ -1142,6 +1155,7 @@ export class UsersCtrl extends entitiesCtrl<TokenUser> {
11421155 this . userdata . data . UsersCtrl . orderby = this . orderby ;
11431156 this . userdata . data . UsersCtrl . searchstring = this . searchstring ;
11441157 this . userdata . data . UsersCtrl . basequeryas = this . basequeryas ;
1158+ this . userdata . data . UsersCtrl . skipcustomerfilter = this . skipcustomerfilter ;
11451159 this . loading = false ;
11461160 if ( ! this . $scope . $$phase ) { this . $scope . $apply ( ) ; }
11471161 }
@@ -1297,6 +1311,7 @@ export class RolesCtrl extends entitiesCtrl<Role> {
12971311 this . orderby = this . userdata . data . RolesCtrl . orderby ;
12981312 this . searchstring = this . userdata . data . RolesCtrl . searchstring ;
12991313 this . basequeryas = this . userdata . data . RolesCtrl . basequeryas ;
1314+ this . skipcustomerfilter = this . userdata . data . RolesCtrl . skipcustomerfilter ;
13001315 }
13011316 WebSocketClientService . onSignedin ( ( user : TokenUser ) => {
13021317 this . loadData ( ) ;
@@ -1310,6 +1325,7 @@ export class RolesCtrl extends entitiesCtrl<Role> {
13101325 this . userdata . data . RolesCtrl . orderby = this . orderby ;
13111326 this . userdata . data . RolesCtrl . searchstring = this . searchstring ;
13121327 this . userdata . data . RolesCtrl . basequeryas = this . basequeryas ;
1328+ this . userdata . data . RolesCtrl . skipcustomerfilter = this . skipcustomerfilter ;
13131329 if ( ! this . $scope . $$phase ) { this . $scope . $apply ( ) ; }
13141330 }
13151331}
@@ -4951,6 +4967,12 @@ export class CustomerCtrl extends entityCtrl<Customer> {
49514967 async processdata ( ) {
49524968 try {
49534969 // this.stripe_customer = await NoderedUtil.EnsureStripeCustomer(this.model, this.userid, null, 2);
4970+ if ( this . model != null ) {
4971+ if ( this . WebSocketClientService . user . selectedcustomerid != this . model . _id ) {
4972+ this . WebSocketClientService . user . selectedcustomerid = this . model . _id ;
4973+ this . $rootScope . $broadcast ( "menurefresh" ) ;
4974+ }
4975+ }
49544976
49554977 } catch ( error ) {
49564978
0 commit comments