Phase B (items 1-6) of docs/AFFINE.md.
Properties: workspaces define custom page properties (text, number,
checkbox, date, select, multi-select, person, link) in the new
workspace_properties collection; pages keep their values in
pages.properties, checked against each property's type. The Info panel
under the title shows tags, custom and built-in properties, following
each property's visibility; the Info side panel shows them all, with the
page's collections and the journal. Settings gains Page properties and
Tags sections.
Tags: coloured, per workspace (tags collection, pages.tags); create from
the picker, rename, recolour, merge and delete. Search filters by tag.
All docs: GET /workspaces/{id}/docs lists the pages the caller can open
with their properties, narrowed by space, tag, collection or filter
rules evaluated on the server. The view shows a list, grid or cards,
groups and orders by any property, picks the properties shown, and acts
on several pages at once (tag, move, trash, collect).
Collections (page_collections): saved rules plus pages added or taken
out by hand, private to their creator until shared with the workspace,
listed in the sidebar.
Journals: one page per person and day in a private journal space
(spaces.journal_owner) that workspace admins do not see into, made on
first use. A week strip marks days with pages, new days can start from
a template, and dates in read mode open that day's journal.
The migration and schema snapshot, OpenAPI spec and generated Go, TS and
Dart types are updated (the Dart generator learns untyped values), the
mobile editor bundle is rebuilt, the new strings are translated into all
five languages, and the user guide covers the new features.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
705 lines
27 KiB
Vue
705 lines
27 KiB
Vue
<!-- SPDX-License-Identifier: AGPL-3.0-or-later -->
|
|
<script setup lang="ts">
|
|
import type { DocFilter, DocItem, DocList, LabelColor } from "@docwell/api-client";
|
|
import { DwButton, DwCallout, DwIcon } from "@docwell/ui";
|
|
import { computed, onBeforeUnmount, ref, watch } from "vue";
|
|
import { useI18n } from "vue-i18n";
|
|
import { useRoute, useRouter } from "vue-router";
|
|
import { useApi } from "../../api";
|
|
import FilterEditor from "../../components/FilterEditor.vue";
|
|
import LabelChip from "../../components/LabelChip.vue";
|
|
import OptionPicker, { type PickerOption } from "../../components/OptionPicker.vue";
|
|
import {
|
|
compareDocs,
|
|
formatDay,
|
|
groupableFields,
|
|
groupDocs,
|
|
localDay,
|
|
propertyOf,
|
|
propField,
|
|
valueList,
|
|
valueText,
|
|
type OrderBy,
|
|
type ValueContext,
|
|
} from "../../lib/properties";
|
|
import { useAuthStore } from "../../stores/auth";
|
|
import { useOrganizeStore } from "../../stores/organize";
|
|
import { spaceAtLeast, useSpacesStore } from "../../stores/spaces";
|
|
import { atLeast, useWorkspacesStore } from "../../stores/workspaces";
|
|
|
|
// All docs: every page of the workspace the caller can open, or one space's,
|
|
// one tag's or one collection's, laid out as a list, a grid or cards,
|
|
// grouped and ordered by any property.
|
|
const props = defineProps<{ id: string }>();
|
|
const emit = defineEmits<{ error: [err: unknown] }>();
|
|
const api = useApi();
|
|
const org = useOrganizeStore();
|
|
const spaces = useSpacesStore();
|
|
const workspaces = useWorkspacesStore();
|
|
const route = useRoute();
|
|
const router = useRouter();
|
|
const { t, locale } = useI18n();
|
|
|
|
const spaceId = computed(() => (typeof route.query.space === "string" ? route.query.space : ""));
|
|
const tagId = computed(() => (typeof route.query.tag === "string" ? route.query.tag : ""));
|
|
const collectionId = computed(() => (typeof route.query.collection === "string" ? route.query.collection : ""));
|
|
const collection = computed(() => (collectionId.value ? org.collection(collectionId.value) : undefined));
|
|
const ws = computed(() => workspaces.items.find((w) => w.id === props.id));
|
|
const canOrganize = computed(() => atLeast(ws.value?.role, "member"));
|
|
const auth = useAuthStore();
|
|
// Only the creator decides who sees a collection.
|
|
const isCreator = computed(() => !!collection.value && collection.value.creator === auth.user?.id);
|
|
|
|
// ---- View settings, remembered per workspace on this device ----
|
|
type Layout = "list" | "grid" | "cards";
|
|
interface ViewPrefs {
|
|
layout: Layout;
|
|
groupBy: string;
|
|
orderBy: OrderBy;
|
|
desc: boolean;
|
|
columns: string[];
|
|
}
|
|
const prefsKey = computed(() => `docwell.docs.${props.id}`);
|
|
const defaults: ViewPrefs = {
|
|
layout: "list",
|
|
groupBy: "",
|
|
orderBy: "updated",
|
|
desc: true,
|
|
columns: ["tags", "updated"],
|
|
};
|
|
function readPrefs(): ViewPrefs {
|
|
try {
|
|
return { ...defaults, ...(JSON.parse(localStorage.getItem(prefsKey.value) ?? "{}") as Partial<ViewPrefs>) };
|
|
} catch {
|
|
return { ...defaults };
|
|
}
|
|
}
|
|
const prefs = ref<ViewPrefs>(readPrefs());
|
|
watch(prefsKey, () => (prefs.value = readPrefs()));
|
|
watch(
|
|
prefs,
|
|
(p) => {
|
|
try {
|
|
localStorage.setItem(prefsKey.value, JSON.stringify(p));
|
|
} catch {
|
|
// per-device convenience only
|
|
}
|
|
},
|
|
{ deep: true },
|
|
);
|
|
|
|
// ---- Loading ----
|
|
const selected = ref(new Set<string>());
|
|
const draft = ref<DocFilter | null>(null);
|
|
const list = ref<DocList | null>(null);
|
|
const loading = ref(false);
|
|
const filter = ref<DocFilter>({ match: "all", rules: [] });
|
|
const filterOpen = ref(false);
|
|
|
|
let seq = 0;
|
|
async function load() {
|
|
const mine = ++seq;
|
|
loading.value = true;
|
|
try {
|
|
const res = await api.workspaces.docs(props.id, {
|
|
space: spaceId.value || undefined,
|
|
tag: tagId.value || undefined,
|
|
collection: collectionId.value || undefined,
|
|
filter: collectionId.value ? undefined : filter.value,
|
|
});
|
|
if (mine === seq) list.value = res;
|
|
} catch (e) {
|
|
if (mine === seq) emit("error", e);
|
|
} finally {
|
|
if (mine === seq) loading.value = false;
|
|
}
|
|
}
|
|
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
watch(
|
|
[() => props.id, spaceId, tagId, collectionId, () => collection.value?.updated],
|
|
() => {
|
|
selected.value = new Set();
|
|
void load();
|
|
},
|
|
{ immediate: true },
|
|
);
|
|
watch(
|
|
filter,
|
|
() => {
|
|
clearTimeout(timer);
|
|
timer = setTimeout(load, 300);
|
|
},
|
|
{ deep: true },
|
|
);
|
|
onBeforeUnmount(() => clearTimeout(timer));
|
|
// A new collection's rules start from the filter that was on screen.
|
|
watch(collectionId, () => {
|
|
filter.value = { match: "all", rules: [] };
|
|
filterOpen.value = false;
|
|
draft.value = null;
|
|
});
|
|
|
|
// ---- Grouping, ordering and printing ----
|
|
const ctx = computed<ValueContext>(() => ({
|
|
tags: org.tags,
|
|
people: list.value?.people ?? {},
|
|
spaces: Object.fromEntries(spaces.items.map((s) => [s.id, s.name])),
|
|
locale: locale.value,
|
|
}));
|
|
const sorted = computed(() =>
|
|
[...(list.value?.items ?? [])].sort((a, b) => compareDocs(a, b, prefs.value.orderBy, prefs.value.desc)),
|
|
);
|
|
const groups = computed(() => groupDocs(sorted.value, prefs.value.groupBy, org.properties, ctx.value));
|
|
|
|
const fieldLabel = (f: string) => propertyOf(f, org.properties)?.name ?? t(`filters.fields.${f}`);
|
|
const columnChoices = computed(() => [
|
|
"tags",
|
|
"space",
|
|
"updated",
|
|
"created",
|
|
"createdBy",
|
|
"lastEditedBy",
|
|
...org.properties.map(propField),
|
|
]);
|
|
const columns = computed(() => prefs.value.columns.filter((c) => columnChoices.value.includes(c)));
|
|
function toggleColumn(c: string) {
|
|
const cur = prefs.value.columns;
|
|
prefs.value.columns = cur.includes(c) ? cur.filter((x) => x !== c) : [...cur, c];
|
|
}
|
|
|
|
interface Cell {
|
|
chips?: { id: string; label: string; color?: LabelColor }[];
|
|
text?: string;
|
|
}
|
|
function cell(d: DocItem, f: string): Cell {
|
|
switch (f) {
|
|
case "tags":
|
|
return {
|
|
chips: d.tags
|
|
.map((id) => org.tag(id))
|
|
.filter((x) => !!x)
|
|
.map((x) => ({ id: x.id, label: x.name, color: x.color })),
|
|
};
|
|
case "space":
|
|
return { text: d.spaceName };
|
|
case "created":
|
|
case "updated":
|
|
return { text: formatDay(localDay(d[f]), locale.value) };
|
|
case "createdBy":
|
|
case "lastEditedBy":
|
|
return { text: ctx.value.people[d[f]] ?? "" };
|
|
}
|
|
const p = propertyOf(f, org.properties);
|
|
if (!p) return {};
|
|
const raw = d.properties[p.id];
|
|
if (p.type === "select" || p.type === "multi_select") {
|
|
return {
|
|
chips: valueList(raw)
|
|
.map((id) => p.options.find((o) => o.id === id))
|
|
.filter((o) => !!o)
|
|
.map((o) => ({ id: o.id, label: o.name, color: o.color })),
|
|
};
|
|
}
|
|
return { text: valueText(p, raw, ctx.value) };
|
|
}
|
|
const groupName = (label: string) => label || t("docs.noValue", { field: fieldLabel(prefs.value.groupBy) });
|
|
|
|
// ---- Title ----
|
|
const heading = computed(() => {
|
|
if (collection.value) return `${collection.value.icon ? `${collection.value.icon} ` : ""}${collection.value.name}`;
|
|
if (tagId.value) return t("docs.tagged", { tag: org.tag(tagId.value)?.name ?? "…" });
|
|
if (spaceId.value) return t("docs.inSpace", { space: spaces.space(spaceId.value)?.name ?? "…" });
|
|
return t("docs.title");
|
|
});
|
|
const count = computed(() => list.value?.items.length ?? 0);
|
|
|
|
// ---- Selection and bulk actions ----
|
|
const chosen = computed(() => (list.value?.items ?? []).filter((d) => selected.value.has(d.id)));
|
|
const editableChosen = computed(() => chosen.value.filter((d) => spaceAtLeast(d.role, "editor")));
|
|
function toggle(id: string) {
|
|
const s = new Set(selected.value);
|
|
if (s.has(id)) s.delete(id);
|
|
else s.add(id);
|
|
selected.value = s;
|
|
}
|
|
const allSelected = computed(() => count.value > 0 && selected.value.size === count.value);
|
|
function toggleAll() {
|
|
selected.value = allSelected.value ? new Set() : new Set(list.value?.items.map((d) => d.id));
|
|
}
|
|
const busy = ref(false);
|
|
async function bulk(action: () => Promise<unknown>, keepSelection = false) {
|
|
busy.value = true;
|
|
try {
|
|
await action();
|
|
} catch (e) {
|
|
emit("error", e);
|
|
} finally {
|
|
busy.value = false;
|
|
if (!keepSelection) selected.value = new Set();
|
|
await Promise.all([load(), org.loadTags().catch(() => {})]);
|
|
}
|
|
}
|
|
const tagOptions = computed<PickerOption[]>(() => org.tags.map((x) => ({ id: x.id, label: x.name, color: x.color })));
|
|
const addTag = (tag: string) =>
|
|
bulk(
|
|
() =>
|
|
Promise.all(
|
|
editableChosen.value
|
|
.filter((d) => !d.tags.includes(tag))
|
|
.map((d) => api.pages.update(d.id, { tags: [...d.tags, tag] })),
|
|
),
|
|
true,
|
|
);
|
|
const createAndAddTag = (name: string) =>
|
|
bulk(async () => {
|
|
const tag = await org.createTag(name);
|
|
await Promise.all(editableChosen.value.map((d) => api.pages.update(d.id, { tags: [...d.tags, tag.id] })));
|
|
}, true);
|
|
function trashSelected() {
|
|
if (!confirm(t("docs.confirmTrash", { n: editableChosen.value.length }, editableChosen.value.length))) return;
|
|
const touched = new Set(editableChosen.value.map((d) => d.space));
|
|
void bulk(async () => {
|
|
for (const d of editableChosen.value) await api.pages.trash(d.id);
|
|
await Promise.all([...touched].map((s) => spaces.loadTree(s)));
|
|
});
|
|
}
|
|
|
|
// Moving: every chosen page in the same space, under a page of it (or its top level).
|
|
const moveSpace = computed(() => {
|
|
const ids = new Set(editableChosen.value.map((d) => d.space));
|
|
return ids.size === 1 && editableChosen.value.length === chosen.value.length ? [...ids][0]! : "";
|
|
});
|
|
const moveTargets = computed(() => {
|
|
if (!moveSpace.value) return [];
|
|
const moving = new Set(chosen.value.map((d) => d.id));
|
|
const nodes = spaces.trees[moveSpace.value] ?? [];
|
|
const parentOf = new Map(nodes.map((n) => [n.id, n.parent]));
|
|
const inside = (id: string) => {
|
|
for (let p: string | undefined = id; p; p = parentOf.get(p)) if (moving.has(p)) return true;
|
|
return false;
|
|
};
|
|
return nodes.filter((n) => !inside(n.id));
|
|
});
|
|
const moveTo = ref("__none");
|
|
function move() {
|
|
const parent = moveTo.value === "__top" ? "" : moveTo.value;
|
|
if (moveTo.value === "__none") return;
|
|
const space = moveSpace.value;
|
|
moveTo.value = "__none";
|
|
void bulk(async () => {
|
|
for (const d of chosen.value) {
|
|
await spaces.move(space, d.id, parent, spaces.childrenOf(space, parent).filter((n) => n.id !== d.id).length);
|
|
}
|
|
});
|
|
}
|
|
|
|
const collectionOptions = computed<PickerOption[]>(() =>
|
|
org.collections.filter((c) => c.canEdit).map((c) => ({ id: c.id, label: `${c.icon ? `${c.icon} ` : ""}${c.name}` })),
|
|
);
|
|
const addToCollection = (id: string) =>
|
|
bulk(async () => {
|
|
for (const d of chosen.value) await org.setCollectionPage(id, d.id, true);
|
|
}, true);
|
|
const removeFromCollection = () =>
|
|
bulk(async () => {
|
|
for (const d of chosen.value) await org.setCollectionPage(collectionId.value, d.id, false);
|
|
});
|
|
|
|
// ---- Collections ----
|
|
async function saveAsCollection() {
|
|
const name = prompt(t("collections.namePrompt"))?.trim();
|
|
if (!name) return;
|
|
const rules = [...filter.value.rules];
|
|
if (tagId.value) rules.push({ field: "tags", op: "contains", value: [tagId.value] });
|
|
if (spaceId.value) rules.push({ field: "space", op: "contains", value: [spaceId.value] });
|
|
try {
|
|
const c = await org.createCollection({ name, filter: { match: filter.value.match, rules } });
|
|
router.push({ name: "docs", params: { id: props.id }, query: { collection: c.id } });
|
|
} catch (e) {
|
|
emit("error", e);
|
|
}
|
|
}
|
|
const rules = computed({
|
|
get: () => draft.value ?? collection.value?.filter ?? { match: "all" as const, rules: [] },
|
|
set: (f: DocFilter) => (draft.value = f),
|
|
});
|
|
const saveRules = () =>
|
|
bulk(async () => {
|
|
if (!draft.value || !collection.value) return;
|
|
await org.updateCollection(collection.value.id, { filter: draft.value });
|
|
draft.value = null;
|
|
}, true);
|
|
async function renameCollection() {
|
|
const c = collection.value;
|
|
const name = c && prompt(t("collections.namePrompt"), c.name)?.trim();
|
|
if (!c || !name || name === c.name) return;
|
|
await bulk(() => org.updateCollection(c.id, { name }), true);
|
|
}
|
|
const toggleShared = () =>
|
|
bulk(() => org.updateCollection(collection.value!.id, { shared: !collection.value!.shared }), true);
|
|
async function deleteCollection() {
|
|
const c = collection.value;
|
|
if (!c || !confirm(t("collections.confirmDelete", { name: c.name }))) return;
|
|
try {
|
|
await org.removeCollection(c.id);
|
|
router.replace({ name: "docs", params: { id: props.id } });
|
|
} catch (e) {
|
|
emit("error", e);
|
|
}
|
|
}
|
|
|
|
// ---- New page here ----
|
|
const newPageSpace = computed(() => {
|
|
if (spaceId.value) return spaces.canEdit(spaceId.value) ? spaceId.value : "";
|
|
const active = spaces.active.space;
|
|
return spaces.canEdit(active) ? active : (spaces.items.find((s) => spaces.canEdit(s.id) && !s.journal)?.id ?? "");
|
|
});
|
|
async function newPage() {
|
|
try {
|
|
const page = await spaces.createPage(newPageSpace.value);
|
|
if (tagId.value) await api.pages.update(page.id, { tags: [tagId.value] });
|
|
if (collection.value?.canEdit) await org.setCollectionPage(collection.value.id, page.id, true);
|
|
router.push({ name: "page", params: { id: page.id } });
|
|
} catch (e) {
|
|
emit("error", e);
|
|
}
|
|
}
|
|
|
|
const filterCount = computed(() => (collectionId.value ? rules.value.rules.length : filter.value.rules.length));
|
|
const tab = (on: boolean) =>
|
|
`flex h-control-sm cursor-pointer items-center gap-1.5 rounded-sm px-2 text-ui-sm ${on ? "bg-surface-hover font-semibold text-ink" : "text-ink-muted hover:bg-surface-hover hover:text-ink"}`;
|
|
const layouts: { id: Layout; icon: "list" | "grid" | "cards" }[] = [
|
|
{ id: "list", icon: "list" },
|
|
{ id: "grid", icon: "grid" },
|
|
{ id: "cards", icon: "cards" },
|
|
];
|
|
const columnsOpen = ref(false);
|
|
</script>
|
|
|
|
<template>
|
|
<Teleport defer to="#app-header">
|
|
<h1 class="min-w-0 flex-1 truncate text-ui-md font-semibold text-ink" data-testid="docs-title">{{ heading }}</h1>
|
|
<span class="hidden text-ui-sm text-ink-muted tabular-nums sm:inline">{{
|
|
$t("docs.count", { n: count }, count)
|
|
}}</span>
|
|
<DwButton v-if="newPageSpace" variant="ghost" size="sm" icon="plus" @click="newPage">
|
|
<span class="sr-only sm:not-sr-only">{{ $t("app.newPage") }}</span>
|
|
</DwButton>
|
|
</Teleport>
|
|
|
|
<div class="mx-auto max-w-6xl px-4 pt-4 pb-16 sm:px-8" data-testid="docs-view">
|
|
<!-- Tags as quick filters; a collection keeps its own rules instead. -->
|
|
<nav
|
|
v-if="!collectionId && org.tags.length"
|
|
class="mb-3 flex flex-wrap items-center gap-1"
|
|
:aria-label="$t('properties.tags')"
|
|
>
|
|
<RouterLink :to="{ query: { ...route.query, tag: undefined } }" :class="tab(!tagId)">{{
|
|
$t("docs.allTags")
|
|
}}</RouterLink>
|
|
<RouterLink
|
|
v-for="tg in org.tags"
|
|
:key="tg.id"
|
|
:to="{ query: { ...route.query, tag: tg.id } }"
|
|
:class="tab(tagId === tg.id)"
|
|
>
|
|
<span class="size-2 rounded-full" :data-color="tg.color || 'gray'" style="background: var(--dw-c)" />
|
|
{{ tg.name }}
|
|
<span class="text-ink-faint tabular-nums">{{ tg.pages }}</span>
|
|
</RouterLink>
|
|
</nav>
|
|
|
|
<div
|
|
v-if="collection"
|
|
class="mb-3 flex flex-wrap items-center gap-2 text-ui-sm text-ink-muted"
|
|
data-testid="collection-bar"
|
|
>
|
|
<DwIcon name="layers" :size="14" />
|
|
<span>{{ collection.shared ? $t("collections.sharedNote") : $t("collections.privateNote") }}</span>
|
|
<template v-if="collection.canEdit">
|
|
<button class="cursor-pointer hover:text-ink hover:underline" @click="renameCollection">
|
|
{{ $t("collections.rename") }}
|
|
</button>
|
|
<button v-if="isCreator" class="cursor-pointer hover:text-ink hover:underline" @click="toggleShared">
|
|
{{ collection.shared ? $t("collections.makePrivate") : $t("collections.share") }}
|
|
</button>
|
|
<button class="cursor-pointer text-danger hover:underline" @click="deleteCollection">
|
|
{{ $t("collections.delete") }}
|
|
</button>
|
|
</template>
|
|
</div>
|
|
|
|
<div class="flex flex-wrap items-center gap-1.5">
|
|
<DwButton
|
|
size="sm"
|
|
variant="ghost"
|
|
icon="filter"
|
|
:class="{ 'bg-surface-hover text-ink': filterOpen }"
|
|
:aria-pressed="filterOpen"
|
|
data-testid="filter-toggle"
|
|
@click="filterOpen = !filterOpen"
|
|
>
|
|
{{ collectionId ? $t("collections.rules") : $t("docs.filter") }}
|
|
<span v-if="filterCount" class="tabular-nums">{{ filterCount }}</span>
|
|
</DwButton>
|
|
<span class="flex rounded-sm border border-line" role="group" :aria-label="$t('docs.layout')">
|
|
<button
|
|
v-for="l in layouts"
|
|
:key="l.id"
|
|
type="button"
|
|
class="grid size-control-sm cursor-pointer place-items-center text-ink-muted hover:text-ink"
|
|
:class="{ 'bg-surface-hover text-ink': prefs.layout === l.id }"
|
|
:aria-pressed="prefs.layout === l.id"
|
|
:aria-label="$t(`docs.layouts.${l.id}`)"
|
|
:title="$t(`docs.layouts.${l.id}`)"
|
|
@click="prefs.layout = l.id"
|
|
>
|
|
<DwIcon :name="l.icon" :size="16" />
|
|
</button>
|
|
</span>
|
|
<label class="flex items-center gap-1 text-ui-sm text-ink-muted">
|
|
{{ $t("docs.groupBy") }}
|
|
<select v-model="prefs.groupBy" class="dw-input h-7" data-testid="group-by">
|
|
<option value="">{{ $t("docs.noGroup") }}</option>
|
|
<option v-for="f in groupableFields(org.properties)" :key="f" :value="f">{{ fieldLabel(f) }}</option>
|
|
</select>
|
|
</label>
|
|
<label class="flex items-center gap-1 text-ui-sm text-ink-muted">
|
|
{{ $t("docs.order") }}
|
|
<select v-model="prefs.orderBy" class="dw-input h-7">
|
|
<option v-for="o in ['updated', 'created', 'title'] as const" :key="o" :value="o">
|
|
{{ $t(`docs.orders.${o}`) }}
|
|
</option>
|
|
</select>
|
|
</label>
|
|
<DwButton
|
|
size="sm"
|
|
variant="ghost"
|
|
:icon="prefs.desc ? 'arrow-down' : 'arrow-up'"
|
|
:aria-label="prefs.desc ? $t('docs.descending') : $t('docs.ascending')"
|
|
:title="prefs.desc ? $t('docs.descending') : $t('docs.ascending')"
|
|
@click="prefs.desc = !prefs.desc"
|
|
/>
|
|
<div class="relative">
|
|
<DwButton
|
|
size="sm"
|
|
variant="ghost"
|
|
icon="sliders"
|
|
:aria-expanded="columnsOpen"
|
|
@click="columnsOpen = !columnsOpen"
|
|
>{{ $t("docs.columns") }}</DwButton
|
|
>
|
|
<div
|
|
v-if="columnsOpen"
|
|
class="absolute top-full left-0 z-40 mt-1 w-56 rounded-md border border-line bg-surface-raised p-2 shadow-menu"
|
|
@keydown.escape="columnsOpen = false"
|
|
>
|
|
<label v-for="c in columnChoices" :key="c" class="flex items-center gap-2 py-0.5 text-ui-md">
|
|
<input type="checkbox" :checked="columns.includes(c)" @change="toggleColumn(c)" />
|
|
<span class="truncate">{{ fieldLabel(c) }}</span>
|
|
</label>
|
|
<DwButton size="sm" variant="ghost" class="mt-1" @click="columnsOpen = false">{{
|
|
$t("common.done")
|
|
}}</DwButton>
|
|
</div>
|
|
</div>
|
|
<span class="flex-1" />
|
|
<DwButton
|
|
v-if="!collectionId && canOrganize && (filter.rules.length || tagId || spaceId)"
|
|
size="sm"
|
|
icon="layers"
|
|
data-testid="save-collection"
|
|
@click="saveAsCollection"
|
|
>{{ $t("collections.saveAs") }}</DwButton
|
|
>
|
|
</div>
|
|
|
|
<div v-if="filterOpen" class="mt-3 rounded-md border border-line bg-surface-sunken p-3">
|
|
<template v-if="collection">
|
|
<p class="mb-2 text-ui-sm text-ink-muted">{{ $t("collections.rulesHint") }}</p>
|
|
<FilterEditor
|
|
v-model="rules"
|
|
:workspace="id"
|
|
:spaces="spaces.items"
|
|
:people="list?.people ?? {}"
|
|
:class="{ 'pointer-events-none opacity-70': !collection.canEdit }"
|
|
/>
|
|
<div v-if="draft && collection.canEdit" class="mt-2 flex gap-2">
|
|
<DwButton size="sm" variant="primary" :disabled="busy" @click="saveRules">{{
|
|
$t("collections.saveRules")
|
|
}}</DwButton>
|
|
<DwButton size="sm" variant="ghost" @click="draft = null">{{ $t("collections.revert") }}</DwButton>
|
|
</div>
|
|
</template>
|
|
<FilterEditor v-else v-model="filter" :workspace="id" :spaces="spaces.items" :people="list?.people ?? {}" />
|
|
</div>
|
|
|
|
<!-- Bulk actions for the chosen pages. -->
|
|
<div
|
|
v-if="selected.size"
|
|
class="sticky top-0 z-20 mt-3 flex flex-wrap items-center gap-2 rounded-md border border-line bg-surface-raised px-3 py-2 shadow-menu"
|
|
data-testid="bulk-bar"
|
|
>
|
|
<span class="text-ui-sm font-semibold">{{ $t("docs.selected", { n: selected.size }, selected.size) }}</span>
|
|
<template v-if="editableChosen.length">
|
|
<OptionPicker
|
|
:options="tagOptions"
|
|
:selected="[]"
|
|
:label="$t('properties.addTag')"
|
|
:creatable="canOrganize"
|
|
:create-label="(name: string) => $t('properties.createTag', { name })"
|
|
:disabled="busy"
|
|
@toggle="addTag"
|
|
@create="createAndAddTag"
|
|
/>
|
|
<label v-if="moveSpace" class="flex items-center gap-1 text-ui-sm text-ink-muted">
|
|
<select
|
|
v-model="moveTo"
|
|
class="dw-input h-7 max-w-56"
|
|
:disabled="busy"
|
|
:aria-label="$t('docs.moveTo')"
|
|
@change="move"
|
|
>
|
|
<option value="__none" disabled>{{ $t("docs.moveTo") }}</option>
|
|
<option value="__top">{{ $t("docs.topLevel", { space: spaces.space(moveSpace)?.name ?? "" }) }}</option>
|
|
<option v-for="n in moveTargets" :key="n.id" :value="n.id">{{ n.title || $t("home.untitled") }}</option>
|
|
</select>
|
|
</label>
|
|
</template>
|
|
<OptionPicker
|
|
v-if="collectionOptions.length"
|
|
:options="collectionOptions"
|
|
:selected="[]"
|
|
:multiple="false"
|
|
:label="$t('collections.addTo')"
|
|
:disabled="busy"
|
|
@toggle="addToCollection"
|
|
/>
|
|
<DwButton v-if="collection?.canEdit" size="sm" variant="ghost" :disabled="busy" @click="removeFromCollection">{{
|
|
$t("collections.removeFrom")
|
|
}}</DwButton>
|
|
<DwButton
|
|
v-if="editableChosen.length"
|
|
size="sm"
|
|
variant="ghost"
|
|
icon="trash"
|
|
:disabled="busy"
|
|
@click="trashSelected"
|
|
>{{ $t("page.moveToTrash") }}</DwButton
|
|
>
|
|
<span class="flex-1" />
|
|
<DwButton size="sm" variant="ghost" @click="selected = new Set()">{{ $t("docs.clearSelection") }}</DwButton>
|
|
</div>
|
|
|
|
<DwCallout v-if="list && !count && !loading" tone="info" size="ui" class="mt-6">
|
|
{{ filterCount || tagId ? $t("docs.noneFiltered") : $t("docs.none") }}
|
|
</DwCallout>
|
|
|
|
<label v-if="count && prefs.layout === 'list'" class="mt-4 flex items-center gap-2 px-3 text-ui-sm text-ink-muted">
|
|
<input type="checkbox" :checked="allSelected" data-testid="select-all" @change="toggleAll" />
|
|
{{ $t("docs.selectAll") }}
|
|
</label>
|
|
|
|
<section v-for="g in groups" :key="g.group.key" class="mt-4" data-testid="docs-group">
|
|
<h2 v-if="prefs.groupBy" class="mb-2 flex items-center gap-2 px-1 text-ui-sm font-medium text-ink-muted">
|
|
<LabelChip v-if="g.group.color !== undefined && g.group.key" :label="g.group.label" :color="g.group.color" />
|
|
<span v-else>{{ groupName(g.group.label) }}</span>
|
|
<span class="text-ink-faint tabular-nums">{{ g.items.length }}</span>
|
|
</h2>
|
|
|
|
<ul v-if="prefs.layout === 'list'" class="divide-y divide-line rounded-md border border-line bg-surface-raised">
|
|
<li
|
|
v-for="d in g.items"
|
|
:key="d.id"
|
|
class="flex min-h-11 flex-wrap items-center gap-x-3 gap-y-1 px-3 py-1.5"
|
|
data-testid="doc-row"
|
|
>
|
|
<input
|
|
type="checkbox"
|
|
:checked="selected.has(d.id)"
|
|
:aria-label="$t('docs.select', { title: d.title || $t('home.untitled') })"
|
|
@change="toggle(d.id)"
|
|
/>
|
|
<RouterLink
|
|
:to="{ name: 'page', params: { id: d.id } }"
|
|
class="flex min-w-40 flex-1 items-center gap-2 rounded-xs py-1 text-ink hover:text-accent"
|
|
>
|
|
<span v-if="d.icon" class="w-4 text-center">{{ d.icon }}</span>
|
|
<DwIcon v-else :name="d.journalDate ? 'journal' : 'page'" :size="16" class="text-ink-muted" />
|
|
<span class="truncate">{{ d.title || $t("home.untitled") }}</span>
|
|
<DwIcon
|
|
v-if="d.isTemplate"
|
|
name="file"
|
|
:size="12"
|
|
class="text-ink-faint"
|
|
:label="$t('properties.template')"
|
|
/>
|
|
</RouterLink>
|
|
<span
|
|
v-for="c in columns"
|
|
:key="c"
|
|
class="flex max-w-64 min-w-0 flex-wrap items-center gap-1 text-ui-sm text-ink-muted"
|
|
:title="fieldLabel(c)"
|
|
>
|
|
<template v-if="cell(d, c).chips">
|
|
<LabelChip v-for="ch in cell(d, c).chips" :key="ch.id" :label="ch.label" :color="ch.color" />
|
|
</template>
|
|
<span v-else class="truncate">{{ cell(d, c).text }}</span>
|
|
</span>
|
|
</li>
|
|
</ul>
|
|
|
|
<ul
|
|
v-else
|
|
class="grid gap-3"
|
|
:class="
|
|
prefs.layout === 'grid'
|
|
? 'grid-cols-[repeat(auto-fill,minmax(11rem,1fr))]'
|
|
: 'grid-cols-[repeat(auto-fill,minmax(17rem,1fr))]'
|
|
"
|
|
>
|
|
<li
|
|
v-for="d in g.items"
|
|
:key="d.id"
|
|
class="group relative flex flex-col gap-2 rounded-md border border-line bg-surface-raised p-3 hover:border-line-strong"
|
|
:class="{ 'ring-2 ring-focus-ring': selected.has(d.id), 'min-h-36': prefs.layout === 'cards' }"
|
|
data-testid="doc-card"
|
|
>
|
|
<input
|
|
type="checkbox"
|
|
class="absolute top-2 right-2 opacity-0 group-hover:opacity-100 focus:opacity-100"
|
|
:class="{ 'opacity-100': selected.has(d.id) }"
|
|
:checked="selected.has(d.id)"
|
|
:aria-label="$t('docs.select', { title: d.title || $t('home.untitled') })"
|
|
@change="toggle(d.id)"
|
|
/>
|
|
<RouterLink
|
|
:to="{ name: 'page', params: { id: d.id } }"
|
|
class="flex items-start gap-2 pr-5 text-ink hover:text-accent"
|
|
>
|
|
<span v-if="d.icon" class="text-lg leading-6">{{ d.icon }}</span>
|
|
<DwIcon v-else :name="d.journalDate ? 'journal' : 'page'" :size="18" class="mt-0.5 text-ink-muted" />
|
|
<span class="line-clamp-2 font-medium">{{ d.title || $t("home.untitled") }}</span>
|
|
</RouterLink>
|
|
<p class="text-ui-xs text-ink-faint">{{ d.spaceName }}</p>
|
|
<dl class="mt-auto space-y-1">
|
|
<div
|
|
v-for="c in prefs.layout === 'cards' ? columns : columns.slice(0, 2)"
|
|
:key="c"
|
|
class="flex min-w-0 flex-wrap items-center gap-1 text-ui-sm text-ink-muted"
|
|
>
|
|
<dt class="sr-only">{{ fieldLabel(c) }}</dt>
|
|
<dd class="flex min-w-0 flex-wrap items-center gap-1">
|
|
<template v-if="cell(d, c).chips">
|
|
<LabelChip v-for="ch in cell(d, c).chips" :key="ch.id" :label="ch.label" :color="ch.color" />
|
|
</template>
|
|
<span v-else class="truncate">{{ cell(d, c).text }}</span>
|
|
</dd>
|
|
</div>
|
|
</dl>
|
|
</li>
|
|
</ul>
|
|
</section>
|
|
</div>
|
|
</template>
|