debian-mirror-gitlab/app/assets/javascripts/frequent_items/index.js

78 lines
2.3 KiB
JavaScript
Raw Normal View History

2018-11-08 19:23:39 +05:30
import $ from 'jquery';
import Vue from 'vue';
2021-06-08 01:23:25 +05:30
import Vuex from 'vuex';
2021-03-11 19:13:27 +05:30
import { createStore } from '~/frequent_items/store';
2021-06-08 01:23:25 +05:30
import VuexModuleProvider from '~/vue_shared/components/vuex_module_provider.vue';
2018-11-08 19:23:39 +05:30
import Translate from '~/vue_shared/translate';
2021-06-08 01:23:25 +05:30
import { FREQUENT_ITEMS_DROPDOWNS } from './constants';
2020-06-23 00:09:42 +05:30
import eventHub from './event_hub';
2018-11-08 19:23:39 +05:30
2021-06-08 01:23:25 +05:30
Vue.use(Vuex);
2018-11-08 19:23:39 +05:30
Vue.use(Translate);
2020-06-23 00:09:42 +05:30
export default function initFrequentItemDropdowns() {
2021-06-08 01:23:25 +05:30
const store = createStore();
FREQUENT_ITEMS_DROPDOWNS.forEach((dropdown) => {
const { namespace, key, vuexModule } = dropdown;
2021-01-29 00:20:46 +05:30
const el = document.getElementById(`js-${namespace}-dropdown`);
2018-11-08 19:23:39 +05:30
const navEl = document.getElementById(`nav-${namespace}-dropdown`);
// Don't do anything if element doesn't exist (No groups dropdown)
// This is for when the user accesses GitLab without logging in
2021-01-29 00:20:46 +05:30
if (!el || !navEl) {
2018-11-08 19:23:39 +05:30
return;
}
2021-01-29 00:20:46 +05:30
import('./components/app.vue')
.then(({ default: FrequentItems }) => {
// eslint-disable-next-line no-new
new Vue({
el,
2021-02-22 17:27:13 +05:30
store,
2021-01-29 00:20:46 +05:30
data() {
const { dataset } = this.$options.el;
const item = {
id: Number(dataset[`${key}Id`]),
name: dataset[`${key}Name`],
namespace: dataset[`${key}Namespace`],
webUrl: dataset[`${key}WebUrl`],
avatarUrl: dataset[`${key}AvatarUrl`] || null,
lastAccessedOn: Date.now(),
};
return {
currentUserName: dataset.userName,
currentItem: item,
};
},
render(createElement) {
2021-06-08 01:23:25 +05:30
return createElement(
VuexModuleProvider,
{
props: {
vuexModule,
},
2021-01-29 00:20:46 +05:30
},
2021-06-08 01:23:25 +05:30
[
createElement(FrequentItems, {
props: {
namespace,
currentUserName: this.currentUserName,
currentItem: this.currentItem,
2021-09-04 01:27:46 +05:30
searchClass: 'gl-display-none gl-sm-display-block',
2021-06-08 01:23:25 +05:30
},
}),
],
);
2021-01-29 00:20:46 +05:30
},
});
})
.catch(() => {});
2020-11-24 15:15:51 +05:30
$(navEl).on('shown.bs.dropdown', () => {
eventHub.$emit(`${namespace}-dropdownOpen`);
});
2020-06-23 00:09:42 +05:30
});
}