debian-mirror-gitlab/app/assets/javascripts/filtered_search/recent_searches_root.js

61 lines
1.5 KiB
JavaScript
Raw Normal View History

2017-08-17 22:00:37 +05:30
import Vue from 'vue';
2018-03-27 19:54:05 +05:30
import RecentSearchesDropdownContent from './components/recent_searches_dropdown_content.vue';
2017-08-17 22:00:37 +05:30
import eventHub from './event_hub';
class RecentSearchesRoot {
2018-12-13 13:39:08 +05:30
constructor(recentSearchesStore, recentSearchesService, wrapperElement) {
2017-08-17 22:00:37 +05:30
this.store = recentSearchesStore;
this.service = recentSearchesService;
this.wrapperElement = wrapperElement;
}
init() {
this.bindEvents();
this.render();
}
bindEvents() {
this.onRequestClearRecentSearchesWrapper = this.onRequestClearRecentSearches.bind(this);
eventHub.$on('requestClearRecentSearches', this.onRequestClearRecentSearchesWrapper);
}
unbindEvents() {
eventHub.$off('requestClearRecentSearches', this.onRequestClearRecentSearchesWrapper);
}
render() {
2018-11-08 19:23:39 +05:30
const { state } = this.store;
2017-08-17 22:00:37 +05:30
this.vm = new Vue({
el: this.wrapperElement,
2018-03-17 18:26:18 +05:30
components: {
2018-03-27 19:54:05 +05:30
RecentSearchesDropdownContent,
2018-03-17 18:26:18 +05:30
},
2018-12-13 13:39:08 +05:30
data() {
return state;
},
2017-08-17 22:00:37 +05:30
template: `
<recent-searches-dropdown-content
:items="recentSearches"
:is-local-storage-available="isLocalStorageAvailable"
2017-09-10 17:25:29 +05:30
:allowed-keys="allowedKeys"
2017-08-17 22:00:37 +05:30
/>
`,
});
}
onRequestClearRecentSearches() {
const resultantSearches = this.store.setRecentSearches([]);
this.service.save(resultantSearches);
}
destroy() {
this.unbindEvents();
if (this.vm) {
this.vm.$destroy();
}
}
}
export default RecentSearchesRoot;