Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Romuald Caplier committed Aug 29, 2024
1 parent bc969b6 commit 6c48600
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 124 deletions.
Original file line number Diff line number Diff line change
@@ -1,40 +1,4 @@
<div class="flex flex-col gap-3">
<div class="flex flex-row flex-wrap gap-2" data-test="rolesToPick">
<!-- <ng-container *ngFor="let role of rolesToPick">-->
<!-- <gn-ui-button-->
<!-- extraClass="px-2 py-1.5"-->
<!-- (buttonClick)="addRoleToDisplay(role)"-->
<!-- >-->
<!-- <div class="flex flex-row gap-1 items-center">-->
<!-- <span class="text-primary text-[20px] leading-[0] font-bold pb-[5px]"-->
<!-- >&#8330;</span-->
<!-- >-->
<!-- <span class="font-bold" translate>{{ roleToLabel(role) }}</span>-->
<!-- </div>-->
<!-- </gn-ui-button>-->
<!-- </ng-container>-->
</div>
<!-- <div-->
<!-- class="mt-8"-->
<!-- *ngIf="-->
<!-- roleSectionsToDisplay && roleSectionsToDisplay.length > 0;-->
<!-- else noContact-->
<!-- "-->
<!-- >-->
<!-- <div-->
<!-- *ngFor="-->
<!-- let role of roleSectionsToDisplay;-->
<!-- let index = index;-->
<!-- let isLast = last-->
<!-- "-->
<!-- class="flex flex-col gap-4"-->
<!-- >-->
<!-- <div class="flex flex-row justify-between">-->
<!-- <span class="font-bold text-base" translate>{{-->
<!-- roleToLabel(role)-->
<!-- }}</span>-->
<!-- </div>-->

<gn-ui-autocomplete
[placeholder]="'Choose a contact'"
[action]="autoCompleteAction"
Expand All @@ -49,7 +13,7 @@
<ng-container *ngFor="let contact of contacts; let index = index">
<gn-ui-contact-card
[contact]="contact"
(contactRemoved)="removeContact()"
[removable]="false"
></gn-ui-contact-card> </ng-container
></ng-container>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -58,10 +58,9 @@ import { map } from 'rxjs/operators'
SortableListComponent,
],
})
export class FormFieldContactsComponent
implements OnInit, OnDestroy, OnChanges
{
@Input() control: FormControl<Individual[]>
export class FormFieldContactsComponent implements OnDestroy, OnChanges {
@Input() value: Individual[]
@Output() valueChange: EventEmitter<Individual[]> = new EventEmitter()

contacts: Individual[] = []
contactsAsDynElem: DynamicElement[] = []
Expand All @@ -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<void> {
const contactsChanges = changes['value']

async ngOnInit(): Promise<void> {
this.allOrganizations = new Map<string, Organization>(
(
await firstValueFrom(this.organizationsServiceInterface.organisations$)
).map((organization) => [organization.name, organization])
)
if (contactsChanges.firstChange) {
this.allOrganizations = new Map<string, Organization>(
(
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
)
Expand All @@ -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
)
Expand Down Expand Up @@ -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)
}

/**
Expand Down Expand Up @@ -193,7 +185,7 @@ export class FormFieldContactsComponent
* gn-ui-autocomplete
*/
addContact(contact: UserModel) {
const newContacts = {
const newContact = {
firstName: contact.name ?? '',
lastName: contact.surname ?? '',
organization:
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,11 @@
(valueChange)="valueChange.emit($event)"
></gn-ui-form-field-contacts-for-resource>
</ng-container>
</ng-container>
<ng-container *ngIf="isContacts">
<gn-ui-form-field-contacts
[control]="formControl"
></gn-ui-form-field-contacts>
<ng-container *ngSwitchCase="'contacts'">
<gn-ui-form-field-contacts
[value]="valueAsIndividuals"
(valueChange)="valueChange.emit($event)"
></gn-ui-form-field-contacts>
</ng-container>
</ng-container>
</ng-template>
Original file line number Diff line number Diff line change
Expand Up @@ -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' ||
Expand Down
1 change: 1 addition & 0 deletions translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions translations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "",
Expand Down
1 change: 1 addition & 0 deletions translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions translations/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions translations/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "",
Expand Down
1 change: 1 addition & 0 deletions translations/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "",
Expand Down
1 change: 1 addition & 0 deletions translations/sk.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 6c48600

Please sign in to comment.