This commit is contained in:
Chris Scoggins
2022-01-24 18:06:54 -06:00
parent 5959914932
commit fcb8e520b7
11 changed files with 229 additions and 152 deletions

View File

@ -6,11 +6,7 @@
<div class="row justify-content-center">
<div class="col-12 col-lg-10 mt-3 mb-3">
<b-input-group>
<b-input
class="form-control form-control-lg form-control-borderless form-control-search"
v-model="search"
v-bind:placeholder="$t('Search')"
></b-input>
<b-input class="form-control form-control-lg form-control-borderless form-control-search" v-model="search" v-bind:placeholder="$t('Search')"></b-input>
<b-input-group-append>
<b-button variant="primary" v-b-tooltip.hover :title="$t('Create')" @click="createNew">
<i class="fas fa-plus"></i>
@ -48,13 +44,7 @@
<loading-spinner v-if="current_book === book.id && loading"></loading-spinner>
<transition name="slide-fade">
<cookbook-slider
:recipes="recipes"
:book="book"
:key="`slider_${book.id}`"
v-if="current_book === book.id && !loading"
v-on:refresh="refreshData"
></cookbook-slider>
<cookbook-slider :recipes="recipes" :book="book" :key="`slider_${book.id}`" v-if="current_book === book.id && !loading" v-on:refresh="refreshData"></cookbook-slider>
</transition>
</div>
</div>

View File

