Skip to content

Commit 1481018

Browse files
authored
fix: Replaced reset buttons with cancel button (#284)
1 parent 441ffdb commit 1481018

10 files changed

Lines changed: 81 additions & 105 deletions

File tree

‎src/app/main/dialog/dialog.component.html‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@
148148
<div *ngSwitchCase="'editListInfo'">
149149
<app-dialog-header [title]="data.title" [subtitle]="'Edit list info'" (close)="dialogRef.close()">
150150
</app-dialog-header>
151-
<app-list-info-form [iri]="data.id" [projectIri]="data.project"></app-list-info-form>
151+
<app-list-info-form [iri]="data.id" [projectIri]="data.project" (closeDialog)="dialogRef.close()"></app-list-info-form>
152152
</div>
153153

154154
<!-- Delete list -->

‎src/app/project/list/list-info-form/list-info-form.component.html‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<dsp-progress-indicator *ngIf="loading"></dsp-progress-indicator>
44

55
<!-- success message after updating -->
6-
<dsp-message *ngIf="success" [message]="successMessage" [short]="true" (click)="closeMessage()"></dsp-message>
6+
<dsp-message *ngIf="success" [message]="successMessage" [short]="true"></dsp-message>
77

88
<div *ngIf="!loading && !createList" class="form-content list-info">
99

@@ -24,8 +24,8 @@
2424

2525
<div class="form-panel form-action">
2626
<span>
27-
<button mat-button type="button" (click)="resetForm($event, list)">
28-
{{ 'appLabels.form.action.reset' | translate }}
27+
<button mat-button type="button" (click)="closeDialog.emit(list)">
28+
{{ 'appLabels.form.action.cancel' | translate }}
2929
</button>
3030
</span>
3131
<span class="fill-remaining-space"></span>

‎src/app/project/list/list-info-form/list-info-form.component.ts‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,4 @@ export class ListInfoFormComponent implements OnInit {
227227
break;
228228
}
229229
}
230-
231-
closeMessage() {
232-
this.closeDialog.emit(this.list);
233-
}
234-
235230
}

‎src/app/project/ontology/source-type-form/source-type-form.component.html‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<div class="no-shadow" *ngIf="!errorMessage; else errorMsg">
22

33
<!-- success message after updating -->
4-
<dsp-message *ngIf="success" [message]="successMessage" [short]="true" (click)="closeMessage()"></dsp-message>
4+
<dsp-message *ngIf="success" [message]="successMessage" [short]="true"></dsp-message>
55

66
<!-- content: Step 1 = define resource type -->
77
<form [formGroup]="sourceTypeForm" class="form-content">
@@ -37,7 +37,7 @@
3737
<!-- action buttons -->
3838
<div class="form-panel form-action">
3939
<span>
40-
<button mat-button type="button" (click)="closeMessage()">
40+
<button mat-button type="button" (click)="closeDialog.emit()">
4141
{{ 'appLabels.form.action.cancel' | translate }}
4242
</button>
4343
</span>

