1
0
Fork 0
mirror of https://github.com/mealie-recipes/mealie.git synced 2025-08-02 12:05:21 +02:00

feat(backend): 🚧 stub out new exporter service (WIP) (#715)

* chore(backend): 🎨 add isort path to vscode settings

* style(frontend): 💄 remove fab and add general create button

* feat(backend): 🚧 stub out new exporter service

* comment out stub tests

Co-authored-by: Hayden <hay-kot@pm.me>
This commit is contained in:
Hayden 2021-10-02 11:37:04 -08:00 committed by GitHub
parent 476aefeeb0
commit 4bdba9f3af
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
26 changed files with 714 additions and 50 deletions

View file

@ -15,6 +15,8 @@
<v-divider></v-divider>
</template>
<slot></slot>
<!-- Primary Links -->
<template v-if="topLink">
<v-list nav dense>

View file

@ -10,7 +10,32 @@
:secondary-links="cookbookLinks || []"
:bottom-links="isAdmin ? bottomLink : []"
@input="sidebar = !sidebar"
/>
>
<v-menu offset-y nudge-bottom="5" open-on-hover close-delay="30" nudge-right="15">
<template #activator="{ on, attrs }">
<v-btn rounded large class="ml-2 mt-3" v-bind="attrs" v-on="on">
<v-icon left large color="primary">
{{ $globals.icons.createAlt }}
</v-icon>
{{ $t("general.create") }}
</v-btn>
</template>
<v-list>
<template v-for="(item, index) in createLinks">
<v-divider v-if="item.divider" :key="index" class="mx-2"></v-divider>
<v-list-item v-else :key="item.title" :to="item.to" exact>
<v-list-item-avatar>
<v-icon v-text="item.icon"></v-icon>
</v-list-item-avatar>
<v-list-item-content>
<v-list-item-title v-text="item.title"></v-list-item-title>
<v-list-item-subtitle v-text="item.subtitle"></v-list-item-subtitle>
</v-list-item-content>
</v-list-item>
</template>
</v-list>
</v-menu>
</AppSidebar>
<AppHeader>
<v-btn icon @click.stop="sidebar = !sidebar">
@ -22,7 +47,6 @@
<Nuxt />
</v-scroll-x-transition>
</v-main>
<AppFloatingButton absolute />
</v-app>
</template>
@ -31,11 +55,10 @@
import { computed, defineComponent, useContext } from "@nuxtjs/composition-api";
import AppHeader from "@/components/Layout/AppHeader.vue";
import AppSidebar from "@/components/Layout/AppSidebar.vue";
import AppFloatingButton from "@/components/Layout/AppFloatingButton.vue";
import { useCookbooks } from "~/composables/use-group-cookbooks";
export default defineComponent({
components: { AppHeader, AppSidebar, AppFloatingButton },
components: { AppHeader, AppSidebar },
// @ts-ignore
middleware: "auth",
setup() {
@ -60,6 +83,35 @@ export default defineComponent({
data() {
return {
sidebar: null,
createLinks: [
{
icon: this.$globals.icons.link,
title: "Import",
subtitle: "Import a recipe by URL",
to: "/recipe/create?tab=url",
restricted: true,
},
{
divider: true,
},
{
icon: this.$globals.icons.edit,
title: "Create",
subtitle: "Create a recipe manually",
to: "/recipe/create?tab=new",
restricted: true,
},
{
divider: true,
},
{
icon: this.$globals.icons.zip,
title: "Restore",
subtitle: "Restore from a exported recipe",
to: "/recipe/create?tab=zip",
restricted: true,
},
],
bottomLink: [
{
icon: this.$globals.icons.cog,

View file

@ -0,0 +1,244 @@
<template>
<v-container class="narrow-container flex-column">
<BasePageTitle divider>
<template #header>
<v-img max-height="175" max-width="175" :src="require('~/static/svgs/recipes-create.svg')"></v-img>
</template>
<template #title> Recipe Creation </template>
Select one of the various ways to create a recipe
</BasePageTitle>
<v-tabs v-model="tab">
<v-tab href="#url">From URL</v-tab>
<v-tab href="#new">Create</v-tab>
<v-tab href="#zip">Import Zip</v-tab>
</v-tabs>
<section>
<v-tabs-items v-model="tab" class="mt-10">
<v-tab-item value="url" eager>
<v-form ref="domUrlForm" @submit.prevent="createByUrl(recipeUrl)">
<v-card outlined>
<v-card-text>
<v-text-field
v-model="recipeUrl"
:label="$t('new-recipe.recipe-url')"
validate-on-blur
autofocus
class="rounded-lg my-auto"
:rules="[validators.url]"
:hint="$t('new-recipe.url-form-hint')"
persistent-hint
></v-text-field>
</v-card-text>
<v-card-actions>
<v-spacer></v-spacer>
<BaseButton type="submit" :loading="loading" />
</v-card-actions>
</v-card>
</v-form>
<v-expand-transition>
<v-alert v-show="error" color="error" class="mt-6 white--text">
<v-card-title class="ma-0 pa-0">
<v-icon left color="white" x-large> {{ $globals.icons.robot }} </v-icon>
{{ $t("new-recipe.error-title") }}
</v-card-title>
<v-divider class="my-3 mx-2"></v-divider>
<p>
{{ $t("new-recipe.error-details") }}
</p>
<div class="d-flex row justify-space-around my-3 force-white">
<a
class="dark"
href="https://developers.google.com/search/docs/data-types/recipe"
target="_blank"
rel="noreferrer nofollow"
>
{{ $t("new-recipe.google-ld-json-info") }}
</a>
<a href="https://github.com/hay-kot/mealie/issues" target="_blank" rel="noreferrer nofollow">
{{ $t("new-recipe.github-issues") }}
</a>
<a href="https://schema.org/Recipe" target="_blank" rel="noreferrer nofollow">
{{ $t("new-recipe.recipe-markup-specification") }}
</a>
</div>
<div class="d-flex justify-end">
<v-btn
dark
outlined
:to="{ path: '/recipes/debugger', query: { test_url: recipeUrl } }"
@click="addRecipe = false"
>
<v-icon left> {{ $globals.icons.externalLink }} </v-icon>
{{ $t("new-recipe.view-scraped-data") }}
</v-btn>
</div>
</v-alert>
</v-expand-transition>
</v-tab-item>
<v-tab-item value="new" eager>
<v-card outlined>
<v-card-text>
<v-form ref="domCreateByName">
<v-text-field
v-model="newRecipeName"
:label="$t('recipe.recipe-name')"
validate-on-blur
autofocus
class="rounded-lg my-auto"
:rules="[validators.required]"
hint="New recipe names must be unique"
persistent-hint
></v-text-field>
</v-form>
</v-card-text>
<v-card-actions>
<v-spacer></v-spacer>
<BaseButton :loading="loading" @click="createByName(newRecipeName)" />
</v-card-actions>
</v-card>
</v-tab-item>
<v-tab-item value="zip" eager>
<v-form>
<v-card outlined>
<v-card-text>
<v-file-input
v-model="newRecipeZip"
accept=".zip"
placeholder="Select your files"
label="File input"
truncate-length="100"
hint=".zip files must have been exported from Mealie"
persistent-hint
:prepend-icon="$globals.icons.zip"
>
</v-file-input>
</v-card-text>
<v-card-actions>
<v-spacer></v-spacer>
<BaseButton :loading="loading" @click="createByZip" />
</v-card-actions>
</v-card>
</v-form>
</v-tab-item>
</v-tabs-items>
</section>
</v-container>
</template>
<script lang="ts">
import { defineComponent, reactive, toRefs, ref, useRouter } from "@nuxtjs/composition-api";
import { useApiSingleton } from "~/composables/use-api";
import { validators } from "~/composables/use-validators";
export default defineComponent({
setup() {
const state = reactive({
error: false,
loading: false,
});
const api = useApiSingleton();
const router = useRouter();
function handleResponse(response: any) {
if (response?.status !== 201) {
state.error = true;
state.loading = false;
return;
}
console.log(response);
router.push(`/recipe/${response.data}`);
}
// ===================================================
// Recipe URL Import
// @ts-ignore
const domUrlForm = ref<VForm>(null);
async function createByUrl(url: string) {
if (!domUrlForm.value.validate() || url === "") {
return;
}
state.loading = true;
const { response } = await api.recipes.createOneByUrl(url);
if (response?.status !== 201) {
state.error = true;
state.loading = false;
return;
}
handleResponse(response);
}
// ===================================================
// Recipe Create By Name
const newRecipeName = ref("");
// @ts-ignore
const domCreateByName = ref<VForm>(null);
async function createByName(name: string) {
if (!domCreateByName.value.validate() || name === "") {
return;
}
const { response } = await api.recipes.createOne({ name });
console.log("Create By Name Func", response);
handleResponse(response);
}
// ===================================================
// Recipe Import From Zip File
// @ts-ignore
const newRecipeZip = ref<File>(null);
const newRecipeZipFileName = "archive";
async function createByZip() {
if (!newRecipeZip.value) {
return;
}
const formData = new FormData();
formData.append(newRecipeZipFileName, newRecipeZip.value);
const { response } = await api.upload.file("/api/recipes/create-from-zip", formData);
console.log(response);
handleResponse(response);
}
return {
domCreateByName,
domUrlForm,
newRecipeName,
newRecipeZip,
createByName,
createByUrl,
createByZip,
...toRefs(state),
validators,
};
},
// Computed State is used because of the limitation of vue-composition-api in v2.0
computed: {
tab: {
set(tab) {
this.$router.replace({ query: { ...this.$route.query, tab } });
},
get() {
return this.$route.query.tab;
},
},
recipeUrl: {
set(recipe_import_url) {
this.$router.replace({ query: { ...this.$route.query, recipe_import_url } });
},
get() {
return this.$route.query.recipe_import_url;
},
},
},
});
</script>
<style>
.force-white > a {
color: white !important;
}
</style>

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 8.3 KiB