- }
- /** Fetching the projects information @public */
- public getProjects(): void {
- this.isLoadingResults = true;
- this.restService.getResource(environment.PROJECTS_URL).subscribe((projectsData: ProjectData[]) => {
- this.projects = projectsData;
- this.getRoles();
- }, (error: ERRORDATA) => {
- this.isLoadingResults = false;
- this.restService.handleError(error, 'get');
- });
- }
-
- /** Fetching the Roles information @public */
- public getRoles(): void {
- this.restService.getResource(environment.ROLES_URL).subscribe((rolesData: RoleData[]) => {
- this.roles = rolesData;
- this.isLoadingResults = false;
- }, (error: ERRORDATA) => {
- this.isLoadingResults = false;
- this.restService.handleError(error, 'get');
- });
- }
-
- /** Set all roles and project values to the form @public */
- public loadMapping(): void {
- this.userDetails.project_role_mappings.forEach((data: ProjectRoleMappings) => {
- // tslint:disable-next-line:no-backbone-get-set-outside-model
- this.projectRoleFormArray = this.projectRoleForm.get('project_role_mappings') as FormArray;
- this.projectRoleFormArray.push(this.projectRoleParamsBuilder);
- });
- this.projectRoleForm.patchValue(this.userDetails);
- }
-
- /** Remove project and roles from the list @public */
- public removeMapping(index: number): void {
- this.projectRoleFormArray.removeAt(index);
- }
-
- /** Submit project and roles @public */
- public addProjectRole(): void {
- this.submitted = true;
- const modalData: MODALCLOSERESPONSEDATA = {
- message: 'Done'
- };
- if (this.projectRoleForm.invalid) { return; }
- const apiURLHeader: APIURLHEADER = {
- url: environment.USERS_URL + '/' + this.userID
- };
- this.projectRoleMap.project_role_mappings = [];
- this.projectRoleForm.value.project_role_mappings.forEach((res: ProjectRoleMappings) => {
- this.projectRoleMap.project_role_mappings.push({ project: res.project_name, role: res.role_name });
- });
- if (this.projectRoleMap.project_role_mappings.length !== 0) {
- this.isLoadingResults = true;
- this.restService.patchResource(apiURLHeader, this.projectRoleMap).subscribe((result: {}) => {
- this.isLoadingResults = false;
- this.activeModal.close(modalData);
- this.projectService.setHeaderProjects();
- this.notifierService.notify('success', this.translateService.instant('PAGE.USERS.EDITEDSUCCESSFULLY'));
- }, (error: ERRORDATA) => {
- this.isLoadingResults = false;
- this.restService.handleError(error, 'patch');
- });
- } else {
- this.notifierService.notify('error', this.translateService.instant('PAGE.USERS.EDITPROJECTROLEERROR'));
+
+ /** convenience getter for easy access to form fields */
+ get f(): FormGroup['controls'] { return this.projectRoleForm.controls; }
+
+ /** Lifecyle Hooks the trigger before component is instantiate @public */
+ public ngOnInit(): void {
+ this.headers = new HttpHeaders({
+ 'Content-Type': 'application/json',
+ Accept: 'application/json',
+ 'Cache-Control': 'no-cache, no-store, must-revalidate, max-age=0'
+ });
+ this.initializeForm();
+ this.getProjects();
+ this.generateData();
+ }
+
+ /** Initializing Form Action @public */
+ public initializeForm(): void {
+ this.projectRoleForm = this.formBuilder.group({
+ project_role_mappings: this.formBuilder.array([])
+ });
+ }
+
+ /** Handle FormArray Controls @public */
+ public getControls(): AbstractControl[] {
+ // tslint:disable-next-line:no-backbone-get-set-outside-model
+ return (this.projectRoleForm.get('project_role_mappings') as FormArray).controls;
+ }
+
+ /** Fetching the data from server to Load in the smarttable @public */
+ public generateData(): void {
+ if (this.userID !== '') {
+ this.isLoadingResults = true;
+ this.restService.getResource(environment.USERS_URL + '/' + this.userID).subscribe((userDetails: UserDetail): void => {
+ this.userDetails = userDetails;
+ this.loadMapping();
+ this.isLoadingResults = false;
+ }, (error: ERRORDATA): void => {
+ this.isLoadingResults = false;
+ this.restService.handleError(error, 'get');
+ });
+ }
+ }
+ /** Fetching the projects information @public */
+ public getProjects(): void {
+ this.isLoadingResults = true;
+ this.restService.getResource(environment.PROJECTS_URL).subscribe((projectsData: ProjectData[]): void => {
+ this.projects = projectsData;
+ this.getRoles();
+ }, (error: ERRORDATA): void => {
+ this.isLoadingResults = false;
+ this.restService.handleError(error, 'get');
+ });
+ }
+
+ /** Fetching the Roles information @public */
+ public getRoles(): void {
+ this.restService.getResource(environment.ROLES_URL).subscribe((rolesData: RoleData[]): void => {
+ this.roles = rolesData;
+ this.isLoadingResults = false;
+ }, (error: ERRORDATA): void => {
+ this.isLoadingResults = false;
+ this.restService.handleError(error, 'get');
+ });
+ }
+
+ /** Set all roles and project values to the form @public */
+ public loadMapping(): void {
+ this.userDetails.project_role_mappings.forEach((data: ProjectRoleMappings): void => {
+ // tslint:disable-next-line:no-backbone-get-set-outside-model
+ this.projectRoleFormArray = this.projectRoleForm.get('project_role_mappings') as FormArray;
+ this.projectRoleFormArray.push(this.projectRoleParamsBuilder);
+ });
+ this.projectRoleForm.patchValue(this.userDetails);
+ }
+
+ /** Remove project and roles from the list @public */
+ public removeMapping(index: number): void {
+ this.projectRoleFormArray.removeAt(index);
+ }
+
+ /** Submit project and roles @public */
+ public addProjectRole(): void {
+ this.submitted = true;
+ const modalData: MODALCLOSERESPONSEDATA = {
+ message: 'Done'
+ };
+ if (this.projectRoleForm.invalid) { return; }
+ const apiURLHeader: APIURLHEADER = {
+ url: environment.USERS_URL + '/' + this.userID
+ };
+ this.projectRoleMap.project_role_mappings = [];
+ this.projectRoleForm.value.project_role_mappings.forEach((res: ProjectRoleMappings): void => {
+ this.projectRoleMap.project_role_mappings.push({ project: res.project_name, role: res.role_name });
+ });
+ if (this.projectRoleMap.project_role_mappings.length !== 0) {
+ this.isLoadingResults = true;
+ this.restService.patchResource(apiURLHeader, this.projectRoleMap).subscribe((result: {}): void => {
+ this.isLoadingResults = false;
+ this.activeModal.close(modalData);
+ this.projectService.setHeaderProjects();
+ this.notifierService.notify('success', this.translateService.instant('PAGE.USERS.EDITEDSUCCESSFULLY'));
+ }, (error: ERRORDATA): void => {
+ this.isLoadingResults = false;
+ this.restService.handleError(error, 'patch');
+ });
+ } else {
+ this.notifierService.notify('error', this.translateService.instant('PAGE.USERS.EDITPROJECTROLEERROR'));
+ }
+ }
+
+ /** Add extra mapping and set empty project and roles @public */
+ public addMapping(): void {
+ // tslint:disable-next-line:no-backbone-get-set-outside-model
+ this.projectRoleFormArray = this.projectRoleForm.get('project_role_mappings') as FormArray;
+ this.projectRoleFormArray.push(this.projectRoleParamsBuilder);
+ }
+
+ /** Remove project and roles for the user @public */
+ public deleteProjectAndRoleMapping(getProjectRoles: ProjectRoleMappings): void {
+ const modalData: MODALCLOSERESPONSEDATA = {
+ message: 'Done'
+ };
+ const removeProjectRole: UserRoleMap = { remove_project_role_mappings: [] };
+ removeProjectRole.remove_project_role_mappings = [{ project: getProjectRoles.project_name, role: getProjectRoles.role_name }];
+ const apiURLHeader: APIURLHEADER = {
+ url: environment.USERS_URL + '/' + this.userID
+ };
+ this.isLoadingResults = true;
+ this.restService.patchResource(apiURLHeader, removeProjectRole).subscribe((result: {}): void => {
+ this.isLoadingResults = false;
+ this.activeModal.close(modalData);
+ this.projectService.setHeaderProjects();
+ this.notifierService.notify('success', this.translateService.instant('PAGE.USERS.EDITEDSUCCESSFULLY'));
+ }, (error: ERRORDATA): void => {
+ this.isLoadingResults = false;
+ this.restService.handleError(error, 'patch');
+ });