diff --git a/src/app/search-page/search-page.component.html b/src/app/search-page/search-page.component.html index f142cc6b4475c2b0b5370fb6667e5f3d8fd6f2eb..a8747a6cf9eed99db6152bb9bd6356b531a832a0 100644 --- a/src/app/search-page/search-page.component.html +++ b/src/app/search-page/search-page.component.html @@ -1,4 +1,4 @@ <div class="search-page"> - <ds-search-form [query]="query" [scope]="scopeObject?.payload" [currentParams]="currentParams" [scopes]="scopeList?.payload | async"></ds-search-form> + <ds-search-form [query]="query" [scope]="scopeObject?.payload | async" [currentParams]="currentParams" [scopes]="scopeList?.payload"></ds-search-form> <ds-search-results [searchResults]="results" [searchConfig]="searchOptions"></ds-search-results> -</div> \ No newline at end of file +</div> diff --git a/src/app/search-page/search-page.component.ts b/src/app/search-page/search-page.component.ts index 4cba88338a453abeabc32e3a166cb10ef72508f9..8aade9ec30303f9a16e7f34a295bfb7c4b073f53 100644 --- a/src/app/search-page/search-page.component.ts +++ b/src/app/search-page/search-page.component.ts @@ -8,7 +8,7 @@ import { SortOptions } from '../core/cache/models/sort-options.model'; import { PaginationComponentOptions } from '../shared/pagination/pagination-component-options.model'; import { SearchOptions } from '../search/search-options.model'; import { CommunityDataService } from '../core/data/community-data.service'; -import { hasValue } from '../shared/empty.util'; +import { isNotEmpty } from '../shared/empty.util'; import { Community } from '../core/shared/community.model'; /** @@ -29,21 +29,14 @@ export class SearchPageComponent implements OnInit, OnDestroy { scopeObject: RemoteData<DSpaceObject>; private page: number; results: RemoteData<Array<SearchResult<DSpaceObject>>>; - private currentParams = {}; + currentParams = {}; searchOptions: SearchOptions; scopeList: RemoteData<Community[]>; constructor(private service: SearchService, private route: ActivatedRoute, private communityService: CommunityDataService,) { - // Sample scope data - const defaultScope: Community = new Community(); - defaultScope.id = ''; this.scopeList = communityService.findAll(); - this.scopeList.payload = this.scopeList.payload.map((list) => { - list.unshift(defaultScope); - return list - }); } ngOnInit(): void { @@ -61,7 +54,7 @@ export class SearchPageComponent implements OnInit, OnDestroy { const sort: SortOptions = new SortOptions(params.sortField, params.sortDirection); this.searchOptions = { pagination: pagination, sort: sort }; this.results = this.service.search(this.query, this.scope, this.searchOptions); - if (hasValue(this.scope)) { + if (isNotEmpty(this.scope)) { this.scopeObject = this.communityService.findById(this.scope); } else { this.scopeObject = undefined; diff --git a/src/app/shared/search-form/search-form.component.html b/src/app/shared/search-form/search-form.component.html index 01a231d8740f7ca5d9966b30cc00c29b326e95e2..ae4132e9509b20d201a547de68aed3854f875317 100644 --- a/src/app/shared/search-form/search-form.component.html +++ b/src/app/shared/search-form/search-form.component.html @@ -1,12 +1,16 @@ -<form #form="ngForm" (ngSubmit)="onSubmit(form.value)"> +<form #form="ngForm" (ngSubmit)="onSubmit(form.value)" class="row"> +<div class="col-12 col-sm-3"> + <select ngif="isNotEmpty(scopes | async)" [(ngModel)]="selectedId" name="scope" class="form-control" aria-label="Search scope" [compareWith]="byId"> + <option value>{{'search.form.search_dspace' | translate}}</option> + <option *ngFor="let scopeOption of scopes | async" [value]="scopeOption.id">{{scopeOption?.name ? scopeOption.name : 'search.form.search_dspace' | translate}}</option> + </select> +</div> + <div class="col-12 col-sm-9"> <div class="form-group input-group"> <input type="text" [(ngModel)]="query" name="query" class="form-control" aria-label="Search input"> - <input type="text" [(ngModel)]="scopeId" name="scopeId" class="form-control" aria-label="Search input scopeId"> - <select ngif="isNotEmpty(scopes)" [(ngModel)]="scopeId" name="scope" class="form-control" aria-label="Search scope" (change)="onChange()" [compareWith]="byId"> - <option *ngFor="let scopeOption of scopes" [ngValue]="scopeOption.id" [value]="scopeOption.id">{{scopeOption?.name ? scopeOption.name : 'search.form.search_dspace' | translate}}</option> - </select> - <div class="input-group-btn"> + <span class="input-group-btn"> <button type="submit" class="search-button btn btn-secondary">{{ ('search.form.search' | translate) }}</button> - </div> + </span> + </div> </div> </form> diff --git a/src/app/shared/search-form/search-form.component.scss b/src/app/shared/search-form/search-form.component.scss index 7d5f9237d26513bce73ac96774d41b03afb179b6..ca8849e3c0516fa5a5ceb9bb9a272b56a066d914 100644 --- a/src/app/shared/search-form/search-form.component.scss +++ b/src/app/shared/search-form/search-form.component.scss @@ -1 +1,7 @@ @import '../../../styles/shared_imports.scss'; + +// temporary fix for bootstrap 4 beta btn color issue +.btn-secondary { + background-color: $input-bg; + color: $input-color; +} diff --git a/src/app/shared/search-form/search-form.component.ts b/src/app/shared/search-form/search-form.component.ts index cc6b6c807525dc4c001844dc0f1cb06ef06f7908..3d06515f312ac196aa53c43c0a0774ae4e64c582 100644 --- a/src/app/shared/search-form/search-form.component.ts +++ b/src/app/shared/search-form/search-form.component.ts @@ -1,8 +1,8 @@ import { Component, Input, OnInit } from '@angular/core'; import { DSpaceObject } from '../../core/shared/dspace-object.model'; import { Router } from '@angular/router'; -import { isNotEmpty, isEmpty, hasNoValue } from '../empty.util'; -import { Observable } from 'rxjs'; +import { isNotEmpty, hasValue, isEmpty } from '../empty.util'; +import { Observable } from 'rxjs/Observable'; /** * This component renders a simple item page. @@ -17,17 +17,27 @@ import { Observable } from 'rxjs'; }) export class SearchFormComponent implements OnInit { @Input() query: string; - @Input() scope: Observable<DSpaceObject>; - scopeId: string; + selectedId = ''; // Optional existing search parameters @Input() currentParams: {}; - @Input() scopes: DSpaceObject[]; + @Input() scopes: Observable<DSpaceObject[]>; + scopeOptions: string[] = []; + + @Input() + set scope(dso: DSpaceObject) { + if (hasValue(dso)) { + this.selectedId = dso.id; + } + } ngOnInit(): void { - this.scope.subscribe((scopeObject) => { - this.scopeId = scopeObject.id; - console.log("Initialized: ", scopeObject.id); - }); + this.scopes + .filter((scopes: DSpaceObject[]) => isEmpty(scopes)) + .subscribe((scopes: DSpaceObject[]) => { + this.scopeOptions = scopes + .map((scope: DSpaceObject) => scope.id); + } + ); } constructor(private router: Router) { @@ -38,11 +48,12 @@ export class SearchFormComponent implements OnInit { } updateSearch(data: any) { + this.router.navigate(['/search'], { queryParams: Object.assign({}, this.currentParams, { query: data.query, - scope: data.scope, + scope: data.scope || undefined, page: data.page || 1 } ) @@ -50,15 +61,10 @@ export class SearchFormComponent implements OnInit { ; } - private isNotEmpty(object: any) { - return isNotEmpty(object); - } - byId(id1: string, id2: string) { + if (isEmpty(id1) && isEmpty(id2)) { + return true; + } return id1 === id2; } - - onChange(): void { - console.log('Scope: ', this.scope); - } }