diff --git a/libs/feature/editor/src/lib/components/contact-card/contact-card.component.html b/libs/feature/editor/src/lib/components/contact-card/contact-card.component.html index 849b22ef30..511e194a22 100644 --- a/libs/feature/editor/src/lib/components/contact-card/contact-card.component.html +++ b/libs/feature/editor/src/lib/components/contact-card/contact-card.component.html @@ -1,22 +1,28 @@ -
- -
-
- {{ contact.firstName }} {{ contact.lastName }} - - +
+
+ +
+
+ {{ contact.firstName }} {{ contact.lastName }} +
+
{{ contact.email }}
-
{{ contact.email }}
+ close +
diff --git a/libs/feature/editor/src/lib/components/contact-card/contact-card.component.ts b/libs/feature/editor/src/lib/components/contact-card/contact-card.component.ts index a178564f4b..494bed0ad9 100644 --- a/libs/feature/editor/src/lib/components/contact-card/contact-card.component.ts +++ b/libs/feature/editor/src/lib/components/contact-card/contact-card.component.ts @@ -24,6 +24,7 @@ import { ButtonComponent } from '@geonetwork-ui/ui/inputs' export class ContactCardComponent { @Input() contact: Individual @Input() organization: Organization + @Input() removable = true @Output() contactRemoved = new EventEmitter() removeContact(contact: Individual) { diff --git a/libs/feature/editor/src/lib/components/record-form/form-field/form-field-contacts-for-resource/form-field-contacts-for-resource.component.html b/libs/feature/editor/src/lib/components/record-form/form-field/form-field-contacts-for-resource/form-field-contacts-for-resource.component.html index 530521aa53..291b27bba4 100644 --- a/libs/feature/editor/src/lib/components/record-form/form-field/form-field-contacts-for-resource/form-field-contacts-for-resource.component.html +++ b/libs/feature/editor/src/lib/components/record-form/form-field/form-field-contacts-for-resource/form-field-contacts-for-resource.component.html @@ -16,7 +16,7 @@
- - - + + + + +
+ +
+ editor.record.form.field.contactsForResource.noContact +
+
diff --git a/libs/feature/editor/src/lib/components/record-form/form-field/form-field-contacts-for-resource/form-field-contacts-for-resource.component.ts b/libs/feature/editor/src/lib/components/record-form/form-field/form-field-contacts-for-resource/form-field-contacts-for-resource.component.ts index cf0d9df6b4..bfd2fdccf8 100644 --- a/libs/feature/editor/src/lib/components/record-form/form-field/form-field-contacts-for-resource/form-field-contacts-for-resource.component.ts +++ b/libs/feature/editor/src/lib/components/record-form/form-field/form-field-contacts-for-resource/form-field-contacts-for-resource.component.ts @@ -7,6 +7,7 @@ import { OnChanges, OnInit, SimpleChanges, + Type, } from '@angular/core' import { FormControl } from '@angular/forms' import { @@ -26,6 +27,10 @@ import { UserModel } from '@geonetwork-ui/common/domain/model/user' import { PlatformServiceInterface } from '@geonetwork-ui/common/domain/platform.service.interface' import { OrganizationsServiceInterface } from '@geonetwork-ui/common/domain/organizations.service.interface' import { ContactCardComponent } from '../../../contact-card/contact-card.component' +import { + DynamicElement, + SortableListComponent, +} from '@geonetwork-ui/ui/elements' @Component({ selector: 'gn-ui-form-field-contacts-for-resource', @@ -41,6 +46,7 @@ import { ContactCardComponent } from '../../../contact-card/contact-card.compone AutocompleteComponent, TranslateModule, ContactCardComponent, + SortableListComponent, ], }) export class FormFieldContactsForResourceComponent @@ -48,7 +54,7 @@ export class FormFieldContactsForResourceComponent { @Input() control: FormControl - allUser$: Observable + allUsers$: Observable rolesToPick: string[] = [ 'resource_provider', @@ -62,12 +68,14 @@ export class FormFieldContactsForResourceComponent allOrganizations: Map = new Map() + addOptions: Array<{ buttonLabel: string; eventName: string }> = [] + constructor( private platformServiceInterface: PlatformServiceInterface, private organizationsServiceInterface: OrganizationsServiceInterface, private changeDetectorRef: ChangeDetectorRef ) { - this.allUser$ = this.platformServiceInterface.getUsers() + this.allUsers$ = this.platformServiceInterface.getUsers() } ngOnInit(): void { @@ -81,7 +89,7 @@ export class FormFieldContactsForResourceComponent ) } - async ngOnChanges(changes: SimpleChanges): Promise { + ngOnChanges(changes: SimpleChanges) { const contactsForResource = changes['control'] if ( @@ -92,6 +100,8 @@ export class FormFieldContactsForResourceComponent (contact: Individual) => contact.role ) + console.log(contactsForResource.currentValue) + rolesToAdd.forEach((role: string) => { if (!this.rolesToDisplay.includes(role)) { this.rolesToDisplay.push(role) @@ -136,7 +146,7 @@ export class FormFieldContactsForResourceComponent * gn-ui-autocomplete */ autoCompleteAction = (query: string) => { - return this.allUser$.pipe( + return this.allUsers$.pipe( switchMap((users) => [ users.filter((user) => user.username.includes(query)), ]), @@ -148,8 +158,8 @@ export class FormFieldContactsForResourceComponent /** * gn-ui-autocomplete */ - async addContact(contact: UserModel, role: string) { - let newContactsforRessource = { + addContact(contact: UserModel, role: string) { + let newContactsForRessource = { firstName: contact.name ?? '', lastName: contact.surname ?? '', organization: { @@ -166,12 +176,12 @@ export class FormFieldContactsForResourceComponent contact.organisation ) - newContactsforRessource = { - ...newContactsforRessource, + newContactsForRessource = { + ...newContactsForRessource, organization: newContactOrganization, } - const newControlValue = [...this.control.value, newContactsforRessource] + const newControlValue = [...this.control.value, newContactsForRessource] this.control.setValue(newControlValue) } @@ -185,4 +195,26 @@ export class FormFieldContactsForResourceComponent getOrganizationByName(name: string): Organization { return this.allOrganizations.get(name) } + + getContactByRoleForSortableList(role: string): Array { + return this.control.value + .filter((contact: Individual) => { + return contact.role === role + }) + .map((contact) => ({ + component: ContactCardComponent, + inputs: { + contact, + organization: contact.organization, + removable: false, + }, + })) as Array<{ + component: Type + inputs: Record + }> + } + + handleContactOrderChange(event) { + console.log(event) + } } diff --git a/libs/feature/editor/src/lib/fields.config.ts b/libs/feature/editor/src/lib/fields.config.ts index 0f4373ddc6..549506ba31 100644 --- a/libs/feature/editor/src/lib/fields.config.ts +++ b/libs/feature/editor/src/lib/fields.config.ts @@ -86,7 +86,6 @@ export const RECORD_ABSTRACT_FIELD: EditorField = { export const CONTACTS_FOR_RESOURCE_FIELD: EditorField = { model: 'contactsForResource', formFieldConfig: { - // labelKey: marker('editor.record.form.field.contactsForResource') labelKey: '', }, } diff --git a/libs/ui/elements/src/lib/sortable-list/sortable-list.component.ts b/libs/ui/elements/src/lib/sortable-list/sortable-list.component.ts index 11acd5c480..fd318e1b68 100644 --- a/libs/ui/elements/src/lib/sortable-list/sortable-list.component.ts +++ b/libs/ui/elements/src/lib/sortable-list/sortable-list.component.ts @@ -17,7 +17,7 @@ import { import { MatIconModule } from '@angular/material/icon' import { ButtonComponent } from '@geonetwork-ui/ui/inputs' -type DynamicElement = { +export type DynamicElement = { component: Type inputs: Record } @@ -40,7 +40,7 @@ type DynamicElement = { }) export class SortableListComponent { @Input() elements: Array - @Input() addOptions: Array<{ buttonLabel: string; eventName: string }> + @Input() addOptions: Array<{ buttonLabel: string; eventName: string }> = [] @Output() elementsChange = new EventEmitter>() @Output() add = new EventEmitter() diff --git a/translations/de.json b/translations/de.json index edef9798c3..dd32408b75 100644 --- a/translations/de.json +++ b/translations/de.json @@ -176,6 +176,7 @@ "editor.record.form.bottomButtons.next": "", "editor.record.form.bottomButtons.previous": "", "editor.record.form.field.abstract": "Kurzbeschreibung", + "editor.record.form.field.contactsForResource.noContact": "", "editor.record.form.field.keywords": "Schlagwörter", "editor.record.form.field.license": "Lizenz", "editor.record.form.field.overviews": "", diff --git a/translations/en.json b/translations/en.json index b6d83f02f4..2f6f409919 100644 --- a/translations/en.json +++ b/translations/en.json @@ -176,6 +176,7 @@ "editor.record.form.bottomButtons.next": "Next", "editor.record.form.bottomButtons.previous": "Previous", "editor.record.form.field.abstract": "Abstract", + "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", "editor.record.form.field.overviews": "Overviews", diff --git a/translations/es.json b/translations/es.json index ed126ec958..5a712c1155 100644 --- a/translations/es.json +++ b/translations/es.json @@ -176,6 +176,7 @@ "editor.record.form.bottomButtons.next": "", "editor.record.form.bottomButtons.previous": "", "editor.record.form.field.abstract": "", + "editor.record.form.field.contactsForResource.noContact": "", "editor.record.form.field.keywords": "", "editor.record.form.field.license": "", "editor.record.form.field.overviews": "", diff --git a/translations/fr.json b/translations/fr.json index d7c5816956..1b39be8636 100644 --- a/translations/fr.json +++ b/translations/fr.json @@ -176,6 +176,7 @@ "editor.record.form.bottomButtons.next": "Suivant", "editor.record.form.bottomButtons.previous": "Précédent", "editor.record.form.field.abstract": "Résumé", + "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", "editor.record.form.field.overviews": "Aperçus", diff --git a/translations/it.json b/translations/it.json index 65bb116313..b5b631952d 100644 --- a/translations/it.json +++ b/translations/it.json @@ -176,6 +176,7 @@ "editor.record.form.bottomButtons.next": "", "editor.record.form.bottomButtons.previous": "", "editor.record.form.field.abstract": "", + "editor.record.form.field.contactsForResource.noContact": "", "editor.record.form.field.keywords": "", "editor.record.form.field.license": "Licenza", "editor.record.form.field.overviews": "", diff --git a/translations/nl.json b/translations/nl.json index 4e4c1bf9d4..7e4fd27abb 100644 --- a/translations/nl.json +++ b/translations/nl.json @@ -176,6 +176,7 @@ "editor.record.form.bottomButtons.next": "", "editor.record.form.bottomButtons.previous": "", "editor.record.form.field.abstract": "", + "editor.record.form.field.contactsForResource.noContact": "", "editor.record.form.field.keywords": "", "editor.record.form.field.license": "", "editor.record.form.field.overviews": "", diff --git a/translations/pt.json b/translations/pt.json index d1acccc992..5fc23d7184 100644 --- a/translations/pt.json +++ b/translations/pt.json @@ -176,6 +176,7 @@ "editor.record.form.bottomButtons.next": "", "editor.record.form.bottomButtons.previous": "", "editor.record.form.field.abstract": "", + "editor.record.form.field.contactsForResource.noContact": "", "editor.record.form.field.keywords": "", "editor.record.form.field.license": "", "editor.record.form.field.overviews": "", diff --git a/translations/sk.json b/translations/sk.json index 28683f7f52..dc34c2fd06 100644 --- a/translations/sk.json +++ b/translations/sk.json @@ -176,6 +176,7 @@ "editor.record.form.bottomButtons.next": "", "editor.record.form.bottomButtons.previous": "", "editor.record.form.field.abstract": "", + "editor.record.form.field.contactsForResource.noContact": "", "editor.record.form.field.keywords": "", "editor.record.form.field.license": "Licencia", "editor.record.form.field.overviews": "",