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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

125 lines
3 KiB
JavaScript
Raw Normal View History

2020-05-24 23:13:21 +05:30
import Vue from 'vue';
2022-01-26 12:08:38 +05:30
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
2021-04-29 21:17:54 +05:30
import { parseRailsFormFields } from '~/lib/utils/forms';
2022-07-23 23:45:48 +05:30
import { __, sprintf } from '~/locale';
2021-04-17 20:07:23 +05:30
2022-07-23 23:45:48 +05:30
import AccessTokenTableApp from './components/access_token_table_app.vue';
2020-05-24 23:13:21 +05:30
import ExpiresAtField from './components/expires_at_field.vue';
2022-07-23 23:45:48 +05:30
import NewAccessTokenApp from './components/new_access_token_app.vue';
2022-01-26 12:08:38 +05:30
import TokensApp from './components/tokens_app.vue';
import { FEED_TOKEN, INCOMING_EMAIL_TOKEN, STATIC_OBJECT_TOKEN } from './constants';
2020-05-24 23:13:21 +05:30
2022-07-23 23:45:48 +05:30
export const initAccessTokenTableApp = () => {
const el = document.querySelector('#js-access-token-table-app');
if (!el) {
return null;
}
const {
accessTokenType,
accessTokenTypePlural,
2022-11-25 23:54:43 +05:30
information,
2022-07-23 23:45:48 +05:30
initialActiveAccessTokens: initialActiveAccessTokensJson,
noActiveTokensMessage: noTokensMessage,
} = el.dataset;
// Default values
const noActiveTokensMessage =
noTokensMessage ||
sprintf(__('This user has no active %{accessTokenTypePlural}.'), { accessTokenTypePlural });
const showRole = 'showRole' in el.dataset;
2022-11-25 23:54:43 +05:30
const initialActiveAccessTokens = JSON.parse(initialActiveAccessTokensJson);
2022-07-23 23:45:48 +05:30
return new Vue({
el,
name: 'AccessTokenTableRoot',
provide: {
accessTokenType,
accessTokenTypePlural,
2022-11-25 23:54:43 +05:30
information,
2022-07-23 23:45:48 +05:30
initialActiveAccessTokens,
noActiveTokensMessage,
showRole,
},
render(h) {
return h(AccessTokenTableApp);
},
});
};
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);
2022-10-11 01:57:18 +05:30
const { minDate, maxDate, defaultDateOffset, description } = el.dataset;
2021-01-29 00:20:46 +05:30
return new Vue({
el,
render(h) {
return h(ExpiresAtField, {
props: {
inputAttrs,
2022-07-23 23:45:48 +05:30
minDate: minDate ? new Date(minDate) : undefined,
2022-05-07 20:08:51 +05:30
maxDate: maxDate ? new Date(maxDate) : undefined,
2022-10-11 01:57:18 +05:30
defaultDateOffset: defaultDateOffset ? Number(defaultDateOffset) : undefined,
description,
2021-01-29 00:20:46 +05:30
},
});
},
2020-05-24 23:13:21 +05:30
});
};
2022-07-23 23:45:48 +05:30
export const initNewAccessTokenApp = () => {
const el = document.querySelector('#js-new-access-token-app');
if (!el) {
return null;
}
const { accessTokenType } = el.dataset;
return new Vue({
el,
name: 'NewAccessTokenRoot',
provide: {
accessTokenType,
},
render(h) {
return h(NewAccessTokenApp);
},
});
};
2022-01-26 12:08:38 +05:30
export const initTokensApp = () => {
const el = document.getElementById('js-tokens-app');
2022-11-25 23:54:43 +05:30
if (!el) return null;
2022-01-26 12:08:38 +05:30
const tokensData = convertObjectPropsToCamelCase(JSON.parse(el.dataset.tokensData), {
deep: true,
});
const tokenTypes = {
[FEED_TOKEN]: tokensData[FEED_TOKEN],
[INCOMING_EMAIL_TOKEN]: tokensData[INCOMING_EMAIL_TOKEN],
[STATIC_OBJECT_TOKEN]: tokensData[STATIC_OBJECT_TOKEN],
};
return new Vue({
el,
provide: {
tokenTypes,
},
render(createElement) {
return createElement(TokensApp);
},
});
};