mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-14 21:43:04 +00:00
63838: Refactor input suggestions to support DSpaceObjects as suggestions
This commit is contained in:
@@ -13,22 +13,11 @@ import {
|
||||
} from '@angular/core';
|
||||
import { BehaviorSubject } from 'rxjs';
|
||||
import { hasValue, isNotEmpty } from '../empty.util';
|
||||
import { InputSuggestion } from './input-suggestions.model';
|
||||
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
|
||||
|
||||
@Component({
|
||||
selector: 'ds-input-suggestions',
|
||||
styleUrls: ['./input-suggestions.component.scss'],
|
||||
templateUrl: './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(() => InputSuggestionsComponent),
|
||||
multi: true
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
/**
|
||||
@@ -38,7 +27,7 @@ export class InputSuggestionsComponent implements ControlValueAccessor, OnChange
|
||||
/**
|
||||
* The suggestions that should be shown
|
||||
*/
|
||||
@Input() suggestions: InputSuggestion[] = [];
|
||||
@Input() suggestions: any[] = [];
|
||||
|
||||
/**
|
||||
* The time waited to detect if any other input will follow before requesting the suggestions
|
||||
@@ -204,16 +193,15 @@ export class InputSuggestionsComponent implements ControlValueAccessor, OnChange
|
||||
return isNotEmpty(data);
|
||||
}
|
||||
|
||||
onSubmit(data: any) {
|
||||
// sub class should decide how to handle the date
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure that if a suggestion is clicked, the suggestions dropdown closes, does not reopen and the focus moves to the input field
|
||||
*/
|
||||
onClickSuggestion(data) {
|
||||
this.value = data;
|
||||
this.clickSuggestion.emit(data);
|
||||
this.close();
|
||||
this.blockReopen = true;
|
||||
this.queryInput.nativeElement.focus();
|
||||
return false;
|
||||
onClickSuggestion(data: any) {
|
||||
// sub class should decide how to handle the date
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -228,11 +216,6 @@ export class InputSuggestionsComponent implements ControlValueAccessor, OnChange
|
||||
this.blockReopen = false;
|
||||
}
|
||||
|
||||
onSubmit(data) {
|
||||
this.value = data;
|
||||
this.submitSuggestion.emit(data);
|
||||
}
|
||||
|
||||
/* START - Method's needed to add ngModel (ControlValueAccessor) to a component */
|
||||
registerOnChange(fn: any): void {
|
||||
this.propagateChange = fn;
|
||||
|
Reference in New Issue
Block a user