diff --git a/src/app/core/data/relationship.service.ts b/src/app/core/data/relationship.service.ts index 1041dd2d5f..dc89f153f2 100644 --- a/src/app/core/data/relationship.service.ts +++ b/src/app/core/data/relationship.service.ts @@ -2,7 +2,7 @@ import { Injectable } from '@angular/core'; import { RequestService } from './request.service'; import { HALEndpointService } from '../shared/hal-endpoint.service'; import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service'; -import { hasValue, hasValueOperator, isNotEmptyOperator } from '../../shared/empty.util'; +import { hasValue, hasValueOperator, isNotEmpty, isNotEmptyOperator } from '../../shared/empty.util'; import { distinctUntilChanged, filter, map, mergeMap, startWith, switchMap, take, tap } from 'rxjs/operators'; import { configureRequest, getRemoteDataPayload, getResponseFromEntry, getSucceededRemoteData } from '../shared/operators'; import { DeleteRequest, FindAllOptions, PostRequest, RestRequest } from './request.models'; @@ -78,7 +78,7 @@ export class RelationshipService extends DataService { ); } - addRelationship(typeId: string, item1: Item, item2: Item): Observable { + addRelationship(typeId: string, item1: Item, item2: Item, leftwardValue?: string, rightwardValue?: string): Observable { const options: HttpOptions = Object.create({}); let headers = new HttpHeaders(); headers = headers.append('Content-Type', 'text/uri-list'); @@ -87,6 +87,8 @@ export class RelationshipService extends DataService { isNotEmptyOperator(), take(1), map((endpointUrl: string) => `${endpointUrl}?relationshipType=${typeId}`), + map((endpointUrl: string) => isNotEmpty(leftwardValue) ? `${endpointUrl}&leftwardValue=${leftwardValue}` : endpointUrl), + map((endpointUrl: string) => isNotEmpty(rightwardValue) ? `${endpointUrl}&rightwardValue=${rightwardValue}` : endpointUrl), map((endpointURL: string) => new PostRequest(this.requestService.generateRequestId(), endpointURL, `${item1.self} \n ${item2.self}`, options)), configureRequest(this.requestService), switchMap((restRequest: RestRequest) => this.requestService.getByUUID(restRequest.uuid)), 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 4185a1f6cd..8144f634a7 100644 --- a/src/app/entity-groups/research-entities/research-entities.module.ts +++ b/src/app/entity-groups/research-entities/research-entities.module.ts @@ -21,6 +21,7 @@ import { ProjectSearchResultGridElementComponent } from './item-grid-elements/se import { PersonItemMetadataListElementComponent } from './metadata-representations/person/person-item-metadata-list-element.component'; 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'; const ENTRY_COMPONENTS = [ OrgUnitComponent, @@ -40,7 +41,8 @@ const ENTRY_COMPONENTS = [ PersonSearchResultGridElementComponent, OrgUnitSearchResultGridElementComponent, ProjectSearchResultGridElementComponent, - PersonSearchResultListSubmissionElementComponent + PersonSearchResultListSubmissionElementComponent, + PersonInputSuggestionsComponent ]; @NgModule({ 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 2a53e88623..4675f649ac 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,9 +1,10 @@ - + + + + + { +export class PersonSearchResultListSubmissionElementComponent extends SearchResultListElementComponent implements OnInit { + suggestions: string[]; + allSuggestions: string[]; + + ngOnInit() { + super.ngOnInit(); + const defaultValue = this.firstMetadataValue('person.familyName') + ', ' + this.firstMetadataValue('person.givenName') + const alternatives = this.allMetadataValues('dc.title.alternative'); + this.allSuggestions = [defaultValue, ...alternatives]; + this.suggestions = this.allSuggestions; + } + + filter(query) { + this.suggestions = this.allSuggestions.filter((suggestion) => suggestion.includes(query)); + } } diff --git a/src/app/entity-groups/research-entities/submission/item-list-elements/person/person-suggestions/person-input-suggestions.component.html b/src/app/entity-groups/research-entities/submission/item-list-elements/person/person-suggestions/person-input-suggestions.component.html new file mode 100644 index 0000000000..e177b2b561 --- /dev/null +++ b/src/app/entity-groups/research-entities/submission/item-list-elements/person/person-suggestions/person-input-suggestions.component.html @@ -0,0 +1,24 @@ +
+ + + +
\ No newline at end of file diff --git a/src/app/entity-groups/research-entities/submission/item-list-elements/person/person-suggestions/person-input-suggestions.component.ts b/src/app/entity-groups/research-entities/submission/item-list-elements/person/person-suggestions/person-input-suggestions.component.ts new file mode 100644 index 0000000000..4975d5d2ff --- /dev/null +++ b/src/app/entity-groups/research-entities/submission/item-list-elements/person/person-suggestions/person-input-suggestions.component.ts @@ -0,0 +1,50 @@ +import { Component, forwardRef, Input, OnInit } from '@angular/core'; +import { NG_VALUE_ACCESSOR } from '@angular/forms'; +import { InputSuggestion } from '../../../../../../shared/input-suggestions/input-suggestions.model'; +import { InputSuggestionsComponent } from '../../../../../../shared/input-suggestions/input-suggestions.component'; + +@Component({ + selector: 'ds-person-input-suggestions', + styleUrls: ['./../../../../../../shared/input-suggestions/input-suggestions.component.scss'], + templateUrl: './person-input-suggestions.component.html', + providers: [ + { + provide: NG_VALUE_ACCESSOR, + // Usage of forwardRef necessary https://github.com/angular/angular.io/issues/1151 + // tslint:disable-next-line:no-forward-ref + useExisting: forwardRef(() => PersonInputSuggestionsComponent), + multi: true + } + ] +}) + +/** + * Component representing a form with a autocomplete functionality + */ +export class PersonInputSuggestionsComponent extends InputSuggestionsComponent implements OnInit { + /** + * The suggestions that should be shown + */ + @Input() suggestions: string[] = []; + + ngOnInit() { + if (this.suggestions.length > 0) { + this.value = this.suggestions[0] + } + } + + onSubmit(data) { + this.value = data; + this.submitSuggestion.emit(data); + } + + onClickSuggestion(data) { + this.value = data; + this.clickSuggestion.emit(data); + this.close(); + this.blockReopen = true; + this.queryInput.nativeElement.focus(); + return false; + } + +} diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/dynamic-lookup-relation-modal.component.html b/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/dynamic-lookup-relation-modal.component.html index 22af294578..88e380107d 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/dynamic-lookup-relation-modal.component.html +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/dynamic-lookup-relation-modal.component.html @@ -14,6 +14,7 @@ [listId]="listId" [relationship]="relationship" [repeatable]="repeatable" + [context]="context" (selectObject)="select($event)" (deselectObject)="deselect($event)" class="d-block pt-3"> @@ -27,6 +28,7 @@ [listId]="listId" [label]="label" [repeatable]="repeatable" + [context]="context" (selectObject)="select($event)" (deselectObject)="deselect($event)" class="d-block pt-3"> @@ -34,7 +36,6 @@ -