Skip to content
Snippets Groups Projects
Commit b853a005 authored by Lotte Hofstede's avatar Lotte Hofstede
Browse files

44024: simple search bugfixing

parent b95900da
No related branches found
No related tags found
No related merge requests found
<div class="search-page"> <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> <ds-search-results [searchResults]="results" [searchConfig]="searchOptions"></ds-search-results>
</div> </div>
\ No newline at end of file
...@@ -8,7 +8,7 @@ import { SortOptions } from '../core/cache/models/sort-options.model'; ...@@ -8,7 +8,7 @@ import { SortOptions } from '../core/cache/models/sort-options.model';
import { PaginationComponentOptions } from '../shared/pagination/pagination-component-options.model'; import { PaginationComponentOptions } from '../shared/pagination/pagination-component-options.model';
import { SearchOptions } from '../search/search-options.model'; import { SearchOptions } from '../search/search-options.model';
import { CommunityDataService } from '../core/data/community-data.service'; 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'; import { Community } from '../core/shared/community.model';
/** /**
...@@ -29,21 +29,14 @@ export class SearchPageComponent implements OnInit, OnDestroy { ...@@ -29,21 +29,14 @@ export class SearchPageComponent implements OnInit, OnDestroy {
scopeObject: RemoteData<DSpaceObject>; scopeObject: RemoteData<DSpaceObject>;
private page: number; private page: number;
results: RemoteData<Array<SearchResult<DSpaceObject>>>; results: RemoteData<Array<SearchResult<DSpaceObject>>>;
private currentParams = {}; currentParams = {};
searchOptions: SearchOptions; searchOptions: SearchOptions;
scopeList: RemoteData<Community[]>; scopeList: RemoteData<Community[]>;
constructor(private service: SearchService, constructor(private service: SearchService,
private route: ActivatedRoute, private route: ActivatedRoute,
private communityService: CommunityDataService,) { private communityService: CommunityDataService,) {
// Sample scope data
const defaultScope: Community = new Community();
defaultScope.id = '';
this.scopeList = communityService.findAll(); this.scopeList = communityService.findAll();
this.scopeList.payload = this.scopeList.payload.map((list) => {
list.unshift(defaultScope);
return list
});
} }
ngOnInit(): void { ngOnInit(): void {
...@@ -61,7 +54,7 @@ export class SearchPageComponent implements OnInit, OnDestroy { ...@@ -61,7 +54,7 @@ export class SearchPageComponent implements OnInit, OnDestroy {
const sort: SortOptions = new SortOptions(params.sortField, params.sortDirection); const sort: SortOptions = new SortOptions(params.sortField, params.sortDirection);
this.searchOptions = { pagination: pagination, sort: sort }; this.searchOptions = { pagination: pagination, sort: sort };
this.results = this.service.search(this.query, this.scope, this.searchOptions); 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); this.scopeObject = this.communityService.findById(this.scope);
} else { } else {
this.scopeObject = undefined; this.scopeObject = undefined;
......
<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"> <div class="form-group input-group">
<input type="text" [(ngModel)]="query" name="query" class="form-control" aria-label="Search input"> <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"> <span class="input-group-btn">
<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">
<button type="submit" class="search-button btn btn-secondary">{{ ('search.form.search' | translate) }}</button> <button type="submit" class="search-button btn btn-secondary">{{ ('search.form.search' | translate) }}</button>
</div> </span>
</div>
</div> </div>
</form> </form>
@import '../../../styles/shared_imports.scss'; @import '../../../styles/shared_imports.scss';
// temporary fix for bootstrap 4 beta btn color issue
.btn-secondary {
background-color: $input-bg;
color: $input-color;
}
import { Component, Input, OnInit } from '@angular/core'; import { Component, Input, OnInit } from '@angular/core';
import { DSpaceObject } from '../../core/shared/dspace-object.model'; import { DSpaceObject } from '../../core/shared/dspace-object.model';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { isNotEmpty, isEmpty, hasNoValue } from '../empty.util'; import { isNotEmpty, hasValue, isEmpty } from '../empty.util';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs/Observable';
/** /**
* This component renders a simple item page. * This component renders a simple item page.
...@@ -17,17 +17,27 @@ import { Observable } from 'rxjs'; ...@@ -17,17 +17,27 @@ import { Observable } from 'rxjs';
}) })
export class SearchFormComponent implements OnInit { export class SearchFormComponent implements OnInit {
@Input() query: string; @Input() query: string;
@Input() scope: Observable<DSpaceObject>; selectedId = '';
scopeId: string;
// Optional existing search parameters // Optional existing search parameters
@Input() currentParams: {}; @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 { ngOnInit(): void {
this.scope.subscribe((scopeObject) => { this.scopes
this.scopeId = scopeObject.id; .filter((scopes: DSpaceObject[]) => isEmpty(scopes))
console.log("Initialized: ", scopeObject.id); .subscribe((scopes: DSpaceObject[]) => {
}); this.scopeOptions = scopes
.map((scope: DSpaceObject) => scope.id);
}
);
} }
constructor(private router: Router) { constructor(private router: Router) {
...@@ -38,11 +48,12 @@ export class SearchFormComponent implements OnInit { ...@@ -38,11 +48,12 @@ export class SearchFormComponent implements OnInit {
} }
updateSearch(data: any) { updateSearch(data: any) {
this.router.navigate(['/search'], { this.router.navigate(['/search'], {
queryParams: Object.assign({}, this.currentParams, queryParams: Object.assign({}, this.currentParams,
{ {
query: data.query, query: data.query,
scope: data.scope, scope: data.scope || undefined,
page: data.page || 1 page: data.page || 1
} }
) )
...@@ -50,15 +61,10 @@ export class SearchFormComponent implements OnInit { ...@@ -50,15 +61,10 @@ export class SearchFormComponent implements OnInit {
; ;
} }
private isNotEmpty(object: any) {
return isNotEmpty(object);
}
byId(id1: string, id2: string) { byId(id1: string, id2: string) {
if (isEmpty(id1) && isEmpty(id2)) {
return true;
}
return id1 === id2; return id1 === id2;
} }
onChange(): void {
console.log('Scope: ', this.scope);
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment