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 dd64f3880e..32a92d7b2e 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,6 +1,6 @@ - + { - this.selected = nameVariant || defaultValue; + this.selectedName = nameVariant || defaultValue; } ); } @@ -66,6 +62,13 @@ export class PersonSearchResultListSubmissionElementComponent extends SearchResu } select(value) { + this.selectableListService.isObjectSelected(this.listID, this.object) + .pipe(take(1)) + .subscribe((selected) => { + if (!selected) { + this.selectableListService.selectSingle(this.listID, this.object); + } + }); this.relationshipService.setNameVariant(this.listID, this.dso.uuid, value); } diff --git a/src/app/shared/object-collection/shared/selectable-list-item-control.component.html b/src/app/shared/object-collection/shared/selectable-list-item-control.component.html new file mode 100644 index 0000000000..4455cedeb9 --- /dev/null +++ b/src/app/shared/object-collection/shared/selectable-list-item-control.component.html @@ -0,0 +1,12 @@ + + + + \ No newline at end of file diff --git a/src/app/shared/object-collection/shared/selectable-list-item-control.component.ts b/src/app/shared/object-collection/shared/selectable-list-item-control.component.ts new file mode 100644 index 0000000000..4a4eea600b --- /dev/null +++ b/src/app/shared/object-collection/shared/selectable-list-item-control.component.ts @@ -0,0 +1,75 @@ +import { Component, ComponentFactoryResolver, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core'; +import { ListableObject } from './listable-object.model'; +import { SelectableListService } from '../../object-list/selectable-list/selectable-list.service'; +import { map, take } from 'rxjs/operators'; +import { Observable } from 'rxjs'; + +@Component({ + selector: 'ds-selectable-list-item-control', + // styleUrls: ['./selectable-list-item-control.component.scss'], + templateUrl: './selectable-list-item-control.component.html' +}) +/** + * Component for determining what component to use depending on the item's relationship type (relationship.type) + */ +export class SelectableListItemControlComponent implements OnInit { + /** + * The item or metadata to determine the component for + */ + @Input() object: ListableObject; + + + @Input() selectionConfig: { repeatable: boolean, listId: string }; + + /** + * Index of the control in the list + */ + @Input() index: number; + + @Output() deselectObject: EventEmitter = new EventEmitter(); + + @Output() selectObject: EventEmitter = new EventEmitter(); + + + selected$: Observable; + constructor(private selectionService: SelectableListService) { + } + + /** + * Setup the dynamic child component + */ + ngOnInit(): void { + this.selected$ = this.selectionService?.isObjectSelected(this.selectionConfig.listId, this.object); + this.selected$.subscribe((selected: ListableObject) => { + + }) + } + + selectCheckbox(value: boolean, object: ListableObject) { + if (value) { + this.selectionService.selectSingle(this.selectionConfig.listId, object); + this.selectObject.emit(object); + } else { + this.selectionService.deselectSingle(this.selectionConfig.listId, object); + this.deselectObject.emit(object); + } + } + + selectRadio(value: boolean, object: ListableObject) { + const selected$ = this.selectionService.getSelectableList(this.selectionConfig.listId); + selected$.pipe( + take(1), + map((selected) => selected ? selected.selection : []) + ).subscribe((selection) => { + // First deselect any existing selections, this is a radio button + selection.forEach((selectedObject) => { + this.selectionService.deselectSingle(this.selectionConfig.listId, selectedObject); + this.deselectObject.emit(selectedObject); + }); + if (value) { + this.selectionService.selectSingle(this.selectionConfig.listId, object); + this.selectObject.emit(object); + } + }); + } +} diff --git a/src/app/shared/object-list/object-list.component.html b/src/app/shared/object-list/object-list.component.html index 770999b808..887be96785 100644 --- a/src/app/shared/object-list/object-list.component.html +++ b/src/app/shared/object-list/object-list.component.html @@ -13,20 +13,14 @@
  • - - - - + - +
diff --git a/src/app/shared/object-list/object-list.component.ts b/src/app/shared/object-list/object-list.component.ts index 4ad2f92e99..2f725bd2e1 100644 --- a/src/app/shared/object-list/object-list.component.ts +++ b/src/app/shared/object-list/object-list.component.ts @@ -180,31 +180,5 @@ export class ObjectListComponent { this.paginationChange.emit(event); } - selectCheckbox(value: boolean, object: ListableObject) { - if (value) { - this.selectionService.selectSingle(this.selectionConfig.listId, object); - this.selectObject.emit(object); - } else { - this.selectionService.deselectSingle(this.selectionConfig.listId, object); - this.deselectObject.emit(object); - } - } - selectRadio(value: boolean, object: ListableObject) { - const selected$ = this.selectionService.getSelectableList(this.selectionConfig.listId); - selected$.pipe( - take(1), - map((selected) => selected ? selected.selection : []) - ).subscribe((selection) => { - // First deselect any existing selections, this is a radio button - selection.forEach((selectedObject) => { - this.selectionService.deselectSingle(this.selectionConfig.listId, selectedObject); - this.deselectObject.emit(selectedObject); - }); - if (value) { - this.selectionService.selectSingle(this.selectionConfig.listId, object); - this.selectObject.emit(object); - } - }); - } } diff --git a/src/app/shared/shared.module.ts b/src/app/shared/shared.module.ts index 3488b4eaab..45848fdde7 100644 --- a/src/app/shared/shared.module.ts +++ b/src/app/shared/shared.module.ts @@ -169,6 +169,7 @@ import { ListableObjectDirective } from './object-collection/shared/listable-obj import { SearchLabelComponent } from './search/search-labels/search-label/search-label.component'; import { ItemMetadataRepresentationListElementComponent } from './object-list/metadata-representation-list-element/item/item-metadata-representation-list-element.component'; import { MetadataRepresentationListComponent } from '../+item-page/simple/metadata-representation-list/metadata-representation-list.component'; +import { SelectableListItemControlComponent } from './object-collection/shared/selectable-list-item-control.component'; const MODULES = [ // Do NOT include UniversalModule, HttpModule, or JsonpModule here @@ -321,6 +322,7 @@ const COMPONENTS = [ ItemSelectComponent, CollectionSelectComponent, MetadataRepresentationLoaderComponent, + SelectableListItemControlComponent ]; const ENTRY_COMPONENTS = [