- }
-
- /** Create project @public */
- public createProject(): void {
- this.isLoadingResults = true;
- const apiURLHeader: APIURLHEADER = {
- url: environment.PROJECTS_URL
- };
- const projectPayload: {} = {
- name: this.projectForm.value.project_name,
- domain_name: !isNullOrUndefined(this.projectForm.value.domain_name) ? this.projectForm.value.domain_name : undefined
- };
- this.restService.postResource(apiURLHeader, projectPayload).subscribe(() => {
- this.activeModal.close(this.modalData);
- this.isLoadingResults = false;
- this.notifierService.notify('success', this.translateService.instant('PAGE.PROJECT.CREATEDSUCCESSFULLY'));
- }, (error: ERRORDATA) => {
- this.restService.handleError(error, 'post');
- this.isLoadingResults = false;
- });
- }
- /** Edit project @public */
- public editProject(): void {
- this.isLoadingResults = true;
- const apiURLHeader: APIURLHEADER = {
- url: environment.PROJECTS_URL + '/' + this.projectRef
- };
- this.restService.patchResource(apiURLHeader, { name: this.projectForm.value.project_name }).subscribe(() => {
- this.activeModal.close(this.modalData);
- this.isLoadingResults = false;
- this.projectService.setHeaderProjects();
- this.notifierService.notify('success', this.translateService.instant('PAGE.PROJECT.UPDATEDSUCCESSFULLY'));
- }, (error: ERRORDATA) => {
- this.restService.handleError(error, 'patch');
- this.isLoadingResults = false;
- });
- }
- /** Get domain name @private */
- private getDomainName(): void {
- this.restService.getResource(environment.DOMAIN_URL).subscribe((domains: { project_domain_name: string, user_domain_name: string }) => {
- let domainNames: string[] = [];
- if (!isNullOrUndefined(domains.project_domain_name)) {
- domainNames = domainNames.concat(domains.project_domain_name.split(','));
- }
- if (!isNullOrUndefined(domains.user_domain_name)) {
- domainNames = domainNames.concat(domains.user_domain_name.split(','));
- }
- domainNames = Array.from(new Set(domainNames));
- this.checkDomainNames(domainNames);
- this.isLoadingResults = false;
- }, (error: ERRORDATA) => {
- this.restService.handleError(error, 'get');
- this.isLoadingResults = false;
- });
- }
-
- /** Check the domain names and create modal for domain select @private */
- private checkDomainNames(domainNames: string[]): void {
- if (domainNames.length > 0) {
- domainNames.forEach((domainName: string) => {
- if (!domainName.endsWith(':ro')) {
- this.domains.push({ id: domainName, text: domainName });
+ /** Handle enable quota limit checkbox event @public */
+ public checkQuota(): void {
+ if (this.getFormControl('enable_quota').value) {
+ this.quotaItems.forEach((quotaItem: QUOTAITEM): void => {
+ this.projectForm.addControl(quotaItem.value, new FormControl(''));
+ });
+ } else {
+ this.quotaItems.forEach((quotaItem: QUOTAITEM): void => {
+ this.getFormControl(quotaItem.value).setValue('');
+ });
+ }
+ }
+ /** Edit project @public */
+ public editProject(): void {
+ this.isLoadingResults = true;
+ const apiURLHeader: APIURLHEADER = {
+ url: environment.PROJECTS_URL + '/' + this.projectRef
+ };
+ const projectPayload: ProjectDetails = {
+ name: this.projectForm.value.project_name
+ };
+ this.addQuotaLimit(projectPayload);
+ this.restService.patchResource(apiURLHeader, projectPayload).subscribe((): void => {
+ this.activeModal.close(this.modalData);
+ this.isLoadingResults = false;
+ this.projectService.setHeaderProjects();
+ this.notifierService.notify('success', this.translateService.instant('PAGE.PROJECT.UPDATEDSUCCESSFULLY'));
+ }, (error: ERRORDATA): void => {
+ this.restService.handleError(error, 'patch');
+ this.isLoadingResults = false;
+ });
+ }
+ /** Get domain name list @private */
+ private getDomainList(): void {
+ this.isLoadingResults = true;
+ this.sharedService.getDomainName().subscribe((domainList: TYPESECTION[]): void => {
+ this.domains = domainList;
+ this.isLoadingResults = false;
+ }, (error: ERRORDATA): void => {
+ this.isLoadingResults = false;
+ this.restService.handleError(error, 'get');
+ });
+ }
+
+ /** Used to get the AbstractControl of controlName passed @private */
+ private getFormControl(controlName: string): AbstractControl {
+ return this.projectForm.controls[controlName];
+ }
+
+ /** Add quota information to payload @private */
+ private addQuotaLimit(payload: ProjectDetails): void {
+ if (this.getFormControl('enable_quota').value) {
+ payload.quotas = {};
+ this.quotaItems.forEach((quotaItem: QUOTAITEM): void => {
+ if (this.getFormControl(quotaItem.value).value !== '') {
+ payload.quotas[quotaItem.value] = this.getFormControl(quotaItem.value).value;
+ }
+ });
+ if (Object.keys(payload.quotas).length === 0) {
+ delete payload.quotas;
+ }
+ }
+ }
+
+ /** Set quota information in project form model @private */
+ private patchQuotaInfo(quotaRef?: {}): void {
+ if (quotaRef !== null && this.getProjectType === 'Edit') {
+ this.getFormControl('enable_quota').setValue(true);
+ this.quotaItems.forEach((quotaItem: QUOTAITEM): void => {
+ if (!isNullOrUndefined(quotaRef[quotaItem.value])) {
+ this.projectForm.addControl(quotaItem.value, new FormControl(quotaRef[quotaItem.value],
+ [Validators.max(quotaItem.maxValue)]));
+ } else {
+ this.projectForm.addControl(quotaItem.value, new FormControl('', [Validators.max(quotaItem.maxValue)]));
+ }
+ });
+ } else {
+ this.quotaItems.forEach((quotaItem: QUOTAITEM): void => {
+ this.projectForm.addControl(quotaItem.value, new FormControl('', [Validators.min(quotaItem.minValue),
+ Validators.max(quotaItem.maxValue)]));
+ });