|
| 1 | +<!-- |
| 2 | +Description: |
| 3 | + Displays Mockup Image upload dropdown as well as minified mockup image once selected |
| 4 | + Functionality includes: importing and clearing mockup image |
| 5 | + --> |
| 6 | + |
| 7 | +<template> |
| 8 | + <div class="home-sidebar drawer-menu"> |
| 9 | + <q-list> |
| 10 | + <q-expansion-item expand-separator label="Upload Mockup Image"> |
| 11 | + <div class="upload"> |
| 12 | + <q-btn |
| 13 | + class="upload-btn" |
| 14 | + color="secondary" |
| 15 | + label="Upload Mockup" |
| 16 | + @click="importMockup" |
| 17 | + /> |
| 18 | + <q-btn |
| 19 | + v-if="source !== ''" |
| 20 | + class="upload-btn" |
| 21 | + color="secondary" |
| 22 | + label="Clear Image" |
| 23 | + @click="removeImage" |
| 24 | + /> |
| 25 | + <q-btn |
| 26 | + v-else |
| 27 | + disable |
| 28 | + class="upload-btn" |
| 29 | + color="secondary" |
| 30 | + label="Clear Image" |
| 31 | + /> |
| 32 | + </div> |
| 33 | + <div class="file-path"> |
| 34 | + <q-card> |
| 35 | + <img |
| 36 | + class="img" |
| 37 | + v-if="this.imagePath[this.activeRoute] !== ''" |
| 38 | + :src="'file:///' + this.imagePath[this.activeRoute]" |
| 39 | + /> |
| 40 | + </q-card> |
| 41 | + </div> |
| 42 | + </q-expansion-item> |
| 43 | + </q-list> |
| 44 | + </div> |
| 45 | +</template> |
| 46 | + |
| 47 | +<script> |
| 48 | +import { mapState, mapActions } from "vuex"; |
| 49 | +import uploadImage from "../../../utils/uploadImage.util"; |
| 50 | +import clearImageDialog from "../../../utils/clearImage.util"; |
| 51 | +
|
| 52 | +export default { |
| 53 | + name: "upload-image", |
| 54 | + data() { |
| 55 | + return { |
| 56 | + files: [], |
| 57 | + source: "", |
| 58 | + }; |
| 59 | + }, |
| 60 | + computed: { |
| 61 | + ...mapState(["imagePath", "activeRoute"]), |
| 62 | + }, |
| 63 | + methods: { |
| 64 | + ...mapActions(["importImage", "clearImage"]), |
| 65 | + // imports mockup image |
| 66 | + // ** Importing mockup image ONLY works in build mode due to path differences |
| 67 | + // In dev mode, error thrown is: "Not allowed to load local resource: PATH " |
| 68 | + importMockup() { |
| 69 | + // A promise gets returned out from uploadImage, imported from uploadImage utils |
| 70 | + const helperPromise = uploadImage(); |
| 71 | + helperPromise |
| 72 | + // res contains the selected file path (string) |
| 73 | + .then((res) => { |
| 74 | + if (this.activeRoute !== "") { |
| 75 | + this.importImage({ img: res, route: this.activeRoute }); |
| 76 | + if (this.imagePath[this.activeRoute]) { |
| 77 | + this.source = "file:///" + this.imagePath[this.activeRoute]; |
| 78 | + } |
| 79 | + } |
| 80 | + }) |
| 81 | + .catch((err) => console.log(err)); |
| 82 | + }, |
| 83 | + // removes mockup image |
| 84 | + removeImage() { |
| 85 | + const responsePromise = clearImageDialog(); |
| 86 | +
|
| 87 | + responsePromise |
| 88 | + .then((res) => { |
| 89 | + // res will have format: { response: 0, checkboxChecked: false } |
| 90 | + // res.response will be 0 if user chose 'Yes' |
| 91 | + // res.response will be 1 if user chose 'Cancel' |
| 92 | + if (res.response === 0) { |
| 93 | + this.clearImage({ route: this.activeRoute }); |
| 94 | + this.source = this.imagePath[this.activeRoute]; |
| 95 | + } |
| 96 | + }) |
| 97 | + .catch((err) => { |
| 98 | + console.log(err); |
| 99 | + }); |
| 100 | + }, |
| 101 | +
|
| 102 | + // imports image on browser |
| 103 | + // currently images aren't able to be stored on browser |
| 104 | + async importMockupBrowser() { |
| 105 | + this.files = this.$refs.myFiles.files[0]; |
| 106 | + await this.importImage(this.files.name); |
| 107 | + }, |
| 108 | + // removes image on browser |
| 109 | + removeImageBrowser() { |
| 110 | + this.clearImage(); |
| 111 | + }, |
| 112 | + }, |
| 113 | + // watches for changes in state to activeRoute |
| 114 | + watch: { |
| 115 | + // once you change your active route, the mockup image should change as well |
| 116 | + activeRoute: function () { |
| 117 | + if (this.imagePath[this.activeRoute]) { |
| 118 | + // if there is a uploaded image |
| 119 | + this.source = "file:///" + this.imagePath[this.activeRoute]; |
| 120 | + } else { |
| 121 | + this.source = ""; |
| 122 | + } |
| 123 | + }, |
| 124 | + }, |
| 125 | +}; |
| 126 | +</script> |
| 127 | + |
| 128 | +<style lang="scss"> |
| 129 | +.home-sidebar { |
| 130 | + margin: 1rem; |
| 131 | + justify-content: center; |
| 132 | + border-radius: 5px; |
| 133 | + padding: 0px; |
| 134 | + background: $subsecondary; |
| 135 | +} |
| 136 | +
|
| 137 | +.upload-btn { |
| 138 | + text-transform: capitalize; |
| 139 | + font-size: 12px; |
| 140 | +} |
| 141 | +
|
| 142 | +.upload { |
| 143 | + margin: 0.5rem; |
| 144 | + display: flex; |
| 145 | + justify-content: space-evenly; |
| 146 | +} |
| 147 | +
|
| 148 | +.file-path { |
| 149 | + padding-bottom: 1em; |
| 150 | + height: 100%; |
| 151 | + margin: 1rem; |
| 152 | + font-size: 11px; |
| 153 | +} |
| 154 | +
|
| 155 | +.file-header { |
| 156 | + padding-left: 0.4em; |
| 157 | +} |
| 158 | +
|
| 159 | +.file-content { |
| 160 | + padding: 0em 1em 1em 1em; |
| 161 | +} |
| 162 | +
|
| 163 | +.browser-btn { |
| 164 | + width: 90px; |
| 165 | + background: $secondary; |
| 166 | +} |
| 167 | +
|
| 168 | +.img { |
| 169 | + max-height: 200px; |
| 170 | +} |
| 171 | +</style> |
0 commit comments