1
0
mirror of https://github.com/immich-app/immich.git synced 2024-11-28 09:33:27 +02:00

refactor(web): admin layout (#4461)

This commit is contained in:
Jason Rasmussen 2023-10-13 11:02:28 -04:00 committed by GitHub
parent 268a9c4803
commit 9d225d3d06
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 333 additions and 344 deletions

View File

@ -3,7 +3,6 @@
notificationController,
NotificationType,
} from '$lib/components/shared-components/notification/notification';
import { AppRoute } from '$lib/constants';
import { featureFlags } from '$lib/stores/server-config.store';
import { handleError } from '$lib/utils/handle-error';
import { AllJobStatusResponseDto, api, JobCommand, JobCommandDto, JobName } from '@api';
@ -14,7 +13,6 @@
import FileXmlBox from 'svelte-material-icons/FileXmlBox.svelte';
import LibraryShelves from 'svelte-material-icons/LibraryShelves.svelte';
import FolderMove from 'svelte-material-icons/FolderMove.svelte';
import CogIcon from 'svelte-material-icons/Cog.svelte';
import Table from 'svelte-material-icons/Table.svelte';
import TagMultiple from 'svelte-material-icons/TagMultiple.svelte';
import VectorCircle from 'svelte-material-icons/VectorCircle.svelte';
@ -22,7 +20,6 @@
import ConfirmDialogue from '../../shared-components/confirm-dialogue.svelte';
import JobTile from './job-tile.svelte';
import StorageMigrationDescription from './storage-migration-description.svelte';
import Button from '../../elements/buttons/button.svelte';
export let jobs: AllJobStatusResponseDto;
@ -149,14 +146,6 @@
{/if}
<div class="flex flex-col gap-7">
<div class="flex justify-end">
<a href="{AppRoute.ADMIN_SETTINGS}?open=job-settings">
<Button size="sm">
<CogIcon size="18" />
<span class="pl-2">Manage Concurrency</span>
</Button>
</a>
</div>
{#each jobList as [jobName, { title, subtitle, disabled, allText, missingText, allowForceCommand, icon, component, handleCommand: handleCommandOverride }]}
{@const { jobCounts, queueStatus } = jobs[jobName]}
<JobTile

View File

@ -3,11 +3,14 @@
import type { UserResponseDto } from '@api';
import NavigationBar from '../shared-components/navigation-bar/navigation-bar.svelte';
import SideBar from '../shared-components/side-bar/side-bar.svelte';
import AdminSideBar from '../shared-components/side-bar/admin-side-bar.svelte';
export let user: UserResponseDto;
export let hideNavbar = false;
export let showUploadButton = false;
export let title: string | undefined = undefined;
export let scrollbar = true;
export let admin = false;
$: scrollbarClass = scrollbar ? 'immich-scrollbar p-4 pb-8' : 'scrollbar-hidden pl-4';
</script>
@ -23,7 +26,11 @@
class="relative grid h-screen grid-cols-[theme(spacing.18)_auto] overflow-hidden bg-immich-bg pt-[var(--navbar-height)] dark:bg-immich-dark-bg md:grid-cols-[theme(spacing.64)_auto]"
>
<slot name="sidebar">
{#if admin}
<AdminSideBar />
{:else}
<SideBar />
{/if}
</slot>
<slot name="content">
{#if title}

View File

@ -0,0 +1,33 @@
<script lang="ts">
import { page } from '$app/stores';
import SideBarButton from '$lib/components/shared-components/side-bar/side-bar-button.svelte';
import SideBarSection from '$lib/components/shared-components/side-bar/side-bar-section.svelte';
import StatusBox from '$lib/components/shared-components/status-box.svelte';
import { AppRoute } from '$lib/constants';
import AccountMultipleOutline from 'svelte-material-icons/AccountMultipleOutline.svelte';
import Cog from 'svelte-material-icons/Cog.svelte';
import Server from 'svelte-material-icons/Server.svelte';
import Sync from 'svelte-material-icons/Sync.svelte';
</script>
<SideBarSection>
<a data-sveltekit-preload-data="hover" href={AppRoute.ADMIN_USER_MANAGEMENT} draggable="false">
<SideBarButton
title="Users"
logo={AccountMultipleOutline}
isSelected={$page.route.id === AppRoute.ADMIN_USER_MANAGEMENT}
/>
</a>
<a data-sveltekit-preload-data="hover" href={AppRoute.ADMIN_JOBS} draggable="false">
<SideBarButton title="Jobs" logo={Sync} isSelected={$page.route.id === AppRoute.ADMIN_JOBS} />
</a>
<a data-sveltekit-preload-data="hover" href={AppRoute.ADMIN_SETTINGS} draggable="false">
<SideBarButton title="Settings" logo={Cog} isSelected={$page.route.id === AppRoute.ADMIN_SETTINGS} />
</a>
<a data-sveltekit-preload-data="hover" href={AppRoute.ADMIN_STATS} draggable="false">
<SideBarButton title="Server Stats" logo={Server} isSelected={$page.route.id === AppRoute.ADMIN_STATS} />
</a>
<div class="mb-6 mt-auto">
<StatusBox />
</div>
</SideBarSection>

View File

@ -1,68 +0,0 @@
<script lang="ts">
// DO NOT include `import { page } from '$app/stores'` here, because this can
// lead to pages not being unmounted, which then causes weird page nesting
// and routing issues.
//
// This is an issue in SvelteKit caused by using the page store in layouts and
// using transitions on pages: https://github.com/sveltejs/kit/issues/7405
import SideBarButton from '$lib/components/shared-components/side-bar/side-bar-button.svelte';
import AccountMultipleOutline from 'svelte-material-icons/AccountMultipleOutline.svelte';
import Sync from 'svelte-material-icons/Sync.svelte';
import Cog from 'svelte-material-icons/Cog.svelte';
import Server from 'svelte-material-icons/Server.svelte';
import StatusBox from '$lib/components/shared-components/status-box.svelte';
import { AppRoute } from '../../lib/constants';
import type { LayoutData } from './$types';
import SideBarSection from '$lib/components/shared-components/side-bar/side-bar-section.svelte';
import UserPageLayout from '$lib/components/layouts/user-page-layout.svelte';
export let data: LayoutData;
// Circumvents the need to import the page store. Should be replaced by
// `$page.data.meta.title` once issue #7405 of SvelteKit is resolved.
const getPageTitle = (routeId: string | null) => {
switch (routeId) {
case AppRoute.ADMIN_USER_MANAGEMENT:
return 'User Management';
case AppRoute.ADMIN_SETTINGS:
return 'System Settings';
case AppRoute.ADMIN_JOBS:
return 'Jobs';
case AppRoute.ADMIN_STATS:
return 'Server Stats';
default:
return '';
}
};
</script>
<UserPageLayout user={data.user} showUploadButton={false} title={getPageTitle(data.routeId)}>
<SideBarSection slot="sidebar">
<a data-sveltekit-preload-data="hover" href={AppRoute.ADMIN_USER_MANAGEMENT} draggable="false">
<SideBarButton
title="Users"
logo={AccountMultipleOutline}
isSelected={data.routeId === AppRoute.ADMIN_USER_MANAGEMENT}
/>
</a>
<a data-sveltekit-preload-data="hover" href={AppRoute.ADMIN_JOBS} draggable="false">
<SideBarButton title="Jobs" logo={Sync} isSelected={data.routeId === AppRoute.ADMIN_JOBS} />
</a>
<a data-sveltekit-preload-data="hover" href={AppRoute.ADMIN_SETTINGS} draggable="false">
<SideBarButton title="Settings" logo={Cog} isSelected={data.routeId === AppRoute.ADMIN_SETTINGS} />
</a>
<a data-sveltekit-preload-data="hover" href={AppRoute.ADMIN_STATS} draggable="false">
<SideBarButton title="Server Stats" logo={Server} isSelected={data.routeId === AppRoute.ADMIN_STATS} />
</a>
<div class="mb-6 mt-auto">
<StatusBox />
</div>
</SideBarSection>
<section id="setting-content" class="flex place-content-center sm:mx-4">
<section class="w-full pb-28 pt-5 sm:w-5/6 md:w-[850px]">
<slot />
</section>
</section>
</UserPageLayout>

View File

@ -1,14 +0,0 @@
import { AppRoute } from '$lib/constants';
import { redirect } from '@sveltejs/kit';
import type { LayoutLoad } from './$types';
export const load = (async ({ parent, route }) => {
const { user } = await parent();
if (!user) {
throw redirect(302, AppRoute.AUTH_LOGIN);
} else if (!user.isAdmin) {
throw redirect(302, AppRoute.PHOTOS);
}
return { routeId: route.id, user };
}) satisfies LayoutLoad;

View File

@ -13,6 +13,7 @@ export const load = (async ({ locals: { user, api } }) => {
const { data: jobs } = await api.jobApi.getAllJobsStatus();
return {
user,
jobs,
meta: {
title: 'Job Status',

View File

@ -1,7 +1,14 @@
<script lang="ts">
import JobsPanel from '$lib/components/admin-page/jobs/jobs-panel.svelte';
import LinkButton from '$lib/components/elements/buttons/link-button.svelte';
import UserPageLayout from '$lib/components/layouts/user-page-layout.svelte';
import { AppRoute } from '$lib/constants';
import { AllJobStatusResponseDto, api } from '@api';
import { onDestroy, onMount } from 'svelte';
import CogIcon from 'svelte-material-icons/Cog.svelte';
import type { PageData } from './$types';
export let data: PageData;
let timer: ReturnType<typeof setInterval>;
@ -22,6 +29,22 @@
});
</script>
{#if jobs}
<UserPageLayout user={data.user} title={data.meta.title} admin>
<div class="flex justify-end" slot="buttons">
<a href="{AppRoute.ADMIN_SETTINGS}?open=job-settings">
<LinkButton>
<div class="flex place-items-center gap-2 text-sm">
<CogIcon size="18" />
Manage Concurrency
</div>
</LinkButton>
</a>
</div>
<section id="setting-content" class="flex place-content-center sm:mx-4">
<section class="w-full pb-28 sm:w-5/6 md:w-[850px]">
{#if jobs}
<JobsPanel {jobs} />
{/if}
{/if}
</section>
</section>
</UserPageLayout>

View File

@ -14,6 +14,7 @@ export const load = (async ({ parent, locals: { api } }) => {
const { data: stats } = await api.serverInfoApi.getStats();
return {
user,
stats,
meta: {
title: 'Server Stats',

View File

@ -1,10 +1,12 @@
<script lang="ts">
import { onMount, onDestroy } from 'svelte';
import { api } from '@api';
import ServerStatsPanel from '$lib/components/admin-page/server-stats/server-stats-panel.svelte';
import UserPageLayout from '$lib/components/layouts/user-page-layout.svelte';
import { api } from '@api';
import { onDestroy, onMount } from 'svelte';
import type { PageData } from './$types';
export let data: PageData;
let setIntervalHandler: ReturnType<typeof setInterval>;
onMount(async () => {
@ -19,4 +21,10 @@
});
</script>
<ServerStatsPanel stats={data.stats} />
<UserPageLayout user={data.user} title={data.meta.title} admin>
<section id="setting-content" class="flex place-content-center sm:mx-4">
<section class="w-full pb-28 sm:w-5/6 md:w-[850px]">
<ServerStatsPanel stats={data.stats} />
</section>
</section>
</UserPageLayout>

View File

@ -2,7 +2,7 @@ import { AppRoute } from '$lib/constants';
import { redirect } from '@sveltejs/kit';
import type { PageServerLoad } from './$types';
export const load: PageServerLoad = async ({ parent }) => {
export const load: PageServerLoad = async ({ parent, locals: { api } }) => {
const { user } = await parent();
if (!user) {
@ -11,8 +11,11 @@ export const load: PageServerLoad = async ({ parent }) => {
throw redirect(302, AppRoute.PHOTOS);
}
const { data: configs } = await api.systemConfigApi.getConfig();
return {
user,
configs,
meta: {
title: 'System Settings',
},

View File

@ -9,26 +9,23 @@
import SettingAccordion from '$lib/components/admin-page/settings/setting-accordion.svelte';
import StorageTemplateSettings from '$lib/components/admin-page/settings/storage-template/storage-template-settings.svelte';
import ThumbnailSettings from '$lib/components/admin-page/settings/thumbnail/thumbnail-settings.svelte';
import Button from '$lib/components/elements/buttons/button.svelte';
import LoadingSpinner from '$lib/components/shared-components/loading-spinner.svelte';
import TrashSettings from '$lib/components/admin-page/settings/trash-settings/trash-settings.svelte';
import LinkButton from '$lib/components/elements/buttons/link-button.svelte';
import UserPageLayout from '$lib/components/layouts/user-page-layout.svelte';
import { downloadManager } from '$lib/stores/download';
import { featureFlags } from '$lib/stores/server-config.store';
import { downloadBlob } from '$lib/utils/asset-utils';
import { SystemConfigDto, api, copyToClipboard } from '@api';
import { copyToClipboard } from '@api';
import Alert from 'svelte-material-icons/Alert.svelte';
import ContentCopy from 'svelte-material-icons/ContentCopy.svelte';
import Download from 'svelte-material-icons/Download.svelte';
import type { PageData } from './$types';
import TrashSettings from '$lib/components/admin-page/settings/trash-settings/trash-settings.svelte';
export let data: PageData;
const getConfig = async () => {
const { data } = await api.systemConfigApi.getConfig();
return data;
};
const configs = data.configs;
const downloadConfig = (configs: SystemConfigDto) => {
const downloadConfig = () => {
const blob = new Blob([JSON.stringify(configs, null, 2)], { type: 'application/json' });
const downloadKey = 'immich-config.json';
downloadManager.add(downloadKey, blob.size);
@ -45,21 +42,24 @@
</div>
{/if}
<section class="">
{#await getConfig()}
<LoadingSpinner />
{:then configs}
<div class="flex justify-end gap-2">
<Button size="sm" on:click={() => copyToClipboard(JSON.stringify(configs, null, 2))}>
<UserPageLayout user={data.user} title={data.meta.title} admin>
<div class="flex justify-end gap-2" slot="buttons">
<LinkButton on:click={() => copyToClipboard(JSON.stringify(configs, null, 2))}>
<div class="flex place-items-center gap-2 text-sm">
<ContentCopy size="18" />
<span class="pl-2">Copy to Clipboard</span>
</Button>
<Button size="sm" on:click={() => downloadConfig(configs)}>
Copy to Clipboard
</div>
</LinkButton>
<LinkButton on:click={() => downloadConfig()}>
<div class="flex place-items-center gap-2 text-sm">
<Download size="18" />
<span class="pl-2">Export as JSON</span>
</Button>
Export as JSON
</div>
</LinkButton>
</div>
<section id="setting-content" class="flex place-content-center sm:mx-4">
<section class="w-full pb-28 sm:w-5/6 md:w-[850px]">
<SettingAccordion
title="Job Settings"
subtitle="Manage job concurrency"
@ -110,5 +110,6 @@
>
<FFmpegSettings disabled={$featureFlags.configFile} ffmpegConfig={configs.ffmpeg} />
</SettingAccordion>
{/await}
</section>
</section>
</section>
</UserPageLayout>

View File

@ -15,6 +15,7 @@
import { page } from '$app/stores';
import { locale } from '$lib/stores/preferences.store';
import Button from '$lib/components/elements/buttons/button.svelte';
import UserPageLayout from '$lib/components/layouts/user-page-layout.svelte';
import type { PageData } from './$types';
export let data: PageData;
@ -107,7 +108,9 @@
};
</script>
<section>
<UserPageLayout user={data.user} title={data.meta.title} admin>
<section id="setting-content" class="flex place-content-center sm:mx-4">
<section class="w-full pb-28 sm:w-5/6 md:w-[850px]">
{#if shouldShowCreateUserForm}
<FullScreenModal on:clickOutside={() => (shouldShowCreateUserForm = false)}>
<CreateUserForm on:user-created={onUserCreated} on:cancel={() => (shouldShowCreateUserForm = false)} />
@ -288,4 +291,6 @@
</table>
<Button size="sm" on:click={() => (shouldShowCreateUserForm = true)}>Create user</Button>
</section>
</section>
</section>
</UserPageLayout>