2023-03-09 21:47:14 +00:00
|
|
|
<template>
|
2023-03-18 19:45:52 +00:00
|
|
|
<aside id="app-sidebar-vue" class="app-sidebar" v-if="reducedOpen">
|
2023-03-09 22:48:18 +00:00
|
|
|
<div class="title">
|
2023-03-10 00:39:26 +00:00
|
|
|
<h2>{{ basename }}</h2>
|
2023-03-09 22:48:18 +00:00
|
|
|
|
|
|
|
<NcActions :inline="1">
|
|
|
|
<NcActionButton :aria-label="t('memories', 'Close')" @click="close()">
|
|
|
|
{{ t("memories", "Close") }}
|
|
|
|
<template #icon> <CloseIcon :size="20" /> </template>
|
|
|
|
</NcActionButton>
|
|
|
|
</NcActions>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<Metadata ref="metadata" />
|
|
|
|
</aside>
|
2023-03-09 21:47:14 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import { defineComponent } from "vue";
|
|
|
|
import { subscribe, unsubscribe, emit } from "@nextcloud/event-bus";
|
|
|
|
|
2023-03-09 22:48:18 +00:00
|
|
|
import NcActions from "@nextcloud/vue/dist/Components/NcActions";
|
|
|
|
import NcActionButton from "@nextcloud/vue/dist/Components/NcActionButton";
|
|
|
|
|
|
|
|
import Metadata from "./Metadata.vue";
|
2023-03-16 16:58:43 +00:00
|
|
|
import { IImageInfo } from "../types";
|
2023-03-09 22:48:18 +00:00
|
|
|
|
|
|
|
import CloseIcon from "vue-material-design-icons/Close.vue";
|
|
|
|
|
2023-03-09 21:47:14 +00:00
|
|
|
export default defineComponent({
|
|
|
|
name: "Sidebar",
|
2023-03-09 22:48:18 +00:00
|
|
|
components: {
|
|
|
|
Metadata,
|
|
|
|
NcActions,
|
|
|
|
NcActionButton,
|
|
|
|
CloseIcon,
|
|
|
|
},
|
2023-03-09 21:47:14 +00:00
|
|
|
|
|
|
|
data: () => {
|
|
|
|
return {
|
|
|
|
nativeOpen: false,
|
2023-03-09 22:48:18 +00:00
|
|
|
reducedOpen: false,
|
2023-03-10 00:39:26 +00:00
|
|
|
basename: "",
|
2023-03-18 19:30:14 +00:00
|
|
|
lastKnownWidth: 0,
|
2023-03-09 21:47:14 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2023-03-18 18:19:36 +00:00
|
|
|
computed: {
|
|
|
|
native() {
|
|
|
|
return globalThis.OCA?.Files?.Sidebar;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2023-03-09 21:47:14 +00:00
|
|
|
mounted() {
|
|
|
|
subscribe("files:sidebar:opened", this.handleNativeOpen);
|
|
|
|
subscribe("files:sidebar:closed", this.handleNativeClose);
|
|
|
|
|
|
|
|
globalThis.mSidebar = {
|
|
|
|
open: this.open.bind(this),
|
|
|
|
close: this.close.bind(this),
|
|
|
|
setTab: this.setTab.bind(this),
|
2023-03-18 19:30:14 +00:00
|
|
|
getWidth: this.getWidth.bind(this),
|
2023-03-09 21:47:14 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
beforeDestroy() {
|
|
|
|
unsubscribe("files:sidebar:opened", this.handleNativeOpen);
|
|
|
|
unsubscribe("files:sidebar:closed", this.handleNativeClose);
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
2023-03-16 16:58:43 +00:00
|
|
|
async open(fileid: number, filename?: string, forceNative = false) {
|
2023-03-18 18:19:36 +00:00
|
|
|
if (!this.reducedOpen && this.native && (!fileid || forceNative)) {
|
2023-03-18 18:39:11 +00:00
|
|
|
// Open native sidebar
|
2023-03-18 18:19:36 +00:00
|
|
|
this.native?.setFullScreenMode?.(true);
|
|
|
|
this.native?.open(filename);
|
2023-03-09 22:48:18 +00:00
|
|
|
} else {
|
2023-03-18 18:39:11 +00:00
|
|
|
// Open reduced sidebar
|
2023-03-09 22:48:18 +00:00
|
|
|
this.reducedOpen = true;
|
|
|
|
await this.$nextTick();
|
2023-03-18 18:39:11 +00:00
|
|
|
|
|
|
|
// Update metadata compoenent
|
|
|
|
const m = <any>this.$refs.metadata;
|
|
|
|
const info: IImageInfo = await m?.update(fileid);
|
2023-03-16 16:58:43 +00:00
|
|
|
this.basename = info.basename;
|
2023-03-18 18:39:11 +00:00
|
|
|
this.handleOpen();
|
2023-03-09 22:48:18 +00:00
|
|
|
}
|
2023-03-09 21:47:14 +00:00
|
|
|
},
|
|
|
|
|
2023-03-09 22:48:18 +00:00
|
|
|
async close() {
|
|
|
|
if (this.nativeOpen) {
|
2023-03-18 18:19:36 +00:00
|
|
|
this.native?.close();
|
2023-03-09 22:48:18 +00:00
|
|
|
} else {
|
|
|
|
if (this.reducedOpen) {
|
|
|
|
this.reducedOpen = false;
|
|
|
|
await this.$nextTick();
|
|
|
|
}
|
2023-03-18 18:39:11 +00:00
|
|
|
this.handleClose();
|
2023-03-09 22:48:18 +00:00
|
|
|
}
|
2023-03-09 21:47:14 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
setTab(tab: string) {
|
2023-03-18 18:19:36 +00:00
|
|
|
this.native?.setActiveTab(tab);
|
2023-03-09 21:47:14 +00:00
|
|
|
},
|
|
|
|
|
2023-03-18 19:30:14 +00:00
|
|
|
getWidth() {
|
2023-03-18 19:45:52 +00:00
|
|
|
const sidebar = document.getElementById("app-sidebar-vue");
|
2023-03-18 19:30:14 +00:00
|
|
|
this.lastKnownWidth = sidebar?.offsetWidth || this.lastKnownWidth;
|
|
|
|
return (this.lastKnownWidth || 2) - 2;
|
|
|
|
},
|
|
|
|
|
2023-03-18 18:39:11 +00:00
|
|
|
handleClose() {
|
|
|
|
emit("memories:sidebar:closed", null);
|
|
|
|
},
|
|
|
|
|
|
|
|
handleOpen() {
|
2023-03-18 19:30:14 +00:00
|
|
|
// Stop sidebar typing from leaking outside
|
2023-03-18 19:45:52 +00:00
|
|
|
const sidebar = document.getElementById("app-sidebar-vue");
|
2023-03-18 19:30:14 +00:00
|
|
|
sidebar?.addEventListener("keydown", (e) => {
|
|
|
|
if (e.key.length === 1) e.stopPropagation();
|
|
|
|
});
|
2023-03-18 18:39:11 +00:00
|
|
|
|
|
|
|
emit("memories:sidebar:opened", null);
|
|
|
|
},
|
|
|
|
|
|
|
|
handleNativeOpen() {
|
2023-03-09 21:47:14 +00:00
|
|
|
this.nativeOpen = true;
|
2023-03-18 18:39:11 +00:00
|
|
|
this.handleOpen();
|
2023-03-09 21:47:14 +00:00
|
|
|
},
|
|
|
|
|
2023-03-18 18:39:11 +00:00
|
|
|
handleNativeClose() {
|
2023-03-09 21:47:14 +00:00
|
|
|
this.nativeOpen = false;
|
2023-03-18 18:19:36 +00:00
|
|
|
this.native?.setFullScreenMode?.(false);
|
2023-03-18 18:39:11 +00:00
|
|
|
this.handleClose();
|
2023-03-09 21:47:14 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped lang="scss">
|
2023-03-18 19:45:52 +00:00
|
|
|
#app-sidebar-vue {
|
2023-03-09 21:47:14 +00:00
|
|
|
position: fixed;
|
2023-03-09 22:48:18 +00:00
|
|
|
top: 0;
|
2023-03-09 21:47:14 +00:00
|
|
|
right: 0;
|
2023-03-09 22:48:18 +00:00
|
|
|
width: 27vw;
|
|
|
|
min-width: 300px;
|
|
|
|
height: 100% !important;
|
|
|
|
z-index: 2525;
|
|
|
|
padding: 10px;
|
|
|
|
background-color: var(--color-main-background);
|
|
|
|
border-left: 1px solid var(--color-border);
|
|
|
|
|
|
|
|
@media (max-width: 512px) {
|
|
|
|
width: 100vw;
|
|
|
|
min-width: unset;
|
|
|
|
}
|
|
|
|
|
|
|
|
.title {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: space-between;
|
|
|
|
padding: 10px;
|
|
|
|
|
|
|
|
h2 {
|
|
|
|
overflow: hidden;
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
white-space: nowrap;
|
|
|
|
margin: 0;
|
|
|
|
}
|
|
|
|
}
|
2023-03-09 21:47:14 +00:00
|
|
|
}
|
|
|
|
</style>
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
// Prevent sidebar from becoming too big
|
2023-03-18 19:45:52 +00:00
|
|
|
#app-sidebar-vue {
|
2023-03-09 21:47:14 +00:00
|
|
|
max-width: 360px !important;
|
2023-03-10 20:45:04 +00:00
|
|
|
position: fixed !important;
|
2023-03-09 22:48:18 +00:00
|
|
|
|
|
|
|
@media (max-width: 512px) {
|
|
|
|
max-width: unset !important;
|
|
|
|
}
|
2023-03-09 21:47:14 +00:00
|
|
|
}
|
2023-03-14 22:01:12 +00:00
|
|
|
|
|
|
|
// Hack to put the floating dropdown menu above the
|
|
|
|
// sidebar ... this may have unintended side effects
|
|
|
|
.vs__dropdown-menu--floating {
|
|
|
|
z-index: 2526;
|
|
|
|
}
|
2023-03-09 21:47:14 +00:00
|
|
|
</style>
|