From ddf5c9356b9d459dededb826faa7a41f34605b72 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Thu, 22 Sep 2022 00:06:25 +0200 Subject: Create model --- assets/sass/main.sass | 3 ++ pages/create.vue | 128 ++++++++++++++++++++++++++++++++++++++++++++++++++ pages/models/_id.vue | 7 ++- store/models.js | 28 ++++++++++- 4 files changed, 164 insertions(+), 2 deletions(-) create mode 100644 pages/create.vue diff --git a/assets/sass/main.sass b/assets/sass/main.sass index fc8c6bf..04466c1 100644 --- a/assets/sass/main.sass +++ b/assets/sass/main.sass @@ -7,3 +7,6 @@ body @media (max-width: 768px) .w-90p max-width: 90% + +.border-1 + border-width: 1px diff --git a/pages/create.vue b/pages/create.vue new file mode 100644 index 0000000..dd59ffc --- /dev/null +++ b/pages/create.vue @@ -0,0 +1,128 @@ + + + diff --git a/pages/models/_id.vue b/pages/models/_id.vue index 48ff0eb..1017032 100644 --- a/pages/models/_id.vue +++ b/pages/models/_id.vue @@ -139,6 +139,11 @@ export default { boxFilesToDownload: false, }; }, + head() { + return { + title: this.model.name + " · Verden", + }; + }, components: { ModelStl, ModelObj, @@ -148,7 +153,7 @@ export default { this.id = this.$route.params.id; this.baseAPI = this.$config.api; - this.$store.dispatch("models/findModal", this.id).then((response) => { + this.$store.dispatch("models/findModel", this.id).then((response) => { if (response.status != 200) { window.location.href = "/models"; } else { diff --git a/store/models.js b/store/models.js index 23c612e..47f14b1 100644 --- a/store/models.js +++ b/store/models.js @@ -50,7 +50,7 @@ export const actions = { return res; }, // Find a model by its id - async findModal({ commit }, id) { + async findModel({ commit }, id) { commit("loadingStatus", true, { root: true }); let res = { status: 0, data: null }; let api = this.$config.api; @@ -70,6 +70,32 @@ export const actions = { commit("loadingStatus", false, { root: true }); + return res; + }, + // Create a new model + async createModel({ commit, rootGetters }, payload) { + commit("loadingStatus", true, { root: true }); + let res = { status: 0, data: null }; + let api = this.$config.api; + + await fetch(`${api}/v1/models`, { + method: "POST", + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${rootGetters["auth/accessToken"]}`, + }, + body: JSON.stringify(payload), + }) + .then(async (response) => { + res.data = await response.json(); + res.status = response.status; + }) + .catch((e) => { + res.status = e.status; + }); + + commit("loadingStatus", false, { root: true }); + return res; }, }; -- cgit v1.2.3-18-g5258