-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #951 from geonetwork/me-record-field-contacts-for-…
…resource EDITOR - Record field: Contacts for resource
- Loading branch information
Showing
29 changed files
with
1,080 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 4 additions & 1 deletion
5
apps/metadata-editor/src/app/edit/components/page-selector/page-selector.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
25 changes: 25 additions & 0 deletions
25
libs/feature/editor/src/lib/components/contact-card/contact-card.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<div class="flex flex-row gap-4 items-center"> | ||
<div class="flex flex-row border border-gray-200 rounded-xl p-4 gap-4 w-full"> | ||
<gn-ui-thumbnail | ||
class="w-[56px] h-[56px] rounded-[4px]" | ||
[thumbnailUrl]="contact.organization.logoUrl?.href" | ||
[fit]="'contain'" | ||
></gn-ui-thumbnail> | ||
<div class="flex flex-col w-full"> | ||
<div class="flex flex-row justify-between"> | ||
<span class="flex flex-wrap font-bold w-full" | ||
>{{ contact.firstName }} {{ contact.lastName }}</span | ||
> | ||
</div> | ||
<div>{{ contact.email }}</div> | ||
</div> | ||
</div> | ||
<gn-ui-button | ||
*ngIf="removable" | ||
data-test="removeContactButton" | ||
type="light" | ||
extraClass="w-[20px] h-[20px] flex items-center justify-center" | ||
(buttonClick)="removeContact(contact)" | ||
><span class="material-symbols-outlined"> close </span> | ||
</gn-ui-button> | ||
</div> |
61 changes: 61 additions & 0 deletions
61
libs/feature/editor/src/lib/components/contact-card/contact-card.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing' | ||
import { ContactCardComponent } from './contact-card.component' | ||
import { | ||
Individual, | ||
Organization, | ||
} from '@geonetwork-ui/common/domain/model/record' | ||
import { MatIconModule } from '@angular/material/icon' | ||
import { CommonModule } from '@angular/common' | ||
import { | ||
AutocompleteComponent, | ||
ButtonComponent, | ||
} from '@geonetwork-ui/ui/inputs' | ||
import { ChangeDetectionStrategy } from '@angular/core' | ||
|
||
describe('ContactCardComponent', () => { | ||
let component: ContactCardComponent | ||
let fixture: ComponentFixture<ContactCardComponent> | ||
|
||
const mockContact: Individual = { | ||
firstName: 'John', | ||
lastName: 'Doe', | ||
organization: { name: 'Org1' } as Organization, | ||
email: '[email protected]', | ||
role: 'admin', | ||
address: '', | ||
phone: '', | ||
position: '', | ||
} | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [ | ||
CommonModule, | ||
MatIconModule, | ||
ButtonComponent, | ||
ContactCardComponent, | ||
], | ||
}) | ||
.overrideComponent(AutocompleteComponent, { | ||
set: { changeDetection: ChangeDetectionStrategy.Default }, | ||
}) | ||
.compileComponents() | ||
}) | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(ContactCardComponent) | ||
component = fixture.componentInstance | ||
component.contact = mockContact | ||
fixture.detectChanges() | ||
}) | ||
|
||
it('should create the component', () => { | ||
expect(component).toBeTruthy() | ||
}) | ||
|
||
it('should emit contactRemoved event with the correct contact', () => { | ||
const contactRemovedSpy = jest.spyOn(component.contactRemoved, 'emit') | ||
component.removeContact(mockContact) | ||
expect(contactRemovedSpy).toHaveBeenCalledWith(mockContact) | ||
}) | ||
}) |
54 changes: 54 additions & 0 deletions
54
libs/feature/editor/src/lib/components/contact-card/contact-card.component.stories.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { | ||
applicationConfig, | ||
componentWrapperDecorator, | ||
Meta, | ||
moduleMetadata, | ||
StoryObj, | ||
} from '@storybook/angular' | ||
import { ContactCardComponent } from './contact-card.component' | ||
import { BrowserAnimationsModule } from '@angular/platform-browser/animations' | ||
import { importProvidersFrom } from '@angular/core' | ||
import { MatIconModule } from '@angular/material/icon' | ||
import { CommonModule } from '@angular/common' | ||
import { ButtonComponent } from '@geonetwork-ui/ui/inputs' | ||
|
||
export default { | ||
title: 'Elements/ContactCardComponent', | ||
component: ContactCardComponent, | ||
decorators: [ | ||
moduleMetadata({ | ||
imports: [ | ||
CommonModule, | ||
MatIconModule, | ||
ButtonComponent, | ||
ContactCardComponent, | ||
], | ||
}), | ||
applicationConfig({ | ||
providers: [importProvidersFrom(BrowserAnimationsModule)], | ||
}), | ||
componentWrapperDecorator( | ||
(story) => `<div style="max-width: 400px; margin: auto;">${story}</div>` | ||
), | ||
], | ||
} as Meta<ContactCardComponent> | ||
|
||
export const Primary: StoryObj<ContactCardComponent> = { | ||
args: { | ||
contact: { | ||
firstName: 'John', | ||
lastName: 'Doe', | ||
organization: { | ||
name: 'Example Organization', | ||
}, | ||
email: '[email protected]', | ||
role: 'Developer', | ||
address: '123 Main St', | ||
phone: '123-456-7890', | ||
position: 'Senior Developer', | ||
}, | ||
organization: { | ||
name: 'Example Organization', | ||
}, | ||
}, | ||
} |
30 changes: 30 additions & 0 deletions
30
libs/feature/editor/src/lib/components/contact-card/contact-card.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { | ||
ChangeDetectionStrategy, | ||
Component, | ||
EventEmitter, | ||
Input, | ||
Output, | ||
} from '@angular/core' | ||
import { Individual } from '@geonetwork-ui/common/domain/model/record' | ||
import { MatIconModule } from '@angular/material/icon' | ||
import { CommonModule } from '@angular/common' | ||
import { ButtonComponent } from '@geonetwork-ui/ui/inputs' | ||
import { ThumbnailComponent } from '@geonetwork-ui/ui/elements' | ||
|
||
@Component({ | ||
selector: 'gn-ui-contact-card', | ||
templateUrl: './contact-card.component.html', | ||
styleUrls: ['./contact-card.component.css'], | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
standalone: true, | ||
imports: [CommonModule, MatIconModule, ButtonComponent, ThumbnailComponent], | ||
}) | ||
export class ContactCardComponent { | ||
@Input() contact: Individual | ||
@Input() removable = true | ||
@Output() contactRemoved = new EventEmitter<Individual>() | ||
|
||
removeContact(contact: Individual) { | ||
this.contactRemoved.emit(contact) | ||
} | ||
} |
Empty file.
76 changes: 76 additions & 0 deletions
76
...rm-field/form-field-contacts-for-resource/form-field-contacts-for-resource.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<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]" | ||
>₊</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 | ||
" | ||
data-test="displayedRoles" | ||
> | ||
<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" | ||
(itemSelected)="addContact($event, role)" | ||
[displayWithFn]="displayWithFn" | ||
[minCharacterCount]="1" | ||
[clearOnSelection]="true" | ||
> | ||
</gn-ui-autocomplete> | ||
|
||
<ng-container *ngIf="contactsForRessourceByRole.get(role) as contacts"> | ||
<ng-container *ngIf="contacts.length > 1"> | ||
<gn-ui-sortable-list | ||
[elements]="contactsAsDynElemByRole.get(role)" | ||
(elementsChange)="handleContactsChanged($event)" | ||
></gn-ui-sortable-list> | ||
</ng-container> | ||
<ng-container *ngIf="contacts.length === 1"> | ||
<ng-container *ngFor="let contact of contacts"> | ||
<gn-ui-contact-card | ||
[contact]="contact" | ||
(contactRemoved)="removeContact(index)" | ||
></gn-ui-contact-card> </ng-container | ||
></ng-container> | ||
</ng-container> | ||
|
||
<hr class="border-t-[#D6D3D1] mt-4 mb-6" *ngIf="!isLast" /> | ||
</div> | ||
</div> | ||
<ng-template #noContact> | ||
<div | ||
class="p-4 border border-primary bg-primary-lightest rounded-lg" | ||
translate | ||
> | ||
editor.record.form.field.contactsForResource.noContact | ||
</div> | ||
</ng-template> | ||
</div> |
Oops, something went wrong.