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:
parent
35adc341e6
commit
3804e1d52c
8 changed files with 189 additions and 192 deletions
|
@ -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>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue