mirror of
https://github.com/TandoorRecipes/recipes.git
synced 2026-01-04 13:48:32 -05:00
meal plan and model editors
- changed signature to options object - added ability to set defaults - meal plan clickable item creation
This commit is contained in:
@@ -49,9 +49,11 @@ const {setupState, deleteObject, saveObject, isUpdate, editingObjName, loading,
|
||||
|
||||
|
||||
onMounted(() => {
|
||||
setupState(props.item, props.itemId, () => {
|
||||
editingObj.value.expires = DateTime.now().plus({year: 1}).toJSDate()
|
||||
editingObj.value.scope = 'read write'
|
||||
setupState(props.item, props.itemId, {
|
||||
newItemFunction: () => {
|
||||
editingObj.value.expires = DateTime.now().plus({year: 1}).toJSDate()
|
||||
editingObj.value.scope = 'read write'
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -52,21 +52,23 @@ const {setupState, deleteObject, saveObject, isUpdate, editingObjName, loading,
|
||||
// object specific data (for selects/display)
|
||||
|
||||
const AUTOMATION_TYPES = [
|
||||
{ value: "FOOD_ALIAS", title: t("Food_Alias") },
|
||||
{ value: "UNIT_ALIAS", title: t("Unit_Alias") },
|
||||
{ value: "KEYWORD_ALIAS", title: t("Keyword_Alias") },
|
||||
{ value: "NAME_REPLACE", title: t("Name_Replace") },
|
||||
{ value: "DESCRIPTION_REPLACE", title: t("Description_Replace") },
|
||||
{ value: "INSTRUCTION_REPLACE", title: t("Instruction_Replace") },
|
||||
{ value: "FOOD_REPLACE", title: t("Food_Replace") },
|
||||
{ value: "UNIT_REPLACE", title: t("Unit_Replace") },
|
||||
{ value: "NEVER_UNIT", title: t("Never_Unit") },
|
||||
{ value: "TRANSPOSE_WORDS", title: t("Transpose_Words") }
|
||||
{value: "FOOD_ALIAS", title: t("Food_Alias")},
|
||||
{value: "UNIT_ALIAS", title: t("Unit_Alias")},
|
||||
{value: "KEYWORD_ALIAS", title: t("Keyword_Alias")},
|
||||
{value: "NAME_REPLACE", title: t("Name_Replace")},
|
||||
{value: "DESCRIPTION_REPLACE", title: t("Description_Replace")},
|
||||
{value: "INSTRUCTION_REPLACE", title: t("Instruction_Replace")},
|
||||
{value: "FOOD_REPLACE", title: t("Food_Replace")},
|
||||
{value: "UNIT_REPLACE", title: t("Unit_Replace")},
|
||||
{value: "NEVER_UNIT", title: t("Never_Unit")},
|
||||
{value: "TRANSPOSE_WORDS", title: t("Transpose_Words")}
|
||||
]
|
||||
|
||||
onMounted(() => {
|
||||
setupState(props.item, props.itemId, () => {
|
||||
editingObj.value.order = 0
|
||||
setupState(props.item, props.itemId, {
|
||||
newItemFunction: () => {
|
||||
editingObj.value.order = 0
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -189,9 +189,11 @@ const stopConversionsWatcher = watch(tab, (value, oldValue, onCleanup) => {
|
||||
|
||||
|
||||
onMounted(() => {
|
||||
setupState(props.item, props.itemId, () => {
|
||||
editingObj.value.propertiesFoodAmount = 100
|
||||
editingObj.value.propertiesFoodUnit = {name: 'g'} as Unit // TODO properly fetch default unit
|
||||
setupState(props.item, props.itemId, {
|
||||
newItemFunction: () => {
|
||||
editingObj.value.propertiesFoodAmount = 100
|
||||
editingObj.value.propertiesFoodUnit = {name: 'g'} as Unit // TODO properly fetch default unit
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -50,9 +50,11 @@ onMounted(() => {
|
||||
api.apiGroupList().then(r => {
|
||||
groups.value = r
|
||||
|
||||
setupState(props.item, props.itemId, () => {
|
||||
editingObj.value.validUntil = DateTime.now().plus({month: 1}).toJSDate()
|
||||
editingObj.value.group = groups.value[0]
|
||||
setupState(props.item, props.itemId, {
|
||||
newItemFunction: () => {
|
||||
editingObj.value.validUntil = DateTime.now().plus({month: 1}).toJSDate()
|
||||
editingObj.value.group = groups.value[0]
|
||||
}
|
||||
})
|
||||
|
||||
}).catch(err => {
|
||||
|
||||
@@ -73,12 +73,13 @@ import {MessageType, useMessageStore} from "@/stores/MessageStore";
|
||||
|
||||
const props = defineProps({
|
||||
item: {type: {} as PropType<MealPlan>, required: false, default: null},
|
||||
itemDefaults: {type: {} as PropType<MealPlan>, required: false, default: {} as MealPlan},
|
||||
itemId: {type: [Number, String], required: false, default: undefined},
|
||||
dialog: {type: Boolean, default: false}
|
||||
})
|
||||
|
||||
const emit = defineEmits(['create', 'save', 'delete', 'close'])
|
||||
const {setupState, deleteObject, saveObject, isUpdate, editingObjName, loading, editingObj, modelClass} = useModelEditorFunctions<MealPlan>('MealPlan', emit)
|
||||
const {setupState, deleteObject, saveObject, isUpdate, editingObjName, applyItemDefaults, loading, editingObj, modelClass} = useModelEditorFunctions<MealPlan>('MealPlan', emit)
|
||||
|
||||
// object specific data (for selects/display)
|
||||
const dateRangeValue = ref([] as Date[])
|
||||
@@ -87,32 +88,35 @@ onMounted(() => {
|
||||
const api = new ApiApi()
|
||||
|
||||
api.apiMealTypeList().then(r => {
|
||||
|
||||
// TODO remove this once moved to user preference from MealType property
|
||||
let defaultMealType = {} as MealType
|
||||
r.results.forEach(r => {
|
||||
if (r._default) {
|
||||
defaultMealType = r
|
||||
}
|
||||
})
|
||||
if (Object.keys(defaultMealType).length == 0 && r.results.length > 0) {
|
||||
defaultMealType = r.results[0]
|
||||
}
|
||||
|
||||
setupState(props.item, props.itemId, () => {
|
||||
editingObj.value.fromDate = DateTime.now().toJSDate()
|
||||
editingObj.value.toDate = DateTime.now().toJSDate()
|
||||
editingObj.value.shared = useUserPreferenceStore().userSettings.planShare
|
||||
editingObj.value.servings = 1
|
||||
editingObj.value.mealType = defaultMealType
|
||||
setupState(props.item, props.itemId, {
|
||||
newItemFunction: () => {
|
||||
console.log('running new Item Function')
|
||||
editingObj.value.fromDate = DateTime.now().toJSDate()
|
||||
editingObj.value.toDate = DateTime.now().toJSDate()
|
||||
editingObj.value.shared = useUserPreferenceStore().userSettings.planShare
|
||||
editingObj.value.servings = 1
|
||||
editingObj.value.mealType = defaultMealType
|
||||
|
||||
// initialize date range slider
|
||||
dateRangeValue.value.push(editingObj.value.fromDate)
|
||||
}, () => {
|
||||
dateRangeValue.value.push(editingObj.value.fromDate)
|
||||
if(editingObj.value.toDate && editingObj.value.toDate != editingObj.value.fromDate) {
|
||||
let currentDate = DateTime.fromJSDate(editingObj.value.fromDate).plus({day: 1}).toJSDate()
|
||||
while(currentDate <= editingObj.value.toDate){
|
||||
dateRangeValue.value.push(currentDate)
|
||||
currentDate = DateTime.fromJSDate(currentDate).plus({day: 1}).toJSDate()
|
||||
}
|
||||
applyItemDefaults(props.itemDefaults)
|
||||
|
||||
initializeDateRange()
|
||||
console.log(editingObj.value)
|
||||
}, existingItemFunction: () => {
|
||||
initializeDateRange()
|
||||
}
|
||||
})
|
||||
},)
|
||||
})
|
||||
|
||||
})
|
||||
@@ -131,6 +135,22 @@ function updateDate() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* initialize the dateRange selector when the editingObject is initialized
|
||||
*/
|
||||
function initializeDateRange() {
|
||||
if (editingObj.value.toDate && DateTime.fromJSDate(editingObj.value.toDate).diff(DateTime.fromJSDate(editingObj.value.fromDate), 'days').toObject().days! >= 1) {
|
||||
dateRangeValue.value = [editingObj.value.fromDate]
|
||||
let currentDate = DateTime.fromJSDate(editingObj.value.fromDate).plus({day: 1}).toJSDate()
|
||||
while (currentDate <= editingObj.value.toDate) {
|
||||
dateRangeValue.value.push(currentDate)
|
||||
currentDate = DateTime.fromJSDate(currentDate).plus({day: 1}).toJSDate()
|
||||
}
|
||||
} else {
|
||||
dateRangeValue.value = [editingObj.value.fromDate, editingObj.value.fromDate]
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
@@ -122,10 +122,12 @@ onMounted(() => {
|
||||
api.apiSupermarketCategoryList({pageSize: 100}).then(r => {
|
||||
supermarketCategories.value = r.results
|
||||
|
||||
setupState(props.item, props.itemId, undefined, () => {
|
||||
editingObj.value.categoryToSupermarket.forEach(cTS => {
|
||||
editingObjSupermarketCategories.value.push(cTS.category)
|
||||
})
|
||||
setupState(props.item, props.itemId, {
|
||||
existingItemFunction: () => {
|
||||
editingObj.value.categoryToSupermarket.forEach(cTS => {
|
||||
editingObjSupermarketCategories.value.push(cTS.category)
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user