debian-mirror-gitlab/app/assets/javascripts/snippets/index.js

57 lines
1.4 KiB
JavaScript
Raw Normal View History

2020-01-01 13:55:28 +05:30
import Vue from 'vue';
import VueApollo from 'vue-apollo';
2020-10-24 23:57:45 +05:30
import Translate from '~/vue_shared/translate';
2020-01-01 13:55:28 +05:30
import createDefaultClient from '~/lib/graphql';
2020-04-22 19:07:51 +05:30
import SnippetsShow from './components/show.vue';
import SnippetsEdit from './components/edit.vue';
2020-11-24 15:15:51 +05:30
import { SNIPPET_LEVELS_MAP, SNIPPET_VISIBILITY_PRIVATE } from '~/snippets/constants';
2020-01-01 13:55:28 +05:30
Vue.use(VueApollo);
Vue.use(Translate);
2020-04-22 19:07:51 +05:30
function appFactory(el, Component) {
2020-01-01 13:55:28 +05:30
if (!el) {
return false;
}
const apolloProvider = new VueApollo({
defaultClient: createDefaultClient(),
});
2020-11-24 15:15:51 +05:30
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,
},
});
2020-01-01 13:55:28 +05:30
return new Vue({
el,
apolloProvider,
render(createElement) {
2020-04-22 19:07:51 +05:30
return createElement(Component, {
2020-01-01 13:55:28 +05:30
props: {
2020-11-24 15:15:51 +05:30
...restDataset,
2020-01-01 13:55:28 +05:30
},
});
},
});
2020-04-22 19:07:51 +05:30
}
export const SnippetShowInit = () => {
appFactory(document.getElementById('js-snippet-view'), SnippetsShow);
2020-01-01 13:55:28 +05:30
};
2020-04-22 19:07:51 +05:30
export const SnippetEditInit = () => {
appFactory(document.getElementById('js-snippet-edit'), SnippetsEdit);
};