@ -903,6 +903,7 @@ export default {
}
if (filter) {
// this can be simplified by calling recipe API {query: {filter: filter_id}} but you lose loading all of the params into the UI
filter = JSON.parse(filter.search)
let fields = ["keywords", "foods", "books"]
let operators = ["_or", "_and", "_or_not", "_and_not"]

View File

@ -1,130 +1,149 @@
<template>
<b-card no-body v-hover>
<b-card-header class="p-4">
<h5>{{ book_copy.icon }}&nbsp;{{ book_copy.name }}
<span class="float-right text-primary" @click="editOrSave"><i
class="fa" v-bind:class="{ 'fa-pen': !editing, 'fa-save': editing }"
aria-hidden="true"></i></span></h5>
<b-badge class="font-weight-normal mr-1" v-for="u in book_copy.shared" v-bind:key="u.id" variant="primary" pill>{{u.username}}</b-badge>
</b-card-header>
<b-card-body class="p-4">
<div class="form-group" v-if="editing">
<label for="inputName1">{{ $t('Name') }}</label>
<input class="form-control" id="inputName1"
placeholder="Name" v-model="book_copy.name">
</div>
<div class="form-group" v-if="editing">
<emoji-input :field="'icon'" :label="$t('Icon')" :value="book_copy.icon"></emoji-input>
</div>
<div class="form-group" v-if="editing">
<label for="inputDesc1">{{ $t('Description') }}</label>
<textarea class="form-control" id="inputDesc1" rows="3" v-model="book_copy.description">
</textarea>
</div>
<div class="form-group" v-if="editing">
<label for="inputDesc1">{{ $t('Share') }}</label>
<generic-multiselect @change="book_copy.shared = $event.val" parent_variable="book.shared"
:initial_selection="book.shared" :label="'username'"
:model="Models.USER_NAME"
style="flex-grow: 1; flex-shrink: 1; flex-basis: 0"
v-bind:placeholder="$t('Share')" :limit="50"></generic-multiselect>
</div>
<button v-if="editing" class="btn btn-danger" @click="deleteBook">{{ $t('Delete') }}</button>
<button v-if="editing" class="btn btn-primary float-right" @click="editOrSave">{{ $t('Save') }}</button>
<b-card-text style="text-overflow: ellipsis;" v-if="!editing">
{{ book_copy.description }}
</b-card-text>
</b-card-body>
</b-card>
<b-card no-body v-hover>
<b-card-header class="p-4">
<h5>
{{ book_copy.icon }}&nbsp;{{ book_copy.name }}
<span class="float-right text-primary" @click="editOrSave"><i class="fa" v-bind:class="{ 'fa-pen': !editing, 'fa-save': editing }" aria-hidden="true"></i></span>
</h5>
<b-badge class="font-weight-normal mr-1" v-for="u in book_copy.shared" v-bind:key="u.id" variant="primary" pill>{{ u.username }}</b-badge>
</b-card-header>
<b-card-body class="p-4">
<div class="form-group" v-if="editing">
<label for="inputName1">{{ $t("Name") }}</label>
<input class="form-control" id="inputName1" placeholder="Name" v-model="book_copy.name" />
</div>
<div class="form-group" v-if="editing">
<emoji-input :field="'icon'" :label="$t('Icon')" :value="book_copy.icon"></emoji-input>
</div>
<div class="form-group" v-if="editing">
<label for="inputDesc1">{{ $t("Description") }}</label>
<textarea class="form-control" id="inputDesc1" rows="3" v-model="book_copy.description"> </textarea>
</div>
<div class="form-group" v-if="editing">
<label for="inputDesc1">{{ $t("Share") }}</label>
<generic-multiselect
@change="book_copy.shared = $event.val"
parent_variable="book.shared"
:initial_selection="book.shared"
:label="'username'"
:model="Models.USER_NAME"
style="flex-grow: 1; flex-shrink: 1; flex-basis: 0"
v-bind:placeholder="$t('Share')"
:limit="50"
></generic-multiselect>
</div>
<div class="form-group" v-if="editing">
<label for="inputDesc1">{{ $t("recipe_filter") }}</label>
<generic-multiselect
@change="book_copy.filter = $event.val"
parent_variable="book.filter"
:initial_single_selection="book.filter"
:model="Models.CUSTOM_FILTER"
:multiple="false"
style="flex-grow: 1; flex-shrink: 1; flex-basis: 0"
v-bind:placeholder="$t('Custom Filter')"
:limit="50"
></generic-multiselect>
<small class="text-muted">{{ $t("book_filter_help") }}</small>
</div>
<button v-if="editing" class="btn btn-danger" @click="deleteBook">{{ $t("Delete") }}</button>
<button v-if="editing" class="btn btn-primary float-right" @click="editOrSave">{{ $t("Save") }}</button>
<b-card-text style="text-overflow: ellipsis" v-if="!editing">
{{ book_copy.description }}
</b-card-text>
</b-card-body>
</b-card>
</template>
<script>
import {ApiApiFactory} from "@/utils/openapi/api";
import {ApiMixin, StandardToasts} from "@/utils/utils";
import EmojiInput from "./Modals/EmojiInput";
import GenericMultiselect from "@/components/GenericMultiselect";
import { ApiApiFactory } from "@/utils/openapi/api"
import { ApiMixin, StandardToasts } from "@/utils/utils"
import EmojiInput from "./Modals/EmojiInput"
import GenericMultiselect from "@/components/GenericMultiselect"
export default {
name: "CookbookEditCard",
components: {EmojiInput, GenericMultiselect},
mixins: [ApiMixin],
props: {
book: Object
},
data() {
return {
editing: false,
book_copy: {},
users: []
}
},
mounted() {
this.book_copy = this.book
this.$root.$on('change', this.updateEmoji);
},
directives: {
hover: {
inserted: function (el) {
el.addEventListener('mouseenter', () => {
el.classList.add("shadow")
});
el.addEventListener('mouseleave', () => {
el.classList.remove("shadow")
});
}
}
},
methods: {
editOrSave: function () {
if (!this.editing) {
this.editing = true
this.$emit("editing", true)
} else {
this.editing = false
this.saveData()
this.$emit("editing", false)
}
name: "CookbookEditCard",
components: { EmojiInput, GenericMultiselect },
mixins: [ApiMixin],
props: {
book: Object,
},
updateEmoji: function (item, value) {
if (item === 'icon') {
this.book_copy.icon = value
}
data() {
return {
editing: false,
book_copy: {},
users: [],
}
},
saveData: function () {
let apiClient = new ApiApiFactory()
mounted() {
this.book_copy = this.book
this.$root.$on("change", this.updateEmoji)
},
directives: {
hover: {
inserted: function (el) {
el.addEventListener("mouseenter", () => {
el.classList.add("shadow")
})
el.addEventListener("mouseleave", () => {
el.classList.remove("shadow")
})
},
},
},
methods: {
editOrSave: function () {
if (!this.editing) {
this.editing = true
this.$emit("editing", true)
} else {
this.editing = false
this.saveData()
this.$emit("editing", false)
}
},
updateEmoji: function (item, value) {
if (item === "icon") {
this.book_copy.icon = value
}
},
saveData: function () {
let apiClient = new ApiApiFactory()
apiClient.updateRecipeBook(this.book_copy.id, this.book_copy).then(result => {
StandardToasts.makeStandardToast(StandardToasts.SUCCESS_UPDATE)
}).catch(error => {
StandardToasts.makeStandardToast(StandardToasts.FAIL_UPDATE)
})
},
refreshData: function () {
let apiClient = new ApiApiFactory()
apiClient
.updateRecipeBook(this.book_copy.id, this.book_copy)
.then((result) => {
console.log(result)
StandardToasts.makeStandardToast(StandardToasts.SUCCESS_UPDATE)
})
.catch((error) => {
StandardToasts.makeStandardToast(StandardToasts.FAIL_UPDATE)
})
},
refreshData: function () {
let apiClient = new ApiApiFactory()
apiClient.listUsers().then(result => {
this.users = result.data
})
},
deleteBook: function () {
if (confirm(this.$t('delete_confirmation', {source: this.book.name}))) {
let apiClient = new ApiApiFactory()
apiClient.listUsers().then((result) => {
this.users = result.data
})
},
deleteBook: function () {
if (confirm(this.$t("delete_confirmation", { source: this.book.name }))) {
let apiClient = new ApiApiFactory()
apiClient.destroyRecipeBook(this.book.id).then(result => {
this.$emit('refresh')
StandardToasts.makeStandardToast(StandardToasts.SUCCESS_DELETE)
}).catch(error => {
StandardToasts.makeStandardToast(StandardToasts.FAIL_DELETE)
})
}
apiClient
.destroyRecipeBook(this.book.id)
.then((result) => {
this.$emit("refresh")
StandardToasts.makeStandardToast(StandardToasts.SUCCESS_DELETE)
})
.catch((error) => {
StandardToasts.makeStandardToast(StandardToasts.FAIL_DELETE)
})
}
},
},
}
}
</script>
<style scoped>
</style>
<style scoped></style>

View File

@ -325,5 +325,7 @@
"date_created": "Date Created",
"show_sortby": "Show Sort By",
"search_rank": "Search Rank",
"make_now": "Make Now"
"make_now": "Make Now",
"recipe_filter": "Recipe Filter",
"book_filter_help": "Include recipes from recipe filter instead of assigning each recipe"
}

View File

@ -249,7 +249,7 @@ export class Models {
name: "Recipe_Book",
apiName: "RecipeBook",
create: {
params: [["name", "description", "icon"]],
params: [["name", "description", "icon", "filter"]],
form: {
name: {
form_field: true,
@ -271,6 +271,13 @@ export class Models {
field: "icon",
label: i18n.t("Icon"),
},
filter: {
form_field: true,
type: "lookup",
field: "filter",
label: i18n.t("Custom Filter"),
list: "CUSTOM_FILTER",
},
},
},
}

View File

@ -1555,6 +1555,12 @@ export interface RecipeBook {
* @memberof RecipeBook
*/
created_by?: string;
/**
*
* @type {RecipeBookFilter}
* @memberof RecipeBook
*/
filter?: RecipeBookFilter;
}
/**
*
@ -1593,6 +1599,43 @@ export interface RecipeBookEntry {
*/
recipe_content?: string;
}
/**
*
* @export
* @interface RecipeBookFilter
*/
export interface RecipeBookFilter {
/**
*
* @type {number}
* @memberof RecipeBookFilter
*/
id?: number;
/**
*
* @type {string}
* @memberof RecipeBookFilter
*/
name: string;
/**
*
* @type {string}
* @memberof RecipeBookFilter
*/
search: string;
/**
*
* @type {Array<CustomFilterShared>}
* @memberof RecipeBookFilter
*/
shared?: Array<CustomFilterShared>;
/**
*
* @type {string}
* @memberof RecipeBookFilter
*/
created_by?: string;
}
/**
*
* @export