1
0
Fork 0
mirror of https://github.com/mealie-recipes/mealie.git synced 2025-08-02 20:15:24 +02:00

feature/new-feature-cleanup (#389)

* add json editor to theme editor

* add toolbars tools to recipe sections

* fix recipe yield

* add updated_date to recipe schema

* update time cards

* fix mobile buttons

* fix asset URL

* fix PG errors CRUD

* remove -d from docker-pro

* fix theme tests

* remvoe old typing

* abstract count function

Co-authored-by: hay-kot <hay-kot@pm.me>
This commit is contained in:
Hayden 2021-05-05 14:08:13 -08:00 committed by GitHub
parent c1370afb16
commit 1b0de02b71
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
34 changed files with 263 additions and 132 deletions

View file

@ -1,7 +1,7 @@
const baseURL = "/api/";
import axios from "axios";
import { store } from "../store";
import utils from "@/utils";
import { utils } from "@/utils";
axios.defaults.headers.common["Authorization"] = `Bearer ${store.getters.getToken}`;

View file

@ -14,7 +14,7 @@ const recipeURLs = {
recipe: slug => prefix + slug,
update: slug => prefix + slug,
delete: slug => prefix + slug,
createAsset: slug => `${prefix}media/${slug}/assets`,
createAsset: slug => `${prefix}${slug}/assets`,
recipeImage: slug => `${prefix}${slug}/image`,
updateImage: slug => `${prefix}${slug}/image`,
};

View file

@ -21,7 +21,7 @@
<script>
import { api } from "@/api";
import utils from "@/utils";
import { utils } from "@/utils";
import MealPlanCard from "./MealPlanCard";
export default {
components: {

View file

@ -82,7 +82,7 @@
const CREATE_EVENT = "created";
import DatePicker from "@/components/FormHelpers/DatePicker";
import { api } from "@/api";
import utils from "@/utils";
import { utils } from "@/utils";
import MealPlanCard from "./MealPlanCard";
export default {
components: {

View file

@ -8,7 +8,7 @@
<v-list-item-title class=" mb-1">{{ name }} </v-list-item-title>
<v-list-item-subtitle> {{ description }} </v-list-item-subtitle>
<div class="d-flex justify-center align-center">
<RecipeChips :items="tags" :title="false" :limit="1" :small="true" :isCategory="false" />
<RecipeChips :truncate="true" :items="tags" :title="false" :limit="1" :small="true" :isCategory="false" />
<v-rating
color="secondary"
class="ml-auto"

View file

@ -56,7 +56,7 @@
import BulkAdd from "@/components/Recipe/Parts/Helpers/BulkAdd";
import VueMarkdown from "@adapttive/vue-markdown";
import draggable from "vuedraggable";
import utils from "@/utils";
import { utils } from "@/utils";
export default {
components: {
BulkAdd,

View file

@ -66,7 +66,7 @@
<script>
import VueMarkdown from "@adapttive/vue-markdown";
import utils from "@/utils";
import { utils } from "@/utils";
export default {
components: {
VueMarkdown,

View file

@ -35,7 +35,7 @@
<script>
import VueMarkdown from "@adapttive/vue-markdown";
import utils from "@/utils";
import { utils } from "@/utils";
export default {
components: {
VueMarkdown,

View file

@ -25,7 +25,7 @@
<v-card-actions>
<Rating :value="rating" :name="name" :slug="slug" :small="true" />
<v-spacer></v-spacer>
<RecipeChips :items="tags" :title="false" :limit="2" :small="true" :isCategory="false" />
<RecipeChips :truncate="true" :items="tags" :title="false" :limit="2" :small="true" :isCategory="false" />
<ContextMenu :slug="slug" />
</v-card-actions>
</v-card>

View file

@ -124,7 +124,7 @@
</template>
<script>
import utils from "@/utils";
import { utils } from "@/utils";
import { api } from "@/api";
export default {

View file

@ -1,29 +1,13 @@
<template>
<v-card
color="accent"
class="custom-transparent d-flex justify-start align-center text-center time-card-flex"
tile
v-if="showCards"
>
<v-card flat color="rgb(255, 0, 0, 0.0)">
<v-icon large color="white" class="mx-2"> mdi-clock-outline </v-icon>
</v-card>
<v-card
v-for="(time, index) in allTimes"
:key="index"
class="d-flex justify-start align-center text-center time-card-flex"
flat
color="rgb(255, 0, 0, 0.0)"
>
<v-card-text class="caption white--text py-2">
<div>
<strong> {{ time.name }} </strong>
</div>
<div>{{ time.value }}</div>
</v-card-text>
</v-card>
</v-card>
<div>
<v-chip label color="accent custom-transparent" class="ma-1" v-for="(time, index) in allTimes" :key="index">
<v-icon left>
mdi-clock-outline
</v-icon>
{{ time.name }} |
{{ time.value }}
</v-chip>
</div>
</template>
<script>

View file

@ -11,7 +11,7 @@
:to="`/recipes/${urlParam}/${getSlug(category)}`"
:key="category"
>
{{ category }}
{{ truncateText(category) }}
</v-chip>
</div>
</template>
@ -19,6 +19,9 @@
<script>
export default {
props: {
truncate: {
default: false,
},
items: {
default: [],
},
@ -34,6 +37,7 @@ export default {
small: {
default: false,
},
maxWidth: {},
},
computed: {
allCategories() {
@ -58,6 +62,14 @@ export default {
if (matches.length > 0) return matches[0].slug;
}
},
truncateText(text, length = 20, clamp) {
if (!this.truncate) return text;
clamp = clamp || "...";
var node = document.createElement("div");
node.innerHTML = text;
var content = node.textContent;
return content.length > length ? content.slice(0, length) + clamp : content;
},
},
};
</script>

View file

@ -8,7 +8,7 @@
<v-row dense disabled>
<v-col>
<v-btn
v-if="recipe.yields"
v-if="recipe.recipeYield"
dense
small
:hover="false"
@ -18,7 +18,7 @@
color="secondary darken-1"
class="rounded-sm static"
>
{{ recipe.yields }}
{{ recipe.recipeYield }}
</v-btn>
</v-col>
<Rating :value="recipe.rating" :name="recipe.name" :slug="recipe.slug" />
@ -88,7 +88,7 @@
<script>
import Nutrition from "@/components/Recipe/Parts/Nutrition";
import VueMarkdown from "@adapttive/vue-markdown";
import utils from "@/utils";
import { utils } from "@/utils";
import RecipeChips from "./RecipeChips";
import Rating from "@/components/Recipe/Parts/Rating";
import Notes from "@/components/Recipe/Parts/Notes";

View file

@ -6,21 +6,28 @@
</v-icon>
<v-toolbar-title class="headline"> {{ title }} </v-toolbar-title>
<v-spacer></v-spacer>
<v-menu offset-y v-if="$listeners.sortRecent || $listeners.sort">
<v-btn text @click="navigateRandom">
Random
</v-btn>
<v-menu offset-y v-if="$listeners.sort">
<template v-slot:activator="{ on, attrs }">
<v-btn-toggle group>
<v-btn text v-bind="attrs" v-on="on">
{{ $t("general.sort") }}
</v-btn>
</v-btn-toggle>
<v-btn text v-bind="attrs" v-on="on">
{{ $t("general.sort") }}
</v-btn>
</template>
<v-list>
<v-list-item @click="$emit('sortRecent')">
<v-list-item-title>{{ $t("general.recent") }}</v-list-item-title>
</v-list-item>
<v-list-item @click="$emit('sort')">
<v-list-item @click="sortRecipes(EVENTS.az)">
<v-list-item-title>{{ $t("general.sort-alphabetically") }}</v-list-item-title>
</v-list-item>
<v-list-item @click="sortRecipes(EVENTS.rating)">
<v-list-item-title>{{ $t("general.rating") }}</v-list-item-title>
</v-list-item>
<v-list-item @click="sortRecipes(EVENTS.updated)">
<v-list-item-title>{{ $t("general.updated") }}</v-list-item-title>
</v-list-item>
<v-list-item @click="sortRecipes(EVENTS.created)">
<v-list-item-title>{{ $t("general.created") }}</v-list-item-title>
</v-list-item>
</v-list>
</v-menu>
</v-app-bar>
@ -76,6 +83,9 @@
<script>
import RecipeCard from "../Recipe/RecipeCard";
import MobileRecipeCard from "@/components/Recipe/MobileRecipeCard";
import { utils } from "@/utils";
const SORT_EVENT = "sort";
export default {
components: {
RecipeCard,
@ -106,6 +116,12 @@ export default {
return {
cardLimit: 30,
loading: false,
EVENTS: {
az: "az",
rating: "rating",
created: "created",
updated: "updated",
},
};
},
watch: {
@ -144,6 +160,31 @@ export default {
await new Promise(r => setTimeout(r, 1000));
this.loading = false;
},
navigateRandom() {
const recipe = utils.recipe.randomRecipe(this.recipes);
this.$router.push(`/recipe/${recipe.slug}`);
},
sortRecipes(sortType) {
let sortTarget = [...this.recipes];
switch (sortType) {
case this.EVENTS.az:
utils.recipe.sortAToZ(sortTarget);
break;
case this.EVENTS.rating:
utils.recipe.sortByRating(sortTarget);
break;
case this.EVENTS.created:
utils.recipe.sortByCreated(sortTarget);
break;
case this.EVENTS.updated:
utils.recipe.sortByUpdated(sortTarget);
break;
default:
console.log("Unknown Event", sortType);
return;
}
this.$emit(SORT_EVENT, sortTarget);
},
},
};
</script>

View file

@ -36,6 +36,7 @@
"close": "Close",
"confirm": "Confirm",
"create": "Create",
"created": "Created",
"current-parenthesis": "(Current)",
"dashboard": "Dashboard",
"delete": "Delete",
@ -63,6 +64,7 @@
"no": "No",
"ok": "OK",
"options": "Options:",
"rating": "Rating",
"random": "Random",
"recent": "Recent",
"recipes": "Recipes",
@ -83,6 +85,7 @@
"token": "Token",
"tuesday": "Tuesday",
"update": "Update",
"updated": "Updated",
"upload": "Upload",
"url": "URL",
"users": "Users",

View file

@ -92,26 +92,36 @@
:label="$t('settings.theme.theme-name')"
v-model="defaultData.name"
:rules="[rules.required]"
:append-outer-icon="jsonEditor ? 'mdi-form-select' : 'mdi-code-braces'"
@click:append-outer="jsonEditor = !jsonEditor"
></v-text-field>
<v-row dense dflex wrap justify-content-center v-if="defaultData.colors">
<v-row dense dflex wrap justify-content-center v-if="defaultData.colors && !jsonEditor">
<v-col cols="12" sm="6" v-for="(_, key) in defaultData.colors" :key="key">
<ColorPickerDialog :button-text="labels[key]" v-model="defaultData.colors[key]" />
</v-col>
</v-row>
<VJsoneditor @error="logError()" v-else v-model="defaultData" height="250px" :options="jsonEditorOptions" />
</v-card-text>
</BaseDialog>
</div>
</template>
<script>
import VJsoneditor from "v-jsoneditor";
import { api } from "@/api";
import ColorPickerDialog from "@/components/FormHelpers/ColorPickerDialog";
import BaseDialog from "@/components/UI/Dialogs/BaseDialog";
import StatCard from "@/components/UI/StatCard";
export default {
components: { StatCard, BaseDialog, ColorPickerDialog },
components: { StatCard, BaseDialog, ColorPickerDialog, VJsoneditor },
data() {
return {
jsonEditor: true,
jsonEditorOptions: {
mode: "code",
search: false,
mainMenuBar: false,
},
availableThemes: [],
color: "accent",
newTheme: false,

View file

@ -54,7 +54,7 @@
<script>
import { api } from "@/api";
import utils from "@/utils";
import { utils } from "@/utils";
import NewMeal from "@/components/MealPlan/MealPlanNew";
import EditPlan from "@/components/MealPlan/MealPlanEditor";
import ShoppingListDialog from "@/components/MealPlan/ShoppingListDialog";

View file

@ -36,7 +36,7 @@
<script>
import { api } from "@/api";
import utils from "@/utils";
import { utils } from "@/utils";
export default {
data() {
return {

View file

@ -6,7 +6,7 @@
<v-card v-else id="myRecipe">
<v-img height="400" :src="getImage(recipeDetails.slug)" class="d-print-none" :key="imageKey">
<RecipeTimeCard
class="force-bottom"
:class="isMobile ? undefined : 'force-bottom'"
:prepTime="recipeDetails.prepTime"
:totalTime="recipeDetails.totalTime"
:performTime="recipeDetails.performTime"
@ -106,6 +106,9 @@ export default {
},
computed: {
isMobile() {
return this.$vuetify.breakpoint.name === "xs";
},
currentRecipe() {
return this.$route.params.recipe;
},

View file

@ -5,9 +5,8 @@
title-icon=""
:sortable="true"
:title="$t('page.all-recipes')"
:recipes="allRecipes"
@sort="sortAZ"
@sort-recent="sortRecent"
:recipes="shownRecipes"
@sort="assignSorted"
/>
</v-container>
</template>
@ -22,6 +21,7 @@ export default {
data() {
return {
loading: false,
sortedResults: [],
};
},
async mounted() {
@ -35,13 +35,17 @@ export default {
allRecipes() {
return this.$store.getters.getAllRecipes;
},
shownRecipes() {
if (this.sortedResults.length > 0) {
return this.sortedResults;
} else {
return this.allRecipes;
}
},
},
methods: {
sortAZ() {
this.allRecipes.sort((a, b) => (a.name > b.name ? 1 : -1));
},
sortRecent() {
this.allRecipes.sort((a, b) => (a.dateAdded > b.dateAdded ? -1 : 1));
assignSorted(val) {
this.sortedResults = val;
},
},
};

View file

@ -47,31 +47,20 @@
</v-col>
</v-row>
<v-row v-if="fuzzyRecipes">
<v-col :sm="6" :md="6" :lg="4" :xl="3" v-for="item in fuzzyRecipes.slice(0, maxResults)" :key="item.name">
<RecipeCard
:name="item.item.name"
:description="item.item.description"
:slug="item.item.slug"
:rating="item.item.rating"
:image="item.item.image"
:tags="item.item.tags"
/>
</v-col>
</v-row>
<CardSection title-icon="mdi-mag" :recipes="showRecipes" :hardLimit="maxResults" @sort="assignFuzzy" />
</v-card>
</v-container>
</template>
<script>
import Fuse from "fuse.js";
import RecipeCard from "@/components/Recipe/RecipeCard";
import CategoryTagSelector from "@/components/FormHelpers/CategoryTagSelector";
import CardSection from "@/components/UI/CardSection";
import FilterSelector from "./FilterSelector.vue";
export default {
components: {
RecipeCard,
CardSection,
CategoryTagSelector,
FilterSelector,
},
@ -88,6 +77,7 @@ export default {
exclude: false,
matchAny: false,
},
sortedResults: [],
includeCategories: [],
includeTags: [],
options: {
@ -126,16 +116,31 @@ export default {
},
fuzzyRecipes() {
if (this.searchString.trim() === "") {
return this.filteredRecipes.map(x => ({ item: x }));
return this.filteredRecipes;
}
const result = this.fuse.search(this.searchString.trim());
return result;
return result.map(x => x.item);
},
isSearching() {
return this.searchString && this.searchString.length > 0;
},
showRecipes() {
if (this.sortedResults.length > 0) {
return this.sortedResults;
} else {
return this.fuzzyRecipes;
}
},
},
watch: {
showRecipes(val) {
console.log(val);
},
},
methods: {
assignFuzzy(val) {
this.sortedResults = val;
},
check(filterBy, recipeList, matchAny, exclude) {
let isMatch = true;
if (filterBy.length === 0) return isMatch;

View file

@ -3,7 +3,7 @@ import ThisWeek from "@/pages/MealPlan/ThisWeek";
import { api } from "@/api";
import i18n from "@/i18n.js";
import utils from "@/utils";
import { utils } from "@/utils";
export const mealRoutes = [
{

View file

@ -1,4 +1,5 @@
import { vueApp } from "../main";
import { recipe } from "@/utils/recipe";
// TODO: Migrate to Mixins
const notifyHelpers = {
@ -9,7 +10,8 @@ const notifyHelpers = {
info: "notify-info-color",
};
export default {
export const utils = {
recipe: recipe,
getImageURL(image) {
return `/api/recipes/${image}/image?image_type=small`;
},

View file

@ -0,0 +1,31 @@
export const recipe = {
/**
* Sorts a list of recipes in place
* @param {Array<Object>} list of recipes
* @param {Boolean} inverse - Z or A First
*/
sortAToZ(list) {
list.sort((a, b) => {
var textA = a.name.toUpperCase();
var textB = b.name.toUpperCase();
return textA < textB ? -1 : textA > textB ? 1 : 0;
});
},
sortByCreated(list) {
list.sort((a, b) => (a.dateAdded > b.dateAdded ? -1 : 1));
},
sortByUpdated(list) {
list.sort((a, b) => (a.dateUpdated > b.dateUpdated ? -1 : 1));
},
sortByRating(list) {
list.sort((a, b) => (a.rating > b.rating ? -1 : 1));
},
/**
*
* @param {Array<Object>} list
* @returns String / Recipe Slug
*/
randomRecipe(list) {
return list[Math.floor(Math.random() * list.length)];
},
};