2021-07-31 23:07:19 +00:00
|
|
|
<template>
|
|
|
|
<div v-if="value.length > 0 || edit">
|
|
|
|
<v-card class="mt-2">
|
|
|
|
<v-card-title class="py-2">
|
|
|
|
{{ $t("asset.assets") }}
|
|
|
|
</v-card-title>
|
|
|
|
<v-divider class="mx-2"></v-divider>
|
2021-08-02 03:24:47 +00:00
|
|
|
<v-list v-if="value.length > 0" :flat="!edit">
|
2021-07-31 23:07:19 +00:00
|
|
|
<v-list-item v-for="(item, i) in value" :key="i">
|
|
|
|
<v-list-item-icon class="ma-auto">
|
|
|
|
<v-tooltip bottom>
|
2021-08-02 03:24:47 +00:00
|
|
|
<template #activator="{ on, attrs }">
|
|
|
|
<v-icon v-bind="attrs" v-on="on" v-text="getIconDefinition(item.icon).icon"></v-icon>
|
2021-07-31 23:07:19 +00:00
|
|
|
</template>
|
|
|
|
<span>{{ getIconDefinition(item.icon).title }}</span>
|
|
|
|
</v-tooltip>
|
|
|
|
</v-list-item-icon>
|
|
|
|
<v-list-item-content>
|
|
|
|
<v-list-item-title class="pl-2" v-text="item.name"></v-list-item-title>
|
|
|
|
</v-list-item-content>
|
|
|
|
<v-list-item-action>
|
|
|
|
<v-btn v-if="!edit" color="primary" icon :href="assetURL(item.fileName)" target="_blank" top>
|
|
|
|
<v-icon> {{ $globals.icons.download }} </v-icon>
|
|
|
|
</v-btn>
|
|
|
|
<div v-else>
|
2021-08-02 03:24:47 +00:00
|
|
|
<v-btn color="error" icon top @click="deleteAsset(i)">
|
2021-07-31 23:07:19 +00:00
|
|
|
<v-icon>{{ $globals.icons.delete }}</v-icon>
|
|
|
|
</v-btn>
|
2021-08-03 06:15:11 +00:00
|
|
|
<AppCopyButton :copy-text="copyLink(item.fileName)" />
|
2021-07-31 23:07:19 +00:00
|
|
|
</div>
|
|
|
|
</v-list-item-action>
|
|
|
|
</v-list-item>
|
|
|
|
</v-list>
|
|
|
|
</v-card>
|
|
|
|
<div class="d-flex ml-auto mt-2">
|
|
|
|
<v-spacer></v-spacer>
|
2021-08-03 06:15:11 +00:00
|
|
|
<BaseDialog :title="$t('asset.new-asset')" :icon="getIconDefinition(newAsset.icon).icon" @submit="addAsset">
|
2021-08-02 03:24:47 +00:00
|
|
|
<template #open="{ open }">
|
|
|
|
<v-btn v-if="edit" color="secondary" dark @click="open">
|
2021-07-31 23:07:19 +00:00
|
|
|
<v-icon>{{ $globals.icons.create }}</v-icon>
|
|
|
|
</v-btn>
|
|
|
|
</template>
|
|
|
|
<v-card-text class="pt-2">
|
2021-08-02 03:24:47 +00:00
|
|
|
<v-text-field v-model="newAsset.name" dense :label="$t('general.name')"></v-text-field>
|
2021-07-31 23:07:19 +00:00
|
|
|
<div class="d-flex justify-space-between">
|
|
|
|
<v-select
|
2021-08-02 03:24:47 +00:00
|
|
|
v-model="newAsset.icon"
|
2021-07-31 23:07:19 +00:00
|
|
|
dense
|
|
|
|
:prepend-icon="getIconDefinition(newAsset.icon).icon"
|
|
|
|
:items="iconOptions"
|
|
|
|
item-text="title"
|
|
|
|
item-value="name"
|
|
|
|
class="mr-2"
|
|
|
|
>
|
2021-08-02 03:24:47 +00:00
|
|
|
<template #item="{ item }">
|
2021-07-31 23:07:19 +00:00
|
|
|
<v-list-item-avatar>
|
|
|
|
<v-icon class="mr-auto">
|
|
|
|
{{ item.icon }}
|
|
|
|
</v-icon>
|
|
|
|
</v-list-item-avatar>
|
|
|
|
{{ item.title }}
|
|
|
|
</template>
|
|
|
|
</v-select>
|
2021-08-03 06:15:11 +00:00
|
|
|
<AppButtonUpload :post="false" file-name="file" :text-btn="false" @uploaded="setFileObject" />
|
2021-07-31 23:07:19 +00:00
|
|
|
</div>
|
|
|
|
{{ fileObject.name }}
|
|
|
|
</v-card-text>
|
2021-08-02 03:24:47 +00:00
|
|
|
</BaseDialog>
|
2021-07-31 23:07:19 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2021-08-03 06:15:11 +00:00
|
|
|
import { useApiSingleton } from "~/composables/use-api";
|
2021-07-31 23:07:19 +00:00
|
|
|
export default {
|
|
|
|
props: {
|
2021-08-03 06:15:11 +00:00
|
|
|
slug: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
2021-07-31 23:07:19 +00:00
|
|
|
value: {
|
|
|
|
type: Array,
|
2021-08-03 06:15:11 +00:00
|
|
|
required: true,
|
2021-07-31 23:07:19 +00:00
|
|
|
},
|
|
|
|
edit: {
|
|
|
|
type: Boolean,
|
|
|
|
default: true,
|
|
|
|
},
|
|
|
|
},
|
2021-08-03 06:15:11 +00:00
|
|
|
setup() {
|
|
|
|
const api = useApiSingleton();
|
|
|
|
|
|
|
|
return { api };
|
|
|
|
},
|
2021-07-31 23:07:19 +00:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
fileObject: {},
|
|
|
|
newAsset: {
|
|
|
|
name: "",
|
|
|
|
icon: "mdi-file",
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
baseURL() {
|
|
|
|
return window.location.origin;
|
|
|
|
},
|
|
|
|
iconOptions() {
|
2021-08-03 06:15:11 +00:00
|
|
|
return [
|
|
|
|
{
|
2021-07-31 23:07:19 +00:00
|
|
|
name: "mdi-file",
|
2021-08-02 03:24:47 +00:00
|
|
|
title: this.$i18n.t("asset.file"),
|
2021-08-03 06:15:11 +00:00
|
|
|
icon: this.$globals.icons.file,
|
2021-07-31 23:07:19 +00:00
|
|
|
},
|
2021-08-03 06:15:11 +00:00
|
|
|
{
|
2021-07-31 23:07:19 +00:00
|
|
|
name: "mdi-file-pdf-box",
|
2021-08-02 03:24:47 +00:00
|
|
|
title: this.$i18n.t("asset.pdf"),
|
2021-08-03 06:15:11 +00:00
|
|
|
icon: this.$globals.icons.filePDF,
|
2021-07-31 23:07:19 +00:00
|
|
|
},
|
2021-08-03 06:15:11 +00:00
|
|
|
{
|
2021-07-31 23:07:19 +00:00
|
|
|
name: "mdi-file-image",
|
2021-08-02 03:24:47 +00:00
|
|
|
title: this.$i18n.t("asset.image"),
|
2021-08-03 06:15:11 +00:00
|
|
|
icon: this.$globals.icons.fileImage,
|
2021-07-31 23:07:19 +00:00
|
|
|
},
|
2021-08-03 06:15:11 +00:00
|
|
|
{
|
2021-07-31 23:07:19 +00:00
|
|
|
name: "mdi-code-json",
|
2021-08-02 03:24:47 +00:00
|
|
|
title: this.$i18n.t("asset.code"),
|
2021-08-03 06:15:11 +00:00
|
|
|
icon: this.$globals.icons.codeJson,
|
2021-07-31 23:07:19 +00:00
|
|
|
},
|
2021-08-03 06:15:11 +00:00
|
|
|
{
|
2021-07-31 23:07:19 +00:00
|
|
|
name: "mdi-silverware-fork-knife",
|
2021-08-02 03:24:47 +00:00
|
|
|
title: this.$i18n.t("asset.recipe"),
|
2021-08-03 06:15:11 +00:00
|
|
|
icon: this.$globals.icons.primary,
|
2021-07-31 23:07:19 +00:00
|
|
|
},
|
|
|
|
];
|
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
getIconDefinition(val) {
|
2021-08-03 06:15:11 +00:00
|
|
|
return this.iconOptions.find(({ name }) => name === val);
|
2021-07-31 23:07:19 +00:00
|
|
|
},
|
|
|
|
assetURL(assetName) {
|
|
|
|
return api.recipes.recipeAssetPath(this.slug, assetName);
|
|
|
|
},
|
|
|
|
setFileObject(obj) {
|
|
|
|
this.fileObject = obj;
|
|
|
|
},
|
|
|
|
async addAsset() {
|
|
|
|
const serverAsset = await api.recipes.createAsset(
|
|
|
|
this.slug,
|
|
|
|
this.fileObject,
|
|
|
|
this.newAsset.name,
|
|
|
|
this.newAsset.icon
|
|
|
|
);
|
|
|
|
this.value.push(serverAsset.data);
|
|
|
|
this.newAsset = { name: "", icon: "mdi-file" };
|
|
|
|
},
|
|
|
|
deleteAsset(index) {
|
|
|
|
this.value.splice(index, 1);
|
|
|
|
},
|
|
|
|
copyLink(fileName) {
|
|
|
|
const assetLink = api.recipes.recipeAssetPath(this.slug, fileName);
|
|
|
|
return `<img src="${this.baseURL}${assetLink}" height="100%" width="100%"> </img>`;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|