summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2022-09-19 21:02:33 +0200
committerSanto Cariotti <santo@dcariotti.me>2022-09-19 21:02:33 +0200
commit0a99b1d5da22b8fdec44d14b12377488091758f9 (patch)
treeb761e0e9927eabff2152ffadb53fef153cbfc1fd
parent6657722d68169ada3f36fff9455413f9cc6d6c53 (diff)
Model info page
-rw-r--r--assets/sass/_models.sass6
-rw-r--r--package-lock.json30
-rw-r--r--package.json1
-rw-r--r--pages/models/_id.vue86
-rw-r--r--pages/models/index.vue3
-rw-r--r--store/models.js23
6 files changed, 149 insertions, 0 deletions
diff --git a/assets/sass/_models.sass b/assets/sass/_models.sass
index e69de29..001a4ec 100644
--- a/assets/sass/_models.sass
+++ b/assets/sass/_models.sass
@@ -0,0 +1,6 @@
+#modelpage
+ .images
+ height: 30rem
+
+ .grid-mini
+ grid-template-rows: 7rem
diff --git a/package-lock.json b/package-lock.json
index bcf3768..d8c72d5 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -13,6 +13,7 @@
"pug": "^3.0.2",
"pug-plain-loader": "^1.1.0",
"vue": "^2.6.14",
+ "vue-3d-model": "^1.4.1",
"vue-server-renderer": "^2.6.14",
"vue-template-compiler": "^2.6.14",
"vue-toastification": "^1.7.14",
@@ -17713,6 +17714,11 @@
"url": "https://opencollective.com/webpack"
}
},
+ "node_modules/three": {
+ "version": "0.135.0",
+ "resolved": "https://registry.npmjs.org/three/-/three-0.135.0.tgz",
+ "integrity": "sha512-kuEpuuxRzLv0MDsXai9huCxOSQPZ4vje6y0gn80SRmQvgz6/+rI0NAvCRAw56zYaWKMGMfqKWsxF9Qa2Z9xymQ=="
+ },
"node_modules/through": {
"version": "2.3.8",
"resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz",
@@ -18487,6 +18493,17 @@
"csstype": "^3.1.0"
}
},
+ "node_modules/vue-3d-model": {
+ "version": "1.4.1",
+ "resolved": "https://registry.npmjs.org/vue-3d-model/-/vue-3d-model-1.4.1.tgz",
+ "integrity": "sha512-IQjpqEjK1OLF/0XgF6O++IvOPLinLQ2aWZQFHxPFoTfPlB4vQW2sgv8EJSqpsIYC/wSCdGlP3CEnv9L3aZHlow==",
+ "dependencies": {
+ "three": "^0.135.0"
+ },
+ "peerDependencies": {
+ "vue": ">=2.0.0"
+ }
+ },
"node_modules/vue-client-only": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/vue-client-only/-/vue-client-only-2.1.0.tgz",
@@ -33795,6 +33812,11 @@
}
}
},
+ "three": {
+ "version": "0.135.0",
+ "resolved": "https://registry.npmjs.org/three/-/three-0.135.0.tgz",
+ "integrity": "sha512-kuEpuuxRzLv0MDsXai9huCxOSQPZ4vje6y0gn80SRmQvgz6/+rI0NAvCRAw56zYaWKMGMfqKWsxF9Qa2Z9xymQ=="
+ },
"through": {
"version": "2.3.8",
"resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz",
@@ -34381,6 +34403,14 @@
"csstype": "^3.1.0"
}
},
+ "vue-3d-model": {
+ "version": "1.4.1",
+ "resolved": "https://registry.npmjs.org/vue-3d-model/-/vue-3d-model-1.4.1.tgz",
+ "integrity": "sha512-IQjpqEjK1OLF/0XgF6O++IvOPLinLQ2aWZQFHxPFoTfPlB4vQW2sgv8EJSqpsIYC/wSCdGlP3CEnv9L3aZHlow==",
+ "requires": {
+ "three": "^0.135.0"
+ }
+ },
"vue-client-only": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/vue-client-only/-/vue-client-only-2.1.0.tgz",
diff --git a/package.json b/package.json
index 01a1623..bd01bbf 100644
--- a/package.json
+++ b/package.json
@@ -16,6 +16,7 @@
"pug": "^3.0.2",
"pug-plain-loader": "^1.1.0",
"vue": "^2.6.14",
+ "vue-3d-model": "^1.4.1",
"vue-server-renderer": "^2.6.14",
"vue-template-compiler": "^2.6.14",
"vue-toastification": "^1.7.14",
diff --git a/pages/models/_id.vue b/pages/models/_id.vue
new file mode 100644
index 0000000..89abf3a
--- /dev/null
+++ b/pages/models/_id.vue
@@ -0,0 +1,86 @@
+<template lang="pug">
+ .mx-auto.max-w-7xl.py-6#modelpage(class="sm:px-6 lg:px-8")
+ .images.shadow-sm.rounded-lg.bg-white.p-4.w-full.w-full
+ .block.gap-4.h-full(class="md:flex")
+ .w-full(class="md:w-4/5")
+ .image.bg-gray-900.border-2.rounded-xl.w-full.h-full.overflow-hidden(v-if="model.uploads && model.uploads[selectedUpload]")
+ img.h-full.block.mx-auto(
+ v-if="isImage(model.uploads[selectedUpload].filepath)"
+ :src="baseAPI + '' + model.uploads[selectedUpload].filepath"
+ )
+ model-stl(
+ v-else
+ :rotate="rotate"
+ :src="baseAPI + '' + model.uploads[selectedUpload].filepath"
+ :backgroundColor="'#111827'"
+ )
+ .w-full.mt-8(class="md:w-1/5 md:mt-0" v-if="model")
+ .grid.grid-cols-3.gap-4.h-full.overflow-y-auto.grid-mini(class="md:grid-cols-2")
+ .border-2.border-gray-300.bg-gray-300.w-24.h-24.rounded-xl.grid.items-center.justify-items-center.overflow-hidden.cursor-pointer(
+ v-for="upload, i in model.uploads"
+ :key="upload.id"
+ :class="{'border-green-700 shadow-md': selectedUpload == i}"
+ @click="selectedUpload = i"
+ )
+ img(
+ v-if="isImage(upload.filepath)"
+ :src="baseAPI + '' + upload.filepath"
+ )
+ model-stl(
+ v-else
+ :rotate="rotate"
+ :src="baseAPI + '' + upload.filepath"
+ :backgroundColor="'#D1D5DB'"
+ :controlsOptions="{'enablePan': false, 'enableZoom': false, 'enableRotate': false}"
+ )
+</template>
+
+<script>
+import { ModelStl } from "vue-3d-model";
+
+export default {
+ name: "ModelView",
+ layout: "default",
+ data() {
+ return {
+ id: 0,
+ model: {},
+ selectedUpload: -1,
+ baseAPI: "",
+ rotate: {
+ x: -Math.PI / 2,
+ y: 0,
+ z: 0,
+ },
+ };
+ },
+ components: {
+ ModelStl,
+ },
+ created() {
+ this.id = this.$route.params.id;
+ this.baseAPI = this.$config.api;
+
+ this.$store.dispatch("models/findModal", this.id).then((response) => {
+ if (response.status != 200) {
+ window.location.href = "/models";
+ } else {
+ this.model = response.data;
+ if (this.model.uploads) {
+ this.selectedUpload = 0;
+ }
+ }
+ });
+ },
+ methods: {
+ isImage(path) {
+ return (
+ path.indexOf(".png") > 0 ||
+ path.indexOf(".jpg") > 0 ||
+ path.indexOf(".jpeg") > 0 ||
+ path.indexOf(".webp") > 0
+ );
+ },
+ },
+};
+</script>
diff --git a/pages/models/index.vue b/pages/models/index.vue
new file mode 100644
index 0000000..3b1b689
--- /dev/null
+++ b/pages/models/index.vue
@@ -0,0 +1,3 @@
+<template lang="pug">
+ div
+</template>
diff --git a/store/models.js b/store/models.js
index e2a0e30..23c612e 100644
--- a/store/models.js
+++ b/store/models.js
@@ -49,4 +49,27 @@ export const actions = {
return res;
},
+ // Find a model by its id
+ async findModal({ commit }, id) {
+ commit("loadingStatus", true, { root: true });
+ let res = { status: 0, data: null };
+ let api = this.$config.api;
+
+ await fetch(`${api}/v1/models/${id}`, {
+ headers: {
+ "Content-Type": "application/json",
+ },
+ })
+ .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;
+ },
};