| .. | .. |
|---|
| 29 | 29 | }) |
|---|
| 30 | 30 | export class UserFormComponent extends FormBase { |
|---|
| 31 | 31 | allOrganizations: IComboOption[]; |
|---|
| 32 | + allApplications: IComboOption[]; |
|---|
| 32 | 33 | 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"}]; |
|---|
| 34 | 36 | user_orgs: string[] = []; |
|---|
| 37 | + user_apps: string[] = []; |
|---|
| 35 | 38 | user_roles: any = {}; |
|---|
| 36 | 39 | constructor(private http: Http, |
|---|
| 37 | 40 | private users: UsersService, |
|---|
| 41 | + private applications: ApplicationsService, |
|---|
| 38 | 42 | private organizations: OrganizationsService, |
|---|
| 39 | 43 | router: Router, |
|---|
| 40 | 44 | toaster: ToastsManager, |
|---|
| .. | .. |
|---|
| 50 | 54 | this.user_orgs.forEach(orgName => { |
|---|
| 51 | 55 | var selectedOrg = this.allOrganizations.find(org => org.label === orgName); |
|---|
| 52 | 56 | 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); |
|---|
| 53 | 61 | }); |
|---|
| 54 | 62 | this.user_roles.advance && this.data.roles.push(1); |
|---|
| 55 | 63 | this.user_roles.admin && this.data.roles.push(2); |
|---|
| .. | .. |
|---|
| 71 | 79 | }, |
|---|
| 72 | 80 | err => console.error('Error loading organizations') |
|---|
| 73 | 81 | ); |
|---|
| 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 | + ); |
|---|
| 74 | 92 | } |
|---|
| 75 | 93 | |
|---|
| 76 | 94 | goBack(): void { |
|---|
| .. | .. |
|---|
| 84 | 102 | }); |
|---|
| 85 | 103 | } |
|---|
| 86 | 104 | } |
|---|
| 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 | + } |
|---|
| 87 | 113 | init() : void { |
|---|
| 88 | 114 | this.loadCombos(); |
|---|
| 89 | 115 | this.user_orgs = []; |
|---|
| .. | .. |
|---|
| 92 | 118 | super.reset(); |
|---|
| 93 | 119 | super.prepareInitialData('username', { |
|---|
| 94 | 120 | organizations_ids: [], |
|---|
| 121 | + applications_ids: [], |
|---|
| 95 | 122 | roles: [] |
|---|
| 96 | 123 | }, (data) => { |
|---|
| 97 | 124 | this._loadOrgs(); |
|---|