View assets detail and download operation (#198)

* Fixed not displaying default user profile picture

* Added buttons to close viewer and micro-interaction for navigating assets left, right

* Add additional buttons to the control bar

* Display EXIF info

* Added map to detail info

* Handle user input keyboard

* Fixed incorrect file name when downloading multiple files

* Implemented download panel
This commit is contained in:
Alex 2022-06-03 11:04:30 -05:00 committed by GitHub
parent 6924aa5eb1
commit 53c3c916a6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 798 additions and 100 deletions

View file

@ -0,0 +1,22 @@
<script lang="ts">
import { createEventDispatcher } from 'svelte';
import ArrowLeft from 'svelte-material-icons/ArrowLeft.svelte';
import DotsVertical from 'svelte-material-icons/DotsVertical.svelte';
import CloudDownloadOutline from 'svelte-material-icons/CloudDownloadOutline.svelte';
import TrashCanOutline from 'svelte-material-icons/TrashCanOutline.svelte';
import InformationOutline from 'svelte-material-icons/InformationOutline.svelte';
import CircleIconButton from '../shared/circle_icon_button.svelte';
const dispatch = createEventDispatcher();
</script>
<div class="h-16 bg-black/5 flex justify-between place-items-center px-3 transition-transform duration-200 z-[9999]">
<div>
<CircleIconButton logo={ArrowLeft} on:click={() => dispatch('goBack')} />
</div>
<div class="text-white flex gap-2">
<CircleIconButton logo={CloudDownloadOutline} on:click={() => dispatch('download')} />
<!-- <CircleIconButton logo={DotsVertical} on:click={() => console.log('Options')} /> -->
<CircleIconButton logo={InformationOutline} on:click={() => dispatch('showDetail')} />
</div>
</div>

View file

@ -0,0 +1,234 @@
<script lang="ts">
import { createEventDispatcher, onDestroy, onMount } from 'svelte';
import { fly, slide } from 'svelte/transition';
import AsserViewerNavBar from './asser-viewer-nav-bar.svelte';
import { flattenAssetGroupByDate } from '$lib/stores/assets';
import ChevronRight from 'svelte-material-icons/ChevronRight.svelte';
import ChevronLeft from 'svelte-material-icons/ChevronLeft.svelte';
import { AssetType, type ImmichAsset, type ImmichExif } from '../../models/immich-asset';
import PhotoViewer from './photo-viewer.svelte';
import DetailPanel from './detail-panel.svelte';
import { session } from '$app/stores';
import { serverEndpoint } from '../../constants';
import axios from 'axios';
import { downloadAssets } from '$lib/stores/download';
const dispatch = createEventDispatcher();
export let selectedAsset: ImmichAsset;
export let selectedIndex: number;
let viewDeviceId: string;
let viewAssetId: string;
let halfLeftHover = false;
let halfRightHover = false;
let isShowDetail = false;
onMount(() => {
viewAssetId = selectedAsset.id;
viewDeviceId = selectedAsset.deviceId;
pushState(viewAssetId);
document.addEventListener('keydown', (keyInfo) => handleKeyboardPress(keyInfo.key));
});
onDestroy(() => {
document.removeEventListener('keydown', (b) => {
console.log('destroyed', b);
});
});
const handleKeyboardPress = (key: string) => {
switch (key) {
case 'Escape':
closeViewer();
return;
case 'i':
isShowDetail = !isShowDetail;
return;
case 'ArrowLeft':
navigateAssetBackward();
return;
case 'ArrowRight':
navigateAssetForward();
return;
}
};
const closeViewer = () => {
history.pushState(null, '', `/photos`);
dispatch('close');
};
const navigateAssetForward = () => {
const nextAsset = $flattenAssetGroupByDate[selectedIndex + 1];
viewDeviceId = nextAsset.deviceId;
viewAssetId = nextAsset.id;
selectedIndex = selectedIndex + 1;
selectedAsset = $flattenAssetGroupByDate[selectedIndex];
pushState(viewAssetId);
};
const navigateAssetBackward = () => {
const lastAsset = $flattenAssetGroupByDate[selectedIndex - 1];
viewDeviceId = lastAsset.deviceId;
viewAssetId = lastAsset.id;
selectedIndex = selectedIndex - 1;
selectedAsset = $flattenAssetGroupByDate[selectedIndex];
pushState(viewAssetId);
};
const pushState = (assetId: string) => {
// add a URL to the browser's history
// changes the current URL in the address bar but doesn't perform any SvelteKit navigation
history.pushState(null, '', `/photos/${assetId}`);
};
const showDetailInfoHandler = () => {
isShowDetail = !isShowDetail;
};
const downloadFile = async () => {
if ($session.user) {
const url = `${serverEndpoint}/asset/download?aid=${selectedAsset.deviceAssetId}&did=${selectedAsset.deviceId}&isThumb=false`;
try {
const imageName = selectedAsset.exifInfo?.imageName ? selectedAsset.exifInfo?.imageName : selectedAsset.id;
const imageExtension = selectedAsset.originalPath.split('.')[1];
const imageFileName = imageName + '.' + imageExtension;
// If assets is already download -> return;
if ($downloadAssets[imageFileName]) {
return;
}
$downloadAssets[imageFileName] = 0;
const res = await axios.get(url, {
responseType: 'blob',
headers: {
Authorization: 'Bearer ' + $session.user.accessToken,
},
onDownloadProgress: (progressEvent) => {
if (progressEvent.lengthComputable) {
const total = progressEvent.total;
const current = progressEvent.loaded;
let percentCompleted = Math.floor((current / total) * 100);
$downloadAssets[imageFileName] = percentCompleted;
}
},
});
if (res.status === 200) {
const fileUrl = URL.createObjectURL(new Blob([res.data]));
const anchor = document.createElement('a');
anchor.href = fileUrl;
anchor.download = imageFileName;
document.body.appendChild(anchor);
anchor.click();
document.body.removeChild(anchor);
URL.revokeObjectURL(fileUrl);
// Remove item from download list
setTimeout(() => {
const copy = $downloadAssets;
delete copy[imageFileName];
$downloadAssets = copy;
}, 2000);
}
} catch (e) {
console.log('Error downloading file ', e);
}
}
};
</script>
<section
id="immich-asset-viewer"
class="absolute h-screen w-screen top-0 overflow-y-hidden bg-black z-[999] grid grid-rows-[64px_1fr] grid-cols-4 "
>
<div class="col-start-1 col-span-4 row-start-1 row-span-1 z-[1000] transition-transform">
<AsserViewerNavBar on:goBack={closeViewer} on:showDetail={showDetailInfoHandler} on:download={downloadFile} />
</div>
<div
class="row-start-2 row-span-end col-start-1- col-span-full z-[1000] flex place-items-center hover:cursor-pointer w-3/4"
on:mouseenter={() => {
halfLeftHover = true;
halfRightHover = false;
}}
on:mouseleave={() => {
halfLeftHover = false;
}}
on:click={navigateAssetBackward}
>
<button
class="rounded-full p-3 hover:bg-gray-500 hover:text-gray-700 text-gray-500 mx-4"
class:navigation-button-hover={halfLeftHover}
on:click={navigateAssetBackward}
>
<ChevronLeft size="36" />
</button>
</div>
<div class="row-start-1 row-span-full col-start-1 col-span-4">
{#key selectedIndex}
{#if viewAssetId && viewDeviceId}
{#if selectedAsset.type == AssetType.IMAGE}
<PhotoViewer assetId={viewAssetId} deviceId={viewDeviceId} on:close={closeViewer} />
{:else}
<div
class="w-full h-full bg-immich-primary/10 flex flex-col place-items-center place-content-center "
on:click={closeViewer}
>
<h1 class="animate-pulse font-bold text-4xl">Video viewer is under construction</h1>
</div>
{/if}
{/if}
{/key}
</div>
<div
class="row-start-2 row-span-full col-start-3 col-span-2 z-[1000] flex justify-end place-items-center hover:cursor-pointer w-3/4 justify-self-end"
on:click={navigateAssetForward}
on:mouseenter={() => {
halfLeftHover = false;
halfRightHover = true;
}}
on:mouseleave={() => {
halfRightHover = false;
}}
>
<button
class="rounded-full p-3 hover:bg-gray-500 hover:text-gray-700 text-gray-500 mx-4"
class:navigation-button-hover={halfRightHover}
on:click={navigateAssetForward}
>
<ChevronRight size="36" />
</button>
</div>
{#if isShowDetail}
<div
transition:fly={{ duration: 150 }}
id="detail-panel"
class="bg-immich-bg w-[360px] row-span-full transition-all "
translate="yes"
>
<DetailPanel asset={selectedAsset} on:close={() => (isShowDetail = false)} />
</div>
{/if}
</section>
<style>
.navigation-button-hover {
background-color: rgb(107 114 128 / var(--tw-bg-opacity));
color: rgb(55 65 81 / var(--tw-text-opacity));
transition: all 150ms;
}
</style>

View file

@ -0,0 +1,164 @@
<script lang="ts">
import Close from 'svelte-material-icons/Close.svelte';
import Calendar from 'svelte-material-icons/Calendar.svelte';
import ImageOutline from 'svelte-material-icons/ImageOutline.svelte';
import CameraIris from 'svelte-material-icons/CameraIris.svelte';
import MapMarkerOutline from 'svelte-material-icons/MapMarkerOutline.svelte';
import moment from 'moment';
import type { ImmichAsset } from '../../models/immich-asset';
import { createEventDispatcher, onMount } from 'svelte';
import { browser } from '$app/env';
// Map Property
let map: any;
let leaflet: any;
let marker: any;
export let asset: ImmichAsset;
$: {
// Redraw map
if (map && leaflet) {
map.removeLayer(marker);
map.setView([asset.exifInfo?.latitude || 0, asset.exifInfo?.longitude || 0], 17);
marker = leaflet.marker([asset.exifInfo?.latitude || 0, asset.exifInfo?.longitude || 0]);
map.addLayer(marker);
}
}
onMount(async () => {
if (browser) {
// @ts-ignore
leaflet = await import('leaflet');
map = leaflet.map('map').setView([asset.exifInfo?.latitude || 0, asset.exifInfo?.longitude || 0], 17);
leaflet
.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a>',
})
.addTo(map);
marker = leaflet.marker([asset.exifInfo?.latitude || 0, asset.exifInfo?.longitude || 0]);
map.addLayer(marker);
}
});
const dispatch = createEventDispatcher();
const getHumanReadableString = (sizeInByte: number) => {
const pepibyte = 1.126 * Math.pow(10, 15);
const tebibyte = 1.1 * Math.pow(10, 12);
const gibibyte = 1.074 * Math.pow(10, 9);
const mebibyte = 1.049 * Math.pow(10, 6);
const kibibyte = 1024;
// Pebibyte
if (sizeInByte >= pepibyte) {
// Pe
return `${(sizeInByte / pepibyte).toFixed(1)}PB`;
} else if (tebibyte <= sizeInByte && sizeInByte < pepibyte) {
// Te
return `${(sizeInByte / tebibyte).toFixed(1)}TB`;
} else if (gibibyte <= sizeInByte && sizeInByte < tebibyte) {
// Gi
return `${(sizeInByte / gibibyte).toFixed(1)}GB`;
} else if (mebibyte <= sizeInByte && sizeInByte < gibibyte) {
// Mega
return `${(sizeInByte / mebibyte).toFixed(1)}MB`;
} else if (kibibyte <= sizeInByte && sizeInByte < mebibyte) {
// Kibi
return `${(sizeInByte / kibibyte).toFixed(1)}KB`;
} else {
return `${sizeInByte}B`;
}
};
</script>
<section class="p-2">
<div class="flex place-items-center gap-2">
<button
class="rounded-full p-3 flex place-items-center place-content-center hover:bg-gray-200 transition-colors"
on:click={() => dispatch('close')}
>
<Close size="24" color="#232323" />
</button>
<p class="text-black text-lg">Info</p>
</div>
<div class="px-4 py-4">
<p class="text-sm pb-4">DETAILS</p>
{#if asset.exifInfo?.dateTimeOriginal}
<div class="flex gap-4 py-4">
<div>
<Calendar size="24" />
</div>
<div>
<p>{moment(asset.exifInfo.dateTimeOriginal).format('MMM DD')}</p>
<div class="flex gap-2 text-sm">
<p>
{moment(
asset.exifInfo.dateTimeOriginal
.toString()
.slice(0, asset.exifInfo.dateTimeOriginal.toString().length - 1),
).format('ddd, hh:mm A')}
</p>
<p>GMT{moment(asset.exifInfo.dateTimeOriginal).format('Z')}</p>
</div>
</div>
</div>{/if}
{#if asset.exifInfo?.fileSizeInByte}
<div class="flex gap-4 py-4">
<div><ImageOutline size="24" /></div>
<div>
<p>{`${asset.exifInfo.imageName}.${asset.originalPath.split('.')[1]}` || ''}</p>
<div class="flex text-sm gap-2">
<p>{((asset.exifInfo.exifImageHeight * asset.exifInfo.exifImageWidth) / 1_000_000).toFixed(0)}MP</p>
<p>{asset.exifInfo.exifImageHeight} x {asset.exifInfo.exifImageWidth}</p>
<p>{getHumanReadableString(asset.exifInfo.fileSizeInByte)}</p>
</div>
</div>
</div>
{/if}
{#if asset.exifInfo?.fNumber}
<div class="flex gap-4 py-4">
<div><CameraIris size="24" /></div>
<div>
<p>{asset.exifInfo.make || ''} {asset.exifInfo.model || ''}</p>
<div class="flex text-sm gap-2">
<p>{`f/${asset.exifInfo.fNumber}` || ''}</p>
<p>{`1/${1 / asset.exifInfo.exposureTime}` || ''}</p>
<p>{`${asset.exifInfo.focalLength}mm` || ''}</p>
<p>{`ISO${asset.exifInfo.iso}` || ''}</p>
</div>
</div>
</div>
{/if}
{#if asset.exifInfo?.city}
<div class="flex gap-4 py-4">
<div><MapMarkerOutline size="24" /></div>
<div>
<p>{asset.exifInfo.city}</p>
<div class="flex text-sm gap-2">
<p>{asset.exifInfo.state},</p>
<p>{asset.exifInfo.country}</p>
</div>
</div>
</div>
{/if}
</div>
</section>
<div class={`${asset.exifInfo?.latitude ? 'visible' : 'hidden'}`}>
<div class="h-[360px] w-full" id="map" />
</div>
<style>
@import 'https://unpkg.com/leaflet@1.7.1/dist/leaflet.css';
</style>

View file

@ -0,0 +1,26 @@
<script lang="ts">
import { downloadAssets, isDownloading } from '$lib/stores/download';
import { fly, slide } from 'svelte/transition';
</script>
{#if $isDownloading}
<div
transition:fly={{ x: -100, duration: 350 }}
class="w-[315px] max-h-[270px] bg-immich-bg border rounded-2xl shadow-sm absolute bottom-10 left-2 p-4 z-[10000] text-sm"
>
<p class="text-gray-500 text-xs mb-2">DOWNLOADING</p>
<div class="max-h-[200px] my-2 overflow-y-auto mb-2 flex flex-col text-sm">
{#each Object.keys($downloadAssets) as fileName}
<div class="mb-2" transition:slide>
<p class="font-medium text-xs truncate">{fileName}</p>
<div class="flex flex-row-reverse place-items-center gap-5">
<p><span class="text-immich-primary font-medium">{$downloadAssets[fileName]}</span>/100</p>
<div class="w-full bg-gray-200 rounded-full h-[7px] dark:bg-gray-700">
<div class="bg-immich-primary h-[7px] rounded-full" style={`width: ${$downloadAssets[fileName]}%`} />
</div>
</div>
</div>
{/each}
</div>
</div>
{/if}

View file

@ -4,8 +4,7 @@
import { createEventDispatcher, onDestroy } from 'svelte';
import { fade } from 'svelte/transition';
import { serverEndpoint } from '../../constants';
import IntersectionObserver from '$lib/components/photos/intersection-observer.svelte';
import IntersectionObserver from '$lib/components/asset-viewer/intersection-observer.svelte';
import CheckCircle from 'svelte-material-icons/CheckCircle.svelte';
import PlayCircleOutline from 'svelte-material-icons/PlayCircleOutline.svelte';
@ -57,6 +56,7 @@
return videoData;
}
};
const parseVideoDuration = (duration: string) => {
const timePart = duration.split(':');
const hours = timePart[0];
@ -71,11 +71,21 @@
};
onDestroy(() => URL.revokeObjectURL(imageContent));
const getSize = () => {
if (asset.exifInfo?.orientation === 'Rotate 90 CW') {
return 'w-[176px] h-[235px]';
} else if (asset.exifInfo?.orientation === 'Horizontal (normal)') {
return 'w-[313px] h-[235px]';
} else {
return 'w-[235px] h-[235px]';
}
};
</script>
<IntersectionObserver once={true} let:intersecting>
<div
class="h-[200px] w-[200px] bg-gray-100 relative hover:cursor-pointer"
class={`bg-gray-100 relative hover:cursor-pointer ${getSize()}`}
on:mouseenter={() => (mouseOver = true)}
on:mouseleave={() => (mouseOver = false)}
on:click={() => dispatch('viewAsset', { assetId: asset.id, deviceId: asset.deviceId })}
@ -104,13 +114,12 @@
{#if intersecting}
{#await loadImageData()}
<div class="bg-immich-primary/10 h-[200px] w-[200px] flex place-items-center place-content-center">...</div>
<div class={`bg-immich-primary/10 ${getSize()} flex place-items-center place-content-center`}>...</div>
{:then imageData}
<img
in:fade={{ duration: 200 }}
src={imageData}
alt={asset.id}
class="object-cover h-[200px] w-[200px] transition-all duration-100 z-0"
class={`object-cover ${getSize()} transition-all duration-100 z-0`}
loading="lazy"
/>
{/await}

View file

@ -3,12 +3,13 @@
import { serverEndpoint } from '$lib/constants';
import { fade } from 'svelte/transition';
import type { ImmichAsset } from '$lib/models/immich-asset';
import type { ImmichAsset, ImmichExif } from '$lib/models/immich-asset';
import { createEventDispatcher, onMount } from 'svelte';
import LoadingSpinner from '../shared/loading-spinner.svelte';
export let assetId: string;
export let deviceId: string;
let assetInfo: ImmichAsset;
const dispatch = createEventDispatcher();
@ -41,22 +42,18 @@
};
</script>
<div on:click={() => dispatch('close')} class="h-screen">
<div transition:fade={{ duration: 150 }} class="flex place-items-center place-content-center h-full select-none">
{#if assetInfo}
{#await loadAssetData()}
<div class="flex place-items-center place-content-center h-full">
<LoadingSpinner />
</div>
<LoadingSpinner />
{:then assetData}
<div class="flex place-items-center place-content-center h-full">
<img
in:fade={{ duration: 200 }}
src={assetData}
alt={assetId}
class="object-cover h-full transition-all duration-100 z-0"
loading="lazy"
/>
</div>
<img
transition:fade={{ duration: 150 }}
src={assetData}
alt={assetId}
class="object-contain h-full transition-all"
loading="lazy"
/>
{/await}
{/if}
</div>

View file

@ -0,0 +1,18 @@
<script lang="ts">
import { createEventDispatcher } from 'svelte';
export let logo: any;
export let backgroundColor: string = '';
export let logoColor: string = '';
const dispatch = createEventDispatcher();
</script>
<button
class="rounded-full p-3 flex place-items-center place-content-center text-gray-50 hover:bg-gray-800"
class:background-color={backgroundColor}
class:color={logoColor}
on:click={() => dispatch('click')}
>
<svelte:component this={logo} size="24" />
</button>

View file

@ -1,4 +1,5 @@
<script lang="ts">
import { goto } from '$app/navigation';
import { page } from '$app/stores';
import type { ImmichUser } from '$lib/models/immich-user';
import { onMount } from 'svelte';
@ -11,13 +12,19 @@
let shouldShowProfileImage = false;
onMount(async () => {
const res = await fetch(`${serverEndpoint}/user/profile-image/${user.id}`);
const res = await fetch(`${serverEndpoint}/user/profile-image/${user.id}`, { method: 'GET' });
if (res.status == 200) shouldShowProfileImage = true;
});
const getFirstLetter = (text?: string) => {
return text?.charAt(0).toUpperCase();
};
const navigateToAdmin = () => {
console.log('Navigating to admin page');
goto('/admin');
};
</script>
<section id="dashboard-navbar" class="fixed w-screen z-[100] bg-immich-bg text-sm">
@ -33,11 +40,11 @@
<!-- <div>Upload</div> -->
{#if user.isAdmin}
<a
<button
class={`hover:text-immich-primary font-medium ${
$page.url.pathname == '/admin' && 'text-immich-primary underline'
}`}
href="/admin">Administration</a
on:click={navigateToAdmin}>Administration</button
>
{/if}

View file

@ -18,8 +18,8 @@
<div
on:click={onButtonClicked}
class={`flex gap-4 place-items-center pl-5 py-3 rounded-tr-xl rounded-br-xl hover:bg-gray-200 hover:text-immich-primary hover:cursor-pointer
${isSelected && 'bg-immich-primary/10 text-immich-primary hover:bg-immich-primary/50'}
class={`flex gap-4 place-items-center pl-5 py-3 rounded-tr-full rounded-br-full hover:bg-gray-200 hover:text-immich-primary hover:cursor-pointer
${isSelected && 'bg-immich-primary/10 text-immich-primary hover:bg-immich-primary/25'}
`}
>
<svelte:component this={logo} size="24" />