From 0791dec1fca3e9a0eb41486a29767a67fdb6533b Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Mon, 17 Oct 2022 21:42:52 +0200 Subject: admin: edit models --- pages/admin/models.vue | 146 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 146 insertions(+) (limited to 'pages/admin') diff --git a/pages/admin/models.vue b/pages/admin/models.vue index 148e206..0804d74 100644 --- a/pages/admin/models.vue +++ b/pages/admin/models.vue @@ -1,6 +1,118 @@ @@ -51,6 +164,7 @@ import { mapGetters } from "vuex"; import AdminSidebar from "@/components/AdminSidebar.vue"; +import FilePreview from "@/components/FilePreview.vue"; import Pagination from "@/components/Pagination.vue"; import VTable from "@/components/VTable.vue"; @@ -67,10 +181,14 @@ export default { page: 0, pages: 0, boxDeleteModel: 0, + boxEditModel: 0, + form: {}, + openPreview: null, }; }, components: { AdminSidebar, + "file-preview": FilePreview, pagination: Pagination, "v-table": VTable, }, @@ -87,6 +205,34 @@ export default { }); }, methods: { + getFileName(path) { + return path.split("/").at(-1); + }, + saveModel(event) { + const f = this.form; + + if (f.name && f.duration && f.height && f.weight) { + this.$store.dispatch("models/editModel", this.form).then((response) => { + if (response.status == 200) { + this.$toast.success("Model has been saved"); + this.$store.dispatch("models/getModels", this.page).then(() => { + this.pages = Math.ceil(this.count / 20); + }); + } else { + this.$toast.error(response.data.error); + } + }); + } else { + this.$toast.error("Fill all the required fields"); + } + event.preventDefault(); + }, + openEditModal(id) { + this.$store.dispatch("models/findModel", id).then((response) => { + this.boxEditModel = id; + this.form = response.data; + }); + }, openModal(id) { this.boxDeleteModel = id; }, -- cgit v1.2.3-18-g5258