From 4cf13df0abe718932339090e9db1e0c7aaf73754 Mon Sep 17 00:00:00 2001 From: "michele.artini" Date: Mon, 30 Jan 2023 14:58:42 +0100 Subject: [PATCH] partial implementatiom of add/edit vocabulary term --- .../src/app/vocabularies/voc-term-dialog.html | 78 ++++++++++++++++++- .../vocabularies/vocabularies.component.ts | 30 ++++++- .../vocabulary-editor.component.html | 37 +++++---- 3 files changed, 124 insertions(+), 21 deletions(-) diff --git a/frontends/dnet-is-application/src/app/vocabularies/voc-term-dialog.html b/frontends/dnet-is-application/src/app/vocabularies/voc-term-dialog.html index fc06c97f..708cce10 100644 --- a/frontends/dnet-is-application/src/app/vocabularies/voc-term-dialog.html +++ b/frontends/dnet-is-application/src/app/vocabularies/voc-term-dialog.html @@ -1 +1,77 @@ -XXXXXX +
+

Edit term

+

New term

+ +
+ + Code + + This field is required + + + + Name + + This field is required + + + + Encoding + + + + *** TO COMPLETE *** + + + + + + + + + + + + + + + + + + + + + + + + + +
SynonymEncoding
0 synonym(s)
{{s.term}}{{s.encoding}} + +
+ + New term + + + + + New encoding + + + + +
+ + +
+ +
+ + + + {{ termForm.errors?.['serverError'] }} + +
+ +
\ No newline at end of file diff --git a/frontends/dnet-is-application/src/app/vocabularies/vocabularies.component.ts b/frontends/dnet-is-application/src/app/vocabularies/vocabularies.component.ts index ee4410fc..22621aa0 100644 --- a/frontends/dnet-is-application/src/app/vocabularies/vocabularies.component.ts +++ b/frontends/dnet-is-application/src/app/vocabularies/vocabularies.component.ts @@ -2,7 +2,7 @@ import { Component, Inject, AfterViewInit, OnInit, ViewChild } from '@angular/co import { ISService } from '../is.service'; import { MatTableDataSource } from '@angular/material/table'; import { MatSort, Sort } from '@angular/material/sort'; -import { Vocabulary } from '../model/controller.model'; +import { Vocabulary, VocabularyTermSynonym } from '../model/controller.model'; import { ActivatedRoute, Params } from '@angular/router'; import { Observable, combineLatest } from 'rxjs'; import { map } from 'rxjs/operators'; @@ -113,7 +113,7 @@ export class VocabularyEditorComponent implements OnInit, AfterViewInit { newVocabularyTermDialog(): void { if (this.voc?.id) { const dialogRef = this.dialog.open(VocTermDialog, { - data: { vocabulary: this.voc.id, code: '', name: '', encoding: '', synonyms: []}, + data: { vocabulary: this.voc.id, code: '', name: '', encoding: 'OPENAIRE', synonyms: []}, width: '80%' }); @@ -179,21 +179,43 @@ export class VocDialog { styleUrls: ['vocabularies.component.css'] }) export class VocTermDialog { + termForm = new FormGroup({ code: new FormControl(''), name: new FormControl(''), encoding: new FormControl('') }); + synonyms:VocabularyTermSynonym[] = []; + tmpSynonym:VocabularyTermSynonym = { term: '', encoding: 'OPENAIRE' }; + constructor(public dialogRef: MatDialogRef, @Inject(MAT_DIALOG_DATA) public data: any, public service: ISService) { - this.termForm.get('code')?.setValue(data.id); + this.termForm.get('code')?.setValue(data.code); this.termForm.get('name')?.setValue(data.name); this.termForm.get('encoding')?.setValue(data.encoding); + this.synonyms = data.synonyms; } onSubmit(): void { + let oldCode = this.data.code; + let voc = this.data.vocabulary; + const term = Object.assign({}, this.data, this.termForm.value); - this.service.saveVocabularyTerm(term.vocabulary, term, (data: void) => this.dialogRef.close(1), this.termForm); + + this.service.saveVocabularyTerm(voc, term, (data: void) => { + if (oldCode && oldCode != term.code) { + this.service.deleteVocabularyTerm(voc, oldCode, (data: void) => this.dialogRef.close(1)) + } else { this.dialogRef.close(1) } + }, this.termForm); + } + + removeSynonym(pos:number) { + this.synonyms.splice(pos, 1); + } + + addSynonym() { + this.synonyms.push(Object.assign({}, this.tmpSynonym)); + this.tmpSynonym = { term: '', encoding: 'OPENAIRE' }; } onNoClick(): void { diff --git a/frontends/dnet-is-application/src/app/vocabularies/vocabulary-editor.component.html b/frontends/dnet-is-application/src/app/vocabularies/vocabulary-editor.component.html index 918b70dc..c921898a 100644 --- a/frontends/dnet-is-application/src/app/vocabularies/vocabulary-editor.component.html +++ b/frontends/dnet-is-application/src/app/vocabularies/vocabulary-editor.component.html @@ -1,15 +1,15 @@

Vocabulary Editor

- Vocabulary ID: {{voc?.id}}
- Vocabulary Name: {{voc?.name}}
- Description: {{voc?.description}} + Vocabulary ID: {{voc?.id}}
+ Vocabulary Name: {{voc?.name}}
+ Description: {{voc?.description}}

- return to vocabulary list - - Download + return to vocabulary list + + Download

@@ -20,34 +20,39 @@ - + - + - + - + @@ -58,4 +63,4 @@ -
Code Code + {{element.code}} Name Name + {{element.name}} Encoding + Encoding {{element.encoding}} Description + Description - - {{s.term}} - + 0 synonym(s) + + {{s.term}} + - - + +
No data matching the filter "{{input.value}}"
+ \ No newline at end of file