Welcome to mirror list, hosted at ThFree Co, Russian Federation.

index.js « frequent_items « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: cef8be37a4051070af0819dcfd03510359529c75 (plain)
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import $ from 'jquery';
import Vue from 'vue';
import Translate from '~/vue_shared/translate';
import eventHub from './event_hub';
import { createStore } from '~/frequent_items/store';

Vue.use(Translate);

const frequentItemDropdowns = [
  {
    namespace: 'projects',
    key: 'project',
  },
  {
    namespace: 'groups',
    key: 'group',
  },
];

export default function initFrequentItemDropdowns() {
  frequentItemDropdowns.forEach((dropdown) => {
    const { namespace, key } = dropdown;
    const el = document.getElementById(`js-${namespace}-dropdown`);
    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
    if (!el || !navEl) {
      return;
    }

    const dropdownType = namespace;
    const store = createStore({ dropdownType });

    import('./components/app.vue')
      .then(({ default: FrequentItems }) => {
        // eslint-disable-next-line no-new
        new Vue({
          el,
          store,
          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(() => {});

    $(navEl).on('shown.bs.dropdown', () => {
      eventHub.$emit(`${namespace}-dropdownOpen`);
    });
  });
}