mirror of https://github.com/nocodb/nocodb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
198 lines
5.7 KiB
198 lines
5.7 KiB
4 years ago
|
<template>
|
||
|
<div>
|
||
3 years ago
|
<v-toolbar flat height="38" class="mt-5">
|
||
3 years ago
|
<v-spacer />
|
||
4 years ago
|
|
||
3 years ago
|
<x-btn
|
||
3 years ago
|
v-ge="['roles', 'reload']"
|
||
3 years ago
|
outlined
|
||
|
tooltip="Reload API tokens"
|
||
|
color="primary"
|
||
|
small
|
||
|
:disabled="loading"
|
||
|
@click="loadApiTokens"
|
||
|
@click.prevent
|
||
|
>
|
||
2 years ago
|
<v-icon small left> refresh </v-icon>
|
||
3 years ago
|
<!-- Reload -->
|
||
2 years ago
|
{{ $t('general.reload') }}
|
||
4 years ago
|
</x-btn>
|
||
|
<x-btn
|
||
|
v-if="_isUIAllowed('newUser')"
|
||
3 years ago
|
v-ge="['roles', 'add new']"
|
||
3 years ago
|
outlined
|
||
|
tooltip="Generate new API token"
|
||
4 years ago
|
color="primary"
|
||
|
small
|
||
|
:disabled="loading"
|
||
3 years ago
|
@click="showNewTokenDlg"
|
||
3 years ago
|
>
|
||
2 years ago
|
<v-icon small left> mdi-plus </v-icon>
|
||
3 years ago
|
<!--New Token-->
|
||
2 years ago
|
{{ $t('activity.newToken') }}
|
||
4 years ago
|
</x-btn>
|
||
|
</v-toolbar>
|
||
|
|
||
|
<v-container fluid>
|
||
2 years ago
|
<v-simple-table v-if="tokens" dense class="mx-auto caption text-center" style="max-width: 700px">
|
||
4 years ago
|
<thead>
|
||
3 years ago
|
<tr class="">
|
||
|
<th class="caption text-center">
|
||
3 years ago
|
<!--Description-->
|
||
2 years ago
|
{{ $t('labels.description') }}
|
||
3 years ago
|
</th>
|
||
|
<th class="caption text-center">
|
||
3 years ago
|
<!--Token-->
|
||
2 years ago
|
{{ $t('labels.token') }}
|
||
3 years ago
|
</th>
|
||
|
<th class="caption text-center">
|
||
3 years ago
|
<!--Actions-->
|
||
2 years ago
|
{{ $t('labels.action') }}
|
||
3 years ago
|
</th>
|
||
|
</tr>
|
||
4 years ago
|
</thead>
|
||
3 years ago
|
|
||
|
<tr v-if="!tokens.length">
|
||
|
<td colspan="3">
|
||
2 years ago
|
<div class="text-center caption grey--text">No tokens available</div>
|
||
3 years ago
|
</td>
|
||
|
</tr>
|
||
|
|
||
3 years ago
|
<tr v-for="(token, i) in tokens" :key="i">
|
||
3 years ago
|
<td class="caption text-center">
|
||
|
{{ token.description }}
|
||
|
</td>
|
||
4 years ago
|
<td class="caption text-center">
|
||
|
<div class="d-flex justify-center">
|
||
|
<span v-if="token.show">{{ token.token }}</span>
|
||
|
<span v-else>****************************************</span>
|
||
|
</div>
|
||
|
</td>
|
||
|
<td class="caption">
|
||
3 years ago
|
<x-icon
|
||
|
x-small
|
||
|
icon.class="ml-2"
|
||
3 years ago
|
:tooltip="`${token.show ? 'Hide' : 'Show'} API token`"
|
||
|
@click="$set(token, 'show', !token.show)"
|
||
3 years ago
|
>
|
||
2 years ago
|
{{ token.show ? 'visibility_off' : 'visibility' }}
|
||
4 years ago
|
</x-icon>
|
||
|
|
||
|
<!-- <v-spacer></v-spacer>-->
|
||
2 years ago
|
<x-icon x-small icon.class="ml-2" tooltip="Copy token to clipboard" @click="copyToken(token.token)">
|
||
4 years ago
|
mdi-content-copy
|
||
|
</x-icon>
|
||
|
<x-icon
|
||
3 years ago
|
tooltip="Remove API token"
|
||
|
class="ml-2"
|
||
|
color="error"
|
||
|
x-small
|
||
4 years ago
|
@click.prevent.stop="deleteToken(token)"
|
||
3 years ago
|
>
|
||
|
mdi-delete-outline
|
||
4 years ago
|
</x-icon>
|
||
|
</td>
|
||
|
</tr>
|
||
3 years ago
|
<!-- <tr>
|
||
4 years ago
|
<td colspan="3" class="text-center">
|
||
3 years ago
|
<x-btn tooltip="Generate new api token" outlined x-small color="primary" @click="showNewTokenDlg">
|
||
4 years ago
|
<v-icon>mdi-plus</v-icon>
|
||
3 years ago
|
<!–Add New Token–>
|
||
3 years ago
|
{{ $t('activity.newToken') }}
|
||
4 years ago
|
</x-btn>
|
||
|
</td>
|
||
3 years ago
|
</tr>-->
|
||
4 years ago
|
</v-simple-table>
|
||
|
</v-container>
|
||
|
|
||
|
<v-dialog v-model="newTokenDialog" width="400">
|
||
3 years ago
|
<v-card class="px-15 py-5" style="min-height: 100%">
|
||
4 years ago
|
<h4 class="text-center text-capitalize mt-2 d-100 display-1">
|
||
|
<template>Generate Token</template>
|
||
|
</h4>
|
||
|
|
||
|
<v-form v-model="valid" @submit.prevent="generateToken">
|
||
|
<v-row class="mt-4">
|
||
|
<v-col cols="12">
|
||
2 years ago
|
<v-text-field v-model="tokenObj.description" filled dense :label="$t('labels.description')" />
|
||
4 years ago
|
</v-col>
|
||
|
</v-row>
|
||
|
</v-form>
|
||
|
|
||
|
<v-card-actions class="justify-center">
|
||
3 years ago
|
<x-btn
|
||
3 years ago
|
v-ge="['rows', 'save']"
|
||
3 years ago
|
tooltip="Generate new api token"
|
||
|
color="primary"
|
||
|
btn.class="mt-5 mb-3 pr-5"
|
||
|
@click="generateToken"
|
||
4 years ago
|
>
|
||
|
Generate
|
||
|
</x-btn>
|
||
|
</v-card-actions>
|
||
|
</v-card>
|
||
|
</v-dialog>
|
||
|
</div>
|
||
|
</template>
|
||
|
|
||
|
<script>
|
||
2 years ago
|
import { copyTextToClipboard } from '~/helpers/xutils';
|
||
3 years ago
|
|
||
4 years ago
|
export default {
|
||
3 years ago
|
name: 'ApiTokens',
|
||
4 years ago
|
data: () => ({
|
||
|
tokens: null,
|
||
|
newTokenDialog: false,
|
||
|
tokenObj: {},
|
||
2 years ago
|
valid: true,
|
||
4 years ago
|
}),
|
||
3 years ago
|
created() {
|
||
2 years ago
|
this.loadApiTokens();
|
||
4 years ago
|
},
|
||
|
methods: {
|
||
3 years ago
|
showNewTokenDlg() {
|
||
2 years ago
|
this.newTokenDialog = true;
|
||
|
this.$e('c:api-token:generate');
|
||
3 years ago
|
},
|
||
3 years ago
|
copyToken(token) {
|
||
2 years ago
|
copyTextToClipboard(token);
|
||
|
this.$toast.info('Copied to clipboard').goAway(1000);
|
||
3 years ago
|
|
||
2 years ago
|
this.$e('c:api-token:copy');
|
||
4 years ago
|
},
|
||
3 years ago
|
async loadApiTokens() {
|
||
2 years ago
|
this.tokens = await this.$api.apiToken.list(this.$store.state.project.projectId);
|
||
4 years ago
|
},
|
||
3 years ago
|
async generateToken() {
|
||
4 years ago
|
try {
|
||
2 years ago
|
this.newTokenDialog = false;
|
||
|
await this.$api.apiToken.create(this.$store.state.project.projectId, this.tokenObj);
|
||
|
this.$toast.success('Token generated successfully').goAway(3000);
|
||
|
this.tokenObj = {};
|
||
|
await this.loadApiTokens();
|
||
4 years ago
|
} catch (e) {
|
||
2 years ago
|
console.log(e);
|
||
|
this.$toast.error(e.message).goAway(3000);
|
||
4 years ago
|
}
|
||
3 years ago
|
|
||
2 years ago
|
this.$e('a:api-token:generate');
|
||
4 years ago
|
},
|
||
3 years ago
|
async deleteToken(item) {
|
||
4 years ago
|
try {
|
||
2 years ago
|
await this.$api.apiToken.delete(this.$store.state.project.projectId, item.token);
|
||
3 years ago
|
// this.tokens = //await this.$store.dispatch('sqlMgr/ActSqlOp', [null, 'xcApiTokenDelete', { id: item.id }])
|
||
2 years ago
|
this.$toast.success('Token deleted successfully').goAway(3000);
|
||
|
await this.loadApiTokens();
|
||
4 years ago
|
} catch (e) {
|
||
2 years ago
|
console.log(e);
|
||
|
this.$toast.error(e.message).goAway(3000);
|
||
4 years ago
|
}
|
||
3 years ago
|
|
||
2 years ago
|
this.$e('a:api-token:delete');
|
||
|
},
|
||
|
},
|
||
|
};
|
||
4 years ago
|
</script>
|
||
|
|
||
3 years ago
|
<style scoped></style>
|