mirror of
https://github.com/TandoorRecipes/recipes.git
synced 2026-01-06 14:48:02 -05:00
changed access token editor to use generic model api
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<v-card>
|
<v-card>
|
||||||
<v-card-title>
|
<v-card-title>
|
||||||
{{ $t(OBJ_LOCALIZATION_KEY) }}
|
{{ $t(modelClass.model.localizationKey) }}
|
||||||
<v-btn class="float-right" icon="$close" variant="plain" @click="emit('close')" v-if="dialog"></v-btn>
|
<v-btn class="float-right" icon="$close" variant="plain" @click="emit('close')" v-if="dialog"></v-btn>
|
||||||
</v-card-title>
|
</v-card-title>
|
||||||
<v-card-text>
|
<v-card-text>
|
||||||
@@ -31,27 +31,26 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
|
||||||
import {VDateInput} from 'vuetify/labs/VDateInput' //TODO remove once component is out of labs
|
import {VDateInput} from 'vuetify/labs/VDateInput' //TODO remove once component is out of labs
|
||||||
import {computed, onMounted, ref} from "vue";
|
import {computed, onBeforeMount, onMounted, PropType, ref} from "vue";
|
||||||
import {AccessToken, ApiApi} from "@/openapi";
|
import {AccessToken} from "@/openapi";
|
||||||
import DeleteConfirmDialog from "@/components/dialogs/DeleteConfirmDialog.vue";
|
import DeleteConfirmDialog from "@/components/dialogs/DeleteConfirmDialog.vue";
|
||||||
import {useI18n} from "vue-i18n";
|
import {useI18n} from "vue-i18n";
|
||||||
import {ErrorMessageType, PreparedMessage, useMessageStore} from "@/stores/MessageStore";
|
import {ErrorMessageType, PreparedMessage, useMessageStore} from "@/stores/MessageStore";
|
||||||
import {DateTime} from "luxon";
|
import {DateTime} from "luxon";
|
||||||
import {useClipboard} from "@vueuse/core";
|
|
||||||
import BtnCopy from "@/components/buttons/BtnCopy.vue";
|
import BtnCopy from "@/components/buttons/BtnCopy.vue";
|
||||||
|
import {GenericModel, getGenericModelFromString} from "@/types/Models";
|
||||||
|
|
||||||
const {t} = useI18n()
|
const {t} = useI18n()
|
||||||
const {copy} = useClipboard()
|
|
||||||
|
|
||||||
const emit = defineEmits(['create', 'save', 'delete', 'close'])
|
const emit = defineEmits(['create', 'save', 'delete', 'close'])
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
item: {type: {} as AccessToken, required: false},
|
item: {type: {} as PropType<AccessToken>, required: false},
|
||||||
dialog: {type: Boolean, default: false}
|
dialog: {type: Boolean, default: false}
|
||||||
})
|
})
|
||||||
|
|
||||||
const OBJ_LOCALIZATION_KEY = 'Access_Token'
|
|
||||||
const editingObj = ref({} as AccessToken)
|
const editingObj = ref({} as AccessToken)
|
||||||
|
const modelClass = ref({} as GenericModel)
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -65,7 +64,11 @@ const isUpdate = computed(() => {
|
|||||||
* display name for object in headers/delete dialog/...
|
* display name for object in headers/delete dialog/...
|
||||||
*/
|
*/
|
||||||
const objectName = computed(() => {
|
const objectName = computed(() => {
|
||||||
return isUpdate ? `${t(OBJ_LOCALIZATION_KEY)} ${editingObj.value.token}` : `${t(OBJ_LOCALIZATION_KEY)} (${t('New')})`
|
return isUpdate ? `${t(modelClass.value.model.localizationKey)} ${editingObj.value.token}` : `${t(modelClass.value.model.localizationKey)} (${t('New')})`
|
||||||
|
})
|
||||||
|
|
||||||
|
onBeforeMount(() => {
|
||||||
|
modelClass.value = getGenericModelFromString('AccessToken', t)
|
||||||
})
|
})
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
@@ -82,9 +85,8 @@ onMounted(() => {
|
|||||||
* saves the edited object in the database
|
* saves the edited object in the database
|
||||||
*/
|
*/
|
||||||
async function saveObject() {
|
async function saveObject() {
|
||||||
let api = new ApiApi()
|
|
||||||
if (isUpdate.value) {
|
if (isUpdate.value) {
|
||||||
api.apiAccessTokenUpdate({id: editingObj.value.id, accessToken: editingObj.value}).then(r => {
|
modelClass.value.update(editingObj.value.id, editingObj.value).then(r => {
|
||||||
editingObj.value = r
|
editingObj.value = r
|
||||||
emit('save', r)
|
emit('save', r)
|
||||||
useMessageStore().addPreparedMessage(PreparedMessage.UPDATE_SUCCESS)
|
useMessageStore().addPreparedMessage(PreparedMessage.UPDATE_SUCCESS)
|
||||||
@@ -92,7 +94,7 @@ async function saveObject() {
|
|||||||
useMessageStore().addError(ErrorMessageType.UPDATE_ERROR, err)
|
useMessageStore().addError(ErrorMessageType.UPDATE_ERROR, err)
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
api.apiAccessTokenCreate({accessToken: editingObj.value}).then(r => {
|
modelClass.value.create(editingObj.value).then(r => {
|
||||||
editingObj.value = r
|
editingObj.value = r
|
||||||
emit('create', r)
|
emit('create', r)
|
||||||
useMessageStore().addPreparedMessage(PreparedMessage.CREATE_SUCCESS)
|
useMessageStore().addPreparedMessage(PreparedMessage.CREATE_SUCCESS)
|
||||||
@@ -106,8 +108,7 @@ async function saveObject() {
|
|||||||
* deletes the editing object from the database
|
* deletes the editing object from the database
|
||||||
*/
|
*/
|
||||||
async function deleteObject() {
|
async function deleteObject() {
|
||||||
let api = new ApiApi()
|
modelClass.value.destroy(editingObj.value.id).then(r => {
|
||||||
api.apiAccessTokenDestroy({id: editingObj.value.id}).then(r => {
|
|
||||||
editingObj.value = {} as AccessToken
|
editingObj.value = {} as AccessToken
|
||||||
emit('delete', editingObj.value)
|
emit('delete', editingObj.value)
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
|
|||||||
@@ -281,6 +281,21 @@ export const TViewLog = {
|
|||||||
} as Model
|
} as Model
|
||||||
SUPPORTED_MODELS.set(TViewLog.name, TViewLog)
|
SUPPORTED_MODELS.set(TViewLog.name, TViewLog)
|
||||||
|
|
||||||
|
export const TAccessToken = {
|
||||||
|
name: 'AccessToken',
|
||||||
|
localizationKey: 'Access_Token',
|
||||||
|
icon: 'fa-solid fa-key',
|
||||||
|
|
||||||
|
isPaginated: true,
|
||||||
|
|
||||||
|
tableHeaders: [
|
||||||
|
{title: 'Access_Token', key: 'token'},
|
||||||
|
{title: 'Created', key: 'createdAt'},
|
||||||
|
{title: 'Actions', key: 'action', align: 'end'},
|
||||||
|
]
|
||||||
|
} as Model
|
||||||
|
SUPPORTED_MODELS.set(TAccessToken.name, TAccessToken)
|
||||||
|
|
||||||
export const TFoodInheritField = {
|
export const TFoodInheritField = {
|
||||||
name: 'FoodInheritField',
|
name: 'FoodInheritField',
|
||||||
localizationKey: 'FoodInherit',
|
localizationKey: 'FoodInherit',
|
||||||
@@ -352,7 +367,7 @@ export class GenericModel {
|
|||||||
throw new Error('Cannot create on this model!')
|
throw new Error('Cannot create on this model!')
|
||||||
} else {
|
} else {
|
||||||
let createRequestParams: any = {}
|
let createRequestParams: any = {}
|
||||||
createRequestParams[this.model.name.toLowerCase()] = obj
|
createRequestParams[this.model.name.charAt(0).toLowerCase() + this.model.name.slice(1)] = obj
|
||||||
return this.api[`api${this.model.name}Create`](createRequestParams)
|
return this.api[`api${this.model.name}Create`](createRequestParams)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -370,7 +385,7 @@ export class GenericModel {
|
|||||||
} else {
|
} else {
|
||||||
let updateRequestParams: any = {}
|
let updateRequestParams: any = {}
|
||||||
updateRequestParams['id'] = id
|
updateRequestParams['id'] = id
|
||||||
updateRequestParams[this.model.name.toLowerCase()] = obj
|
updateRequestParams[this.model.name.charAt(0).toLowerCase() + this.model.name.slice(1)] = obj
|
||||||
return this.api[`api${this.model.name}Update`](updateRequestParams)
|
return this.api[`api${this.model.name}Update`](updateRequestParams)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user