Added name variant dialog

This commit is contained in:
lotte
2019-11-14 16:00:48 +01:00
parent 4a7c7a61f1
commit c2ae71b1b8
9 changed files with 126 additions and 17 deletions

View File

@@ -786,6 +786,9 @@
"submission.sections.describe.relationship-lookup.selection-tab.title.Journal": "Selected Journals",
"submission.sections.describe.relationship-lookup.selection-tab.title.Journal Volume": "Selected Journal Volume",
"submission.sections.describe.relationship-lookup.selection-tab.title.Journal Issue": "Selected Issue",
"submission.sections.describe.relationship-lookup.name-variant.notification.content": "Would you like to save \"{{ value }}\" as a name variant for this person so you and others can reuse it for future submissions? If you don\'t you can still use it for this submission.",
"submission.sections.describe.relationship-lookup.name-variant.notification.confirm": "Save a new name variant",
"submission.sections.describe.relationship-lookup.name-variant.notification.decline": "Use only for this submission",
"submission.sections.general.add-more": "Add more",
"submission.sections.general.collection": "Collection",
"submission.sections.general.deposit_error_notice": "There was an issue when submitting the item, please try again later.",

View File

@@ -99,13 +99,13 @@ export class ObjectCacheService {
getObjectBySelfLink<T extends CacheableObject>(selfLink: string): Observable<NormalizedObject<T>> {
return this.getBySelfLink(selfLink).pipe(
map((entry: ObjectCacheEntry) => {
// if (isNotEmpty(entry.patches)) {
// const flatPatch: Operation[] = [].concat(...entry.patches.map((patch) => patch.operations));
// const patchedData = applyPatch(entry.data, flatPatch, undefined, false).newDocument;
// return Object.assign({}, entry, { data: patchedData });
// } else {
if (isNotEmpty(entry.patches)) {
const flatPatch: Operation[] = [].concat(...entry.patches.map((patch) => patch.operations));
const patchedData = applyPatch(entry.data, flatPatch, undefined, false).newDocument;
return Object.assign({}, entry, { data: patchedData });
} else {
return entry;
// }
}
}
),
map((entry: ObjectCacheEntry) => {

View File

@@ -22,6 +22,7 @@ import { PersonItemMetadataListElementComponent } from './metadata-representatio
import { OrgUnitItemMetadataListElementComponent } from './metadata-representations/org-unit/org-unit-item-metadata-list-element.component';
import { PersonSearchResultListSubmissionElementComponent } from './submission/item-list-elements/person/person-search-result-list-submission-element.component';
import { PersonInputSuggestionsComponent } from './submission/item-list-elements/person/person-suggestions/person-input-suggestions.component';
import { NameVariantModalComponent } from './submission/item-list-elements/person/name-variant-modal/name-variant-modal.component';
const ENTRY_COMPONENTS = [
OrgUnitComponent,
@@ -42,7 +43,8 @@ const ENTRY_COMPONENTS = [
OrgUnitSearchResultGridElementComponent,
ProjectSearchResultGridElementComponent,
PersonSearchResultListSubmissionElementComponent,
PersonInputSuggestionsComponent
PersonInputSuggestionsComponent,
NameVariantModalComponent
];
@NgModule({
@@ -53,7 +55,7 @@ const ENTRY_COMPONENTS = [
ItemPageModule
],
declarations: [
...ENTRY_COMPONENTS
...ENTRY_COMPONENTS,
],
entryComponents: [
...ENTRY_COMPONENTS

View File

@@ -0,0 +1,13 @@
<div class="modal-header">
<h4 class="modal-title">New name variant</h4>
<button type="button" class="close" aria-label="Close" (click)="modal.dismiss('Cross click')">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
{{'submission.sections.describe.relationship-lookup.name-variant.notification.content' | translate: { value: value } }}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-light" (click)="modal.close()">{{'submission.sections.describe.relationship-lookup.name-variant.notification.confirm' | translate }}</button>
<button type="button" class="btn btn-light" (click)="modal.dismiss()">{{'submission.sections.describe.relationship-lookup.name-variant.notification.decline' | translate }}</button>
</div>

View File

@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { NameVariantModalComponent } from './name-variant-modal.component';
describe('NameVariantModalComponent', () => {
let component: NameVariantModalComponent;
let fixture: ComponentFixture<NameVariantModalComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ NameVariantModalComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(NameVariantModalComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@@ -0,0 +1,20 @@
import { Component, Input, OnInit } from '@angular/core';
import { NgbActiveModal, NgbModal } from '@ng-bootstrap/ng-bootstrap';
@Component({
selector: 'name-variant-modal',
templateUrl: './name-variant-modal.component.html',
styleUrls: ['./name-variant-modal.component.scss']
})
export class NameVariantModalComponent implements OnInit {
@Input() value: string;
constructor(private modalService: NgbModal,
public modal: NgbActiveModal) {
}
ngOnInit() {
}
}

View File

@@ -1,10 +1,6 @@
<ds-item-type-badge [object]="dso"></ds-item-type-badge>
<ds-truncatable [id]="dso.id">
<ds-person-input-suggestions [suggestions]="suggestions" (typeSuggestion)="filter($event)" [(ngModel)]="selected" (clickSuggestion)="select($event)" (submitSuggestion)="select($event)"></ds-person-input-suggestions>
<!-- <select>-->
<!-- <option [value]="firstMetadataValue('person.familyName') + ', ' + firstMetadataValue('person.givenName')" [innerHTML]="firstMetadataValue('person.familyName') + ', ' + firstMetadataValue('person.givenName')"></option>-->
<!-- <option *ngFor="let value of allMetadataValues('dc.title.alternative')" [value]="value" [innerHTML]="value"></option>-->
<!-- </select>-->
<ds-person-input-suggestions [suggestions]="suggestions" (typeSuggestion)="filter($event)" [(ngModel)]="selected" (clickSuggestion)="select($event)" (submitSuggestion)="selectCustom($event)"></ds-person-input-suggestions>
<span class="text-muted">
<ds-truncatable-part [id]="dso.id" [minLines]="1">
<span *ngIf="dso.allMetadata(['person.jobTitle']).length > 0"

View File

@@ -8,6 +8,18 @@ import { Context } from '../../../../../core/shared/context.model';
import { RelationshipService } from '../../../../../core/data/relationship.service';
import { TruncatableService } from '../../../../../shared/truncatable/truncatable.service';
import { take } from 'rxjs/operators';
import { NotificationsService } from '../../../../../shared/notifications/notifications.service';
import { TranslateService } from '@ngx-translate/core';
import { DsDynamicLookupRelationModalComponent } from '../../../../../shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/dynamic-lookup-relation-modal.component';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { NameVariantModalComponent } from './name-variant-modal/name-variant-modal.component';
import { Community } from '../../../../../core/shared/community.model';
import { MetadataValue } from '../../../../../core/shared/metadata.models';
import { ItemDataService } from '../../../../../core/data/item-data.service';
const NOTIFICATION_CONTENT_KEY = 'submission.sections.describe.relationship-lookup.name-variant.notification.content';
const NOTIFICATION_CONFIRM_KEY = 'submission.sections.describe.relationship-lookup.name-variant.notification.confirm';
const NOTIFICATION_DECLINE_KEY = 'submission.sections.describe.relationship-lookup.name-variant.notification.decline';
@listableObjectComponent('PersonSearchResult', ViewMode.ListElement, Context.Workspace)
@Component({
@@ -15,6 +27,7 @@ import { take } from 'rxjs/operators';
styleUrls: ['./person-search-result-list-submission-element.component.scss'],
templateUrl: './person-search-result-list-submission-element.component.html'
})
/**
* The component for displaying a list element for an item search result of the type Person
*/
@@ -22,23 +35,30 @@ export class PersonSearchResultListSubmissionElementComponent extends SearchResu
suggestions: string[];
allSuggestions: string[];
selected: string;
alternativeField = 'dc.title.alternative';
constructor(protected truncatableService: TruncatableService, private relationshipService: RelationshipService) {
constructor(protected truncatableService: TruncatableService,
private relationshipService: RelationshipService,
private notificationsService: NotificationsService,
private translateService: TranslateService,
private modalService: NgbModal,
private itemDataService: ItemDataService) {
super(truncatableService);
}
ngOnInit() {
super.ngOnInit();
const defaultValue = this.firstMetadataValue('person.familyName') + ', ' + this.firstMetadataValue('person.givenName');
const alternatives = this.allMetadataValues('dc.title.alternative');
const alternatives = this.allMetadataValues(this.alternativeField);
this.allSuggestions = [defaultValue, ...alternatives];
this.suggestions = this.allSuggestions;
this.relationshipService.getNameVariant(this.listID, this.dso.uuid)
.pipe(take(1))
.subscribe((nameVariant: string) => {
this.selected = nameVariant || defaultValue;
});
this.selected = nameVariant || defaultValue;
}
);
}
filter(query) {
@@ -48,4 +68,34 @@ export class PersonSearchResultListSubmissionElementComponent extends SearchResu
select(value) {
this.relationshipService.setNameVariant(this.listID, this.dso.uuid, value);
}
selectCustom(value) {
if (!this.allSuggestions.includes(value)) {
this.openModal(value)
.then(() => {
const newName: MetadataValue = new MetadataValue();
newName.value = value;
const existingNames: MetadataValue[] = this.dso.metadata[this.alternativeField] || [];
const alternativeNames = { [this.alternativeField]: [...existingNames, newName] };
const updatedItem =
Object.assign({}, this.dso, {
metadata: {
...this.dso.metadata,
...alternativeNames
},
});
this.itemDataService.update(updatedItem).pipe(take(1)).subscribe();
})
}
this.select(value);
}
openModal(value): Promise<any> {
const modalRef = this.modalService.open(NameVariantModalComponent, { size: 'lg' });
const modalComp = modalRef.componentInstance;
modalComp.value = value;
return modalRef.result;
}
}