1
0
Fork 0
mirror of https://github.com/mealie-recipes/mealie.git synced 2025-07-20 21:59:40 +02:00

add print-view component (#407)

Co-authored-by: hay-kot <hay-kot@pm.me>
This commit is contained in:
Hayden 2021-05-14 21:10:03 -08:00 committed by GitHub
parent 35adc341e6
commit 3804e1d52c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 189 additions and 192 deletions

View file

@ -58,10 +58,10 @@ export default {
defaultMenu() {
return [
{
title: this.$t("general.download"),
icon: "mdi-download",
title: this.$t("general.print"),
icon: "mdi-printer",
color: "accent",
action: "download",
action: "print",
},
{
title: this.$t("general.link"),
@ -108,8 +108,8 @@ export default {
case "edit":
this.$router.push(`/recipe/${this.slug}` + "?edit=true");
break;
case "download":
await this.downloadJson();
case "print":
this.$router.push(`/recipe/${this.slug}` + "?print=true");
break;
default:
break;
@ -127,25 +127,6 @@ export default {
() => console.log("Copied Failed", copyText)
);
},
async downloadJson() {
const recipe = await api.recipes.requestDetails(this.slug);
this.downloadString(JSON.stringify(recipe, "", 4), "text/json", recipe.slug + ".json");
},
downloadString(text, fileType, fileName) {
let blob = new Blob([text], { type: fileType });
let a = document.createElement("a");
a.download = fileName;
a.href = URL.createObjectURL(blob);
a.dataset.downloadurl = [fileType, a.download, a.href].join(":");
a.style.display = "none";
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
setTimeout(function() {
URL.revokeObjectURL(a.href);
}, 1500);
},
},
};
</script>