Skip to content

Commit

Permalink
More info on admin view
Browse files Browse the repository at this point in the history
  • Loading branch information
arildm committed Mar 18, 2024
1 parent 72b8805 commit d8f61e4
Show file tree
Hide file tree
Showing 7 changed files with 177 additions and 27 deletions.
11 changes: 3 additions & 8 deletions src/components/TextData.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,13 @@ import TerminalOutput from "./TerminalOutput.vue";
defineProps<{
text: string;
height?: number;
}>();
</script>

<template>
<div
class="relative bg-zinc-700 dark:bg-zinc-600 rounded shadow-inner text-sm"
>
<TerminalOutput class="h-fit max-h-40 resize-y">
{{ text }}
</TerminalOutput>
</div>
<TerminalOutput class="h-fit max-h-40 resize-y">
{{ text }}
</TerminalOutput>
</template>

<style scoped>
Expand Down
4 changes: 3 additions & 1 deletion src/i18n/locales/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ files: No files | 1 file | {count} files
none: None
new_corpus: New corpus
fileName: Name
fileType: Type
type: Type
uploaded: Uploaded
lastModify: Last modified
fileSize: Size
Expand Down Expand Up @@ -175,6 +175,7 @@ docx: Microsoft Word
odt: OpenDocument Text
pdf: PDF
load: Load
not_loaded: Not loaded
file.archive: Archive
file.singles: Single files
name: Name
Expand Down Expand Up @@ -223,6 +224,7 @@ annotations.info: |
</p>
admin.page.subtitle: Administration
admin.goto: Shortcuts
admin.resources.help: In this administrative listing, you need to load detailed information manually, because loading everything takes a long time.
accessdenied: Access denied
accessdenied.contact: If you have questions, or you want to report a bug, please contact sb-info{'@'}svenska.gu.se. Thank you!
notfound: Page not found
Expand Down
4 changes: 3 additions & 1 deletion src/i18n/locales/sv.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ files: Inga filer | 1 fil | {count} filer
none: Inget
new_corpus: Ny korpus
fileName: Filnamn
fileType: Typ
type: Typ
uploaded: Uppladdad
lastModify: Senast ändrad
fileSize: Storlek
Expand Down Expand Up @@ -176,6 +176,7 @@ docx: Microsoft Word
odt: OpenDocument Text
pdf: PDF
load: Ladda in
not_loaded: Ej laddad
file.archive: Arkivfil
file.singles: Enskilda filer
name: Namn
Expand Down Expand Up @@ -225,6 +226,7 @@ annotations.info: |
</p>
admin.page.subtitle: Administration
admin.goto: Genvägar
admin.resources.help: I denna administrativa resurslista behöver du ladda in detaljerad resursinformation manuellt, eftersom det tar lång tid att ladda allt.
accessdenied: Åtkomst nekad
accessdenied.contact: Om du har frågor eller vill rapportera en bugg, kontakta gärna sb-info{'@'}svenska.gu.se. Tack!
notfound: Sidan kan inte hittas
Expand Down
83 changes: 83 additions & 0 deletions src/library/AdminResourcePreview.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<script setup lang="ts">
import { onMounted } from "vue";
import { isCorpus, type Resource } from "@/store/resource.store";
import TerminalOutput from "@/components/TerminalOutput.vue";
import useConfig from "@/corpus/config/config.composable";
import PendingContent from "@/spin/PendingContent.vue";
const props = defineProps<{
resourceId: string;
resource: Resource;
}>();
const { loadConfig } = useConfig(props.resourceId);
onMounted(() => {
if (isCorpus(props.resource) && !props.resource.config) loadConfig();
});
</script>

<template>
<div class="flex flex-wrap items-stretch text-sm">
<table v-if="resource" class="flex-1 flex">
<tbody>
<tr>
<th>{{ $t("type") }}</th>
<td>{{ $t(resource.type) }}</td>
</tr>

<template v-if="isCorpus(resource)">
<tr>
<th>{{ $t("texts") }}</th>
<td>
<div
v-for="source in resource.sources.slice(0, 3)"
:key="source.name"
>
{{ source.name }}
</div>
<div v-if="resource.sources.length > 3">
... ({{ $t("files", resource.sources.length) }})
</div>
</td>
</tr>
<tr>
<th>{{ $t("job.status") }}</th>
<td>
<table>
<tr
v-for="(status, jobType) in resource.status.status"
:key="jobType"
>
<th>{{ jobType }}</th>
<td>{{ $t(`job.status.${status}`) }}</td>
</tr>
</table>
</td>
</tr>
</template>
</tbody>
</table>
<PendingContent
v-if="isCorpus(resource)"
:on="`corpus/${resourceId}/config`"
class="flex-1"
>
<h3 class="font-bold">{{ $t("configuration") }}</h3>
<TerminalOutput class="max-h-80">
{{ resource.config }}
</TerminalOutput>
</PendingContent>
</div>
</template>

