use AuthenticatedImage component in Items view
This commit is contained in:
parent
21ec29caa8
commit
c5023202fc
3 changed files with 52 additions and 14 deletions
43
web/src/components/AuthenticatedImage.vue
Normal file
43
web/src/components/AuthenticatedImage.vue
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
<template>
|
||||||
|
<img :src="image_data" :alt="src">
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
|
||||||
|
import {mapActions} from "vuex";
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: "AuthenticatedImage",
|
||||||
|
props: {
|
||||||
|
src: {
|
||||||
|
type: String,
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
image_data: "",
|
||||||
|
servers: []
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
...mapActions(['fetchImage']),
|
||||||
|
loadImage() {
|
||||||
|
this.fetchImage(this.src).then((response) => {
|
||||||
|
const mime_type = response.headers.get("content-type");
|
||||||
|
response.arrayBuffer().then((buf) => {
|
||||||
|
const base64 = btoa(new Uint8Array(buf)
|
||||||
|
.reduce((data, byte) => data + String.fromCharCode(byte), ""));
|
||||||
|
this.image_data = "data:" + mime_type + ";base64," + base64;
|
||||||
|
});
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
mounted() {
|
||||||
|
this.loadImage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
|
@ -1,12 +1,12 @@
|
||||||
<template>
|
<template>
|
||||||
<Modal @close="$emit('close')">
|
<Modal @close="$emit('close')">
|
||||||
<template #body>
|
<template #body>
|
||||||
<img
|
<AuthenticatedImage
|
||||||
class="img-fluid rounded mx-auto d-block mb-3 w-100"
|
class="img-fluid rounded mx-auto d-block mb-3 w-100"
|
||||||
:src="`${baseUrl}/1/images/${file}`"
|
:src="`/media/2/${file}/`"
|
||||||
alt="Image not available."
|
alt="Image not available."
|
||||||
id="lightbox-image"
|
id="lightbox-image"
|
||||||
>
|
/>
|
||||||
</template>
|
</template>
|
||||||
<template #buttons>
|
<template #buttons>
|
||||||
<button type="button" class="btn btn-secondary" @click="$emit('close')">Cancel</button>
|
<button type="button" class="btn btn-secondary" @click="$emit('close')">Cancel</button>
|
||||||
|
@ -16,15 +16,11 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import Modal from '@/components/Modal';
|
import Modal from '@/components/Modal';
|
||||||
import config from '../config';
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'Lightbox',
|
name: 'Lightbox',
|
||||||
components: {Modal},
|
components: {Modal},
|
||||||
props: ['file'],
|
props: ['file']
|
||||||
data: () => ({
|
|
||||||
baseUrl: config.service.url,
|
|
||||||
}),
|
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
@ -44,10 +44,10 @@
|
||||||
v-slot="{ item }"
|
v-slot="{ item }"
|
||||||
@itemActivated="openLightboxModalWith($event)"
|
@itemActivated="openLightboxModalWith($event)"
|
||||||
>
|
>
|
||||||
<img
|
<AuthenticatedImage v-if="item.file"
|
||||||
:src="`${baseUrl}/1/thumbs/${item.file}`"
|
:src="`/media/2/256/${item.file}/`"
|
||||||
class="card-img-top img-fluid"
|
class="card-img-top img-fluid"
|
||||||
>
|
/>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<h6 class="card-title">{{ item.description }}</h6>
|
<h6 class="card-title">{{ item.description }}</h6>
|
||||||
<h6 class="card-subtitle text-secondary">uid: {{ item.uid }} box: {{ item.box }}</h6>
|
<h6 class="card-subtitle text-secondary">uid: {{ item.uid }} box: {{ item.box }}</h6>
|
||||||
|
@ -75,17 +75,16 @@ import Cards from '@/components/Cards';
|
||||||
import Modal from '@/components/Modal';
|
import Modal from '@/components/Modal';
|
||||||
import EditItem from '@/components/EditItem';
|
import EditItem from '@/components/EditItem';
|
||||||
import {mapActions, mapState} from 'vuex';
|
import {mapActions, mapState} from 'vuex';
|
||||||
import config from '../config';
|
|
||||||
import Lightbox from '../components/Lightbox';
|
import Lightbox from '../components/Lightbox';
|
||||||
|
import AuthenticatedImage from "@/components/AuthenticatedImage.vue";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'Items',
|
name: 'Items',
|
||||||
data: () => ({
|
data: () => ({
|
||||||
lightboxItem: null,
|
lightboxItem: null,
|
||||||
editingItem: null,
|
editingItem: null,
|
||||||
baseUrl: config.service.url,
|
|
||||||
}),
|
}),
|
||||||
components: {Lightbox, Table, Cards, Modal, EditItem},
|
components: {AuthenticatedImage, Lightbox, Table, Cards, Modal, EditItem},
|
||||||
computed: mapState(['loadedItems', 'layout']),
|
computed: mapState(['loadedItems', 'layout']),
|
||||||
methods: {
|
methods: {
|
||||||
...mapActions(['deleteItem', 'markItemReturned']),
|
...mapActions(['deleteItem', 'markItemReturned']),
|
||||||
|
|
Loading…
Reference in a new issue