2018-03-20 10:12:48 -04:00
|
|
|
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';
|
2018-03-20 10:12:48 -04:00
|
|
|
import Translate from '~/vue_shared/translate';
|
|
|
|
import ide from './components/ide.vue';
|
|
|
|
import store from './stores';
|
|
|
|
import router from './ide_router';
|
2018-11-21 10:13:04 -05:00
|
|
|
import { parseBoolean } from '../lib/utils/common_utils';
|
2019-02-08 09:06:24 -05:00
|
|
|
import { resetServiceWorkersPublicPath } from '../lib/utils/webpack';
|
2018-03-20 10:12:48 -04:00
|
|
|
|
2018-05-03 12:16:56 -04:00
|
|
|
Vue.use(Translate);
|
|
|
|
|
2019-01-14 16:46:21 -05:00
|
|
|
/**
|
|
|
|
* Function that receives the default store and returns an extended one.
|
|
|
|
* @callback extendStoreCallback
|
|
|
|
* @param {Vuex.Store} store
|
|
|
|
* @param {Element} el
|
|
|
|
*/
|
|
|
|
|
2018-09-24 17:37:04 -04:00
|
|
|
/**
|
|
|
|
* 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).
|
2018-09-26 23:59:02 -04:00
|
|
|
* @param {Component} options.rootComponent -
|
|
|
|
* Component that overrides the root component.
|
2019-01-14 16:46:21 -05:00
|
|
|
* @param {extendStoreCallback} options.extendStore -
|
2018-12-03 13:00:03 -05:00
|
|
|
* Function that receives the default store and returns an extended one.
|
2018-09-24 17:37:04 -04:00
|
|
|
*/
|
|
|
|
export function initIde(el, options = {}) {
|
2018-03-20 10:12:48 -04:00
|
|
|
if (!el) return null;
|
|
|
|
|
2018-12-03 13:00:03 -05:00
|
|
|
const { rootComponent = ide, extendStore = _.identity } = options;
|
2018-09-24 17:37:04 -04:00
|
|
|
|
2018-03-20 10:12:48 -04:00
|
|
|
return new Vue({
|
|
|
|
el,
|
2018-12-03 13:00:03 -05:00
|
|
|
store: extendStore(store, el),
|
2018-03-20 10:12:48 -04:00
|
|
|
router,
|
2018-04-16 11:29:34 -04:00
|
|
|
created() {
|
2018-05-29 06:06:00 -04:00
|
|
|
this.setEmptyStateSvgs({
|
2018-04-16 11:29:34 -04:00
|
|
|
emptyStateSvgPath: el.dataset.emptyStateSvgPath,
|
|
|
|
noChangesStateSvgPath: el.dataset.noChangesStateSvgPath,
|
|
|
|
committedStateSvgPath: el.dataset.committedStateSvgPath,
|
2018-05-29 05:35:13 -04:00
|
|
|
pipelinesEmptyStateSvgPath: el.dataset.pipelinesEmptyStateSvgPath,
|
2018-06-13 12:06:35 -04:00
|
|
|
promotionSvgPath: el.dataset.promotionSvgPath,
|
2018-04-16 11:29:34 -04:00
|
|
|
});
|
2018-05-29 06:06:00 -04:00
|
|
|
this.setLinks({
|
|
|
|
ciHelpPagePath: el.dataset.ciHelpPagePath,
|
2018-06-13 12:06:35 -04:00
|
|
|
webIDEHelpPagePath: el.dataset.webIdeHelpPagePath,
|
|
|
|
});
|
|
|
|
this.setInitialData({
|
2018-11-21 10:13:04 -05:00
|
|
|
clientsidePreviewEnabled: parseBoolean(el.dataset.clientsidePreviewEnabled),
|
2018-05-29 06:06:00 -04:00
|
|
|
});
|
|
|
|
},
|
|
|
|
methods: {
|
2018-06-13 12:06:35 -04:00
|
|
|
...mapActions(['setEmptyStateSvgs', 'setLinks', 'setInitialData']),
|
2018-04-16 11:29:34 -04:00
|
|
|
},
|
2018-03-20 10:12:48 -04:00
|
|
|
render(createElement) {
|
2018-09-26 23:59:02 -04:00
|
|
|
return createElement(rootComponent);
|
2018-03-20 10:12:48 -04:00
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-09-24 17:37:04 -04:00
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|