diff --git a/resources/i18n/en.json5 b/resources/i18n/en.json5 index 75617b8bcf..e59a8f38c1 100644 --- a/resources/i18n/en.json5 +++ b/resources/i18n/en.json5 @@ -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.", diff --git a/src/app/core/cache/object-cache.service.ts b/src/app/core/cache/object-cache.service.ts index 598fb3937d..6a07b8074d 100644 --- a/src/app/core/cache/object-cache.service.ts +++ b/src/app/core/cache/object-cache.service.ts @@ -99,13 +99,13 @@ export class ObjectCacheService { getObjectBySelfLink(selfLink: string): Observable> { 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) => { diff --git a/src/app/entity-groups/research-entities/research-entities.module.ts b/src/app/entity-groups/research-entities/research-entities.module.ts index 8144f634a7..1ac4828bb9 100644 --- a/src/app/entity-groups/research-entities/research-entities.module.ts +++ b/src/app/entity-groups/research-entities/research-entities.module.ts @@ -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 diff --git a/src/app/entity-groups/research-entities/submission/item-list-elements/person/name-variant-modal/name-variant-modal.component.html b/src/app/entity-groups/research-entities/submission/item-list-elements/person/name-variant-modal/name-variant-modal.component.html new file mode 100644 index 0000000000..f46319d16b --- /dev/null +++ b/src/app/entity-groups/research-entities/submission/item-list-elements/person/name-variant-modal/name-variant-modal.component.html @@ -0,0 +1,13 @@ + + + \ No newline at end of file diff --git a/src/app/entity-groups/research-entities/submission/item-list-elements/person/name-variant-modal/name-variant-modal.component.scss b/src/app/entity-groups/research-entities/submission/item-list-elements/person/name-variant-modal/name-variant-modal.component.scss new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/app/entity-groups/research-entities/submission/item-list-elements/person/name-variant-modal/name-variant-modal.component.spec.ts b/src/app/entity-groups/research-entities/submission/item-list-elements/person/name-variant-modal/name-variant-modal.component.spec.ts new file mode 100644 index 0000000000..2f041bc391 --- /dev/null +++ b/src/app/entity-groups/research-entities/submission/item-list-elements/person/name-variant-modal/name-variant-modal.component.spec.ts @@ -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; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ NameVariantModalComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(NameVariantModalComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/entity-groups/research-entities/submission/item-list-elements/person/name-variant-modal/name-variant-modal.component.ts b/src/app/entity-groups/research-entities/submission/item-list-elements/person/name-variant-modal/name-variant-modal.component.ts new file mode 100644 index 0000000000..ea036e0b0f --- /dev/null +++ b/src/app/entity-groups/research-entities/submission/item-list-elements/person/name-variant-modal/name-variant-modal.component.ts @@ -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() { + + } + +} diff --git a/src/app/entity-groups/research-entities/submission/item-list-elements/person/person-search-result-list-submission-element.component.html b/src/app/entity-groups/research-entities/submission/item-list-elements/person/person-search-result-list-submission-element.component.html index baa3edcdc5..dd64f3880e 100644 --- a/src/app/entity-groups/research-entities/submission/item-list-elements/person/person-search-result-list-submission-element.component.html +++ b/src/app/entity-groups/research-entities/submission/item-list-elements/person/person-search-result-list-submission-element.component.html @@ -1,10 +1,6 @@ - - - - - + { - 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 { + const modalRef = this.modalService.open(NameVariantModalComponent, { size: 'lg' }); + const modalComp = modalRef.componentInstance; + modalComp.value = value; + return modalRef.result; + } }