‎src/app/project/ontology/source-type-form/source-type-form.component.ts‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -562,9 +562,6 @@ export class SourceTypeFormComponent implements OnInit, OnDestroy, AfterViewChec
562562
);
563563
564564
*/
565-
566-
// show message to close dialog box
567-
// this.closeMessage();
568565
}
569566
/**
570567
* Convert cardinality values (multiple? & required?) from form to string 1-0, 0-n, 1, 0-1

‎src/app/project/project-form/project-form.component.html‎

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<dsp-progress-indicator *ngIf="loading"></dsp-progress-indicator>
44

55
<!-- success message after updating -->
6-
<dsp-message *ngIf="success" [message]="successMessage" [short]="true" (click)="closeMessage()"></dsp-message>
6+
<dsp-message *ngIf="success" [message]="successMessage" [short]="true"></dsp-message>
77

88
<!-- content -->
99
<form *ngIf="!loading && project.status" [formGroup]="form" class="form-content project-data"
@@ -39,7 +39,7 @@
3939

4040
<!-- description -->
4141
<dsp-string-literal-input placeholder="{{'appLabels.form.project.general.description' | translate}} *"
42-
[disabled]="project.id !== undefined && !project.status" [textarea]="true" [value]="project.description"
42+
[disabled]="!project.status" [textarea]="true" [value]="project.description"
4343
(dataChanged)="getStringLiteral($event)">
4444
</dsp-string-literal-input>
4545
<mat-hint class="string-literal-error" *ngIf="formErrors.description">
@@ -80,12 +80,6 @@
8080
[matChipInputSeparatorKeyCodes]="separatorKeyCodes" [matChipInputAddOnBlur]="addOnBlur"
8181
(matChipInputTokenEnd)="addKeyword($event)" />
8282
</mat-chip-list>
83-
84-
<!--
85-
<mat-hint *ngIf="formErrors.keywords">
86-
{{ formErrors.keywords }}
87-
</mat-hint>
88-
-->
8983
</mat-form-field>
9084

9185
<!-- upload logo -->
@@ -102,10 +96,9 @@
10296

10397
<div class="form-panel form-action">
10498
<span>
105-
<button mat-button type="reset" (click)="resetForm($event, project)">
106-
{{ 'appLabels.form.action.reset' | translate }}
99+
<button mat-button type="reset" (click)="closeDialog.emit()">
100+
{{ 'appLabels.form.action.cancel' | translate }}
107101
</button>
108-
109102
</span>
110103
<span class="fill-remaining-space"></span>
111104
<span>

‎src/app/project/project-form/project-form.component.ts‎

Lines changed: 65 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,25 @@ import { CacheService } from '../../main/cache/cache.service';
1414
})
1515
export class ProjectFormComponent implements OnInit {
1616

17-
loading: boolean = true;
18-
19-
errorMessage: any;
20-
21-
@Input() projectcode: string;
17+
/**
18+
* Param of project form component:
19+
* Optional projectcode; if exists we are in edit mode
20+
* otherwise we build empty form to create new project
21+
*/
22+
@Input() projectcode?: string;
2223

24+
/**
25+
* Output of project form component:
26+
* emits info to parent that dialog box was closed
27+
*/
2328
@Output() closeDialog: EventEmitter<any> = new EventEmitter<any>();
2429

2530
project: ReadProject;
31+
description: StringLiteral[];
32+
33+
loading = true;
34+
35+
errorMessage: any;
2636

2737
// is the logged-in user system admin?
2838
sysAdmin: boolean = false;
@@ -40,7 +50,6 @@ export class ProjectFormComponent implements OnInit {
4050
];
4151
shortcodeRegex = /^[0-9A-Fa-f]+$/;
4252

