mirror of
https://github.com/TandoorRecipes/recipes.git
synced 2026-01-01 12:18:45 -05:00
model editors default prop
This commit is contained in:
@@ -42,6 +42,7 @@ import ModelEditorBase from "@/components/model_editors/ModelEditorBase.vue";
|
||||
const props = defineProps({
|
||||
item: {type: {} as PropType<AccessToken>, required: false, default: null},
|
||||
itemId: {type: [Number, String], required: false, default: undefined},
|
||||
itemDefaults: {type: {} as PropType<AccessToken>, required: false, default: {} as AccessToken},
|
||||
dialog: {type: Boolean, default: false}
|
||||
})
|
||||
|
||||
@@ -54,7 +55,8 @@ onMounted(() => {
|
||||
newItemFunction: () => {
|
||||
editingObj.value.expires = DateTime.now().plus({year: 1}).toJSDate()
|
||||
editingObj.value.scope = 'read write'
|
||||
}
|
||||
},
|
||||
itemDefaults: props.itemDefaults
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -37,13 +37,13 @@ import ModelEditorBase from "@/components/model_editors/ModelEditorBase.vue";
|
||||
import {useModelEditorFunctions} from "@/composables/useModelEditorFunctions";
|
||||
import {useI18n} from "vue-i18n";
|
||||
import {VNumberInput} from "vuetify/labs/VNumberInput";
|
||||
import {DateTime} from "luxon";
|
||||
|
||||
const {t} = useI18n()
|
||||
|
||||
const props = defineProps({
|
||||
item: {type: {} as PropType<Automation>, required: false, default: null},
|
||||
itemId: {type: [Number, String], required: false, default: undefined},
|
||||
itemDefaults: {type: {} as PropType<Automation>, required: false, default: {} as Automation},
|
||||
dialog: {type: Boolean, default: false}
|
||||
})
|
||||
|
||||
@@ -69,7 +69,8 @@ onMounted(() => {
|
||||
setupState(props.item, props.itemId, {
|
||||
newItemFunction: () => {
|
||||
editingObj.value.order = 0
|
||||
}
|
||||
},
|
||||
itemDefaults: props.itemDefaults
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ import ModelEditorBase from "@/components/model_editors/ModelEditorBase.vue";
|
||||
const props = defineProps({
|
||||
item: {type: {} as PropType<CustomFilter>, required: false, default: null},
|
||||
itemId: {type: [Number, String], required: false, default: undefined},
|
||||
itemDefaults: {type: {} as PropType<CustomFilter>, required: false, default: {} as CustomFilter},
|
||||
dialog: {type: Boolean, default: false}
|
||||
})
|
||||
|
||||
@@ -36,7 +37,7 @@ const {setupState, deleteObject, saveObject, isUpdate, editingObjName, loading,
|
||||
|
||||
|
||||
onMounted(() => {
|
||||
setupState(props.item, props.itemId, {})
|
||||
setupState(props.item, props.itemId, {itemDefaults: props.itemDefaults})
|
||||
})
|
||||
|
||||
</script>
|
||||
|
||||
@@ -116,8 +116,7 @@
|
||||
<script setup lang="ts">
|
||||
|
||||
import {computed, onMounted, PropType, ref, watch} from "vue";
|
||||
import {ApiApi, Food, Property, Unit, UnitConversion} from "@/openapi";
|
||||
import {useI18n} from "vue-i18n";
|
||||
import {ApiApi, Food, Unit, UnitConversion} from "@/openapi";
|
||||
import {ErrorMessageType, useMessageStore} from "@/stores/MessageStore";
|
||||
import ModelSelect from "@/components/inputs/ModelSelect.vue";
|
||||
import {VNumberInput} from 'vuetify/labs/VNumberInput'
|
||||
@@ -125,11 +124,13 @@ import ModelEditDialog from "@/components/dialogs/ModelEditDialog.vue";
|
||||
import ModelEditorBase from "@/components/model_editors/ModelEditorBase.vue";
|
||||
import {useModelEditorFunctions} from "@/composables/useModelEditorFunctions";
|
||||
import PropertiesEditor from "@/components/inputs/PropertiesEditor.vue";
|
||||
import {useUserPreferenceStore} from "@/stores/UserPreferenceStore";
|
||||
|
||||
|
||||
const props = defineProps({
|
||||
item: {type: {} as PropType<Food>, required: false, default: null},
|
||||
itemId: {type: [Number, String], required: false, default: undefined},
|
||||
itemDefaults: {type: {} as PropType<Food>, required: false, default: {} as Food},
|
||||
dialog: {type: Boolean, default: false}
|
||||
})
|
||||
|
||||
@@ -171,8 +172,9 @@ onMounted(() => {
|
||||
setupState(props.item, props.itemId, {
|
||||
newItemFunction: () => {
|
||||
editingObj.value.propertiesFoodAmount = 100
|
||||
editingObj.value.propertiesFoodUnit = {name: 'g'} as Unit // TODO properly fetch default unit
|
||||
}
|
||||
editingObj.value.propertiesFoodUnit = {name: (useUserPreferenceStore().userSettings.defaultUnit != undefined ? useUserPreferenceStore().userSettings.defaultUnit : 'g')} as Unit
|
||||
},
|
||||
itemDefaults: props.itemDefaults,
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ import {useModelEditorFunctions} from "@/composables/useModelEditorFunctions";
|
||||
const props = defineProps({
|
||||
item: {type: {} as PropType<InviteLink>, required: false, default: null},
|
||||
itemId: {type: [Number, String], required: false, default: undefined},
|
||||
itemDefaults: {type: {} as PropType<InviteLink>, required: false, default: {} as InviteLink},
|
||||
dialog: {type: Boolean, default: false}
|
||||
})
|
||||
|
||||
@@ -55,7 +56,8 @@ onMounted(() => {
|
||||
newItemFunction: () => {
|
||||
editingObj.value.validUntil = DateTime.now().plus({month: 1}).toJSDate()
|
||||
editingObj.value.group = groups.value[0]
|
||||
}
|
||||
},
|
||||
itemDefaults: props.itemDefaults
|
||||
})
|
||||
|
||||
}).catch(err => {
|
||||
|
||||
@@ -27,14 +27,11 @@ import {onMounted, PropType} from "vue";
|
||||
import {Keyword} from "@/openapi";
|
||||
import ModelEditorBase from "@/components/model_editors/ModelEditorBase.vue";
|
||||
import {useModelEditorFunctions} from "@/composables/useModelEditorFunctions";
|
||||
import {useI18n} from "vue-i18n";
|
||||
import {DateTime} from "luxon";
|
||||
|
||||
const {t} = useI18n()
|
||||
|
||||
const props = defineProps({
|
||||
item: {type: {} as PropType<Keyword>, required: false, default: null},
|
||||
itemId: {type: [Number, String], required: false, default: undefined},
|
||||
itemDefaults: {type: {} as PropType<Keyword>, required: false, default: {} as Keyword},
|
||||
dialog: {type: Boolean, default: false}
|
||||
})
|
||||
|
||||
@@ -44,7 +41,7 @@ const {setupState, deleteObject, saveObject, isUpdate, editingObjName, loading,
|
||||
// object specific data (for selects/display)
|
||||
|
||||
onMounted(() => {
|
||||
setupState(props.item, props.itemId)
|
||||
setupState(props.item, props.itemId, {itemDefaults: props.itemDefaults})
|
||||
})
|
||||
|
||||
</script>
|
||||
|
||||
@@ -52,6 +52,7 @@ import {DateTime} from "luxon";
|
||||
const props = defineProps({
|
||||
item: {type: {} as PropType<MealType>, required: false, default: null},
|
||||
itemId: {type: [Number, String], required: false, default: undefined},
|
||||
itemDefaults: {type: {} as PropType<MealType>, required: false, default: {} as MealType},
|
||||
dialog: {type: Boolean, default: false}
|
||||
})
|
||||
|
||||
@@ -63,7 +64,7 @@ const timePickerMenu = ref(false)
|
||||
|
||||
|
||||
onMounted(() => {
|
||||
setupState(props.item, props.itemId)
|
||||
setupState(props.item, props.itemId, {itemDefaults: props.itemDefaults})
|
||||
})
|
||||
|
||||
</script>
|
||||
|
||||
@@ -38,6 +38,7 @@ import {useModelEditorFunctions} from "@/composables/useModelEditorFunctions";
|
||||
const props = defineProps({
|
||||
item: {type: {} as PropType<Property>, required: false, default: null},
|
||||
itemId: {type: [Number, String], required: false, default: undefined},
|
||||
itemDefaults: {type: {} as PropType<Property>, required: false, default: {} as Property},
|
||||
dialog: {type: Boolean, default: false}
|
||||
})
|
||||
|
||||
@@ -46,7 +47,7 @@ const {setupState, deleteObject, saveObject, isUpdate, editingObjName, loading,
|
||||
|
||||
|
||||
onMounted(() => {
|
||||
setupState(props.item, props.itemId)
|
||||
setupState(props.item, props.itemId, {itemDefaults: props.itemDefaults})
|
||||
})
|
||||
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ import {VNumberInput} from "vuetify/labs/VNumberInput";
|
||||
const props = defineProps({
|
||||
item: {type: {} as PropType<PropertyType>, required: false, default: null},
|
||||
itemId: {type: [Number, String], required: false, default: undefined},
|
||||
itemDefaults: {type: {} as PropType<PropertyType>, required: false, default: {} as PropertyType},
|
||||
dialog: {type: Boolean, default: false}
|
||||
})
|
||||
|
||||
@@ -45,7 +46,7 @@ const {setupState, deleteObject, saveObject, isUpdate, editingObjName, loading,
|
||||
// object specific data (for selects/display)
|
||||
|
||||
onMounted(() => {
|
||||
setupState(props.item, props.itemId)
|
||||
setupState(props.item, props.itemId, {itemDefaults: props.itemDefaults})
|
||||
})
|
||||
|
||||
</script>
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
<v-tabs-window-item value="recipes">
|
||||
<model-select model="Recipe" v-model="selectedRecipe">
|
||||
<template #append>
|
||||
<v-btn @click="addRecipeToBook()">
|
||||
<v-btn icon color="create" @click="addRecipeToBook()">
|
||||
<v-icon icon="$create"></v-icon>
|
||||
</v-btn>
|
||||
</template>
|
||||
@@ -43,12 +43,13 @@
|
||||
:headers="tableHeaders"
|
||||
:items-length="itemCount"
|
||||
>
|
||||
<template #item.action="{item}">
|
||||
<v-btn icon="$delete" color="delete" @click="removeRecipeFromBook(item)"></v-btn>
|
||||
</template>
|
||||
|
||||
</v-data-table-server>
|
||||
</v-tabs-window-item>
|
||||
</v-tabs-window>
|
||||
|
||||
|
||||
</v-card-text>
|
||||
</model-editor-base>
|
||||
</template>
|
||||
@@ -63,13 +64,14 @@ import {VDataTableUpdateOptions} from "@/vuetify";
|
||||
import {useModelEditorFunctions} from "@/composables/useModelEditorFunctions";
|
||||
import ModelEditorBase from "@/components/model_editors/ModelEditorBase.vue";
|
||||
import ModelSelect from "@/components/inputs/ModelSelect.vue";
|
||||
import {ErrorMessageType, useMessageStore} from "@/stores/MessageStore";
|
||||
import {ErrorMessageType, PreparedMessage, useMessageStore} from "@/stores/MessageStore";
|
||||
import {useUserPreferenceStore} from "@/stores/UserPreferenceStore";
|
||||
import {useI18n} from "vue-i18n";
|
||||
|
||||
const props = defineProps({
|
||||
item: {type: {} as PropType<RecipeBook>, required: false, default: null},
|
||||
itemId: {type: [Number, String], required: false, default: undefined},
|
||||
itemDefaults: {type: {} as PropType<RecipeBook>, required: false, default: {} as RecipeBook},
|
||||
dialog: {type: Boolean, default: false}
|
||||
})
|
||||
|
||||
@@ -86,7 +88,7 @@ const tablePage = ref(1)
|
||||
const itemCount = ref(0)
|
||||
|
||||
const tableHeaders = [
|
||||
{title: t('Name'), key: 'recipeContent.name', },
|
||||
{title: t('Name'), key: 'recipeContent.name',},
|
||||
{key: 'action', width: '1%', noBreak: true, align: 'end'},
|
||||
]
|
||||
|
||||
@@ -98,19 +100,39 @@ onMounted(() => {
|
||||
},
|
||||
existingItemFunction: () => {
|
||||
recipeBookEntries.value = []
|
||||
}
|
||||
},
|
||||
itemDefaults: props.itemDefaults
|
||||
})
|
||||
})
|
||||
|
||||
/**
|
||||
* add selected recipe into the book and client list
|
||||
*/
|
||||
function addRecipeToBook() {
|
||||
let api = new ApiApi()
|
||||
// TODO check both for null, handle errors
|
||||
|
||||
api.apiRecipeBookEntryCreate({recipeBookEntry: {book: editingObj.value.id!, recipe: selectedRecipe.value.id!}}).then(r => {
|
||||
recipeBookEntries.value.push(r) // TODO or reload ?
|
||||
selectedRecipe.value = {} as Recipe
|
||||
if (Object.keys(selectedRecipe.value).length > 0) {
|
||||
api.apiRecipeBookEntryCreate({recipeBookEntry: {book: editingObj.value.id!, recipe: selectedRecipe.value.id!}}).then(r => {
|
||||
recipeBookEntries.value.push(r)
|
||||
selectedRecipe.value = {} as Recipe
|
||||
}).catch(err => {
|
||||
useMessageStore().addError(ErrorMessageType.CREATE_ERROR, err)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* remove the given entry from the book both in the database and on the frontend
|
||||
* @param recipeBookEntry
|
||||
*/
|
||||
function removeRecipeFromBook(recipeBookEntry: RecipeBookEntry) {
|
||||
let api = new ApiApi()
|
||||
|
||||
api.apiRecipeBookEntryDestroy({id: recipeBookEntry.id!}).then((r) => {
|
||||
recipeBookEntries.value.splice(recipeBookEntries.value.findIndex(rBE => rBE.id! == recipeBookEntry.id!), 1)
|
||||
useMessageStore().addPreparedMessage(PreparedMessage.DELETE_SUCCESS)
|
||||
}).catch(err => {
|
||||
useMessageStore().addError(ErrorMessageType.CREATE_ERROR, err)
|
||||
useMessageStore().addError(ErrorMessageType.DELETE_ERROR, err)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -132,7 +154,7 @@ function loadRecipeBookEntries(options: VDataTableUpdateOptions) {
|
||||
|
||||
useUserPreferenceStore().deviceSettings.general_tableItemsPerPage = options.itemsPerPage
|
||||
|
||||
api.apiRecipeBookEntryList({page: options.page, pageSize: options.itemsPerPage,}).then((r: any) => {
|
||||
api.apiRecipeBookEntryList({page: options.page, pageSize: options.itemsPerPage, book: editingObj.value.id}).then((r: any) => {
|
||||
recipeBookEntries.value = r.results
|
||||
itemCount.value = r.count
|
||||
}).catch((err: any) => {
|
||||
|
||||
@@ -139,7 +139,6 @@ import {onMounted, PropType, ref, shallowRef} from "vue";
|
||||
import {Ingredient, Recipe, Step} from "@/openapi";
|
||||
import ModelEditorBase from "@/components/model_editors/ModelEditorBase.vue";
|
||||
import {useModelEditorFunctions} from "@/composables/useModelEditorFunctions";
|
||||
import {useI18n} from "vue-i18n";
|
||||
import ModelSelect from "@/components/inputs/ModelSelect.vue";
|
||||
import StepEditor from "@/components/inputs/StepEditor.vue";
|
||||
import {VueDraggable} from "vue-draggable-plus";
|
||||
@@ -155,6 +154,7 @@ import {useUserPreferenceStore} from "@/stores/UserPreferenceStore";
|
||||
const props = defineProps({
|
||||
item: {type: {} as PropType<Recipe>, required: false, default: null},
|
||||
itemId: {type: [Number, String], required: false, default: undefined},
|
||||
itemDefaults: {type: {} as PropType<Recipe>, required: false, default: {} as Recipe},
|
||||
dialog: {type: Boolean, default: false}
|
||||
})
|
||||
|
||||
@@ -175,7 +175,8 @@ onMounted(() => {
|
||||
newItemFunction: () => {
|
||||
editingObj.value.steps = [] as Step[]
|
||||
editingObj.value.internal = true //TODO make database default after v2
|
||||
}
|
||||
},
|
||||
itemDefaults: props.itemDefaults,
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -37,13 +37,13 @@ import {onMounted, PropType} from "vue";
|
||||
import {ShoppingListEntry} from "@/openapi";
|
||||
import ModelEditorBase from "@/components/model_editors/ModelEditorBase.vue";
|
||||
import {useModelEditorFunctions} from "@/composables/useModelEditorFunctions";
|
||||
import {useI18n} from "vue-i18n";
|
||||
import {VNumberInput} from "vuetify/labs/VNumberInput";
|
||||
import ModelSelect from "@/components/inputs/ModelSelect.vue";
|
||||
|
||||
const props = defineProps({
|
||||
item: {type: {} as PropType<ShoppingListEntry>, required: false, default: null},
|
||||
itemId: {type: [Number, String], required: false, default: undefined},
|
||||
itemDefaults: {type: {} as PropType<ShoppingListEntry>, required: false, default: {} as ShoppingListEntry},
|
||||
dialog: {type: Boolean, default: false}
|
||||
})
|
||||
|
||||
@@ -53,7 +53,7 @@ const {setupState, deleteObject, saveObject, isUpdate, editingObjName, loading,
|
||||
// object specific data (for selects/display)
|
||||
|
||||
onMounted(() => {
|
||||
setupState(props.item, props.itemId)
|
||||
setupState(props.item, props.itemId, {itemDefaults: props.itemDefaults})
|
||||
})
|
||||
|
||||
</script>
|
||||
|
||||
@@ -29,11 +29,10 @@ import ModelEditorBase from "@/components/model_editors/ModelEditorBase.vue";
|
||||
import {useModelEditorFunctions} from "@/composables/useModelEditorFunctions";
|
||||
import {useI18n} from "vue-i18n";
|
||||
|
||||
const {t} = useI18n()
|
||||
|
||||
const props = defineProps({
|
||||
item: {type: {} as PropType<SupermarketCategory>, required: false, default: null},
|
||||
itemId: {type: [Number, String], required: false, default: undefined},
|
||||
itemDefaults: {type: {} as PropType<SupermarketCategory>, required: false, default: {} as SupermarketCategory},
|
||||
dialog: {type: Boolean, default: false}
|
||||
})
|
||||
|
||||
@@ -43,7 +42,7 @@ const {setupState, deleteObject, saveObject, isUpdate, editingObjName, loading,
|
||||
// object specific data (for selects/display)
|
||||
|
||||
onMounted(() => {
|
||||
setupState(props.item, props.itemId)
|
||||
setupState(props.item, props.itemId, {itemDefaults: props.itemDefaults})
|
||||
})
|
||||
|
||||
</script>
|
||||
|
||||
@@ -112,6 +112,7 @@ import {ErrorMessageType, useMessageStore} from "@/stores/MessageStore";
|
||||
const props = defineProps({
|
||||
item: {type: {} as PropType<Supermarket>, required: false, default: null},
|
||||
itemId: {type: [Number, String], required: false, default: undefined},
|
||||
itemDefaults: {type: {} as PropType<Supermarket>, required: false, default: {} as Supermarket},
|
||||
dialog: {type: Boolean, default: false}
|
||||
})
|
||||
|
||||
@@ -154,7 +155,8 @@ onMounted(() => {
|
||||
existingItemFunction: () => {
|
||||
// initialize list of supermarket category relations
|
||||
editingObjectSupermarketCategoriesRelations.value = editingObj.value.categoryToSupermarket
|
||||
}
|
||||
},
|
||||
itemDefaults: props.itemDefaults,
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -58,6 +58,7 @@ import ModelEditorBase from "@/components/model_editors/ModelEditorBase.vue";
|
||||
const props = defineProps({
|
||||
item: {type: {} as PropType<UnitConversion>, required: false, default: null},
|
||||
itemId: {type: [Number, String], required: false, default: undefined},
|
||||
itemDefaults: {type: {} as PropType<UnitConversion>, required: false, default: {} as UnitConversion},
|
||||
dialog: {type: Boolean, default: false}
|
||||
})
|
||||
|
||||
@@ -66,7 +67,7 @@ const {setupState, deleteObject, saveObject, isUpdate, editingObjName, loading,
|
||||
|
||||
|
||||
onMounted(() => {
|
||||
setupState(props.item, props.itemId)
|
||||
setupState(props.item, props.itemId, {itemDefaults: props.itemDefaults})
|
||||
})
|
||||
|
||||
</script>
|
||||
|
||||
@@ -35,6 +35,7 @@ const {t} = useI18n()
|
||||
const props = defineProps({
|
||||
item: {type: {} as PropType<Unit>, required: false, default: null},
|
||||
itemId: {type: [Number, String], required: false, default: undefined},
|
||||
itemDefaults: {type: {} as PropType<Unit>, required: false, default: {} as Unit},
|
||||
dialog: {type: Boolean, default: false}
|
||||
})
|
||||
|
||||
@@ -66,7 +67,7 @@ const BASE_UNITS = [
|
||||
]
|
||||
|
||||
onMounted(() => {
|
||||
setupState(props.item, props.itemId)
|
||||
setupState(props.item, props.itemId, {itemDefaults: props.itemDefaults})
|
||||
})
|
||||
|
||||
</script>
|
||||
|
||||
@@ -48,7 +48,7 @@
|
||||
<script setup lang="ts">
|
||||
|
||||
import {onMounted, PropType, shallowRef} from "vue";
|
||||
import {UserFile} from "@/openapi";
|
||||
import {UserFile, UserSpace} from "@/openapi";
|
||||
import ModelEditorBase from "@/components/model_editors/ModelEditorBase.vue";
|
||||
import {useModelEditorFunctions} from "@/composables/useModelEditorFunctions";
|
||||
import {DateTime} from "luxon";
|
||||
@@ -59,6 +59,7 @@ import {ErrorMessageType, PreparedMessage, useMessageStore} from "@/stores/Messa
|
||||
const props = defineProps({
|
||||
item: {type: {} as PropType<UserFile>, required: false, default: null},
|
||||
itemId: {type: [Number, String], required: false, default: undefined},
|
||||
itemDefaults: {type: {} as PropType<UserFile>, required: false, default: {} as UserFile},
|
||||
dialog: {type: Boolean, default: false}
|
||||
})
|
||||
|
||||
@@ -71,7 +72,7 @@ const {fileApiLoading, createOrUpdateUserFile} = useFileApi()
|
||||
const file = shallowRef<File | null>(null)
|
||||
|
||||
onMounted(() => {
|
||||
setupState(props.item, props.itemId)
|
||||
setupState(props.item, props.itemId, {itemDefaults: props.itemDefaults})
|
||||
})
|
||||
|
||||
/**
|
||||
|
||||
@@ -32,6 +32,7 @@ import {useModelEditorFunctions} from "@/composables/useModelEditorFunctions";
|
||||
const props = defineProps({
|
||||
item: {type: {} as PropType<UserSpace>, required: false, default: null},
|
||||
itemId: {type: [Number, String], required: false, default: undefined},
|
||||
itemDefaults: {type: {} as PropType<UserSpace>, required: false, default: {} as UserSpace},
|
||||
dialog: {type: Boolean, default: false}
|
||||
})
|
||||
|
||||
@@ -49,7 +50,7 @@ onMounted(() => {
|
||||
useMessageStore().addError(ErrorMessageType.FETCH_ERROR, err)
|
||||
})
|
||||
|
||||
setupState(props.item, props.itemId)
|
||||
setupState(props.item, props.itemId, {itemDefaults: props.itemDefaults})
|
||||
})
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user