2018-11-08 19:23:39 +05:30
|
|
|
import $ from 'jquery';
|
|
|
|
import Vue from 'vue';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { createStore } from '~/frequent_items/store';
|
2018-11-08 19:23:39 +05:30
|
|
|
import Translate from '~/vue_shared/translate';
|
2020-06-23 00:09:42 +05:30
|
|
|
import eventHub from './event_hub';
|
2018-11-08 19:23:39 +05:30
|
|
|
|
|
|
|
Vue.use(Translate);
|
|
|
|
|
|
|
|
const frequentItemDropdowns = [
|
|
|
|
{
|
|
|
|
namespace: 'projects',
|
|
|
|
key: 'project',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
namespace: 'groups',
|
|
|
|
key: 'group',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
export default function initFrequentItemDropdowns() {
|
2021-03-08 18:12:59 +05:30
|
|
|
frequentItemDropdowns.forEach((dropdown) => {
|
2018-11-08 19:23:39 +05:30
|
|
|
const { namespace, key } = 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-02-22 17:27:13 +05:30
|
|
|
const dropdownType = namespace;
|
|
|
|
const store = createStore({ dropdownType });
|
|
|
|
|
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) {
|
|
|
|
return createElement(FrequentItems, {
|
|
|
|
props: {
|
|
|
|
namespace,
|
|
|
|
currentUserName: this.currentUserName,
|
|
|
|
currentItem: this.currentItem,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.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
|
|
|
});
|
|
|
|
}
|