43-
description: StringLiteral[];
4453
/**
4554
* some restrictions and rules for
4655
* description, shortcode, shortname and keywords
@@ -84,8 +93,7 @@ export class ProjectFormComponent implements OnInit {
8493
'longname': '',
8594
'shortcode': '',
8695
'description': ''
87-
// 'institution': '',
88-
// 'keywords': '',
96+
// 'institution': ''
8997
};
9098

9199
validationMessages = {
@@ -110,10 +118,7 @@ export class ProjectFormComponent implements OnInit {
110118
'required': 'A description is required.',
111119
'maxlength': 'Description cannot be more than ' + this.descriptionMaxLength + ' characters long.'
112120
}
113-
// 'institution': {},
114-
// 'keywords': {
115-
// 'required': 'At least one keyword is required.'
116-
// }
121+
// 'institution': {}
117122
};
118123

119124
constructor(
@@ -126,11 +131,30 @@ export class ProjectFormComponent implements OnInit {
126131

127132
ngOnInit() {
128133

129-
// get a list of all projects and create an array of the short names, but only in "create new" mode
130-
// the short name should be unique and with the array list, we can prevent
131-
// to have the same short name; proof it with the ForbiddenName directive
132-
if (!this.projectcode) {
134+
// if projectcode exists, we are in edit mode
135+
// otherwise create new project
136+
if(this.projectcode) {
137+
// edit existing project
138+
// get origin project data first
139+
this._dspApiConnection.admin.projectsEndpoint.getProjectByShortcode(this.projectcode).subscribe(
140+
(response: ApiResponseData<ProjectResponse>) => {
141+
// save the origin project data in case of reset
142+
this.project = response.body.project;
143+
144+
this.buildForm(this.project);
145+
146+
this.loading = false;
147+
},
148+
(error: ApiResponseError) => {
149+
this.errorMessage = error;
150+
}
151+
);
152+
153+
} else {
133154
// create new project
155+
156+
// to avoid dublicate shortcodes or shortnames
157+
// we have to create a list of already exisiting short codes and names
134158
this._dspApiConnection.admin.projectsEndpoint.getProjects().subscribe(
135159
(response: ApiResponseData<ProjectsResponse>) => {
136160

@@ -149,58 +173,43 @@ export class ProjectFormComponent implements OnInit {
149173
}
150174
);
151175

152-
if (this.project === undefined) {
153-
this.project = new ReadProject();
154-
this.project.status = true;
155-
}
176+
this.project = new ReadProject();
177+
this.project.status = true;
156178

157179
this.buildForm(this.project);
158180

159181
this.loading = false;
160182

161-
} else {
162-
// edit mode
163-
this.sysAdmin = this._session.getSession().user.sysAdmin;
164-
this._dspApiConnection.admin.projectsEndpoint.getProjectByShortcode(this.projectcode).subscribe(
165-
(response: ApiResponseData<ProjectResponse>) => {
166-
this.project = response.body.project;
167-
168-
this.buildForm(this.project);
169-
170-
this.loading = false;
171-
},
172-
(error: ApiResponseError) => {
173-
this.errorMessage = error;
174-
}
175-
);
176183
}
177184
}
178185

179186
/**
187+
* Build form with project data
188+
* Project data contains exising data (edit mode)
189+
* or no data (create mode) => new ReadProject()
180190
*
181-
* @param project Project data: "empty" means "create new project",
182-
* but if there are project data, it means edit mode
191+
* @param project
183192
*/
184193
buildForm(project: ReadProject): void {
185194
// if project is defined, we're in the edit mode
186195
// otherwise "create new project" mode is active
187-
// edit mode is true, when a project id (iri) exists
188-
const editMode: boolean = (!!project.id);
196+
// edit mode is true, when a projectcode exists
197+
198+
// disabled is true, if project status is false (= archived);
199+
const disabled: boolean = (!project.status);
189200

190-
if (!editMode) {
201+
// separate description
202+
if (!this.projectcode) {
191203
this.description = [new StringLiteral()];
192204
this.formErrors['description'] = '';
193205
}
194206

195-
// disabled is true, if project status is false (= archived);
196-
const disabled: boolean = (project.id !== undefined && !project.status);
197-
198207
// separate list of keywords
199208
this.keywords = project.keywords;
200209

201210
this.form = this._fb.group({
202211
'shortname': new FormControl({
203-
value: project.shortname, disabled: editMode
212+
value: project.shortname, disabled: (this.projectcode)
204213
}, [
205214
Validators.required,
206215
Validators.minLength(this.shortnameMinLength),
@@ -214,42 +223,33 @@ export class ProjectFormComponent implements OnInit {
214223
Validators.required
215224
]),
216225
'shortcode': new FormControl({
217-
value: project.shortcode, disabled: (editMode && project.shortcode !== null)
226+
value: project.shortcode, disabled: ((this.projectcode) && project.shortcode !== null)
218227
}, [
219228
Validators.required,
220229
Validators.minLength(this.shortcodeMinLength),
221230
Validators.maxLength(this.shortcodeMaxLength),
222231
existingNamesValidator(this.existingShortcodes),
223232
Validators.pattern(this.shortcodeRegex)
224233
]),
225-
// 'description': new FormControl({
226-
// value: project.description,
227-
// disabled: disabled
228-
// }, [
229-
// Validators.maxLength(this.descriptionMaxLength),
230-
// Validators.required
231-
// ]),
232-
// 'institution': new FormControl({
233-
// value: project.institution, disabled: disabled
234-
// }),
235234
'logo': new FormControl({
236235
value: project.logo, disabled: disabled
237236
}),
238237
'status': [true],
239238
'selfjoin': [false],
240239
'keywords': new FormControl({
240+
// must be empty (even in edit mode), because of the mat-chip-list
241241
value: [], disabled: disabled
242-
}) // must be empty (even in edit mode), because of the mat-chip-list
242+
})
243243
});
244244

245245
this.form.valueChanges
246246
.subscribe(data => this.onValueChanged(data));
247247
}
248248

