Skip to content

Commit

Permalink
sidebar: fix for albums and shares (fix #320)
Browse files Browse the repository at this point in the history
  • Loading branch information
pulsejet committed Mar 9, 2023
1 parent 8000616 commit 05e55e2
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 27 deletions.
18 changes: 10 additions & 8 deletions lib/Controller/ImageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,15 +193,17 @@ public function info(
// Get the image info
$info = $this->timelineQuery->getInfoById($file->getId(), $basic);

// Get list of tags for this file
if ($tags) {
$info['tags'] = $this->getTags($file->getId());
}
// Allow these ony for logged in users
if (null !== $this->userSession->getUser()) {
// Get list of tags for this file
if ($tags) {
$info['tags'] = $this->getTags($file->getId());
}

// Get latest exif data if requested
// Allow this ony for logged in users
if ($current && null !== $this->userSession->getUser()) {
$info['current'] = Exif::getExifFromFile($file);
// Get latest exif data if requested
if ($current) {
$info['current'] = Exif::getExifFromFile($file);
}
}

return new JSONResponse($info, Http::STATUS_OK);
Expand Down
9 changes: 7 additions & 2 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,11 @@ export default defineComponent({
// Register sidebar metadata tab
const OCA = globalThis.OCA;
if (OCA.Files && OCA.Files.Sidebar) {
const pf = (fileInfo) => {
fileInfo.fileid = Number(fileInfo.id);
return fileInfo;
};
OCA.Files.Sidebar.registerTab(
new OCA.Files.Sidebar.Tab({
id: "memories-metadata",
Expand All @@ -201,10 +206,10 @@ export default defineComponent({
this.metadataComponent?.$destroy?.();
this.metadataComponent = new Vue(Metadata as any);
this.metadataComponent.$mount(el);
this.metadataComponent.update(fileInfo);
this.metadataComponent.update(pf(fileInfo));
},
update(fileInfo) {
this.metadataComponent.update(fileInfo);
this.metadataComponent.update(pf(fileInfo));
},
destroy() {
this.metadataComponent?.$destroy?.();
Expand Down
2 changes: 1 addition & 1 deletion src/components/Metadata.vue
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ export default defineComponent({
this.exif = {};
const state = this.state;
const url = API.Q(API.IMAGE_INFO(fileInfo.id), "tags=1");
const url = API.Q(API.IMAGE_INFO(fileInfo.fileid), "tags=1");
const res = await axios.get<any>(url);
if (state !== this.state) return;
Expand Down
101 changes: 92 additions & 9 deletions src/components/Sidebar.vue
Original file line number Diff line number Diff line change
@@ -1,18 +1,46 @@
<template>
<aside class="app-sidebar" v-if="false"></aside>
<aside class="app-sidebar" v-if="reducedOpen">
<div class="title">
<h2>{{ filename }}</h2>

<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>
</template>

<script lang="ts">
import { defineComponent } from "vue";
import { subscribe, unsubscribe, emit } from "@nextcloud/event-bus";
import NcActions from "@nextcloud/vue/dist/Components/NcActions";
import NcActionButton from "@nextcloud/vue/dist/Components/NcActionButton";
import Metadata from "./Metadata.vue";
import { IFileInfo } from "../types";
import CloseIcon from "vue-material-design-icons/Close.vue";
export default defineComponent({
name: "Sidebar",
components: {},
components: {
Metadata,
NcActions,
NcActionButton,
CloseIcon,
},
data: () => {
return {
nativeOpen: false,
reducedOpen: false,
filename: "",
};
},
Expand All @@ -33,17 +61,42 @@ export default defineComponent({
},
methods: {
open(filename: string) {
globalThis.OCA.Files.Sidebar.setFullScreenMode?.(true);
globalThis.OCA.Files.Sidebar.open(filename);
async open(file: IFileInfo) {
if (
!this.reducedOpen &&
this.native() &&
(!file.fileid || file.originalFilename?.startsWith("/files/"))
) {
this.native()?.setFullScreenMode?.(true);
this.native()?.open(file.filename);
} else {
this.reducedOpen = true;
await this.$nextTick();
this.filename = file.basename;
(<any>this.$refs.metadata)?.update(file);
emit("memories:sidebar:opened", null);
}
},
close() {
globalThis.OCA.Files.Sidebar.close();
async close() {
if (this.nativeOpen) {
this.native()?.close();
} else {
if (this.reducedOpen) {
this.reducedOpen = false;
await this.$nextTick();
}
emit("memories:sidebar:closed", null);
}
},
setTab(tab: string) {
globalThis.OCA.Files.Sidebar.setActiveTab(tab);
this.native()?.setActiveTab(tab);
},
native() {
return globalThis.OCA?.Files?.Sidebar;
},
handleNativeOpen(event: any) {
Expand All @@ -62,14 +115,44 @@ export default defineComponent({
<style scoped lang="scss">
aside.app-sidebar {
position: fixed;
top: 0;
right: 0;
z-index: 100000000;
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;
}
}
}
</style>

<style lang="scss">
// Prevent sidebar from becoming too big
aside.app-sidebar {
max-width: 360px !important;
@media (max-width: 512px) {
max-width: unset !important;
}
}
</style>
4 changes: 3 additions & 1 deletion src/components/modal/Modal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ export default defineComponent({
mounted() {
if (this.sidebar) {
globalThis.mSidebar.open(this.sidebar);
globalThis.mSidebar.open({
filename: this.sidebar,
} as any);
}
},
Expand Down
10 changes: 6 additions & 4 deletions src/components/viewer/Viewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
</template>
</NcActionButton>
<NcActionButton
v-if="!routeIsPublic"
:aria-label="t('memories', 'Sidebar')"
@click="toggleSidebar"
:close-after-click="true"
Expand Down Expand Up @@ -170,7 +169,7 @@
<script lang="ts">
import { defineComponent } from "vue";
import { IDay, IPhoto, IRow, IRowType } from "../../types";
import { IDay, IFileInfo, IPhoto, IRow, IRowType } from "../../types";
import NcActions from "@nextcloud/vue/dist/Components/NcActions";
import NcActionButton from "@nextcloud/vue/dist/Components/NcActionButton";
Expand Down Expand Up @@ -1016,9 +1015,12 @@ export default defineComponent({

/** Open the sidebar */
async openSidebar(photo?: IPhoto) {
const fInfo = await dav.getFiles([photo || this.currentPhoto]);
let fInfo: IFileInfo | IPhoto = photo || this.currentPhoto;
if (!this.routeIsPublic) {
fInfo = (await dav.getFiles([fInfo]))[0];
}
globalThis.mSidebar.setTab("memories-metadata");
globalThis.mSidebar.open(fInfo[0].filename);
globalThis.mSidebar.open(fInfo as IFileInfo);
},

async updateSizeWithoutAnim() {
Expand Down
4 changes: 2 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import router from "./router";
import { Route } from "vue-router";
import { generateFilePath } from "@nextcloud/router";
import { getRequestToken } from "@nextcloud/auth";
import { IPhoto } from "./types";
import { IFileInfo, IPhoto } from "./types";

import "./global.scss";

Expand All @@ -25,7 +25,7 @@ declare global {
var editMetadata: (photos: IPhoto[], sections?: number[]) => void;

var mSidebar: {
open: (filename: string) => void;
open: (filename: IFileInfo) => void;
close: () => void;
setTab: (tab: string) => void;
};
Expand Down

0 comments on commit 05e55e2

Please sign in to comment.