From 15315fda39da778db375631742c9fd5b40f0273e Mon Sep 17 00:00:00 2001 From: Giuseppe Date: Thu, 11 Oct 2018 11:21:48 +0200 Subject: [PATCH] Fixed issue with scrollable dropdown component --- .../integration-response-parsing.service.ts | 2 +- ...dynamic-scrollable-dropdown.component.html | 2 +- .../dynamic-scrollable-dropdown.component.ts | 35 +++++++++++++++++-- 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/src/app/core/integration/integration-response-parsing.service.ts b/src/app/core/integration/integration-response-parsing.service.ts index 5d6ce09114..d07cf02025 100644 --- a/src/app/core/integration/integration-response-parsing.service.ts +++ b/src/app/core/integration/integration-response-parsing.service.ts @@ -33,7 +33,7 @@ export class IntegrationResponseParsingService extends BaseResponseParsingServic parse(request: RestRequest, data: DSpaceRESTV2Response): RestResponse { if (isNotEmpty(data.payload) && isNotEmpty(data.payload._links)) { const dataDefinition = this.process(data.payload, request.href); - return new IntegrationSuccessResponse(dataDefinition[Object.keys(dataDefinition)[0]], data.statusCode, this.processPageInfo(data.payload.page)); + return new IntegrationSuccessResponse(dataDefinition[Object.keys(dataDefinition)[0]], data.statusCode, this.processPageInfo(data.payload)); } else { return new ErrorResponse( Object.assign( diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/models/scrollable-dropdown/dynamic-scrollable-dropdown.component.html b/src/app/shared/form/builder/ds-dynamic-form-ui/models/scrollable-dropdown/dynamic-scrollable-dropdown.component.html index 6a5e588610..c9c082bc07 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/models/scrollable-dropdown/dynamic-scrollable-dropdown.component.html +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/models/scrollable-dropdown/dynamic-scrollable-dropdown.component.html @@ -6,7 +6,7 @@ [name]="model.name" [readonly]="model.readOnly" [type]="model.inputType" - [value]="formatItemForInput(model.value)" + [value]="(currentValue | async)" (blur)="onBlur($event)" (click)="$event.stopPropagation(); openDropdown(sdRef);" (focus)="onFocus($event)" diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/models/scrollable-dropdown/dynamic-scrollable-dropdown.component.ts b/src/app/shared/form/builder/ds-dynamic-form-ui/models/scrollable-dropdown/dynamic-scrollable-dropdown.component.ts index 1c8bf15f1a..e918aae830 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/models/scrollable-dropdown/dynamic-scrollable-dropdown.component.ts +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/models/scrollable-dropdown/dynamic-scrollable-dropdown.component.ts @@ -9,6 +9,7 @@ import { IntegrationSearchOptions } from '../../../../../../core/integration/mod import { IntegrationData } from '../../../../../../core/integration/integration-data'; import { AuthorityValueModel } from '../../../../../../core/integration/models/authority-value.model'; import { NgbDropdown } from '@ng-bootstrap/ng-bootstrap'; +import { Observable } from 'rxjs'; @Component({ selector: 'ds-dynamic-scrollable-dropdown', @@ -25,6 +26,7 @@ export class DsDynamicScrollableDropdownComponent implements OnInit { @Output() change: EventEmitter = new EventEmitter(); @Output() focus: EventEmitter = new EventEmitter(); + public currentValue: Observable; public loading = false; public pageInfo: PageInfo; public optionsList: any; @@ -44,17 +46,28 @@ export class DsDynamicScrollableDropdownComponent implements OnInit { this.authorityService.getEntriesByName(this.searchOptions) .subscribe((object: IntegrationData) => { this.optionsList = object.payload; + if (this.model.value) { + this.setCurrentValue(this.model.value); + } + console.log(this.optionsList); this.pageInfo = object.pageInfo; this.cdr.detectChanges(); }) } - public formatItemForInput(item: any): string { + formatItemForInput(item: any): string { + let result: any; if (isUndefined(item) || isNull(item)) { return '' } + if (typeof item === 'string') { result = item } + if (this.optionsList) { + this.optionsList.forEach((key) => { + console.log(this.optionsList[key]); + }); + } return (typeof item === 'string') ? item : this.inputFormatter(item); } - inputFormatter = (x: AuthorityValueModel) => x.display || x.value; + inputFormatter = (x: AuthorityValueModel): string => x.display || x.value; openDropdown(sdRef: NgbDropdown) { if (!this.model.readOnly) { @@ -88,5 +101,23 @@ export class DsDynamicScrollableDropdownComponent implements OnInit { this.group.markAsDirty(); this.model.valueUpdates.next(event); this.change.emit(event); + this.setCurrentValue(event); + } + + setCurrentValue(value): void { + let result: string; + if (isUndefined(value) || isNull(value)) { + result = ''; + } else if (typeof value === 'string') { + result = value; + } else { + for (const item of this.optionsList) { + if (value.value === (item as any).value) { + result = this.inputFormatter(item); + break; + } + } + } + this.currentValue = Observable.of(result); } }