2019-08-31 20:51:14 -07:00
|
|
|
import Controller from '@ember/controller';
|
2020-08-26 15:44:50 -07:00
|
|
|
import { setProperties, action } from '@ember/object';
|
2019-08-31 20:51:14 -07:00
|
|
|
import { DatasetEntity } from '@datahub/data-models/entity/dataset/dataset-entity';
|
2020-08-26 15:44:50 -07:00
|
|
|
import { DataModelName } from '@datahub/data-models/constants/entity';
|
2019-08-31 20:51:14 -07:00
|
|
|
|
|
|
|
export default class SearchController extends Controller {
|
|
|
|
queryParams = ['entity', 'page', 'facets', 'keyword'];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The category to narrow/ filter search results
|
|
|
|
*/
|
2020-08-26 15:44:50 -07:00
|
|
|
entity?: DataModelName = DatasetEntity.displayName;
|
2019-08-31 20:51:14 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Encoded facets state in a restli fashion
|
|
|
|
*/
|
|
|
|
facets: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The current search page
|
|
|
|
* @type {number}
|
|
|
|
*/
|
|
|
|
page = 1;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Will clean previous data
|
|
|
|
*/
|
|
|
|
resetData(): void {
|
|
|
|
setProperties(this, {
|
|
|
|
page: 1,
|
|
|
|
facets: '',
|
|
|
|
entity: DatasetEntity.displayName
|
|
|
|
});
|
|
|
|
}
|
2020-08-26 15:44:50 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Changes our search context to a new entity and resets the current page (to avoid variable leak)
|
|
|
|
* @param {DataModelName} newEntity - the name of the entity to change our search context to
|
|
|
|
*/
|
|
|
|
@action
|
|
|
|
onChangeEntity(newEntity: DataModelName): void {
|
|
|
|
setProperties(this, {
|
|
|
|
entity: newEntity,
|
|
|
|
page: 1,
|
|
|
|
facets: ''
|
|
|
|
});
|
|
|
|
}
|
2019-08-31 20:51:14 -07:00
|
|
|
}
|