From 6c486001617abcca6a2610351b7b2b9132a67035 Mon Sep 17 00:00:00 2001 From: Romuald Caplier Date: Thu, 29 Aug 2024 10:39:04 +0200 Subject: [PATCH] wip --- .../form-field-contacts.component.html | 38 +---------- .../form-field-contacts.component.ts | 64 ++++++++----------- .../form-field/form-field.component.html | 11 ++-- .../form-field/form-field.component.ts | 45 ------------- translations/de.json | 1 + translations/en.json | 1 + translations/es.json | 1 + translations/fr.json | 1 + translations/it.json | 1 + translations/nl.json | 1 + translations/pt.json | 1 + translations/sk.json | 1 + 12 files changed, 42 insertions(+), 124 deletions(-) diff --git a/libs/feature/editor/src/lib/components/record-form/form-field/form-field-contacts/form-field-contacts.component.html b/libs/feature/editor/src/lib/components/record-form/form-field/form-field-contacts/form-field-contacts.component.html index 86db0afdf0..5bf1b7c49a 100644 --- a/libs/feature/editor/src/lib/components/record-form/form-field/form-field-contacts/form-field-contacts.component.html +++ b/libs/feature/editor/src/lib/components/record-form/form-field/form-field-contacts/form-field-contacts.component.html @@ -1,40 +1,4 @@
-
- - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - diff --git a/libs/feature/editor/src/lib/components/record-form/form-field/form-field-contacts/form-field-contacts.component.ts b/libs/feature/editor/src/lib/components/record-form/form-field/form-field-contacts/form-field-contacts.component.ts index 371379b611..ed75b78c66 100644 --- a/libs/feature/editor/src/lib/components/record-form/form-field/form-field-contacts/form-field-contacts.component.ts +++ b/libs/feature/editor/src/lib/components/record-form/form-field/form-field-contacts/form-field-contacts.component.ts @@ -3,13 +3,13 @@ import { ChangeDetectionStrategy, ChangeDetectorRef, Component, + EventEmitter, Input, OnChanges, OnDestroy, - OnInit, + Output, SimpleChanges, } from '@angular/core' -import { FormControl } from '@angular/forms' import { AutocompleteComponent, DropdownSelectorComponent, @@ -58,10 +58,9 @@ import { map } from 'rxjs/operators' SortableListComponent, ], }) -export class FormFieldContactsComponent - implements OnInit, OnDestroy, OnChanges -{ - @Input() control: FormControl +export class FormFieldContactsComponent implements OnDestroy, OnChanges { + @Input() value: Individual[] + @Output() valueChange: EventEmitter = new EventEmitter() contacts: Individual[] = [] contactsAsDynElem: DynamicElement[] = [] @@ -82,32 +81,31 @@ export class FormFieldContactsComponent this.allUsers$ = this.platformServiceInterface.getUsers() } - ngOnChanges(changes: SimpleChanges): void { - console.log(changes['control']) - } + async ngOnChanges(changes: SimpleChanges): Promise { + const contactsChanges = changes['value'] - async ngOnInit(): Promise { - this.allOrganizations = new Map( - ( - await firstValueFrom(this.organizationsServiceInterface.organisations$) - ).map((organization) => [organization.name, organization]) - ) + if (contactsChanges.firstChange) { + this.allOrganizations = new Map( + ( + await firstValueFrom( + this.organizationsServiceInterface.organisations$ + ) + ).map((organization) => [organization.name, organization]) + ) + } - this.updateContacts() + if (contactsChanges.currentValue !== contactsChanges.previousValue) { + const contacts = contactsChanges.currentValue + console.log(contacts) - this.changeDetectorRef.markForCheck() + this.updateContacts() - this.subscription.add( - this.control.valueChanges.subscribe((contacts) => { - console.log('new contacts (valueChange): ', contacts) - this.updateContacts() - this.changeDetectorRef.markForCheck() - }) - ) + this.changeDetectorRef.markForCheck() + } } updateContacts() { - this.contacts = this.control.value.reduce((acc, contact) => { + this.contacts = this.value.reduce((acc, contact) => { const completeOrganization = this.allOrganizations.get( contact.organization.name ) @@ -124,7 +122,7 @@ export class FormFieldContactsComponent return acc }, [] as Individual[]) - this.contactsAsDynElem = this.control.value.reduce((acc, contact) => { + this.contactsAsDynElem = this.value.reduce((acc, contact) => { const completeOrganization = this.allOrganizations.get( contact.organization.name ) @@ -152,18 +150,12 @@ export class FormFieldContactsComponent this.changeDetectorRef.markForCheck() } - removeContact() { - this.control.setValue([]) - } - handleContactsChanged(event: DynamicElement[]) { const newContactsOrdered = event.map( (contactAsDynElem) => contactAsDynElem.inputs['contact'] ) as Individual[] - console.log('newContactsOrdered :', newContactsOrdered) - - this.control.setValue(newContactsOrdered) + this.valueChange.emit(newContactsOrdered) } /** @@ -193,7 +185,7 @@ export class FormFieldContactsComponent * gn-ui-autocomplete */ addContact(contact: UserModel) { - const newContacts = { + const newContact = { firstName: contact.name ?? '', lastName: contact.surname ?? '', organization: @@ -206,9 +198,7 @@ export class FormFieldContactsComponent position: '', } as Individual - const newControlValue = [...this.control.value, newContacts] - - this.control.setValue(newControlValue) + this.valueChange.emit([...this.value, newContact]) } ngOnDestroy(): void { diff --git a/libs/feature/editor/src/lib/components/record-form/form-field/form-field.component.html b/libs/feature/editor/src/lib/components/record-form/form-field/form-field.component.html index 4a7a090ebb..81cb556900 100644 --- a/libs/feature/editor/src/lib/components/record-form/form-field/form-field.component.html +++ b/libs/feature/editor/src/lib/components/record-form/form-field/form-field.component.html @@ -115,10 +115,11 @@ (valueChange)="valueChange.emit($event)" > - - - + + + diff --git a/libs/feature/editor/src/lib/components/record-form/form-field/form-field.component.ts b/libs/feature/editor/src/lib/components/record-form/form-field/form-field.component.ts index 2c72a6406b..c4f383416f 100644 --- a/libs/feature/editor/src/lib/components/record-form/form-field/form-field.component.ts +++ b/libs/feature/editor/src/lib/components/record-form/form-field/form-field.component.ts @@ -87,51 +87,6 @@ export class FormFieldComponent { this.titleInput.nativeElement.children[0].focus() } - onVisibilityChange(visibility: boolean) { - this.isHidden = visibility - } - - get isTitle() { - return this.model === 'title' - } - get isAbstract() { - return this.model === 'abstract' - } - get isLicenses() { - return this.model === 'licenses' - } - get isResourceUpdated() { - return this.model === 'resourceUpdated' - } - get isUpdateFrequency() { - return this.model === 'updateFrequency' - } - get isTemporalExtents() { - return this.model === 'temporalExtents' - } - get isSpatialExtentField() { - return this.model === 'spatialExtents' - } - get isGraphicOverview() { - return this.model === 'overviews' - } - get isSimpleField() { - return this.model === 'uniqueIdentifier' || this.model === 'recordUpdated' - } - get isReadOnly() { - return this.model === 'uniqueIdentifier' || this.model === 'recordUpdated' - } - get isKeywords() { - return this.model === 'keywords' - } - get isContactsForResource() { - return this.model === 'contactsForResource' - } - - get isContacts() { - return this.model === 'contacts' - } - get withoutWrapper() { return ( this.model === 'title' || diff --git a/translations/de.json b/translations/de.json index c20fa1c966..9298db6b42 100644 --- a/translations/de.json +++ b/translations/de.json @@ -201,6 +201,7 @@ "editor.record.form.bottomButtons.previous": "", "editor.record.form.classification.opendata": "", "editor.record.form.field.abstract": "Kurzbeschreibung", + "editor.record.form.field.contacts.noContact": "", "editor.record.form.field.contactsForResource.noContact": "", "editor.record.form.field.keywords": "Schlagwörter", "editor.record.form.field.license": "Lizenz", diff --git a/translations/en.json b/translations/en.json index 4116250685..1b92726415 100644 --- a/translations/en.json +++ b/translations/en.json @@ -201,6 +201,7 @@ "editor.record.form.bottomButtons.previous": "Previous", "editor.record.form.classification.opendata": "Open Data", "editor.record.form.field.abstract": "Abstract", + "editor.record.form.field.contacts.noContact": "Please provide at least one point of contact.", "editor.record.form.field.contactsForResource.noContact": "Please provide at least one point of contact responsible for the data.", "editor.record.form.field.keywords": "Keywords", "editor.record.form.field.license": "License", diff --git a/translations/es.json b/translations/es.json index f7a021de9e..51a5e3db18 100644 --- a/translations/es.json +++ b/translations/es.json @@ -201,6 +201,7 @@ "editor.record.form.bottomButtons.previous": "", "editor.record.form.classification.opendata": "", "editor.record.form.field.abstract": "", + "editor.record.form.field.contacts.noContact": "", "editor.record.form.field.contactsForResource.noContact": "", "editor.record.form.field.keywords": "", "editor.record.form.field.license": "", diff --git a/translations/fr.json b/translations/fr.json index 516c31de84..533bb01187 100644 --- a/translations/fr.json +++ b/translations/fr.json @@ -201,6 +201,7 @@ "editor.record.form.bottomButtons.previous": "Précédent", "editor.record.form.classification.opendata": "Données ouvertes", "editor.record.form.field.abstract": "Résumé", + "editor.record.form.field.contacts.noContact": "Veuillez renseigner au moins un point de contact.", "editor.record.form.field.contactsForResource.noContact": "Veuillez renseigner au moins un point de contact responsable de la donnée.", "editor.record.form.field.keywords": "Mots-clés", "editor.record.form.field.license": "Licence", diff --git a/translations/it.json b/translations/it.json index 67fb2dabda..1debc3b110 100644 --- a/translations/it.json +++ b/translations/it.json @@ -201,6 +201,7 @@ "editor.record.form.bottomButtons.previous": "", "editor.record.form.classification.opendata": "", "editor.record.form.field.abstract": "", + "editor.record.form.field.contacts.noContact": "", "editor.record.form.field.contactsForResource.noContact": "", "editor.record.form.field.keywords": "", "editor.record.form.field.license": "Licenza", diff --git a/translations/nl.json b/translations/nl.json index c230ea1acf..e10fef019a 100644 --- a/translations/nl.json +++ b/translations/nl.json @@ -201,6 +201,7 @@ "editor.record.form.bottomButtons.previous": "", "editor.record.form.classification.opendata": "", "editor.record.form.field.abstract": "", + "editor.record.form.field.contacts.noContact": "", "editor.record.form.field.contactsForResource.noContact": "", "editor.record.form.field.keywords": "", "editor.record.form.field.license": "", diff --git a/translations/pt.json b/translations/pt.json index 12d0a7438b..1bb73bb5b0 100644 --- a/translations/pt.json +++ b/translations/pt.json @@ -201,6 +201,7 @@ "editor.record.form.bottomButtons.previous": "", "editor.record.form.classification.opendata": "", "editor.record.form.field.abstract": "", + "editor.record.form.field.contacts.noContact": "", "editor.record.form.field.contactsForResource.noContact": "", "editor.record.form.field.keywords": "", "editor.record.form.field.license": "", diff --git a/translations/sk.json b/translations/sk.json index 8ba003d5dc..05783419f3 100644 --- a/translations/sk.json +++ b/translations/sk.json @@ -201,6 +201,7 @@ "editor.record.form.bottomButtons.previous": "", "editor.record.form.classification.opendata": "", "editor.record.form.field.abstract": "", + "editor.record.form.field.contacts.noContact": "", "editor.record.form.field.contactsForResource.noContact": "", "editor.record.form.field.keywords": "", "editor.record.form.field.license": "Licencia",