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