Files
dspace-angular/src/app/shared/search-form/search-form.component.ts
Lotte Hofstede d5114a87da search page fix
2018-04-05 15:54:51 +02:00

54 lines
1.2 KiB
TypeScript

import { Component, Input } from '@angular/core';
import { DSpaceObject } from '../../core/shared/dspace-object.model';
import { Router } from '@angular/router';
import { isNotEmpty, hasValue, isEmpty } from '../empty.util';
/**
* This component renders a simple item page.
* The route parameter 'id' is used to request the item it represents.
* All fields of the item that should be displayed, are defined in its template.
*/
@Component({
selector: 'ds-search-form',
styleUrls: ['./search-form.component.scss'],
templateUrl: './search-form.component.html'
})
export class SearchFormComponent {
@Input() query: string;
selectedId = '';
// Optional existing search parameters
@Input() currentParams: {};
@Input() scopes: DSpaceObject[];
@Input()
set scope(id: string) {
this.selectedId = id;
}
constructor(private router: Router) {
}
onSubmit(data: any) {
this.updateSearch(data);
}
updateSearch(data: any) {
this.router.navigate(['/search'], {
queryParams: Object.assign({}, this.currentParams,
{
query: data.query,
scope: data.scope || undefined,
page: data.page || 1
}
)
})
;
}
isNotEmpty(object: any) {
return isNotEmpty(object);
}
}