summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/packages_and_registries/harbor_registry/index.js
blob: ecfefead61a71af24134b0164f8631f4b59cb680 (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 { GlToast } from '@gitlab/ui';
import Vue from 'vue';
import { parseBoolean } from '~/lib/utils/common_utils';
import PerformancePlugin from '~/performance/vue_performance_plugin';
import Translate from '~/vue_shared/translate';
import RegistryBreadcrumb from '~/packages_and_registries/shared/components/registry_breadcrumb.vue';
import { renderBreadcrumb } from '~/packages_and_registries/shared/utils';
import { helpPagePath } from '~/helpers/help_page_helper';
import {
  dockerBuildCommand,
  dockerPushCommand,
  dockerLoginCommand,
} from '~/packages_and_registries/harbor_registry/constants';
import createRouter from './router';
import HarborRegistryExplorer from './pages/index.vue';

Vue.use(Translate);
Vue.use(GlToast);

Vue.use(PerformancePlugin, {
  components: [
    'RegistryListPage',
    'ListHeader',
    'ImageListRow',
    'RegistryDetailsPage',
    'DetailsHeader',
    'TagsList',
  ],
});

export default (id) => {
  const el = document.getElementById(id);

  if (!el) {
    return null;
  }

  const { endpoint, connectionError, invalidPathError, isGroupPage, ...config } = el.dataset;

  const breadCrumbState = Vue.observable({
    name: '',
    updateName(value) {
      this.name = value;
    },
  });

  const router = createRouter(endpoint, breadCrumbState);

  const attachMainComponent = () => {
    return new Vue({
      el,
      router,
      provide() {
        return {
          breadCrumbState,
          config: {
            ...config,
            connectionError: parseBoolean(connectionError),
            invalidPathError: parseBoolean(invalidPathError),
            isGroupPage: parseBoolean(isGroupPage),
            helpPagePath: helpPagePath('user/packages/container_registry/index'),
          },
          dockerBuildCommand: dockerBuildCommand(config.repositoryUrl),
          dockerPushCommand: dockerPushCommand(config.repositoryUrl),
          dockerLoginCommand: dockerLoginCommand(config.registryHostUrlWithPort),
        };
      },
      render(createElement) {
        return createElement(HarborRegistryExplorer);
      },
    });
  };

  return {
    attachBreadcrumb: renderBreadcrumb(router, null, RegistryBreadcrumb),
    attachMainComponent,
  };
};