split code to components, add arrow functions

This commit is contained in:
Miloš Holba
2020-08-15 17:41:46 +02:00
parent 8387f56048
commit ba315014fa
11 changed files with 1768 additions and 1451 deletions
@@ -1,59 +1,20 @@
<template>
<div class="media-full-preview" @keydown.esc="closeFullPreview">
<div class="navigation-panel">
<div class="name-wrapper">
<div @click="closeFullPreview" class="icon-close">&#215;</div>
<div class="name">
<p>{{ formatedName }}</p>
<p class="file-count">
({{
this.currentIndex +
1 +
" " +
$t("pronouns.of") +
" " +
this.sliderFile.length
}})
</p>
</div>
<div class="fast-menu" @click="menuOpen()">
<p>...</p>
<DesktopMediaPreviewMenu :fileInfoDetail="this.fileInfoDetail" />
</div>
</div>
<div class="created_at-wrapper">
<p>{{ currentFile.filesize }}, {{ currentFile.created_at }}</p>
</div>
<div class="navigation-icons">
<ToolbarButton
source="download"
@click.native="downloadItem"
:action="$t('actions.download')"
/>
<ToolbarButton
source="share"
:class="{ 'is-inactive': canShareInView }"
:action="$t('actions.share')"
@click.native="shareItem"
/>
<ToolbarButton
v-if="this.fileInfoDetail.type === 'image'"
source="print"
:action="$t('actions.print')"
@click.native="printMethod()"
/>
</div>
</div>
<div class="file-wrapper-preview" v-for="i in [currentIndex]" :key="i">
<div class="file-wrapper">
<audio
class="file"
v-if="fileInfoDetail.type == 'audio'"
:src="fileInfoDetail.file_url"
controlsList="nodownload"
controls
></audio>
<img
v-if="fileInfoDetail.type === 'image' && currentFile.thumbnail"
class="file"
id="image"
:src="currentFile.thumbnail"
:src="currentFile.file_url"
:style="{ width: sizeWidth, height: sizeHeight }"
v-on:load="onLoaded"
v-show="loaded"
@@ -71,8 +32,6 @@
<spinner v-if="!loaded && fileInfoDetail.type === 'image'" />
</div>
</div>
<a class="prev" @click.prevent="prev" href="#">&#10094; </a>
<a class="next" @click.prevent="next" href="#">&#10095; </a>
</div>
</template>
@@ -80,11 +39,10 @@
import { events } from "@/bus";
import { mapGetters } from "vuex";
import ToolbarButton from "@/components/FilesView/ToolbarButton";
import DesktopMediaPreviewMenu from "@/components/FilesView/DesktopMediaPreviewMenu";
import Spinner from "@/components/FilesView/Spinner";
export default {
components: { ToolbarButton, DesktopMediaPreviewMenu, Spinner },
components: { ToolbarButton, Spinner },
data() {
return {
currentIndex: 1,
@@ -92,7 +50,6 @@ export default {
loaded: false,
sizeWidth: "",
sizeHeight: "",
showingFile: "",
};
},
computed: {
@@ -103,18 +60,6 @@ export default {
Math.abs(this.currentIndex) % this.sliderFile.length
];
},
formatedName() {
let name = this.currentFile.name;
if (name.lastIndexOf(".") > -1) {
return _.truncate(name.substring(0, name.lastIndexOf(".")), {
length: 20,
});
} else {
return _.truncate(name, {
length: 20,
});
}
},
canShareInView() {
return !this.$isThisLocation([
@@ -126,15 +71,32 @@ export default {
]);
},
},
mounted() {
events.$on("filePreviewAction:next", () => {
this.currentIndex += 1;
if (this.currentIndex > this.sliderFile.length - 1) {
this.currentIndex = 0;
}
});
events.$on("filePreviewAction:prev", () => {
this.currentIndex -= 1;
if (this.currentIndex < 0) {
this.currentIndex = this.sliderFile.length - 1;
}
});
},
created() {
this.filteredFiles();
this.imageSizing();
},
watch: {
currentFile() {
//HANDLE ACUTAL VIEW IMAGE IN FIELINFODETAIL
this.$store.commit("GET_FILEINFO_DETAIL", this.currentFile);
events.$emit("actualShowingImage:ContextMenu", this.currentFile);
},
fileInfoDetail() {
//FILE DELETE HANDLING
if (!this.fileInfoDetail) {
if (this.data.length == 0) {
events.$emit("fileFullPreview:hide");
@@ -143,11 +105,11 @@ export default {
this.$store.commit("GET_FILEINFO_DETAIL", this.currentFile);
this.sliderFile = [];
this.filteredFiles();
this.$forceUpdate();
}
}
},
data(newValue, oldValue) {
//MOVE ITEM HANDLING
if (newValue != oldValue) {
this.sliderFile = [];
this.filteredFiles();
@@ -164,23 +126,10 @@ export default {
this.sizeHeight = "100%";
}
},
menuOpen() {
if (this.$isMobile()) {
events.$emit("mobileMenu:show", "showFromMediaPreview");
} else {
events.$emit("desktopMediaMenu:show");
}
},
closeFullPreview() {
events.$emit("fileFullPreview:hide");
},
printMethod() {
var tab = document.getElementById("image");
var win = window.open("", "", "height=700,width=700");
win.document.write(tab.outerHTML);
win.document.close();
win.print();
},
filteredFiles() {
this.data.filter((element) => {
if (element.type == this.fileInfoDetail.type) {
@@ -199,40 +148,6 @@ export default {
}
});
},
downloadItem() {
// Download file
this.$downloadFile(
this.currentFile.file_url,
this.currentFile.name + "." + this.currentFile.mimetype
);
},
next: function () {
this.currentIndex += 1;
if (this.currentIndex > this.sliderFile.length - 1) {
this.currentIndex = 0;
}
},
prev: function () {
this.currentIndex -= 1;
if (this.currentIndex < 0) {
this.currentIndex = this.sliderFile.length - 1;
}
},
shareItem() {
if (this.fileInfoDetail.shared) {
events.$emit("popup:open", {
name: "share-edit",
item: this.currentFile,
});
} else {
events.$emit("popup:open", {
name: "share-create",
item: this.currentFile,
});
}
},
},
};
</script>
@@ -242,84 +157,10 @@ export default {
@import "@assets/vue-file-manager/_mixins";
.media-full-preview {
height: 100%;
height: 93%;
position: relative;
}
.name-wrapper {
width: 33%;
height: 100%;
display: flex;
align-items: center;
@include font-size(15);
font-weight: 700;
.name {
display: flex;
}
.icon-close {
@include font-size(15);
font-weight: 700;
display: flex;
align-items: center;
margin-right: 10px;
color: $text;
cursor: pointer;
}
.fast-menu {
cursor: pointer;
margin-left: 10px;
p {
margin-top: -10px;
}
p:hover {
color: $theme;
}
}
}
@media (min-width: 420px) and (max-width: 750px) {
.name-wrapper {
width: 67%;
}
}
@media (max-width: 430px) {
.name-wrapper {
width: 100%;
justify-content: space-between;
}
}
.created_at-wrapper {
width: 33%;
height: 100%;
display: flex;
text-align: center;
justify-content: center;
p {
display: flex;
align-items: center;
@include font-size(11);
}
@media (max-width: 750px) {
display: none;
}
}
.navigation-icons {
width: 33%;
height: 100%;
list-style: none;
display: flex;
align-items: center;
justify-content: flex-end;
& > * {
margin-left: 5px;
}
@media (max-width: 430px) {
display: none;
}
}
.navigation-panel {
width: 100%;
height: 7%;
@@ -340,7 +181,7 @@ export default {
.file-wrapper-preview {
width: 100%;
height: 93%;
height: 100%;
padding: 30px 0px;
display: flex;
overflow: hidden;
@@ -360,47 +201,8 @@ export default {
}
}
.prev,
.next {
cursor: pointer;
position: absolute;
top: 50%;
width: 40px;
height: 40;
display: flex;
justify-content: center;
background-color: white;
padding: 8px;
color: $text;
font-weight: bold;
font-size: 18px;
// border-radius: 0 4px 4px 0;
border-radius: 50%;
text-decoration: none;
user-select: none;
}
.next {
right: 0;
}
.prev {
left: 0;
}
.prev:hover,
.next:hover {
color: $theme;
}
@media (prefers-color-scheme: dark) {
.navigation-panel {
background-color: $dark_mode_foreground;
color: $light-text;
.icon-close {
color: $light-text;
}
}
.prev,
.next {
color: $light-text;
.file-wrapper-preview {
background-color: $dark_mode_background;
}
}