2017-03-24 22:01:30 -07:00
|
|
|
import Ember from 'ember';
|
2017-04-05 09:02:04 -07:00
|
|
|
|
2017-03-24 22:01:30 -07:00
|
|
|
const {
|
|
|
|
get,
|
2017-04-05 09:02:04 -07:00
|
|
|
set,
|
|
|
|
computed,
|
|
|
|
Component,
|
|
|
|
inject: { service },
|
|
|
|
run: { debounce }
|
2017-03-24 22:01:30 -07:00
|
|
|
} = Ember;
|
|
|
|
|
2017-04-05 09:02:04 -07:00
|
|
|
/**
|
|
|
|
* Number of milliseconds to wait before triggering a request for keywords
|
|
|
|
* @type {Number}
|
|
|
|
*/
|
|
|
|
const keyPressDelay = 300;
|
|
|
|
|
2017-03-24 22:01:30 -07:00
|
|
|
export default Component.extend({
|
2017-04-05 09:02:04 -07:00
|
|
|
/**
|
|
|
|
* Service to retrieve type ahead keywords for a dataset
|
|
|
|
* @type {Ember.Service}
|
|
|
|
*/
|
|
|
|
keywords: service('search-keywords'),
|
|
|
|
|
|
|
|
// Keywords and search Category filter
|
|
|
|
currentFilter: 'datasets',
|
|
|
|
|
2017-03-24 22:01:30 -07:00
|
|
|
tagName: 'form',
|
|
|
|
|
|
|
|
elementId: 'global-search-form',
|
|
|
|
|
2017-04-05 09:02:04 -07:00
|
|
|
|
2017-03-24 22:01:30 -07:00
|
|
|
search: '',
|
|
|
|
|
2017-04-05 09:02:04 -07:00
|
|
|
/**
|
|
|
|
* Based on the currentFilter returns a list of options
|
|
|
|
* for the dynamic-link component
|
|
|
|
*/
|
|
|
|
filterOptions: computed('currentFilter', function () {
|
|
|
|
const currentFilter = get(this, 'currentFilter');
|
|
|
|
return ['datasets', 'metrics', 'flows'].map(filter => ({
|
|
|
|
title: filter,
|
|
|
|
text: filter,
|
|
|
|
action: `filter${filter.capitalize()}`,
|
|
|
|
activeWhen: filter === currentFilter
|
|
|
|
}));
|
|
|
|
}),
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Based on the currentFilter returns placeholder text
|
|
|
|
*/
|
|
|
|
placeholder: computed('currentFilter', function () {
|
|
|
|
return `Search ${get(this, 'currentFilter')} by keywords... e.g. pagekey`;
|
|
|
|
}),
|
|
|
|
|
2017-03-24 22:01:30 -07:00
|
|
|
actions: {
|
2017-04-05 09:02:04 -07:00
|
|
|
/**
|
|
|
|
* When a search action is performed, invoke the parent search action with
|
|
|
|
* the user entered search value as keyword and the currentFilter
|
|
|
|
* as category
|
|
|
|
*/
|
2017-03-24 22:01:30 -07:00
|
|
|
search() {
|
2017-04-05 09:02:04 -07:00
|
|
|
this.sendAction('didSearch', {
|
|
|
|
keyword: get(this, 'search'),
|
|
|
|
category: get(this, 'currentFilter')
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles the text input action for potential typeahead matches
|
|
|
|
*/
|
|
|
|
onInput() {
|
|
|
|
const queryResolver = get(this, 'keywords.apiResultsFor')(
|
|
|
|
get(this, 'currentFilter')
|
|
|
|
);
|
|
|
|
|
|
|
|
// Delay invocation until after the given number of ms after each
|
|
|
|
// text input
|
|
|
|
debounce(this, queryResolver, [...arguments], keyPressDelay);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The current dynamic-link implementation sends an action without the option
|
|
|
|
* to pass arguments or using closure actions, hence the need to create
|
|
|
|
* ugly separate individual actions for each filter
|
|
|
|
* A PR will be created to fix this and then the implementation below
|
|
|
|
* refactored to correct this.
|
|
|
|
* TODO: DSS-6760 Create PR to handle action as closure action in dynamic-link
|
|
|
|
* component
|
|
|
|
*/
|
|
|
|
filterDatasets() {
|
|
|
|
set(this, 'currentFilter', 'datasets');
|
|
|
|
},
|
|
|
|
|
|
|
|
filterMetrics() {
|
|
|
|
set(this, 'currentFilter', 'metrics');
|
|
|
|
},
|
|
|
|
|
|
|
|
filterFlows() {
|
|
|
|
set(this, 'currentFilter', 'flows');
|
2017-03-24 22:01:30 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|