2019-12-13 13:08:06 -05:00
|
|
|
import Vue from 'vue';
|
|
|
|
import VueApollo from 'vue-apollo';
|
2020-08-17 17:09:56 -04:00
|
|
|
import Translate from '~/vue_shared/translate';
|
2019-12-13 13:08:06 -05:00
|
|
|
import createDefaultClient from '~/lib/graphql';
|
|
|
|
|
2020-04-21 11:21:10 -04:00
|
|
|
import SnippetsShow from './components/show.vue';
|
|
|
|
import SnippetsEdit from './components/edit.vue';
|
2020-09-04 20:08:43 -04:00
|
|
|
import { SNIPPET_LEVELS_MAP, SNIPPET_VISIBILITY_PRIVATE } from '~/snippets/constants';
|
2019-12-13 13:08:06 -05:00
|
|
|
|
|
|
|
Vue.use(VueApollo);
|
|
|
|
Vue.use(Translate);
|
|
|
|
|
2020-03-24 11:08:44 -04:00
|
|
|
function appFactory(el, Component) {
|
2019-12-13 13:08:06 -05:00
|
|
|
if (!el) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const apolloProvider = new VueApollo({
|
|
|
|
defaultClient: createDefaultClient(),
|
|
|
|
});
|
|
|
|
|
2020-09-04 20:08:43 -04:00
|
|
|
const {
|
|
|
|
visibilityLevels = '[]',
|
|
|
|
selectedLevel,
|
|
|
|
multipleLevelsRestricted,
|
|
|
|
...restDataset
|
|
|
|
} = el.dataset;
|
|
|
|
|
|
|
|
apolloProvider.clients.defaultClient.cache.writeData({
|
|
|
|
data: {
|
|
|
|
visibilityLevels: JSON.parse(visibilityLevels),
|
|
|
|
selectedLevel: SNIPPET_LEVELS_MAP[selectedLevel] ?? SNIPPET_VISIBILITY_PRIVATE,
|
|
|
|
multipleLevelsRestricted: 'multipleLevelsRestricted' in el.dataset,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2019-12-13 13:08:06 -05:00
|
|
|
return new Vue({
|
|
|
|
el,
|
|
|
|
apolloProvider,
|
|
|
|
render(createElement) {
|
2020-03-24 11:08:44 -04:00
|
|
|
return createElement(Component, {
|
2019-12-13 13:08:06 -05:00
|
|
|
props: {
|
2020-09-04 20:08:43 -04:00
|
|
|
...restDataset,
|
2019-12-13 13:08:06 -05:00
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
2020-03-24 11:08:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export const SnippetShowInit = () => {
|
2020-04-21 11:21:10 -04:00
|
|
|
appFactory(document.getElementById('js-snippet-view'), SnippetsShow);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const SnippetEditInit = () => {
|
|
|
|
appFactory(document.getElementById('js-snippet-edit'), SnippetsEdit);
|
2019-12-13 13:08:06 -05:00
|
|
|
};
|