-
Notifications
You must be signed in to change notification settings - Fork 65
/
page-layout.js
59 lines (55 loc) · 1.87 KB
/
page-layout.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { resolve } from 'rsvp';
import { computed } from '@ember/object';
import { inject as service } from '@ember/service';
import Component from '@ember/component';
import { isBlank } from '@ember/utils';
import { task, timeout } from 'ember-concurrency';
export default Component.extend({
showHeaderSearch: true,
searchTerm: null,
store: service(),
session: service(),
routing: service(),
metrics: service(),
searchService: service('search'),
categories: computed(function() {
return this.get('store').peekAll('category');
}),
goSearch(term) {
if (!isBlank(term)) {
this.get('metrics').trackEvent({ category: 'Header search', action: `Search on ${document.location.pathname}`, label: this.get('searchTerm') });
this.get('routing').transitionTo('index', { queryParams: { query: term } });
}
},
searchForAddons: task(function* (term) {
if (term.length === 0) {
return resolve([]);
}
yield timeout(250);
this.get('metrics').trackEvent({ category: 'Header autocomplete', action: `Autocomplete on ${document.location.pathname}`, label: term });
let results = yield this.get('searchService.searchAddonNames').perform(term);
let limitedResults = results.slice(0, 5);
if (!limitedResults.length) {
return [{
noResults: true,
isFullSearchLink: true
}];
}
limitedResults.insertAt(1, { isFullSearchLink: true });
return limitedResults;
}).restartable(),
goToAddon: task(function* (selected, options) {
if (selected.isFullSearchLink) {
this.goSearch(options.searchText);
} else {
this.set('selectedAddon', selected);
yield this.get('routing').transitionTo('addons.show', selected);
this.set('selectedAddon', null);
}
}),
logoutUser() {
this.get('session').close().finally(() => {
this.get('routing').transitionTo('index');
});
}
});