index.js 1.8 KB
Newer Older
P
Phil Hughes 已提交
1
import Vue from 'vue';
2
import { mapActions } from 'vuex';
P
Phil Hughes 已提交
3 4 5 6
import Translate from '~/vue_shared/translate';
import ide from './components/ide.vue';
import store from './stores';
import router from './ide_router';
P
Phil Hughes 已提交
7
import { convertPermissionToBoolean } from '../lib/utils/common_utils';
P
Phil Hughes 已提交
8

9 10 11
Vue.use(Translate);

export function initIde(el) {
P
Phil Hughes 已提交
12 13 14 15 16 17 18 19 20
  if (!el) return null;

  return new Vue({
    el,
    store,
    router,
    components: {
      ide,
    },
P
Phil Hughes 已提交
21
    created() {
22
      this.setEmptyStateSvgs({
P
Phil Hughes 已提交
23 24 25
        emptyStateSvgPath: el.dataset.emptyStateSvgPath,
        noChangesStateSvgPath: el.dataset.noChangesStateSvgPath,
        committedStateSvgPath: el.dataset.committedStateSvgPath,
26
        pipelinesEmptyStateSvgPath: el.dataset.pipelinesEmptyStateSvgPath,
P
Phil Hughes 已提交
27
        promotionSvgPath: el.dataset.promotionSvgPath,
P
Phil Hughes 已提交
28
      });
29 30
      this.setLinks({
        ciHelpPagePath: el.dataset.ciHelpPagePath,
P
Phil Hughes 已提交
31 32 33 34
        webIDEHelpPagePath: el.dataset.webIdeHelpPagePath,
      });
      this.setInitialData({
        clientsidePreviewEnabled: convertPermissionToBoolean(el.dataset.clientsidePreviewEnabled),
35 36 37
      });
    },
    methods: {
P
Phil Hughes 已提交
38
      ...mapActions(['setEmptyStateSvgs', 'setLinks', 'setInitialData']),
P
Phil Hughes 已提交
39
    },
P
Phil Hughes 已提交
40
    render(createElement) {
P
Phil Hughes 已提交
41
      return createElement('ide');
P
Phil Hughes 已提交
42 43 44 45
    },
  });
}

46
// tell webpack to load assets from origin so that web workers don't break
47
export function resetServiceWorkersPublicPath() {
48 49 50
  // __webpack_public_path__ is a global variable that can be used to adjust
  // the webpack publicPath setting at runtime.
  // see: https://webpack.js.org/guides/public-path/
51 52 53 54
  const relativeRootPath = (gon && gon.relative_url_root) || '';
  const webpackAssetPath = `${relativeRootPath}/assets/webpack/`;
  __webpack_public_path__ = webpackAssetPath; // eslint-disable-line camelcase
}