249249
/**
250+
* This method is for the form error handling
250251
*
251252
* @param data Data which changed.
252-
* This method is for the form error handling
253253
*/
254254
onValueChanged(data?: any) {
255255

@@ -272,9 +272,12 @@ export class ProjectFormComponent implements OnInit {
272272
});
273273
}
274274

275+
/**
276+
* Gets string literal
277+
* @param data
278+
*/
275279
getStringLiteral(data: StringLiteral[]) {
276280
this.description = data;
277-
278281
if (!this.description.length) {
279282
this.formErrors['description'] = this.validationMessages['description'].required;
280283
} else {
@@ -302,7 +305,6 @@ export class ProjectFormComponent implements OnInit {
302305
}
303306

304307
removeKeyword(keyword: any): void {
305-
306308
const index = this.keywords.indexOf(keyword);
307309

308310
if (index >= 0) {
@@ -349,6 +351,7 @@ export class ProjectFormComponent implements OnInit {
349351
this._dspApiConnection.admin.projectsEndpoint.updateProject(this.project.id, projectData).subscribe(
350352
(response: ApiResponseData<ProjectResponse>) => {
351353

354+
// this.originProject = response.body.project;
352355
this.project = response.body.project;
353356
this.buildForm(this.project);
354357

@@ -359,13 +362,6 @@ export class ProjectFormComponent implements OnInit {
359362

360363
this.loading = false;
361364

362-
// redirect to project page
363-
/*
364-
this._router.navigateByUrl('/project', {skipLocationChange: true}).then(() =>
365-
this._router.navigate(['/project/' + this.form.controls['shortcode'].value])
366-
);
367-
*/
368-
369365
},
370366
(error: ApiResponseError) => {
371367
this.errorMessage = error;
@@ -406,7 +402,7 @@ export class ProjectFormComponent implements OnInit {
406402
(response: ApiResponseData<UserResponse>) => {
407403

408404
this.loading = false;
409-
this.closeMessage();
405+
this.closeDialog.emit();
410406
// redirect to (new) project page
411407
this._router.navigateByUrl('/project', { skipLocationChange: true }).then(() =>
412408
this._router.navigate(['/project/' + this.form.controls['shortcode'].value])
@@ -519,6 +515,8 @@ export class ProjectFormComponent implements OnInit {
519515
}
520516

521517
/**
518+
* @deprecated Maybe we can reactivate later.
519+
*
522520
* Reset the form
523521
*/
524522
resetForm(ev: Event, project?: ReadProject) {
@@ -533,7 +531,4 @@ export class ProjectFormComponent implements OnInit {
533531
// this.form.controls['keywords'].setValue(this.keywords);
534532
}
535533

536-
closeMessage() {
537-
this.closeDialog.emit();
538-
}
539534
}

0 commit comments

Comments
 (0)