<style scoped>
* + tr > th,
* + tr > td {
@apply pt-2;
}
td th,
td td {
@apply pt-0;
}
</style>
86 changes: 74 additions & 12 deletions src/library/AdminResourcesView.vue
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
<script setup lang="ts">
import { watch } from "vue";
import { reactive, watch } from "vue";
import { useRouter } from "vue-router";
import LayoutSection from "@/components/LayoutSection.vue";
import PendingContent from "@/spin/PendingContent.vue";
import useResources from "./resources.composable";
import { useAuth } from "@/auth/auth.composable";
import PageTitle from "@/components/PageTitle.vue";
import { useResourceStore } from "@/store/resource.store";
import { isCorpus, useResourceStore } from "@/store/resource.store";
import useAdmin from "@/user/admin.composable";
import RouteButton from "@/components/RouteButton.vue";
import HelpBox from "@/components/HelpBox.vue";
import ActionButton from "@/components/ActionButton.vue";
import AdminResourcePreview from "./AdminResourcePreview.vue";
const router = useRouter();
const resourceStore = useResourceStore();
const { requireAuthentication, isAuthenticated } = useAuth();
const { adminMode } = useAdmin();
const { loadResourceIds } = useResources();
const { loadResourceIds, loadResource } = useResources();
const previewToggles = reactive<Record<string, boolean>>({});
requireAuthentication();
Expand All @@ -26,23 +30,81 @@ watch(adminMode, () => {
loadResourceIds();
}
});
async function load(resourceId: string) {
await loadResource(resourceId);
previewToggles[resourceId] = true;
}
</script>

<template>
<div v-if="adminMode">
<PageTitle subtitle="admin.page.subtitle">{{ $t("resources") }}</PageTitle>

<HelpBox>
{{ $t("admin.resources.help") }}
</HelpBox>

<LayoutSection v-if="isAuthenticated">
<PendingContent on="corpora" class="my-4 flex flex-col gap-3">
<RouteButton
<PendingContent on="corpora" class="my-4 flex flex-col gap-6">
<PendingContent
v-for="(resource, resourceId) of resourceStore.resources"
:key="resourceId"
:to="`/library/resource/${resourceId}`"
class="flex items-baseline gap-2"
:on="`corpus/${resourceId}/job`"
>
<header class="text-lg font-bold font-mono">
{{ resourceId }}
</header>
</RouteButton>
<div class="flex items-baseline gap-2">
<router-link :to="`/library/resource/${resourceId}`">
<header class="text-lg font-bold font-mono">
{{ resourceId }}
</header>
</router-link>

<ActionButton
v-if="!('type' in resource)"
@click.stop="load(resourceId)"
>
{{ $t("load") }}
</ActionButton>
<ActionButton
v-else-if="previewToggles[resourceId]"
@click.stop="previewToggles[resourceId] = false"
>
{{ $t("expand.close") }}
</ActionButton>
<ActionButton
v-else
@click.stop="previewToggles[resourceId] = true"
>
{{ $t("expand.open") }}
</ActionButton>

<!-- Show a few selected details if loaded -->
<div class="ml-4">
<div v-if="'type' in resource" class="flex gap-4">
{{ $t(resource.type) }}
<span
v-if="
isCorpus(resource) &&
Object.values(resource.status.status).some(
(status) => status == 'error',
)
"
>
{{ $t("job.status.error") }}
</span>
</div>
<div v-else class="italic opacity-75">
{{ $t("not_loaded") }}
</div>
</div>
</div>

<AdminResourcePreview
v-if="previewToggles[resourceId] && 'type' in resource"
:resource-id="resourceId"
:resource="resource"
/>
</PendingContent>
</PendingContent>
</LayoutSection>
</div>
Expand Down
8 changes: 4 additions & 4 deletions src/store/resource.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ export type Resource = {
export type Corpus = Resource & {
type: "corpus";
sources: FileMeta[];
config: ConfigOptions;
config?: ConfigOptions;
status: CorpusStatus;
exports: FileMeta[];
exports?: FileMeta[];
};

export type Metadata = Resource & {
Expand All @@ -31,9 +31,9 @@ export type Metadata = Resource & {

// User-defined type guards to help inform TypeScript
// See https://www.typescriptlang.org/docs/handbook/advanced-types.html#user-defined-type-guards
const isCorpus = (resource: Partial<Resource>): resource is Corpus =>
export const isCorpus = (resource: Partial<Resource>): resource is Corpus =>
resource.type == "corpus";
const isMetadata = (resource: Partial<Resource>): resource is Metadata =>
export const isMetadata = (resource: Partial<Resource>): resource is Metadata =>
resource.type == "metadata";

export const useResourceStore = defineStore("resource", () => {
Expand Down
8 changes: 7 additions & 1 deletion src/user/AdminModeBanner.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,15 @@ function disable() {
{{ $t("disable") }}
</ActionButton>
{{ $t("admin.goto") }}:
<router-link to="/admin/resources" class="text-indigo-600">
<router-link to="/admin/resources">
{{ $t("resources") }}
</router-link>
</div>
</div>
</template>

<style scoped>
a {
@apply text-indigo-600;
}
</style>

0 comments on commit d8f61e4

Please sign in to comment.