2020-05-24 23:13:21 +05:30
|
|
|
import Vue from 'vue';
|
2021-04-17 20:07:23 +05:30
|
|
|
import createFlash from '~/flash';
|
2021-04-29 21:17:54 +05:30
|
|
|
import { parseRailsFormFields } from '~/lib/utils/forms';
|
2021-04-17 20:07:23 +05:30
|
|
|
import { __ } from '~/locale';
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
import ExpiresAtField from './components/expires_at_field.vue';
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
export const initExpiresAtField = () => {
|
2021-01-29 00:20:46 +05:30
|
|
|
const el = document.querySelector('.js-access-tokens-expires-at');
|
|
|
|
|
|
|
|
if (!el) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
const { expiresAt: inputAttrs } = parseRailsFormFields(el);
|
2021-01-29 00:20:46 +05:30
|
|
|
|
|
|
|
return new Vue({
|
|
|
|
el,
|
|
|
|
render(h) {
|
|
|
|
return h(ExpiresAtField, {
|
|
|
|
props: {
|
|
|
|
inputAttrs,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
2020-05-24 23:13:21 +05:30
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
export const initProjectsField = () => {
|
|
|
|
const el = document.querySelector('.js-access-tokens-projects');
|
|
|
|
|
|
|
|
if (!el) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
const { projects: inputAttrs } = parseRailsFormFields(el);
|
2021-04-17 20:07:23 +05:30
|
|
|
|
|
|
|
if (window.gon.features.personalAccessTokensScopedToProjects) {
|
|
|
|
return new Promise((resolve) => {
|
|
|
|
Promise.all([
|
|
|
|
import('./components/projects_field.vue'),
|
|
|
|
import('vue-apollo'),
|
|
|
|
import('~/lib/graphql'),
|
|
|
|
])
|
|
|
|
.then(
|
|
|
|
([
|
|
|
|
{ default: ProjectsField },
|
|
|
|
{ default: VueApollo },
|
|
|
|
{ default: createDefaultClient },
|
|
|
|
]) => {
|
|
|
|
const apolloProvider = new VueApollo({
|
2021-11-18 22:05:49 +05:30
|
|
|
defaultClient: createDefaultClient({}, { assumeImmutableResults: true }),
|
2021-04-17 20:07:23 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
Vue.use(VueApollo);
|
|
|
|
|
|
|
|
resolve(
|
|
|
|
new Vue({
|
|
|
|
el,
|
|
|
|
apolloProvider,
|
|
|
|
render(h) {
|
|
|
|
return h(ProjectsField, {
|
|
|
|
props: {
|
|
|
|
inputAttrs,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
)
|
|
|
|
.catch(() => {
|
|
|
|
createFlash({
|
|
|
|
message: __(
|
|
|
|
'An error occurred while loading the access tokens form, please try again.',
|
|
|
|
),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
};
|