summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/repository/index.js
blob: d9216e886769cf4ea3b939833f0642110422046d (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
75
76
77
78
import Vue from 'vue';
import createRouter from './router';
import App from './components/app.vue';
import Breadcrumbs from './components/breadcrumbs.vue';
import LastCommit from './components/last_commit.vue';
import apolloProvider from './graphql';
import { setTitle } from './utils/title';

export default function setupVueRepositoryList() {
  const el = document.getElementById('js-tree-list');
  const { projectPath, projectShortPath, ref, fullName } = el.dataset;
  const router = createRouter(projectPath, ref);

  apolloProvider.clients.defaultClient.cache.writeData({
    data: {
      projectPath,
      projectShortPath,
      ref,
    },
  });

  router.afterEach(({ params: { pathMatch } }) => {
    const isRoot = pathMatch === undefined || pathMatch === '/';

    setTitle(pathMatch, ref, fullName);

    if (!isRoot) {
      document
        .querySelectorAll('.js-keep-hidden-on-navigation')
        .forEach(elem => elem.classList.add('hidden'));
    }

    document
      .querySelectorAll('.js-hide-on-navigation')
      .forEach(elem => elem.classList.toggle('hidden', !isRoot));
  });

  // eslint-disable-next-line no-new
  new Vue({
    el: document.getElementById('js-repo-breadcrumb'),
    router,
    apolloProvider,
    render(h) {
      return h(Breadcrumbs, {
        props: {
          currentPath: this.$route.params.pathMatch,
        },
      });
    },
  });

  const commitEl = document.getElementById('js-last-commit');

  if (commitEl) {
    // eslint-disable-next-line no-new
    new Vue({
      el: commitEl,
      router,
      apolloProvider,
      render(h) {
        return h(LastCommit, {
          props: {
            currentPath: this.$route.params.pathMatch,
          },
        });
      },
    });
  }

  return new Vue({
    el,
    router,
    apolloProvider,
    render(h) {
      return h(App);
    },
  });
}