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