mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-06-03 13:44:55 -04:00
feat: Cookbook Create & Delete Improvements (#2902)
* add delete dialog
* put editor into component
* return data on createCookbook store action
* verry basic dialog with create & cancel functions
* 🧹
* cleanup
* add translation
* add dialog-closed to BaseDialog
* update delete dialog messaging
* use cancel instead of dialog-closed
This commit is contained in:
parent
292672601c
commit
67b7fb007b
55
frontend/components/Domain/Cookbook/CookbookEditor.vue
Normal file
55
frontend/components/Domain/Cookbook/CookbookEditor.vue
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<v-card-text v-if="cookbook">
|
||||||
|
<v-text-field v-model="cookbook.name" :label="$t('cookbook.cookbook-name')"></v-text-field>
|
||||||
|
<v-textarea v-model="cookbook.description" auto-grow :rows="2" :label="$t('recipe.description')"></v-textarea>
|
||||||
|
<RecipeOrganizerSelector v-model="cookbook.categories" selector-type="categories" />
|
||||||
|
<RecipeOrganizerSelector v-model="cookbook.tags" selector-type="tags" />
|
||||||
|
<RecipeOrganizerSelector v-model="cookbook.tools" selector-type="tools" />
|
||||||
|
<v-switch v-model="cookbook.public" hide-details single-line>
|
||||||
|
<template #label>
|
||||||
|
{{ $t('cookbook.public-cookbook') }}
|
||||||
|
<HelpIcon small right class="ml-2">
|
||||||
|
{{ $t('cookbook.public-cookbook-description') }}
|
||||||
|
</HelpIcon>
|
||||||
|
</template>
|
||||||
|
</v-switch>
|
||||||
|
<div class="mt-4">
|
||||||
|
<h3 class="text-subtitle-1 d-flex align-center mb-0 pb-0">
|
||||||
|
{{ $t('cookbook.filter-options') }}
|
||||||
|
<HelpIcon right small class="ml-2">
|
||||||
|
{{ $t('cookbook.filter-options-description') }}
|
||||||
|
</HelpIcon>
|
||||||
|
</h3>
|
||||||
|
<v-switch v-model="cookbook.requireAllCategories" class="mt-0" hide-details single-line>
|
||||||
|
<template #label> {{ $t('cookbook.require-all-categories') }} </template>
|
||||||
|
</v-switch>
|
||||||
|
<v-switch v-model="cookbook.requireAllTags" hide-details single-line>
|
||||||
|
<template #label> {{ $t('cookbook.require-all-tags') }} </template>
|
||||||
|
</v-switch>
|
||||||
|
<v-switch v-model="cookbook.requireAllTools" hide-details single-line>
|
||||||
|
<template #label> {{ $t('cookbook.require-all-tools') }} </template>
|
||||||
|
</v-switch>
|
||||||
|
</div>
|
||||||
|
</v-card-text>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts">
|
||||||
|
import { defineComponent } from "@nuxtjs/composition-api";
|
||||||
|
import { ReadCookBook } from "~/lib/api/types/cookbook";
|
||||||
|
import RecipeOrganizerSelector from "~/components/Domain/Recipe/RecipeOrganizerSelector.vue";
|
||||||
|
export default defineComponent({
|
||||||
|
components: { RecipeOrganizerSelector },
|
||||||
|
props: {
|
||||||
|
cookbook: {
|
||||||
|
type: Object as () => ReadCookBook,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
actions: {
|
||||||
|
type: Object as () => any,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
</script>
|
@ -12,6 +12,8 @@
|
|||||||
$emit('submit');
|
$emit('submit');
|
||||||
dialog = false;
|
dialog = false;
|
||||||
"
|
"
|
||||||
|
@click:outside="$emit('cancel')"
|
||||||
|
@keydown.esc="$emit('cancel')"
|
||||||
>
|
>
|
||||||
<v-card height="100%">
|
<v-card height="100%">
|
||||||
<v-app-bar dark dense :color="color" class="">
|
<v-app-bar dark dense :color="color" class="">
|
||||||
|
@ -109,6 +109,7 @@ export const useCookbooks = function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
|
return data;
|
||||||
},
|
},
|
||||||
async updateOne(updateData: UpdateCookBook) {
|
async updateOne(updateData: UpdateCookBook) {
|
||||||
if (!updateData.id) {
|
if (!updateData.id) {
|
||||||
|
@ -1185,6 +1185,8 @@
|
|||||||
"require-all-tags": "Require All Tags",
|
"require-all-tags": "Require All Tags",
|
||||||
"require-all-tools": "Require All Tools",
|
"require-all-tools": "Require All Tools",
|
||||||
"cookbook-name": "Cookbook Name",
|
"cookbook-name": "Cookbook Name",
|
||||||
"cookbook-with-name": "Cookbook {0}"
|
"cookbook-with-name": "Cookbook {0}",
|
||||||
|
"create-a-cookbook": "Create a Cookbook",
|
||||||
|
"cookbook": "Cookbook"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,73 +1,81 @@
|
|||||||
<template>
|
<template>
|
||||||
<v-container class="narrow-container">
|
<div>
|
||||||
<BasePageTitle divider>
|
<!-- Create Dialog -->
|
||||||
<template #header>
|
<BaseDialog
|
||||||
<v-img max-height="100" max-width="100" :src="require('~/static/svgs/manage-cookbooks.svg')"></v-img>
|
v-if="createTarget"
|
||||||
</template>
|
v-model="dialogStates.create"
|
||||||
<template #title> {{ $t('cookbook.cookbooks') }} </template>
|
:width="650"
|
||||||
{{ $t('cookbook.description') }}
|
:icon="$globals.icons.pages"
|
||||||
</BasePageTitle>
|
:title="$t('cookbook.create-a-cookbook')"
|
||||||
|
:submit-icon="$globals.icons.save"
|
||||||
|
:submit-text="$tc('general.save')"
|
||||||
|
@submit="actions.updateOne(createTarget)"
|
||||||
|
@cancel="actions.deleteOne(createTarget.id)"
|
||||||
|
>
|
||||||
|
<v-card-text>
|
||||||
|
<CookbookEditor
|
||||||
|
:cookbook=createTarget
|
||||||
|
:actions="actions"
|
||||||
|
/>
|
||||||
|
</v-card-text>
|
||||||
|
</BaseDialog>
|
||||||
|
|
||||||
<BaseButton create @click="actions.createOne()" />
|
<!-- Delete Dialog -->
|
||||||
<v-expansion-panels class="mt-2">
|
<BaseDialog
|
||||||
<draggable v-model="cookbooks" handle=".handle" style="width: 100%" @change="actions.updateOrder()">
|
v-model="dialogStates.delete"
|
||||||
<v-expansion-panel v-for="(cookbook, index) in cookbooks" :key="index" class="my-2 left-border rounded">
|
:title="$t('general.delete-with-name', { name: $t('cookbook.cookbook') })"
|
||||||
<v-expansion-panel-header disable-icon-rotate class="headline">
|
:icon="$globals.icons.alertCircle"
|
||||||
<div class="d-flex align-center">
|
color="error"
|
||||||
<v-icon large left>
|
@confirm="deleteCookbook()"
|
||||||
{{ $globals.icons.pages }}
|
>
|
||||||
</v-icon>
|
<v-card-text>
|
||||||
{{ cookbook.name }}
|
<p>{{ $t("general.confirm-delete-generic-with-name", { name: $t('cookbook.cookbook') }) }}</p>
|
||||||
</div>
|
<p v-if="deleteTarget" class="mt-4 ml-4">{{ deleteTarget.name }}</p>
|
||||||
<template #actions>
|
</v-card-text>
|
||||||
<v-icon class="handle">
|
</BaseDialog>
|
||||||
{{ $globals.icons.arrowUpDown }}
|
|
||||||
</v-icon>
|
<!-- Cookbook Page -->
|
||||||
<v-btn icon small class="ml-2">
|
<!-- Page Title -->
|
||||||
<v-icon>
|
<v-container class="narrow-container">
|
||||||
{{ $globals.icons.edit }}
|
<BasePageTitle divider>
|
||||||
|
<template #header>
|
||||||
|
<v-img max-height="100" max-width="100" :src="require('~/static/svgs/manage-cookbooks.svg')"></v-img>
|
||||||
|
</template>
|
||||||
|
<template #title> {{ $t('cookbook.cookbooks') }} </template>
|
||||||
|
{{ $t('cookbook.description') }}
|
||||||
|
</BasePageTitle>
|
||||||
|
|
||||||
|
<!-- Create New -->
|
||||||
|
<BaseButton create @click="createCookbook" />
|
||||||
|
|
||||||
|
<!-- Cookbook List -->
|
||||||
|
<v-expansion-panels class="mt-2">
|
||||||
|
<draggable v-model="cookbooks" handle=".handle" style="width: 100%" @change="actions.updateOrder()">
|
||||||
|
<v-expansion-panel v-for="(cookbook, index) in cookbooks" :key="index" class="my-2 left-border rounded">
|
||||||
|
<v-expansion-panel-header disable-icon-rotate class="headline">
|
||||||
|
<div class="d-flex align-center">
|
||||||
|
<v-icon large left>
|
||||||
|
{{ $globals.icons.pages }}
|
||||||
</v-icon>
|
</v-icon>
|
||||||
</v-btn>
|
{{ cookbook.name }}
|
||||||
</template>
|
|
||||||
</v-expansion-panel-header>
|
|
||||||
<v-expansion-panel-content>
|
|
||||||
<v-card-text v-if="cookbooks">
|
|
||||||
<v-text-field v-model="cookbooks[index].name" :label="$t('cookbook.cookbook-name')"></v-text-field>
|
|
||||||
<v-textarea v-model="cookbooks[index].description" auto-grow :rows="2" :label="$t('recipe.description')"></v-textarea>
|
|
||||||
<RecipeOrganizerSelector v-model="cookbooks[index].categories" selector-type="categories" />
|
|
||||||
<RecipeOrganizerSelector v-model="cookbooks[index].tags" selector-type="tags" />
|
|
||||||
<RecipeOrganizerSelector v-model="cookbooks[index].tools" selector-type="tools" />
|
|
||||||
<v-switch v-model="cookbooks[index].public" hide-details single-line>
|
|
||||||
<template #label>
|
|
||||||
{{ $t('cookbook.public-cookbook') }}
|
|
||||||
<HelpIcon small right class="ml-2">
|
|
||||||
{{ $t('cookbook.public-cookbook-description') }}
|
|
||||||
</HelpIcon>
|
|
||||||
</template>
|
|
||||||
</v-switch>
|
|
||||||
<div class="mt-4">
|
|
||||||
<h3 class="text-subtitle-1 d-flex align-center mb-0 pb-0">
|
|
||||||
{{ $t('cookbook.filter-options') }}
|
|
||||||
<HelpIcon right small class="ml-2">
|
|
||||||
{{ $t('cookbook.filter-options-description') }}
|
|
||||||
</HelpIcon>
|
|
||||||
</h3>
|
|
||||||
<v-switch v-model="cookbooks[index].requireAllCategories" class="mt-0" hide-details single-line>
|
|
||||||
<template #label> {{ $t('cookbook.require-all-categories') }} </template>
|
|
||||||
</v-switch>
|
|
||||||
<v-switch v-model="cookbooks[index].requireAllTags" hide-details single-line>
|
|
||||||
<template #label> {{ $t('cookbook.require-all-tags') }} </template>
|
|
||||||
</v-switch>
|
|
||||||
<v-switch v-model="cookbooks[index].requireAllTools" hide-details single-line>
|
|
||||||
<template #label> {{ $t('cookbook.require-all-tools') }} </template>
|
|
||||||
</v-switch>
|
|
||||||
</div>
|
</div>
|
||||||
</v-card-text>
|
<template #actions>
|
||||||
<v-card-actions>
|
<v-icon class="handle">
|
||||||
<v-spacer></v-spacer>
|
{{ $globals.icons.arrowUpDown }}
|
||||||
<BaseButtonGroup
|
</v-icon>
|
||||||
:buttons="[
|
<v-btn icon small class="ml-2">
|
||||||
{
|
<v-icon>
|
||||||
|
{{ $globals.icons.edit }}
|
||||||
|
</v-icon>
|
||||||
|
</v-btn>
|
||||||
|
</template>
|
||||||
|
</v-expansion-panel-header>
|
||||||
|
<v-expansion-panel-content>
|
||||||
|
<CookbookEditor :cookbook="cookbook" :actions="actions" :collapsable="false" @delete="deleteEventHandler" />
|
||||||
|
<v-card-actions>
|
||||||
|
<v-spacer></v-spacer>
|
||||||
|
<BaseButtonGroup
|
||||||
|
:buttons="[{
|
||||||
icon: $globals.icons.delete,
|
icon: $globals.icons.delete,
|
||||||
text: $tc('general.delete'),
|
text: $tc('general.delete'),
|
||||||
event: 'delete',
|
event: 'delete',
|
||||||
@ -78,26 +86,27 @@
|
|||||||
event: 'save',
|
event: 'save',
|
||||||
},
|
},
|
||||||
]"
|
]"
|
||||||
@delete="actions.deleteOne(cookbook.id)"
|
@delete="deleteEventHandler(cookbook)"
|
||||||
@save="actions.updateOne(cookbook)"
|
@save="actions.updateOne(cookbook)" />
|
||||||
/>
|
</v-card-actions>
|
||||||
</v-card-actions>
|
</v-expansion-panel-content>
|
||||||
</v-expansion-panel-content>
|
</v-expansion-panel>
|
||||||
</v-expansion-panel>
|
</draggable>
|
||||||
</draggable>
|
</v-expansion-panels>
|
||||||
</v-expansion-panels>
|
</v-container>
|
||||||
</v-container>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { defineComponent, useRouter } from "@nuxtjs/composition-api";
|
import { defineComponent, reactive, ref, useRouter } from "@nuxtjs/composition-api";
|
||||||
import draggable from "vuedraggable";
|
import draggable from "vuedraggable";
|
||||||
import { useCookbooks } from "@/composables/use-group-cookbooks";
|
import { useCookbooks } from "@/composables/use-group-cookbooks";
|
||||||
import { useLoggedInState } from "~/composables/use-logged-in-state";
|
import { useLoggedInState } from "~/composables/use-logged-in-state";
|
||||||
import RecipeOrganizerSelector from "~/components/Domain/Recipe/RecipeOrganizerSelector.vue";
|
import CookbookEditor from "~/components/Domain/Cookbook/CookbookEditor.vue";
|
||||||
|
import { ReadCookBook } from "~/lib/api/types/cookbook";
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
components: { draggable, RecipeOrganizerSelector },
|
components: { CookbookEditor, draggable },
|
||||||
setup() {
|
setup() {
|
||||||
const { isOwnGroup, loggedIn } = useLoggedInState();
|
const { isOwnGroup, loggedIn } = useLoggedInState();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
@ -106,11 +115,50 @@ export default defineComponent({
|
|||||||
router.back();
|
router.back();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const dialogStates = reactive({
|
||||||
|
create: false,
|
||||||
|
delete: false,
|
||||||
|
});
|
||||||
|
|
||||||
const { cookbooks, actions } = useCookbooks();
|
const { cookbooks, actions } = useCookbooks();
|
||||||
|
|
||||||
|
|
||||||
|
// create
|
||||||
|
const createTarget = ref<ReadCookBook | null>(null);
|
||||||
|
async function createCookbook() {
|
||||||
|
await actions.createOne().then((cookbook) => {
|
||||||
|
createTarget.value = cookbook as ReadCookBook;
|
||||||
|
});
|
||||||
|
dialogStates.create = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// delete
|
||||||
|
const deleteTarget = ref<ReadCookBook | null>(null);
|
||||||
|
function deleteEventHandler(item: ReadCookBook){
|
||||||
|
deleteTarget.value = item;
|
||||||
|
dialogStates.delete = true;
|
||||||
|
}
|
||||||
|
function deleteCookbook() {
|
||||||
|
if (!deleteTarget.value) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
actions.deleteOne(deleteTarget.value.id);
|
||||||
|
dialogStates.delete = false;
|
||||||
|
deleteTarget.value = null;
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
cookbooks,
|
cookbooks,
|
||||||
actions,
|
actions,
|
||||||
|
dialogStates,
|
||||||
|
// create
|
||||||
|
createTarget,
|
||||||
|
createCookbook,
|
||||||
|
|
||||||
|
// delete
|
||||||
|
deleteTarget,
|
||||||
|
deleteEventHandler,
|
||||||
|
deleteCookbook,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
head() {
|
head() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user