Home: Add searchable at search form. Fos: Create fos options for autocomplete

This commit is contained in:
Konstantinos Triantafyllou 2022-06-09 16:23:01 +03:00
parent 7962556b8f
commit 58d45c9088
4 changed files with 24 additions and 6 deletions

View File

@ -39,7 +39,7 @@
<div class="uk-container uk-container-large uk-section" uk-scrollspy="target: [uk-scrollspy-class]; cls: uk-animation-slide-bottom-medium; delay: 200">
<div class="uk-grid uk-flex uk-flex-middle uk-flex-center uk-padding-small" uk-grid>
<div class="uk-margin-large-bottom">
<div search-input [searchControl]="keywordControl" placeholder="Search" (searchEmitter)="onSubmit()"
<div search-input [searchControl]="keywordControl" [options]="fosOptions" placeholder="Search" (searchEmitter)="onSubmit()"
class="uk-width-large"></div>
</div>
</div>

View File

@ -16,7 +16,8 @@ import {Location} from "@angular/common";
})
export class FosComponent implements OnInit, OnDestroy {
public fos: any = [];
public fos: any[] = [];
public fosOptions: string[] = [];
public index: number = 0;
public keywordControl: FormControl;
@ -42,6 +43,7 @@ export class FosComponent implements OnInit, OnDestroy {
this.keywordControl = this.fb.control('');
this.httpClient.get(properties.domain+'/assets/vocabulary/fos.json').subscribe(data => {
this.fos = data['fos'];
this.convertFosToOptions();
this.subscriptions.push(this.route.queryParams.subscribe(params => {
if(params.keyword) {
this.keywordControl.setValue(params.keyword);
@ -70,9 +72,25 @@ export class FosComponent implements OnInit, OnDestroy {
this.findMatches();
}
}
convertFosToOptions() {
this.fosOptions = [];
this.fos.forEach(fos => {
this.fosOptions.push(fos.id);
if(fos.children) {
fos.children.forEach(child => {
this.fosOptions.push(child.id);
if(child.children) {
child.children.forEach(child2 => {
this.fosOptions.push(child2.id);
});
}
});
}
});
}
findMatches() {
console.log(this.keyword);
this.viewResults = JSON.parse(JSON.stringify(this.fos));
let matchLevel1: boolean = false;
let matchLevel2: boolean = false;
@ -117,4 +135,4 @@ export class FosComponent implements OnInit, OnDestroy {
this.keywordControl.setValue('');
this.location.go(window.location.pathname);
}
}
}

View File

@ -31,7 +31,7 @@
<entities-selection [simpleView]="true" currentEntity="all" [selectedEntity]="selectedEntity"
(selectionChange)="entityChanged($event);advanced.focusNext(input, $event)" (disableSelectEmitter)="disableSelectChange($event)"
[onChangeNavigate]="false"></entities-selection>
<div input #input placeholder="Scholary works" [hint]="'Search in OpenAIRE'" [(value)]="keyword"></div>
<div input #input placeholder="Scholary works" [searchable]="true" [hint]="'Search in OpenAIRE'" [(value)]="keyword"></div>
</advanced-search-input>
<div *ngIf="selectedEntity === 'result' && input.focused" (click)="$event.stopPropagation();advanced.focusNext(input, $event)" class="uk-dropdown uk-display-block uk-margin-small-top uk-width-auto">
<div class="uk-padding-small">

@ -1 +1 @@
Subproject commit f3af762dab9b3d489dd4f78c46f3537aff840efd
Subproject commit 5e11488c8ff49da0675ce58924a415964aefd968