rsanchez
2017-04-10 8d99c88af55041ff06e6b9372b6b1f66220bed38
securis/src/main/webapp/src/app/forms/user.form.component.ts
....@@ -29,12 +29,16 @@
2929 })
3030 export class UserFormComponent extends FormBase {
3131 allOrganizations: IComboOption[];
32
+ allApplications: IComboOption[];
3233 orgNames: string[] = [];
33
- allRoles: any[] = [{"id":1, "code": "advance", "label":"Advance"}, {"id":2, "code": "admin","label":"Admin"}];
34
+ appNames: string[] = [];
35
+ allRoles: any[] = [{"id":4, "code": "basic","label":"Basic"}, {"id":1, "code": "advance", "label":"Advance"}, {"id":2, "code": "admin","label":"Admin"}];
3436 user_orgs: string[] = [];
37
+ user_apps: string[] = [];
3538 user_roles: any = {};
3639 constructor(private http: Http,
3740 private users: UsersService,
41
+ private applications: ApplicationsService,
3842 private organizations: OrganizationsService,
3943 router: Router,
4044 toaster: ToastsManager,
....@@ -50,6 +54,10 @@
5054 this.user_orgs.forEach(orgName => {
5155 var selectedOrg = this.allOrganizations.find(org => org.label === orgName);
5256 this.data.organizations_ids.push(selectedOrg.id);
57
+ });
58
+ this.user_apps.forEach(appName => {
59
+ var selectedApp = this.allApplications.find(app => app.label === appName);
60
+ this.data.applications_ids.push(selectedApp.id);
5361 });
5462 this.user_roles.advance && this.data.roles.push(1);
5563 this.user_roles.admin && this.data.roles.push(2);
....@@ -71,6 +79,16 @@
7179 },
7280 err => console.error('Error loading organizations')
7381 );
82
+ this.applications.get()
83
+ .map(list => list.map((app : any) => <IComboOption>{id: app.id, label: app.name}))
84
+ .subscribe(
85
+ data => {
86
+ this.allApplications = (<IComboOption[]>data).sort((e1, e2) => e1.label.localeCompare(e2.label));
87
+ this.appNames = this.allApplications.map(org => org.label);
88
+ this._loadApps();
89
+ },
90
+ err => console.error('Error loading organizations')
91
+ );
7492 }
7593
7694 goBack(): void {
....@@ -84,6 +102,14 @@
84102 });
85103 }
86104 }
105
+ _loadApps() {
106
+ if (this.data && this.data.applications_ids && this.allApplications && this.allApplications.length > 0) {
107
+ this.data.applications_ids.forEach((appId : number) => {
108
+ var selectedApp = this.allApplications.find(app => app.id === appId);
109
+ this.user_apps.push(selectedApp.label);
110
+ });
111
+ }
112
+ }
87113 init() : void {
88114 this.loadCombos();
89115 this.user_orgs = [];
....@@ -92,6 +118,7 @@
92118 super.reset();
93119 super.prepareInitialData('username', {
94120 organizations_ids: [],
121
+ applications_ids: [],
95122 roles: []
96123 }, (data) => {
97124 this._loadOrgs();