diff --git a/src/app/main/dialog/dialog.component.html b/src/app/main/dialog/dialog.component.html index d6780e7180..7188015ea2 100644 --- a/src/app/main/dialog/dialog.component.html +++ b/src/app/main/dialog/dialog.component.html @@ -148,7 +148,7 @@
- +
diff --git a/src/app/project/list/list-info-form/list-info-form.component.html b/src/app/project/list/list-info-form/list-info-form.component.html index cef31512d0..d3bb55f624 100644 --- a/src/app/project/list/list-info-form/list-info-form.component.html +++ b/src/app/project/list/list-info-form/list-info-form.component.html @@ -3,7 +3,7 @@ - +
@@ -24,8 +24,8 @@
- diff --git a/src/app/project/list/list-info-form/list-info-form.component.ts b/src/app/project/list/list-info-form/list-info-form.component.ts index ae6a00123d..1008321757 100644 --- a/src/app/project/list/list-info-form/list-info-form.component.ts +++ b/src/app/project/list/list-info-form/list-info-form.component.ts @@ -227,9 +227,4 @@ export class ListInfoFormComponent implements OnInit { break; } } - - closeMessage() { - this.closeDialog.emit(this.list); - } - } diff --git a/src/app/project/ontology/source-type-form/source-type-form.component.html b/src/app/project/ontology/source-type-form/source-type-form.component.html index 9ebdf227a0..aacd346278 100644 --- a/src/app/project/ontology/source-type-form/source-type-form.component.html +++ b/src/app/project/ontology/source-type-form/source-type-form.component.html @@ -1,7 +1,7 @@
- +
@@ -37,7 +37,7 @@
- diff --git a/src/app/project/ontology/source-type-form/source-type-form.component.ts b/src/app/project/ontology/source-type-form/source-type-form.component.ts index b188579c0d..658b1a09f3 100644 --- a/src/app/project/ontology/source-type-form/source-type-form.component.ts +++ b/src/app/project/ontology/source-type-form/source-type-form.component.ts @@ -562,9 +562,6 @@ export class SourceTypeFormComponent implements OnInit, OnDestroy, AfterViewChec ); */ - - // show message to close dialog box - // this.closeMessage(); } /** * Convert cardinality values (multiple? & required?) from form to string 1-0, 0-n, 1, 0-1 diff --git a/src/app/project/project-form/project-form.component.html b/src/app/project/project-form/project-form.component.html index 4c291b7671..0eef8b6494 100644 --- a/src/app/project/project-form/project-form.component.html +++ b/src/app/project/project-form/project-form.component.html @@ -3,7 +3,7 @@ - + @@ -80,12 +80,6 @@ [matChipInputSeparatorKeyCodes]="separatorKeyCodes" [matChipInputAddOnBlur]="addOnBlur" (matChipInputTokenEnd)="addKeyword($event)" /> - - @@ -102,10 +96,9 @@
- - diff --git a/src/app/project/project-form/project-form.component.ts b/src/app/project/project-form/project-form.component.ts index 4a3d06c5b2..a25bfd32d2 100644 --- a/src/app/project/project-form/project-form.component.ts +++ b/src/app/project/project-form/project-form.component.ts @@ -14,15 +14,25 @@ import { CacheService } from '../../main/cache/cache.service'; }) export class ProjectFormComponent implements OnInit { - loading: boolean = true; - - errorMessage: any; - - @Input() projectcode: string; + /** + * Param of project form component: + * Optional projectcode; if exists we are in edit mode + * otherwise we build empty form to create new project + */ + @Input() projectcode?: string; + /** + * Output of project form component: + * emits info to parent that dialog box was closed + */ @Output() closeDialog: EventEmitter = new EventEmitter(); project: ReadProject; + description: StringLiteral[]; + + loading = true; + + errorMessage: any; // is the logged-in user system admin? sysAdmin: boolean = false; @@ -40,7 +50,6 @@ export class ProjectFormComponent implements OnInit { ]; shortcodeRegex = /^[0-9A-Fa-f]+$/; - description: StringLiteral[]; /** * some restrictions and rules for * description, shortcode, shortname and keywords @@ -84,8 +93,7 @@ export class ProjectFormComponent implements OnInit { 'longname': '', 'shortcode': '', 'description': '' - // 'institution': '', - // 'keywords': '', + // 'institution': '' }; validationMessages = { @@ -110,10 +118,7 @@ export class ProjectFormComponent implements OnInit { 'required': 'A description is required.', 'maxlength': 'Description cannot be more than ' + this.descriptionMaxLength + ' characters long.' } - // 'institution': {}, - // 'keywords': { - // 'required': 'At least one keyword is required.' - // } + // 'institution': {} }; constructor( @@ -126,11 +131,30 @@ export class ProjectFormComponent implements OnInit { ngOnInit() { - // get a list of all projects and create an array of the short names, but only in "create new" mode - // the short name should be unique and with the array list, we can prevent - // to have the same short name; proof it with the ForbiddenName directive - if (!this.projectcode) { + // if projectcode exists, we are in edit mode + // otherwise create new project + if(this.projectcode) { + // edit existing project + // get origin project data first + this._dspApiConnection.admin.projectsEndpoint.getProjectByShortcode(this.projectcode).subscribe( + (response: ApiResponseData) => { + // save the origin project data in case of reset + this.project = response.body.project; + + this.buildForm(this.project); + + this.loading = false; + }, + (error: ApiResponseError) => { + this.errorMessage = error; + } + ); + + } else { // create new project + + // to avoid dublicate shortcodes or shortnames + // we have to create a list of already exisiting short codes and names this._dspApiConnection.admin.projectsEndpoint.getProjects().subscribe( (response: ApiResponseData) => { @@ -149,58 +173,43 @@ export class ProjectFormComponent implements OnInit { } ); - if (this.project === undefined) { - this.project = new ReadProject(); - this.project.status = true; - } + this.project = new ReadProject(); + this.project.status = true; this.buildForm(this.project); this.loading = false; - } else { - // edit mode - this.sysAdmin = this._session.getSession().user.sysAdmin; - this._dspApiConnection.admin.projectsEndpoint.getProjectByShortcode(this.projectcode).subscribe( - (response: ApiResponseData) => { - this.project = response.body.project; - - this.buildForm(this.project); - - this.loading = false; - }, - (error: ApiResponseError) => { - this.errorMessage = error; - } - ); } } /** + * Build form with project data + * Project data contains exising data (edit mode) + * or no data (create mode) => new ReadProject() * - * @param project Project data: "empty" means "create new project", - * but if there are project data, it means edit mode + * @param project */ buildForm(project: ReadProject): void { // if project is defined, we're in the edit mode // otherwise "create new project" mode is active - // edit mode is true, when a project id (iri) exists - const editMode: boolean = (!!project.id); + // edit mode is true, when a projectcode exists + + // disabled is true, if project status is false (= archived); + const disabled: boolean = (!project.status); - if (!editMode) { + // separate description + if (!this.projectcode) { this.description = [new StringLiteral()]; this.formErrors['description'] = ''; } - // disabled is true, if project status is false (= archived); - const disabled: boolean = (project.id !== undefined && !project.status); - // separate list of keywords this.keywords = project.keywords; this.form = this._fb.group({ 'shortname': new FormControl({ - value: project.shortname, disabled: editMode + value: project.shortname, disabled: (this.projectcode) }, [ Validators.required, Validators.minLength(this.shortnameMinLength), @@ -214,7 +223,7 @@ export class ProjectFormComponent implements OnInit { Validators.required ]), 'shortcode': new FormControl({ - value: project.shortcode, disabled: (editMode && project.shortcode !== null) + value: project.shortcode, disabled: ((this.projectcode) && project.shortcode !== null) }, [ Validators.required, Validators.minLength(this.shortcodeMinLength), @@ -222,24 +231,15 @@ export class ProjectFormComponent implements OnInit { existingNamesValidator(this.existingShortcodes), Validators.pattern(this.shortcodeRegex) ]), - // 'description': new FormControl({ - // value: project.description, - // disabled: disabled - // }, [ - // Validators.maxLength(this.descriptionMaxLength), - // Validators.required - // ]), - // 'institution': new FormControl({ - // value: project.institution, disabled: disabled - // }), 'logo': new FormControl({ value: project.logo, disabled: disabled }), 'status': [true], 'selfjoin': [false], 'keywords': new FormControl({ + // must be empty (even in edit mode), because of the mat-chip-list value: [], disabled: disabled - }) // must be empty (even in edit mode), because of the mat-chip-list + }) }); this.form.valueChanges @@ -247,9 +247,9 @@ export class ProjectFormComponent implements OnInit { } /** + * This method is for the form error handling * * @param data Data which changed. - * This method is for the form error handling */ onValueChanged(data?: any) { @@ -272,9 +272,12 @@ export class ProjectFormComponent implements OnInit { }); } + /** + * Gets string literal + * @param data + */ getStringLiteral(data: StringLiteral[]) { this.description = data; - if (!this.description.length) { this.formErrors['description'] = this.validationMessages['description'].required; } else { @@ -302,7 +305,6 @@ export class ProjectFormComponent implements OnInit { } removeKeyword(keyword: any): void { - const index = this.keywords.indexOf(keyword); if (index >= 0) { @@ -349,6 +351,7 @@ export class ProjectFormComponent implements OnInit { this._dspApiConnection.admin.projectsEndpoint.updateProject(this.project.id, projectData).subscribe( (response: ApiResponseData) => { + // this.originProject = response.body.project; this.project = response.body.project; this.buildForm(this.project); @@ -359,13 +362,6 @@ export class ProjectFormComponent implements OnInit { this.loading = false; - // redirect to project page - /* - this._router.navigateByUrl('/project', {skipLocationChange: true}).then(() => - this._router.navigate(['/project/' + this.form.controls['shortcode'].value]) - ); - */ - }, (error: ApiResponseError) => { this.errorMessage = error; @@ -406,7 +402,7 @@ export class ProjectFormComponent implements OnInit { (response: ApiResponseData) => { this.loading = false; - this.closeMessage(); + this.closeDialog.emit(); // redirect to (new) project page this._router.navigateByUrl('/project', { skipLocationChange: true }).then(() => this._router.navigate(['/project/' + this.form.controls['shortcode'].value]) @@ -519,6 +515,8 @@ export class ProjectFormComponent implements OnInit { } /** + * @deprecated Maybe we can reactivate later. + * * Reset the form */ resetForm(ev: Event, project?: ReadProject) { @@ -533,7 +531,4 @@ export class ProjectFormComponent implements OnInit { // this.form.controls['keywords'].setValue(this.keywords); } - closeMessage() { - this.closeDialog.emit(); - } } diff --git a/src/app/user/user-form/password-form/password-form.component.html b/src/app/user/user-form/password-form/password-form.component.html index 8ed3e9ca97..28550768f1 100644 --- a/src/app/user/user-form/password-form/password-form.component.html +++ b/src/app/user/user-form/password-form/password-form.component.html @@ -125,5 +125,5 @@

As system admin, please enter your password before - + diff --git a/src/app/user/user-form/user-form.component.html b/src/app/user/user-form/user-form.component.html index 65db236589..5d055515a7 100644 --- a/src/app/user/user-form/user-form.component.html +++ b/src/app/user/user-form/user-form.component.html @@ -3,7 +3,7 @@ - + @@ -75,10 +75,9 @@
- - diff --git a/src/app/user/user-form/user-form.component.ts b/src/app/user/user-form/user-form.component.ts index cf21786cc5..2264db7a4d 100644 --- a/src/app/user/user-form/user-form.component.ts +++ b/src/app/user/user-form/user-form.component.ts @@ -422,7 +422,7 @@ export class UserFormComponent implements OnInit, OnChanges { // update project cache and member of project cache this._cache.get(this.projectcode, this._dspApiConnection.admin.projectsEndpoint.getProjectByShortcode(this.projectcode)); this._cache.get('members_of_' + this.projectcode, this._dspApiConnection.admin.projectsEndpoint.getProjectMembersByShortcode(this.projectcode)); - this.closeMessage(); + this.closeDialog.emit(this.user); this.loading = false; }, (error: any) => { @@ -435,7 +435,7 @@ export class UserFormComponent implements OnInit, OnChanges { } ); } else { - this.closeMessage(); + this.closeDialog.emit(this.user); this.loading = false; } }, @@ -458,7 +458,4 @@ export class UserFormComponent implements OnInit, OnChanges { this.buildForm(user); } - closeMessage() { - this.closeDialog.emit(this.user); - } }