mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-12 20:43:08 +00:00
Fixed issue with scrollable dropdown component
This commit is contained in:
@@ -33,7 +33,7 @@ export class IntegrationResponseParsingService extends BaseResponseParsingServic
|
|||||||
parse(request: RestRequest, data: DSpaceRESTV2Response): RestResponse {
|
parse(request: RestRequest, data: DSpaceRESTV2Response): RestResponse {
|
||||||
if (isNotEmpty(data.payload) && isNotEmpty(data.payload._links)) {
|
if (isNotEmpty(data.payload) && isNotEmpty(data.payload._links)) {
|
||||||
const dataDefinition = this.process<IntegrationModel,IntegrationType>(data.payload, request.href);
|
const dataDefinition = this.process<IntegrationModel,IntegrationType>(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 {
|
} else {
|
||||||
return new ErrorResponse(
|
return new ErrorResponse(
|
||||||
Object.assign(
|
Object.assign(
|
||||||
|
@@ -6,7 +6,7 @@
|
|||||||
[name]="model.name"
|
[name]="model.name"
|
||||||
[readonly]="model.readOnly"
|
[readonly]="model.readOnly"
|
||||||
[type]="model.inputType"
|
[type]="model.inputType"
|
||||||
[value]="formatItemForInput(model.value)"
|
[value]="(currentValue | async)"
|
||||||
(blur)="onBlur($event)"
|
(blur)="onBlur($event)"
|
||||||
(click)="$event.stopPropagation(); openDropdown(sdRef);"
|
(click)="$event.stopPropagation(); openDropdown(sdRef);"
|
||||||
(focus)="onFocus($event)"
|
(focus)="onFocus($event)"
|
||||||
|
@@ -9,6 +9,7 @@ import { IntegrationSearchOptions } from '../../../../../../core/integration/mod
|
|||||||
import { IntegrationData } from '../../../../../../core/integration/integration-data';
|
import { IntegrationData } from '../../../../../../core/integration/integration-data';
|
||||||
import { AuthorityValueModel } from '../../../../../../core/integration/models/authority-value.model';
|
import { AuthorityValueModel } from '../../../../../../core/integration/models/authority-value.model';
|
||||||
import { NgbDropdown } from '@ng-bootstrap/ng-bootstrap';
|
import { NgbDropdown } from '@ng-bootstrap/ng-bootstrap';
|
||||||
|
import { Observable } from 'rxjs';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-dynamic-scrollable-dropdown',
|
selector: 'ds-dynamic-scrollable-dropdown',
|
||||||
@@ -25,6 +26,7 @@ export class DsDynamicScrollableDropdownComponent implements OnInit {
|
|||||||
@Output() change: EventEmitter<any> = new EventEmitter<any>();
|
@Output() change: EventEmitter<any> = new EventEmitter<any>();
|
||||||
@Output() focus: EventEmitter<any> = new EventEmitter<any>();
|
@Output() focus: EventEmitter<any> = new EventEmitter<any>();
|
||||||
|
|
||||||
|
public currentValue: Observable<string>;
|
||||||
public loading = false;
|
public loading = false;
|
||||||
public pageInfo: PageInfo;
|
public pageInfo: PageInfo;
|
||||||
public optionsList: any;
|
public optionsList: any;
|
||||||
@@ -44,17 +46,28 @@ export class DsDynamicScrollableDropdownComponent implements OnInit {
|
|||||||
this.authorityService.getEntriesByName(this.searchOptions)
|
this.authorityService.getEntriesByName(this.searchOptions)
|
||||||
.subscribe((object: IntegrationData) => {
|
.subscribe((object: IntegrationData) => {
|
||||||
this.optionsList = object.payload;
|
this.optionsList = object.payload;
|
||||||
|
if (this.model.value) {
|
||||||
|
this.setCurrentValue(this.model.value);
|
||||||
|
}
|
||||||
|
console.log(this.optionsList);
|
||||||
this.pageInfo = object.pageInfo;
|
this.pageInfo = object.pageInfo;
|
||||||
this.cdr.detectChanges();
|
this.cdr.detectChanges();
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
public formatItemForInput(item: any): string {
|
formatItemForInput(item: any): string {
|
||||||
|
let result: any;
|
||||||
if (isUndefined(item) || isNull(item)) { return '' }
|
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);
|
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) {
|
openDropdown(sdRef: NgbDropdown) {
|
||||||
if (!this.model.readOnly) {
|
if (!this.model.readOnly) {
|
||||||
@@ -88,5 +101,23 @@ export class DsDynamicScrollableDropdownComponent implements OnInit {
|
|||||||
this.group.markAsDirty();
|
this.group.markAsDirty();
|
||||||
this.model.valueUpdates.next(event);
|
this.model.valueUpdates.next(event);
|
||||||
this.change.emit(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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user