2018-05-09 12:01:36 +05:30
|
|
|
import Vue from 'vue';
|
2018-11-08 19:23:39 +05:30
|
|
|
import { mapActions } from 'vuex';
|
2018-05-09 12:01:36 +05:30
|
|
|
import Translate from '~/vue_shared/translate';
|
|
|
|
import ide from './components/ide.vue';
|
|
|
|
import store from './stores';
|
|
|
|
import router from './ide_router';
|
2019-01-03 12:48:30 +05:30
|
|
|
import { convertPermissionToBoolean } from '../lib/utils/common_utils';
|
2018-05-09 12:01:36 +05:30
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
Vue.use(Translate);
|
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
/**
|
|
|
|
* 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).
|
2019-01-03 12:48:30 +05:30
|
|
|
* @param {(e:Element) => Object} options.extraInitialData -
|
|
|
|
* Function that returns extra properties to seed initial data.
|
2018-12-05 23:21:45 +05:30
|
|
|
* @param {Component} options.rootComponent -
|
|
|
|
* Component that overrides the root component.
|
|
|
|
*/
|
|
|
|
export function initIde(el, options = {}) {
|
2018-05-09 12:01:36 +05:30
|
|
|
if (!el) return null;
|
|
|
|
|
2019-01-03 12:48:30 +05:30
|
|
|
const { extraInitialData = () => ({}), rootComponent = ide } = options;
|
2018-12-05 23:21:45 +05:30
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
return new Vue({
|
|
|
|
el,
|
2019-01-03 12:48:30 +05:30
|
|
|
store,
|
2018-05-09 12:01:36 +05:30
|
|
|
router,
|
2018-10-15 14:42:47 +05:30
|
|
|
created() {
|
2018-11-08 19:23:39 +05:30
|
|
|
this.setEmptyStateSvgs({
|
2018-10-15 14:42:47 +05:30
|
|
|
emptyStateSvgPath: el.dataset.emptyStateSvgPath,
|
|
|
|
noChangesStateSvgPath: el.dataset.noChangesStateSvgPath,
|
|
|
|
committedStateSvgPath: el.dataset.committedStateSvgPath,
|
2018-11-08 19:23:39 +05:30
|
|
|
pipelinesEmptyStateSvgPath: el.dataset.pipelinesEmptyStateSvgPath,
|
2018-11-18 11:00:15 +05:30
|
|
|
promotionSvgPath: el.dataset.promotionSvgPath,
|
2018-05-09 12:01:36 +05:30
|
|
|
});
|
2018-11-08 19:23:39 +05:30
|
|
|
this.setLinks({
|
|
|
|
ciHelpPagePath: el.dataset.ciHelpPagePath,
|
2018-11-18 11:00:15 +05:30
|
|
|
webIDEHelpPagePath: el.dataset.webIdeHelpPagePath,
|
|
|
|
});
|
|
|
|
this.setInitialData({
|
2019-01-03 12:48:30 +05:30
|
|
|
clientsidePreviewEnabled: convertPermissionToBoolean(el.dataset.clientsidePreviewEnabled),
|
|
|
|
...extraInitialData(el),
|
2018-11-08 19:23:39 +05:30
|
|
|
});
|
|
|
|
},
|
|
|
|
methods: {
|
2018-11-18 11:00:15 +05:30
|
|
|
...mapActions(['setEmptyStateSvgs', 'setLinks', 'setInitialData']),
|
2018-05-09 12:01:36 +05:30
|
|
|
},
|
2018-10-15 14:42:47 +05:30
|
|
|
render(createElement) {
|
2018-12-05 23:21:45 +05:30
|
|
|
return createElement(rootComponent);
|
2018-10-15 14:42:47 +05:30
|
|
|
},
|
2018-05-09 12:01:36 +05:30
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
// tell webpack to load assets from origin so that web workers don't break
|
|
|
|
export function resetServiceWorkersPublicPath() {
|
|
|
|
// __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/
|
|
|
|
const relativeRootPath = (gon && gon.relative_url_root) || '';
|
|
|
|
const webpackAssetPath = `${relativeRootPath}/assets/webpack/`;
|
|
|
|
__webpack_public_path__ = webpackAssetPath; // eslint-disable-line camelcase
|
|
|
|
}
|
2018-12-05 23:21:45 +05:30
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|