Paginated admin library & upgrade manifests (#351)

* feat: new page layout + endpoint

* feat: non-parallel mass import

* feat: paginated admin library

* feat: lint and performance improvement

* feat: library filter util

* feat: link frontend features to backend

* fix: lint

* fix: small fixes

* feat: bump torrential

* fix: lint
This commit is contained in:
DecDuck
2026-02-25 02:17:33 +11:00
committed by GitHub
parent 3375e8c972
commit 7dc889852d
35 changed files with 1823 additions and 416 deletions
+1 -1
View File
@@ -93,7 +93,7 @@
<NuxtLink
:href="`/store/${game.id}`"
type="button"
class="whitespace-nowrap inline-flex w-fit items-center gap-x-2 rounded-md bg-zinc-800 px-3 py-1 text-sm font-semibold font-display text-white shadow-sm hover:bg-zinc-700 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-600"
class="whitespace-nowrap inline-flex w-fit items-center gap-x-2 rounded-md bg-zinc-800 px-3 py-1 text-sm font-semibold font-display text-white shadow-sm hover:bg-zinc-700 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-600"
>
{{ $t("library.admin.openStore") }}
<ArrowTopRightOnSquareIcon
+6
View File
@@ -344,6 +344,7 @@ import {
import { XCircleIcon } from "@heroicons/vue/16/solid";
import { CheckIcon, ChevronUpDownIcon } from "@heroicons/vue/20/solid";
import { MagnifyingGlassIcon } from "@heroicons/vue/24/outline";
import { FetchError } from "ofetch";
import type { GameType } from "~/prisma/client/enums";
import type { GameMetadataSearchResult } from "~/server/internal/metadata/types";
@@ -406,6 +407,11 @@ async function searchGame() {
gameSearchLoading.value = false;
} catch (e) {
gameSearchLoading.value = false;
if (e instanceof FetchError) {
gameSearchResultsError.value = e.data?.message ?? t("errors.unknown");
} else {
gameSearchResultsError.value = (e as string)?.toString();
}
throw e;
}
+492 -91
View File
@@ -12,7 +12,7 @@
<div class="mt-4 sm:ml-16 sm:mt-0 sm:flex-none">
<NuxtLink
to="/admin/library/sources"
class="block rounded-md bg-blue-600 px-3 py-2 text-center text-sm font-semibold text-white shadow-sm transition-all duration-200 hover:bg-blue-500 hover:scale-105 hover:shadow-lg hover:shadow-blue-500/25 active:scale-95 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-600"
class="block rounded-md bg-blue-600 px-3 py-2 text-center text-sm font-semibold text-white shadow-sm transition-all duration-200 hover:bg-blue-500 hover:scale-105 hover:shadow-lg hover:shadow-blue-500/25 active:scale-95 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-600"
>
<i18n-t
keypath="library.admin.sources.link"
@@ -26,57 +26,240 @@
</NuxtLink>
</div>
</div>
<div v-if="toImport" class="rounded-md bg-blue-600/10 p-4">
<div class="flex">
<div class="flex-shrink-0">
<InformationCircleIcon
class="h-5 w-5 text-blue-400"
aria-hidden="true"
/>
</div>
<div class="ml-3 flex-1 md:flex md:justify-between">
<p class="text-sm text-blue-400">
{{ $t("library.admin.detectedGame") }}
</p>
<p class="mt-3 text-sm md:ml-6 md:mt-0">
<NuxtLink
href="/admin/library/import"
class="whitespace-nowrap font-medium text-blue-400 hover:text-blue-500"
>
<i18n-t
keypath="library.admin.import.link"
tag="span"
scope="global"
<div class="flex flex-row justify-between gap-x-5">
<div v-if="toImport" class="rounded-md bg-zinc-600/10 p-3">
<div class="flex">
<div class="flex-shrink-0">
<WrenchScrewdriverIcon
class="h-5 w-5 text-zinc-400"
aria-hidden="true"
/>
</div>
<div class="ml-3 flex-1 md:flex md:justify-between">
<p class="text-sm text-zinc-400">
{{ $t("library.admin.massImportTool") }}
</p>
<p class="mt-3 text-sm md:ml-6 md:mt-0">
<NuxtLink
href="/admin/library/mass-import"
class="whitespace-nowrap font-medium text-zinc-400 hover:text-zinc-500"
>
<template #arrow>
<span aria-hidden="true">{{ $t("chars.arrow") }}</span>
</template>
</i18n-t>
</NuxtLink>
</p>
<i18n-t
keypath="library.admin.import.link"
tag="span"
scope="global"
>
<template #arrow>
<span aria-hidden="true">{{ $t("chars.arrow") }}</span>
</template>
</i18n-t>
</NuxtLink>
</p>
</div>
</div>
</div>
<div v-if="toImport" class="rounded-md bg-blue-600/10 p-3">
<div class="flex">
<div class="flex-shrink-0">
<InformationCircleIcon
class="h-5 w-5 text-blue-400"
aria-hidden="true"
/>
</div>
<div class="ml-3 flex-1 md:flex md:justify-between">
<p class="text-sm text-blue-400">
{{ $t("library.admin.detectedGame") }}
</p>
<p class="mt-3 text-sm md:ml-6 md:mt-0">
<NuxtLink
href="/admin/library/import"
class="whitespace-nowrap font-medium text-blue-400 hover:text-blue-500"
>
<i18n-t
keypath="library.admin.import.link"
tag="span"
scope="global"
>
<template #arrow>
<span aria-hidden="true">{{ $t("chars.arrow") }}</span>
</template>
</i18n-t>
</NuxtLink>
</p>
</div>
</div>
</div>
</div>
<div class="mt-2 grid grid-cols-1">
<input
id="search"
v-model="searchQuery"
type="text"
name="search"
class="col-start-1 row-start-1 block w-full rounded-md bg-zinc-900 py-1.5 pl-10 pr-3 text-base text-zinc-100 outline outline-1 -outline-offset-1 outline-zinc-700 placeholder:text-gray-400 focus:outline focus:outline-2 focus:-outline-offset-2 focus:outline-blue-600 sm:pl-9 sm:text-sm/6"
:placeholder="$t('library.search')"
/>
<MagnifyingGlassIcon
class="pointer-events-none col-start-1 row-start-1 ml-3 size-5 self-center text-zinc-400 sm:size-4"
aria-hidden="true"
/>
</div>
<!-- Search & filter -->
<Disclosure
as="section"
aria-labelledby="filter-heading"
class="mt-2 relative flex items-center border-y border-zinc-800 gap-x-4"
>
<h2 id="filter-heading" class="sr-only">
{{ $t("library.admin.nav.filterLabel") }}
</h2>
<div class="relative col-start-1 row-start-1 py-4">
<div class="mx-auto flex max-w-7xl divide-x divide-zinc-700 text-sm">
<div class="pr-6">
<DisclosureButton
class="group flex items-center font-medium text-zinc-400"
>
<FunnelIcon
class="mr-2 size-5 flex-none text-gray-400 group-hover:text-gray-500"
aria-hidden="true"
/>
{{
$t("library.admin.nav.filterCount", [
Object.values(currentFilters).filter((v) => v).length,
])
}}
</DisclosureButton>
</div>
<div class="pl-6">
<button type="button" class="text-zinc-400">
{{ $t("library.admin.nav.clearAllFilters") }}
</button>
</div>
</div>
</div>
<DisclosurePanel
class="absolute bottom-0 translate-y-full left-0 border border-zinc-800 py-4 bg-zinc-900 rounded-b-xl z-10 shadow"
>
<div
class="flex flex-wrap flex-col lg:flex-row max-w-7xl text-sm px-4 gap-4"
>
<fieldset v-for="filter in filterScaffold" :key="filter.value">
<legend class="block font-medium text-zinc-100">
{{ filter.title }}
</legend>
<div class="space-y-6 sm:space-y-4 pt-2">
<div
v-for="option in filter.values"
:key="option.value"
class="flex gap-3"
>
<div class="flex h-5 shrink-0 items-center">
<div class="group grid size-4 grid-cols-1">
<input
:id="createFilterKey(filter, option)"
v-model="currentFilters[createFilterKey(filter, option)]"
:value="createFilterKey(filter, option)"
type="checkbox"
class="col-start-1 row-start-1 appearance-none rounded-sm border border-zinc-700 bg-zinc-950 checked:border-blue-600 checked:bg-blue-600 indeterminate:border-blue-600 indeterminate:bg-blue-600 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-600 disabled:border-gray-300 disabled:bg-gray-100 disabled:checked:bg-gray-100 forced-colors:appearance-auto"
/>
<svg
class="pointer-events-none col-start-1 row-start-1 size-3.5 self-center justify-self-center stroke-white group-has-disabled:stroke-gray-950/25"
viewBox="0 0 14 14"
fill="none"
>
<path
class="opacity-0 group-has-checked:opacity-100"
d="M3 8L6 11L11 3.5"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
/>
<path
class="opacity-0 group-has-indeterminate:opacity-100"
d="M3 7H11"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
/>
</svg>
</div>
</div>
<label
:for="createFilterKey(filter, option)"
class="text-base text-zinc-300 sm:text-sm"
>{{ option.label }}</label
>
</div>
</div>
</fieldset>
</div>
</DisclosurePanel>
<div class="grow grid grid-cols-1">
<input
id="search"
v-model="searchQuery"
type="text"
name="search"
class="col-start-1 row-start-1 block w-full rounded-md bg-zinc-900 py-1.5 pl-10 pr-3 text-base text-zinc-100 border-[0px] outline-[0px] placeholder:text-zinc-400 sm:pl-9 sm:text-sm/6"
:placeholder="$t('library.search')"
/>
<MagnifyingGlassIcon
class="pointer-events-none col-start-1 row-start-1 ml-3 size-5 self-center text-zinc-400 sm:size-4"
aria-hidden="true"
/>
</div>
<div class="col-start-1 row-start-1 py-4">
<div class="mx-auto flex max-w-7xl justify-end px-2">
<Menu as="div" class="relative inline-block text-left">
<div>
<MenuButton
class="group inline-flex justify-center text-sm font-medium text-zinc-400 hover:text-zinc-100"
>
{{ $t("store.view.sort") }}
<ChevronDownIcon
class="-mr-1 ml-1 size-5 shrink-0 text-gray-400 group-hover:text-zinc-100"
aria-hidden="true"
/>
</MenuButton>
</div>
<transition
enter-active-class="transition ease-out duration-100"
enter-from-class="transform opacity-0 scale-95"
enter-to-class="transform opacity-100 scale-100"
leave-active-class="transition ease-in duration-75"
leave-from-class="transform opacity-100 scale-100"
leave-to-class="transform opacity-0 scale-95"
>
<MenuItems
class="absolute right-0 z-10 mt-2 w-40 origin-top-right rounded-md bg-zinc-950 shadow-2xl ring-1 ring-white/5 focus:outline-hidden"
>
<div class="py-1">
<MenuItem
v-for="option in sorts"
:key="option.param"
v-slot="{ active }"
>
<button
:class="[
currentSort == option.param
? 'font-medium text-zinc-100'
: 'text-zinc-400',
active ? 'bg-zinc-900 outline-hidden' : '',
'w-full text-left block px-4 py-2 text-sm',
]"
@click.prevent="handleSortClick(option, $event)"
>
{{ option.name }}
<span v-if="currentSort === option.param">
{{
sortOrder === "asc"
? $t("chars.arrowUp")
: $t("chars.arrowDown")
}}
</span>
</button>
</MenuItem>
</div>
</MenuItems>
</transition>
</Menu>
</div>
</div>
</Disclosure>
<ul
role="list"
class="grid grid-cols-1 gap-6 sm:grid-cols-2 md:grid-cols-3 xl:grid-cols-4"
class="relative grid grid-cols-1 gap-6 sm:grid-cols-2 md:grid-cols-3 xl:grid-cols-4"
>
<li
v-for="game in filteredLibraryGames"
v-for="game in libraryGames"
:key="game.id"
class="relative overflow-hidden col-span-1 flex flex-col justify-center divide-y divide-zinc-800 rounded-xl bg-zinc-950/30 text-left shadow-md border hover:scale-102 hover:shadow-xl hover:bg-zinc-950/70 border-zinc-800 transition-all duration-200 group"
>
@@ -240,23 +423,13 @@
</div>
</li>
<p
v-if="filteredLibraryGames.length == 0 && libraryGames.length != 0"
v-if="libraryGames.length == 0 && hasLibraries"
class="text-zinc-600 text-sm font-display font-bold uppercase text-center col-span-4"
>
{{ $t("common.noResults") }}
</p>
<p
v-if="
filteredLibraryGames.length == 0 &&
libraryGames.length == 0 &&
libraryState.hasLibraries
"
class="text-zinc-600 text-sm font-display font-bold uppercase text-center col-span-4"
>
{{ $t("library.admin.noGames") }}
</p>
<p
v-else-if="!libraryState.hasLibraries"
v-else-if="!hasLibraries"
class="flex flex-col gap-2 text-zinc-600 text-center col-span-4"
>
<span class="text-sm font-display font-bold uppercase">{{
@@ -280,7 +453,77 @@
</i18n-t>
</NuxtLink>
</p>
<div
v-if="gamesLoading"
class="absolute inset-0 bg-zinc-900/50 flex items-start p-4 justify-center"
>
<div role="status">
<svg
aria-hidden="true"
class="size-8 text-transparent animate-spin fill-white"
viewBox="0 0 100 101"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z"
fill="currentColor"
/>
<path
d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z"
fill="currentFill"
/>
</svg>
<span class="sr-only">{{ $t("common.srLoading") }}</span>
</div>
</div>
</ul>
<nav
class="flex items-center justify-between border-t border-white/10 px-4 sm:px-0"
>
<div class="-mt-px flex w-0 flex-1">
<button
class="group inline-flex items-center border-t-2 border-transparent pt-4 pr-1 text-sm font-medium text-zinc-400 disabled:text-zinc-700 hover:not-disabled:border-white/20 hover:not-disabled:text-zinc-200"
:disabled="currentIndex == 0"
@click="previousPage"
>
<ArrowLongLeftIcon
class="mr-3 size-5 text-zinc-500 group-disabled:text-zinc-700"
aria-hidden="true"
/>
{{ $t("library.admin.nav.backPagination") }}
</button>
</div>
<div class="hidden md:-mt-px md:flex">
<button
v-for="page in maxPages"
:key="page"
:class="[
currentIndex == page - 1
? 'border-blue-400 text-blue-400'
: 'border-transparent hover:not-disabled:text-zinc-white/20 text-zinc-400 hover:not-disabled:border-white/20',
'transition inline-flex items-center border-t-2 px-4 pt-4 text-sm font-medium',
]"
@click="currentIndex = page - 1"
>
{{ page }}
</button>
</div>
<div class="-mt-px flex w-0 flex-1 justify-end">
<button
class="group inline-flex items-center border-t-2 border-transparent pt-4 pl-1 text-sm font-medium text-zinc-400 disabled:text-zinc-700 hover:not-disabled:border-white/20 hover:not-disabled:text-zinc-200"
:disabled="currentIndex == maxPages - 1"
@click="nextPage"
>
{{ $t("library.admin.nav.nextPagination") }}
<ArrowLongRightIcon
class="ml-3 size-5 text-zinc-500 group-disabled:text-zinc-700"
aria-hidden="true"
/>
</button>
</div>
</nav>
</div>
</template>
@@ -293,8 +536,23 @@ import {
ArrowTopRightOnSquareIcon,
InformationCircleIcon,
StarIcon,
WrenchScrewdriverIcon,
ArrowLongLeftIcon,
ArrowLongRightIcon,
ChevronDownIcon,
FunnelIcon,
} from "@heroicons/vue/20/solid";
import { MagnifyingGlassIcon } from "@heroicons/vue/24/outline";
import type { AdminLibraryGame } from "~/server/api/v1/admin/library/index.get";
import {
Disclosure,
DisclosureButton,
DisclosurePanel,
Menu,
MenuButton,
MenuItem,
MenuItems,
} from "@headlessui/vue";
const { t } = useI18n();
@@ -306,33 +564,46 @@ useHead({
title: t("library.admin.title"),
});
const searchQuery = ref("");
const libraryState = await $dropFetch("/api/v1/admin/library");
type LibraryStateGame = (typeof libraryState.games)[number]["game"];
const toImport = ref(
Object.values(libraryState.unimportedGames).flat().length > 0,
const { unimportedGames, hasLibraries } = await $dropFetch(
"/api/v1/admin/library/libraries",
);
const libraryGames = ref<
Array<
LibraryStateGame & {
status: "online" | "offline";
hasNotifications?: boolean;
notifications: {
noVersions?: boolean;
toImport?: boolean;
offline?: boolean;
};
}
>
>(
libraryState.games.map((e) => {
const route = useRoute();
const router = useRouter();
// Hard limit on server
const pageSize = 24;
const currentIndex = ref(
route.query.page ? parseInt(route.query.page.toString()) - 1 : 0,
);
const maxIndex = ref(0);
const maxPages = computed(() => Math.ceil(maxIndex.value / pageSize));
const games = ref<AdminLibraryGame[]>([]);
const gamesLoading = ref(false);
const searchQuery = ref("");
function nextPage() {
if (currentIndex.value < maxPages.value - 1) {
currentIndex.value++;
}
}
function previousPage() {
if (currentIndex.value > 0) {
currentIndex.value--;
}
}
const toImport = ref(Object.values(unimportedGames).flat().length > 0);
const libraryGames = computed(() =>
games.value.map((e) => {
if (e.status == "offline") {
return {
...e.game,
status: "offline" as const,
status: "offline",
hasNotifications: true,
notifications: {
offline: true,
@@ -355,19 +626,6 @@ const libraryGames = ref<
}),
);
const filteredLibraryGames = computed(() =>
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore excessively deep ts
libraryGames.value.filter((e) => {
if (!searchQuery.value) return true;
const searchQueryLower = searchQuery.value.toLowerCase();
if (e.mName.toLowerCase().includes(searchQueryLower)) return true;
if (e.mShortDescription.toLowerCase().includes(searchQueryLower))
return true;
return false;
}),
);
async function deleteGame(id: string) {
await $dropFetch(`/api/v1/admin/game/${id}`, {
method: "DELETE",
@@ -396,4 +654,147 @@ async function featureGame(id: string) {
libraryGames.value[gameIndex].featured = !game.featured;
gameFeatureLoading.value[game.id] = false;
}
const currentFilters = ref<{ [key: string]: boolean }>({});
function createFilterKey(
filter: { value: string },
subfilter: { value: string },
) {
return `${filter.value}.${subfilter.value}`;
}
const filters = computed(
() =>
({
version: [
{
value: "none",
label: t("library.admin.nav.filters.version.none"),
},
/*{
value: "available",
label: t("library.admin.nav.filters.version.available"),
},*/
],
metadata: [
{
value: "featured",
label: t("library.admin.nav.filters.metadata.featured"),
},
{
value: "noCarousel",
label: t("library.admin.nav.filters.metadata.noCarousel"),
},
{
value: "emptyDescription",
label: t("library.admin.nav.filters.metadata.emptyDescription"),
},
],
}) as const,
);
const filterScaffold = computed(
() =>
({
version: {
title: t("library.admin.nav.filters.version.title"),
value: "version",
// eslint-disable-next-line @typescript-eslint/no-explicit-any
values: filters.value.version as any,
},
metadata: {
title: t("library.admin.nav.filters.metadata.title"),
value: "metadata",
// eslint-disable-next-line @typescript-eslint/no-explicit-any
values: filters.value.metadata as any,
},
}) satisfies {
[key in keyof typeof filters.value]: {
title: string;
value: string;
values: Array<{ value: string; label: string }>;
};
},
);
const sorts: Array<StoreSortOption> = [
{
name: "Default",
param: "default",
},
{
name: "Newest",
param: "newest",
},
{
name: "Recently Added",
param: "recent",
},
{
name: "Name",
param: "name",
},
];
const currentSort = ref(sorts[0].param);
const sortOrder = ref<"asc" | "desc">("desc");
function handleSortClick(option: StoreSortOption, event: MouseEvent) {
event.stopPropagation();
if (currentSort.value === option.param) {
sortOrder.value = sortOrder.value === "asc" ? "desc" : "asc";
} else {
currentSort.value = option.param;
sortOrder.value = option.param === "name" ? "asc" : "desc";
}
}
async function fetchPage() {
gamesLoading.value = true;
const { results, count } = await $dropFetch("/api/v1/admin/library", {
query: {
skip: currentIndex.value * pageSize,
limit: pageSize,
sort: currentSort.value,
order: sortOrder.value,
filters: Object.entries(currentFilters.value)
.filter(([_, enabled]) => enabled)
.map(([name, _]) => name)
.join(","),
query: searchQuery.value ? searchQuery.value : undefined,
},
failTitle: "Failed to fetch game library",
});
maxIndex.value = count;
games.value = results;
gamesLoading.value = false;
router.push({
path: route.path,
query: {
...route.query,
page: currentIndex.value + 1,
},
});
}
function watchHandler() {
fetchPage();
document.body.scrollTop = document.documentElement.scrollTop = 0;
}
watch([currentIndex, currentSort, sortOrder], watchHandler);
watch(currentFilters, watchHandler, { deep: true });
let searchTimeout: NodeJS.Timeout | undefined;
watch(searchQuery, () => {
if (searchTimeout) clearTimeout(searchTimeout);
gamesLoading.value = true;
searchTimeout = setTimeout(() => {
watchHandler();
}, 80);
});
await fetchPage();
</script>
+363
View File
@@ -0,0 +1,363 @@
<template>
<div>
<div class="sm:flex sm:items-center">
<div class="sm:flex-auto">
<h1
class="inline-flex items-center gap-x-2 text-base font-semibold text-white"
>
<WrenchScrewdriverIcon class="size-6" /> Mass Import Tool
</h1>
<p class="mt-2 text-sm text-zinc-300">
Quickly import a large amount of versions at once.
</p>
</div>
<div class="mt-4 sm:mt-0 sm:ml-16 sm:flex-none">
<LoadingButton
:loading="false"
:disabled="!hasSelected"
@click="triggerImport"
>
Import &rarr;
</LoadingButton>
</div>
</div>
<div class="mt-8 flow-root">
<div class="-mx-4 -my-2 overflow-x-auto sm:-mx-6 lg:-mx-8">
<div class="inline-block min-w-full py-2 align-middle sm:px-6 lg:px-8">
<div class="group/table relative">
<table
class="relative min-w-full table-fixed divide-y divide-white/15"
>
<thead>
<tr>
<th scope="col" class="relative px-7 sm:w-12 sm:px-6">
<div
class="group absolute top-1/2 left-4 -mt-2 grid size-4 grid-cols-1"
>
<input
v-model="globalState"
:indeterminate="globalState === 'indeterminate'"
type="checkbox"
class="col-start-1 row-start-1 appearance-none rounded-sm border border-white/20 bg-zinc-800/50 checked:border-blue-500 checked:bg-blue-500 indeterminate:border-blue-500 indeterminate:bg-blue-500 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-500 disabled:border-white/10 disabled:bg-zinc-800 disabled:checked:bg-zinc-800 forced-colors:appearance-auto"
/>
<svg
class="pointer-events-none col-start-1 row-start-1 size-3.5 self-center justify-self-center stroke-white group-has-disabled:stroke-zinc-50/25"
viewBox="0 0 14 14"
fill="none"
>
<path
class="opacity-0 group-has-checked:opacity-100"
d="M3 8L6 11L11 3.5"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
/>
<path
class="opacity-0 group-has-indeterminate:opacity-100"
d="M3 7H11"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
/>
</svg>
</div>
</th>
<th
scope="col"
class="w-full py-3.5 pr-3 text-left text-sm font-semibold text-white whitespace-nowrap"
>
Name
</th>
<th
scope="col"
class="px-3 py-3.5 text-left text-sm font-semibold text-white whitespace-nowrap"
>
Type
</th>
<th
scope="col"
class="px-3 py-3.5 text-left text-sm font-semibold text-white whitespace-nowrap"
>
Display Name
</th>
<th
scope="col"
class="px-3 py-3.5 text-left text-sm font-semibold text-white whitespace-nowrap"
>
Setup Mode
</th>
</tr>
</thead>
<tbody class="divide-y divide-white/10 bg-zinc-900">
<template v-for="game in massImport" :key="game.id">
<tr class="text-sm/6 text-zinc-100 bg-zinc-950">
<th scope="colgroup" colspan="5" class="py-2 text-left">
<div class="inline-flex gap-x-2 px-4">
<img
:src="useObject(game.icon)"
class="size-6 rounded-sm"
/>
{{ game.name }}
</div>
</th>
</tr>
<tr
v-for="version in game.versions"
:key="version.identifier"
class="group has-checked:bg-zinc-800/50"
>
<td class="relative px-7 sm:w-12 sm:px-6">
<div
className="hidden group-has-checked:block absolute inset-y-0 left-0 w-0.5 bg-blue-500"
/>
<div
class="absolute top-1/2 left-4 -mt-2 grid size-4 grid-cols-1"
>
<input
v-model="version.enabled"
type="checkbox"
class="col-start-1 row-start-1 appearance-none rounded-sm border border-white/20 bg-zinc-800/50 checked:border-blue-500 checked:bg-blue-500 indeterminate:border-blue-500 indeterminate:bg-blue-500 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-500 disabled:border-white/10 disabled:bg-zinc-800 disabled:checked:bg-zinc-800 forced-colors:appearance-auto"
/>
<svg
class="pointer-events-none col-start-1 row-start-1 size-3.5 self-center justify-self-center stroke-white group-has-disabled:stroke-zinc-50/25"
viewBox="0 0 14 14"
fill="none"
>
<path
class="opacity-0 group-has-checked:opacity-100"
d="M3 8L6 11L11 3.5"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
/>
<path
class="opacity-0 group-has-indeterminate:opacity-100"
d="M3 7H11"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
/>
</svg>
</div>
</td>
<td
class="py-4 pr-3 text-sm font-medium whitespace-nowrap text-white group-has-checked:text-blue-400"
>
{{ version.name }}
</td>
<td
class="px-3 py-4 text-sm whitespace-nowrap text-zinc-400"
>
{{ version.type }}
</td>
<td class="px-3 text-sm whitespace-nowrap text-zinc-400">
<input
id="display-name"
v-model="version.settings.displayName"
type="text"
class="min-w-48 block w-full rounded-md border-radius-md bg-zinc-900 px-3 py-1.5 text-white outline-2 -outline-offset-1 outline-zinc-800 placeholder:text-zinc-500 focus:outline-2 focus:-outline-offset-2 focus:outline-blue-500 sm:text-sm/6"
placeholder="My New Version"
/>
</td>
<td class="px-3 text-sm whitespace-nowrap text-zinc-400">
<Switch
v-model="version.settings.setupMode"
:class="[
version.settings.setupMode
? 'bg-blue-600'
: 'bg-zinc-900',
'relative inline-flex h-6 w-11 flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none focus:ring-2 focus:ring-blue-600 focus:ring-offset-2',
]"
>
<span
aria-hidden="true"
:class="[
version.settings.setupMode
? 'translate-x-5'
: 'translate-x-0',
'pointer-events-none inline-block h-5 w-5 transform rounded-full bg-white shadow ring-0 transition duration-200 ease-in-out',
]"
/>
</Switch>
</td>
</tr>
</template>
</tbody>
</table>
</div>
</div>
</div>
</div>
<TransitionRoot as="template" :show="open">
<Dialog class="relative z-10" @close="open = false">
<TransitionChild
as="template"
enter="ease-out duration-300"
enter-from="opacity-0"
enter-to=""
leave="ease-in duration-200"
leave-from=""
leave-to="opacity-0"
>
<div class="fixed inset-0 bg-zinc-900/70 transition-opacity"></div>
</TransitionChild>
<div class="fixed inset-0 z-10 w-screen overflow-y-auto">
<div
class="flex min-h-full items-end justify-center p-4 text-center sm:items-center sm:p-0"
>
<TransitionChild
as="template"
enter="ease-out duration-300"
enter-from="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
enter-to=" translate-y-0 sm:scale-100"
leave="ease-in duration-200"
leave-from=" translate-y-0 sm:scale-100"
leave-to="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
>
<DialogPanel
class="relative transform overflow-hidden rounded-lg bg-zinc-900 px-4 pt-5 pb-4 text-left shadow-xl outline -outline-offset-1 outline-white/10 transition-all sm:my-8 sm:w-full sm:max-w-sm sm:p-6"
>
<div>
<div
class="mx-auto flex size-12 items-center justify-center rounded-full bg-yellow-500/10"
>
<ExclamationTriangleIcon
class="size-6 text-yellow-400"
aria-hidden="true"
/>
</div>
<div class="mt-3 text-center sm:mt-5">
<DialogTitle
as="h3"
class="text-base font-semibold text-white"
>This tool is basic.</DialogTitle
>
<div class="mt-2">
<p class="text-sm text-zinc-400">
While it is useful to import a lot of versions at once,
this tool is designed for migrating from other projects,
rather than building your Drop library from scratch.
<span class="text-sm text-zinc-100 font-bold">
It is missing functionality present in the normal
import wizard.
</span>
</p>
</div>
</div>
</div>
<div class="mt-5 sm:mt-6">
<button
type="button"
class="inline-flex w-full justify-center rounded-md bg-zinc-800 px-3 py-2 text-sm font-semibold text-white hover:bg-zinc-700 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-zinc-800"
@click="open = false"
>
Accept
</button>
</div>
</DialogPanel>
</TransitionChild>
</div>
</div>
</Dialog>
</TransitionRoot>
</div>
</template>
<script setup lang="ts">
import {
WrenchScrewdriverIcon,
ExclamationTriangleIcon,
} from "@heroicons/vue/24/outline";
import {
Switch,
Dialog,
DialogPanel,
DialogTitle,
TransitionChild,
TransitionRoot,
} from "@headlessui/vue";
definePageMeta({
layout: "admin",
});
const open = ref(true);
const raw = await $dropFetch("/api/v1/admin/import/massversion");
const massImport = ref(
raw.map((game) => ({
...game,
versions: game.versions!.map((version) => ({
...version,
enabled: true,
settings: {
displayName: undefined,
setupMode: false,
},
})),
})),
);
const hasSelected = computed(
() =>
massImport.value
.map((v) => v.versions)
.flat()
.filter((e) => e.enabled).length > 0,
);
const globalState = computed({
get() {
let lastSeen = undefined;
for (const game of massImport.value) {
for (const version of game.versions!) {
if (lastSeen === undefined) {
lastSeen = version.enabled;
continue;
}
if (lastSeen != version.enabled) return "indeterminate" as const;
}
}
return lastSeen;
},
set(v) {
if (typeof v !== "boolean") return;
for (const game of massImport.value) {
for (const version of game.versions!) {
version.enabled = v;
}
}
},
});
const router = useRouter();
async function triggerImport() {
const { taskId } = await $dropFetch("/api/v1/admin/import/massversion", {
method: "POST",
body: {
versions: massImport.value
.map((game) =>
game.versions
.filter((version) => version.enabled)
.map((version) => ({
id: game.id,
version: {
type: version.type,
identifier: version.identifier,
name: version.name,
},
...version.settings,
})),
)
.flat(),
},
});
router.push(`/admin/task/${taskId}`);
}
</script>
+1 -1
View File
@@ -40,7 +40,7 @@
</div>
</div>
</div>
<ul class="flex flex-row items-center h-12 gap-x-3">
<ul class="flex flex-row flex-wrap items-center h-12 gap-x-3">
<li
v-for="[name, link] in task.actions.map((v) => v.split(':'))"
:key="link"
+60 -4
View File
@@ -23,18 +23,69 @@
{{ $t("tasks.admin.noTasksRunning") }}
</div>
</div>
<div class="mt-6 w-full grid lg:grid-cols-2 gap-8">
<div>
<div class="mt-6 w-full grid lg:grid-cols-3 gap-8">
<div class="col-span-2">
<h2 class="text-sm font-medium text-zinc-400">
{{ $t("tasks.admin.completedTasksTitle") }}
</h2>
<ul role="list" class="mt-4 grid grid-cols-1 gap-6 lg:grid-cols-2">
<ul
role="list"
class="mt-4 grid grid-cols-1 gap-2 lg:grid-cols-4 overflow-y-scroll max-h-[80vh]"
>
<li
v-for="task in historicalTasks"
:key="task.id"
class="col-span-1 divide-y divide-gray-200 rounded-lg bg-zinc-800 border border-zinc-700 shadow-sm"
>
<TaskWidget :task="task" />
<div class="flex w-full items-center justify-between space-x-6 p-2">
<div class="flex-1 truncate">
<div class="flex items-center space-x-1">
<div>
<CheckCircleIcon
v-if="task.success"
class="size-5 text-green-600"
/>
<XMarkIcon
v-else-if="task.error"
class="size-5 text-red-600"
/>
<div
v-else
class="size-2 bg-blue-600 rounded-full animate-pulse m-1"
/>
</div>
<h3 class="truncate text-sm font-medium text-zinc-100">
{{ task.name }}
</h3>
</div>
<ul v-if="task.actions" class="mt-1 flex flex-row gap-x-2">
<NuxtLink
v-for="[name, link] in task.actions.map((v) =>
v.split(':'),
)"
:key="link"
:href="link"
class="text-xs text-zinc-100 bg-blue-900 p-1 rounded"
>{{ name }}</NuxtLink
>
</ul>
<NuxtLink
type="button"
:href="`/admin/task/${task.id}`"
class="mt-3 ml-1 rounded-md text-xs font-medium text-zinc-100 hover:text-zinc-300 focus:outline-none focus:ring-2 focus:ring-zinc-100 focus:ring-offset-2"
>
<i18n-t
keypath="tasks.admin.viewTask"
tag="span"
scope="global"
>
<template #arrow>
<span aria-hidden="true">{{ $t("chars.arrow") }}</span>
</template>
</i18n-t>
</NuxtLink>
</div>
</div>
</li>
</ul>
</div>
@@ -120,6 +171,7 @@
</div>
</template>
<script lang="ts" setup>
import { CheckCircleIcon, XMarkIcon } from "@heroicons/vue/24/solid";
import { PlayIcon } from "@heroicons/vue/24/outline";
import type { TaskGroup } from "~/server/internal/tasks/group";
@@ -163,6 +215,10 @@ const scheduledTasks: {
name: "",
description: "",
},
"import:version": {
name: "",
description: "",
},
debug: {
name: "",
description: "",