gitlab-org--gitlab-foss/app/assets/javascripts/ide/index.js

78 lines
2.3 KiB
JavaScript
Raw Normal View History

import Vue from 'vue';
2018-05-29 06:06:00 -04:00
import { mapActions } from 'vuex';
2018-12-03 13:00:03 -05:00
import _ from 'underscore';
import Translate from '~/vue_shared/translate';
import ide from './components/ide.vue';
import store from './stores';
import router from './ide_router';
import { parseBoolean } from '../lib/utils/common_utils';
import { resetServiceWorkersPublicPath } from '../lib/utils/webpack';
Vue.use(Translate);
/**
* Function that receives the default store and returns an extended one.
* @callback extendStoreCallback
* @param {Vuex.Store} store
* @param {Element} el
*/
/**
* Initialize the IDE on the given element.
*
* @param {Element} el - The element that will contain the IDE.
* @param {Object} options - Extra options for the IDE (Used by EE).
* @param {Component} options.rootComponent -
* Component that overrides the root component.
* @param {extendStoreCallback} options.extendStore -
2018-12-03 13:00:03 -05:00
* Function that receives the default store and returns an extended one.
*/
export function initIde(el, options = {}) {
if (!el) return null;
2018-12-03 13:00:03 -05:00
const { rootComponent = ide, extendStore = _.identity } = options;
return new Vue({
el,
2018-12-03 13:00:03 -05:00
store: extendStore(store, el),
router,
created() {
2018-05-29 06:06:00 -04:00
this.setEmptyStateSvgs({
emptyStateSvgPath: el.dataset.emptyStateSvgPath,
noChangesStateSvgPath: el.dataset.noChangesStateSvgPath,
committedStateSvgPath: el.dataset.committedStateSvgPath,
2018-05-29 05:35:13 -04:00
pipelinesEmptyStateSvgPath: el.dataset.pipelinesEmptyStateSvgPath,
promotionSvgPath: el.dataset.promotionSvgPath,
});
2018-05-29 06:06:00 -04:00
this.setLinks({
ciHelpPagePath: el.dataset.ciHelpPagePath,
webIDEHelpPagePath: el.dataset.webIdeHelpPagePath,
});
this.setInitialData({
clientsidePreviewEnabled: parseBoolean(el.dataset.clientsidePreviewEnabled),
2018-05-29 06:06:00 -04:00
});
},
methods: {
...mapActions(['setEmptyStateSvgs', 'setLinks', 'setInitialData']),
},
render(createElement) {
return createElement(rootComponent);
},
});
}
/**
* Start the IDE.
*
* @param {Objects} options - Extra options for the IDE (Used by EE).
*/
export function startIde(options) {
document.addEventListener('DOMContentLoaded', () => {
const ideElement = document.getElementById('ide');
if (ideElement) {
resetServiceWorkersPublicPath();
initIde(ideElement, options);
}
});
}