2021-11-03 16:40:31 +00:00
|
|
|
<template>
|
2022-10-27 22:55:07 +00:00
|
|
|
<Scaffold>
|
|
|
|
<template #title>{{ $t('user.settings') }}</template>
|
|
|
|
<template #titleActions><Button :text="$t('logout')" :to="`${address}/logout`" /></template>
|
|
|
|
<div class="space-y-4 flex flex-col">
|
|
|
|
<SelectField v-model="selectedLocale" :options="localeOptions" />
|
2021-11-03 16:40:31 +00:00
|
|
|
|
2022-10-27 22:55:07 +00:00
|
|
|
<div>
|
|
|
|
<h2 class="text-lg text-color">{{ $t('user.token') }}</h2>
|
|
|
|
<pre class="cli-box">{{ token }}</pre>
|
|
|
|
</div>
|
2021-11-03 16:40:31 +00:00
|
|
|
|
2022-10-27 22:55:07 +00:00
|
|
|
<div>
|
|
|
|
<h2 class="text-lg text-color">{{ $t('user.shell_setup') }}</h2>
|
|
|
|
<pre class="cli-box">{{ usageWithShell }}</pre>
|
|
|
|
</div>
|
2021-11-03 16:40:31 +00:00
|
|
|
|
2022-10-27 22:55:07 +00:00
|
|
|
<div>
|
|
|
|
<h2 class="text-lg text-color">{{ $t('user.api_usage') }}</h2>
|
|
|
|
<pre class="cli-box">{{ usageWithCurl }}</pre>
|
|
|
|
</div>
|
2021-11-03 16:40:31 +00:00
|
|
|
|
2022-10-27 22:55:07 +00:00
|
|
|
<div>
|
|
|
|
<div class="flex items-center">
|
|
|
|
<h2 class="text-lg text-color">{{ $t('user.cli_usage') }}</h2>
|
|
|
|
<a :href="cliDownload" target="_blank" class="ml-4 text-link">{{ $t('user.dl_cli') }}</a>
|
|
|
|
</div>
|
|
|
|
<pre class="cli-box">{{ usageWithCli }}</pre>
|
2021-11-03 16:40:31 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-10-27 22:55:07 +00:00
|
|
|
</Scaffold>
|
2021-11-03 16:40:31 +00:00
|
|
|
</template>
|
|
|
|
|
2022-10-27 00:42:39 +00:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import { useLocalStorage } from '@vueuse/core';
|
|
|
|
import dayjs from 'dayjs';
|
|
|
|
import TimeAgo from 'javascript-time-ago';
|
2022-12-29 12:41:59 +00:00
|
|
|
import { SUPPORTED_LOCALES } from 'virtual:vue-i18n-supported-locales';
|
2022-10-27 00:42:39 +00:00
|
|
|
import { computed, onMounted, ref } from 'vue';
|
2022-05-16 19:18:48 +00:00
|
|
|
import { useI18n } from 'vue-i18n';
|
2021-11-03 16:40:31 +00:00
|
|
|
|
|
|
|
import Button from '~/components/atomic/Button.vue';
|
2022-10-27 00:42:39 +00:00
|
|
|
import SelectField from '~/components/form/SelectField.vue';
|
2022-10-27 22:55:07 +00:00
|
|
|
import Scaffold from '~/components/layout/scaffold/Scaffold.vue';
|
2021-11-03 16:40:31 +00:00
|
|
|
import useApiClient from '~/compositions/useApiClient';
|
2022-12-29 12:41:59 +00:00
|
|
|
import { setI18nLanguage } from '~/compositions/useI18n';
|
2021-11-03 16:40:31 +00:00
|
|
|
|
2022-12-29 12:41:59 +00:00
|
|
|
const { t, locale } = useI18n();
|
2021-11-03 16:40:31 +00:00
|
|
|
|
2022-10-27 00:42:39 +00:00
|
|
|
const apiClient = useApiClient();
|
|
|
|
const token = ref<string | undefined>();
|
2021-11-03 16:40:31 +00:00
|
|
|
|
2022-10-27 00:42:39 +00:00
|
|
|
onMounted(async () => {
|
|
|
|
token.value = await apiClient.getToken();
|
|
|
|
});
|
2021-11-03 16:40:31 +00:00
|
|
|
|
2022-10-27 00:42:39 +00:00
|
|
|
// eslint-disable-next-line no-restricted-globals
|
|
|
|
const address = `${location.protocol}//${location.host}`; // port is included in location.host
|
2021-11-03 16:40:31 +00:00
|
|
|
|
2022-10-27 00:42:39 +00:00
|
|
|
const usageWithShell = computed(() => {
|
|
|
|
let usage = `export WOODPECKER_SERVER="${address}"\n`;
|
|
|
|
usage += `export WOODPECKER_TOKEN="${token.value}"\n`;
|
|
|
|
return usage;
|
|
|
|
});
|
2021-11-03 16:40:31 +00:00
|
|
|
|
2022-10-27 00:42:39 +00:00
|
|
|
const usageWithCurl = `# ${t(
|
|
|
|
'user.shell_setup_before',
|
|
|
|
)}\ncurl -i \${WOODPECKER_SERVER}/api/user -H "Authorization: Bearer \${WOODPECKER_TOKEN}"`;
|
2021-11-03 16:40:31 +00:00
|
|
|
|
2022-10-27 00:42:39 +00:00
|
|
|
const usageWithCli = `# ${t('user.shell_setup_before')}\nwoodpecker info`;
|
2021-11-03 16:40:31 +00:00
|
|
|
|
2022-10-27 00:42:39 +00:00
|
|
|
const cliDownload = 'https://github.com/woodpecker-ci/woodpecker/releases';
|
2021-11-03 16:40:31 +00:00
|
|
|
|
2022-10-27 00:42:39 +00:00
|
|
|
const localeOptions = computed(() =>
|
2022-12-29 12:41:59 +00:00
|
|
|
SUPPORTED_LOCALES.map((supportedLocale) => ({
|
|
|
|
value: supportedLocale,
|
|
|
|
text: new Intl.DisplayNames(supportedLocale, { type: 'language' }).of(supportedLocale) || supportedLocale,
|
2022-10-27 00:42:39 +00:00
|
|
|
})),
|
|
|
|
);
|
2021-11-03 16:40:31 +00:00
|
|
|
|
2022-10-27 00:42:39 +00:00
|
|
|
const storedLocale = useLocalStorage('woodpecker:locale', locale.value);
|
|
|
|
const selectedLocale = computed<string>({
|
2022-12-29 12:41:59 +00:00
|
|
|
async set(_selectedLocale) {
|
|
|
|
await setI18nLanguage(_selectedLocale);
|
2022-10-27 00:42:39 +00:00
|
|
|
storedLocale.value = _selectedLocale;
|
|
|
|
dayjs.locale(_selectedLocale);
|
|
|
|
TimeAgo.setDefaultLocale(_selectedLocale);
|
|
|
|
},
|
|
|
|
get() {
|
|
|
|
return storedLocale.value;
|
2021-11-03 16:40:31 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
.cli-box {
|
2022-06-17 00:00:31 +00:00
|
|
|
@apply bg-gray-500 p-2 rounded-md text-white break-words dark:bg-dark-400 dark:text-gray-400;
|
2021-11-03 16:40:31 +00:00
|
|
|
white-space: pre-wrap;
|
|
|
|
}
|
|
|
|
</style>
|