Skip to content

πŸ“š The open-source, offline-first Notion, Obsidian & Confluence alternative. Advanced Markdown, multi-tenant teams, OIDC/SSO, and local S3 backups. Deploy in one command.

Test map

Smaug673987883acdfe54
diff --git a/frontend/app/.env.production b/frontend/app/.env.production
index a11ac8ed..30dc16bf 100644
--- a/frontend/app/.env.production
+++ b/frontend/app/.env.production
@@ -1,2 +1,2 @@
-VITE_BASE_API="https://api.alexandrie-hub.fr"
-VITE_BASE_CDN="https://cdn.alexandrie-hub.fr"
\ No newline at end of file
+VITE_BASE_API="http://localhost:8201"
+VITE_BASE_CDN="http://localhost:9000/alexandrie"
\ No newline at end of file
diff --git a/frontend/app/composables/useNodesTree.ts b/frontend/app/composables/useNodesTree.ts
index be5dee6b..a4b2b74f 100644
--- a/frontend/app/composables/useNodesTree.ts
+++ b/frontend/app/composables/useNodesTree.ts
@@ -55,12 +55,7 @@ function useSidebarTree() {
nodes = computed(() =>
isReady.value
? nodesStore.nodes
- .sort((a, b) => {
- if ((a.order ?? 0) !== (b.order ?? 0)) return (a.order ?? 0) - (b.order ?? 0);
- return a.name.localeCompare(b.name);
- })
- .sort((a, b) => (a.order ?? 0) - (b.order ?? 0) || a.name.localeCompare(b.name))
- .map(node => ({
+ .map<Item<Node>>(node => ({
id: node.id,
parent_id: node.role !== 1 ? node.parent_id || '' : '',
label: node.name,
@@ -69,6 +64,11 @@ function useSidebarTree() {
data: node,
show: ref(getCollapseState(node.id)),
}))
+ .sort((a, b) => {
+ if ((a.data.order ?? 0) !== (b.data.order ?? 0)) return (a.data.order ?? 0) - (b.data.order ?? 0);
+ return a.data.name.localeCompare(b.data.name);
+ })
+ .sort((a, b) => (a.data.order ?? 0) - (b.data.order ?? 0) || a.data.name.localeCompare(b.data.name))
: [],
);
}
diff --git a/frontend/app/pages/dashboard/home.vue b/frontend/app/pages/dashboard/home.vue
index ed028590..d4b2d635 100644
--- a/frontend/app/pages/dashboard/home.vue
+++ b/frontend/app/pages/dashboard/home.vue
@@ -9,7 +9,7 @@
<div class="search-container">
<input v-model="searchQuery" type="text" placeholder="Search documents..." class="search-input" />
- <div v-if="results.length" class="results">
+ <div v-if="results?.length" class="results">
<NuxtLink v-for="result in results" :key="result.id" class="result" :to="`/dashboard/docs/${result.id}`">
<Icon
:name="category(result.parent_id)?.icon || 'files'"
@@ -64,11 +64,15 @@ const results = computed(() => {
const tags = Array.isArray(doc.tags) ? doc.tags.join(' ') : String(doc.tags || '');
return tokens.every(t => name.toLowerCase().includes(t) || tags.toLowerCase().includes(t));
})
- .slice(0, 5);
+ .toArray()
+ ?.slice(0, 5);
});
const category = (id?: string) => nodesStore.getById(id || '');
const recentDocuments = computed(() => {
- return nodesStore.getAll.toSorted((a, b) => b.updated_timestamp - a.updated_timestamp).slice(0, 3);
+ return nodesStore.getAll
+ .toArray()
+ ?.toSorted((a, b) => b.updated_timestamp - a.updated_timestamp)
+ .slice(0, 3);
});
</script>
<style scoped lang="scss">
diff --git a/frontend/app/stores/collection.ts b/frontend/app/stores/collection.ts
new file mode 100644
index 00000000..bc33c078
--- /dev/null
+++ b/frontend/app/stores/collection.ts
@@ -0,0 +1,140 @@
+type CollectionFunction<K, V> = (value: V, key: K, collection: Collection<K, V>) => boolean;
+
+export class Collection<K, V> extends Map<K, V> {
+ public static readonly default: typeof Collection = Collection;
+
+ public hasAllKeys(keys: K[]): boolean {
+ return keys.every(k => this.has(k));
+ }
+ public hasAnyKey(keys: K[]): boolean {
+ return keys.some(k => this.has(k));
+ }
+
+ public isUnique(key: K): boolean {
+ const valOne = this.get(key);
+ if (!valOne) throw new TypeError('Cannot find value for key: ' + key);
+ // for (const val of this.filter()) {
+ // if (val === valOne) return false;
+ // }
+
+ if (this.filter((v: V) => v === valOne).size <= 1) return true;
+ return false;
+ }
+ public nextKey(key: K): K | undefined {
+ const keys = [...this.keys()];
+ const index = keys.indexOf(key);
+ if (index === -1 || index === keys.length - 1) return undefined;
+ return keys[index + 1];
+ }
+ public next(key: K): V | undefined {
+ const nextKey = this.nextKey(key);
+ if (!nextKey) return undefined;
+ return this.get(nextKey);
+ }
+ public previousKey(key: K): K | undefined {
+ const keys = [...this.keys()];
+ const index = keys.indexOf(key);
+ if (index <= 0) return undefined;
+ return keys[index - 1];
+ }
+ public previous(key: K): V | undefined {
+ const previousKey = this.previousKey(key);
+ if (!previousKey) return undefined;
+ return this.get(previousKey);
+ }
+ public firstKey(): K | null {
+ const firstKey = this.keys().next().value;
+ if (firstKey) return firstKey;
+ return null;
+ }
+
+ public first(): V | undefined {
+ if (this.values().next().value) return this.values().next().value;
+ return undefined;
+ }
+
+ public lastKey(): K | undefined {
+ const arr = [...this.keys()];
+ if (arr[arr.length - 1]) return arr[arr.length - 1];
+ return undefined;
+ }
+ public last(): V | undefined {
+ const arr = [...this.values()];
+ if (arr[arr.length - 1]) return arr[arr.length - 1];
+ return undefined;
+ }
+
+ public find(fn: (value: V, key: K, collection: this) => boolean, thisArg?: unknown): V | undefined {
+ if (typeof thisArg !== 'undefined') fn = fn.bind(thisArg);
+ for (const [key, val] of this) {
+ if (fn(val, key, this)) return val;
+ }
+ return undefined;
+ }
+
+ public map<S = unknown>(fn: (value: V, key: K, collection: this) => S, thisArg?: unknown): Array<S> {
+ const newArray = [];
+ if (typeof thisArg !== 'undefined') fn = fn.bind(thisArg);
+ for (const [key, val] of this) {
+ newArray.push(fn(val, key, this));
+ }
+ return newArray;
+ }
+
+ filter(f: CollectionFunction<K, V>): Collection<K, V> {
+ const newCollection = new Collection<K, V>();
+ for (const [k, v] of this) {
+ if (f(v, k, this)) newCollection.set(k, v);
+ }
+ return newCollection;
+ }
+
+ public keysList(): K[] | null {
+ const list: K[] = [];
+ for (const k of this.keys()) {
+ list.push(k);
+ }
+ if (list) return list;
+ return null;
+ }
+
+ public valuesList(): V[] | null {
+ const list: V[] = [];
+ for (const v of this.values()) {
+ list.push(v);
+ }
+ if (list) return list;
+ return null;
+ }
+
+ public merge(...maps: Array<Collection<K, V> | Map<K, V>>): Collection<K, V> {
+ for (const map of maps) {
+ for (const [k, v] of map) {
+ this.set(k, v);
+ }
+ }
+ return this;
+ }
+
+ public toArray(): Array<V> | null {
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
+ const that: this = this;
+ if (that == null) return that as null;
+ const newArray = [];
+ for (const [_, v] of that) {
+ newArray.push(v);
+ }
+ return newArray;
+ }
+ public toJSON() {
+ const obj = Object.fromEntries(this);
+ return obj;
+ }
+
+ public each(fn: (value: V, key: K, collection: this) => void, thisArg?: unknown): this {
+ this.forEach(fn as (value: V, key: K, map: Map<K, V>) => void, thisArg);
+ return this;
+ }
+}
+
+export default Collection;
diff --git a/frontend/app/stores/nodes.store.ts b/frontend/app/stores/nodes.store.ts
index 8ba082b2..87cfc25a 100644
--- a/frontend/app/stores/nodes.store.ts
+++ b/frontend/app/stores/nodes.store.ts
@@ -1,4 +1,5 @@
import { makeRequest, type FetchOptions } from './_utils';
+import { Collection } from './collection';
import type { DB_Node, Node, Permission } from './db_strustures';
interface SearchOptions {
@@ -12,7 +13,7 @@ interface SearchOptions {
export const useNodesStore = defineStore('nodes', {
state: () => ({
- nodes: [] as Array<Node | Node>,
+ nodes: new Collection<string, Node>(),
public_nodes: [] as Node[],
allTags: [] as string[],
isFetching: false,
@@ -20,7 +21,7 @@ export const useNodesStore = defineStore('nodes', {
getters: {
getAll: state => state.nodes,
getAllTags: state => state.allTags,
- getById: state => (id: string) => state.nodes.find((d: Node) => d.id == id),
+ getById: state => (id: string) => state.nodes.get(id),
getByCategories: state => (category: string) => state.nodes.filter(d => d.parent_id == category),
getParents: state => state.nodes.filter(c => !c.parent_id),
getChilds: state => (id: string) => state.nodes.filter(c => c.parent_id == id),
@@ -33,25 +34,21 @@ export const useNodesStore = defineStore('nodes', {
const checkDescendants = (currentNode: Node): boolean => {
const children = state.nodes.filter(d => d.parent_id === currentNode.id);
for (const child of children) {
- if (child.id === descendantId) return true;
- if (checkDescendants(child)) return true;
+ if (child[0] === descendantId) return true;
+ if (checkDescendants(child[1])) return true;
}
return false;
};
return checkDescendants(node);
},
getNext: state => (node?: Node) => {
- const cnodes = state.nodes.filter(d => d.parent_id == node?.parent_id && d.role === 3);
- const index = cnodes.findIndex(d => d.id == node?.id);
- if (index == -1) return;
- return cnodes[index + 1];
+ if (!node) return state.nodes.first();
+ return state.nodes.next(node.id);
},
getPrevious: state => (node?: Node) => {
- const cnodes = state.nodes.filter(d => d.parent_id == node?.parent_id && d.role === 3);
- const index = cnodes.findIndex(d => d.id == node?.id);
- if (index == -1) return;
- return cnodes[index - 1];
+ if (!node) return state.nodes.last();
+ return state.nodes.previous(node.id);
},
getAllChildrens: state => (id: string) => {
@@ -85,7 +82,7 @@ export const useNodesStore = defineStore('nodes', {
},
search: state => (options: SearchOptions) => {
const { query, fromDate, toDate, dateType, tags, category } = options;
- let filtered = [...state.nodes];
+ let filtered = state.nodes.toArray()!;
if (query) {
filtered = filtered.filter(node => {
const nodeContent = `${node.name} ${node.description} ${node.tags}`.toLowerCase();
@@ -154,30 +151,31 @@ export const useNodesStore = defineStore('nodes', {
});
this.allTags = Array.from(tags).sort();
},
- async fetch<T extends FetchOptions>(opts?: T): Promise<'id' extends keyof T ? Node : Node[]> {
- if (opts?.id && this.nodes.find(d => d.id == opts.id && !d.partial)) return this.nodes.find(d => d.id == opts.id) as 'id' extends keyof T ? Node : Node[];
+ async fetch<T extends FetchOptions>(opts?: T): Promise<'id' extends keyof T ? Node : Collection<string, Node>> {
+ if (opts?.id && this.nodes.find(d => d.id == opts.id && !d.partial))
+ return this.nodes.find(d => d.id == opts.id) as 'id' extends keyof T ? Node : Collection<string, Node>;
console.log(`[store/nodes] Fetching nodes with options: ${JSON.stringify(opts)}`);
- if (!this.nodes.length) this.isFetching = true;
+ if (!this.nodes.size) this.isFetching = true;
const request = await makeRequest(`nodes/@me/${opts?.id || ''}`, 'GET', {});
this.isFetching = false;
if (request.status == 'success') {
if (opts?.id) {
const result = request.result as { node: DB_Node; permissions: Permission[] };
- const index = this.nodes.findIndex(d => d.id == opts?.id);
+ const n = this.nodes.get(opts.id);
let shared = false;
- if (index != -1) shared = this.nodes[index]!.shared;
+ if (n) shared = n.shared;
const updatedNode: Node = { ...(result.node as DB_Node), partial: false, shared: shared, permissions: result.permissions };
- if (index == -1) this.nodes.push(updatedNode);
- else this.nodes[index] = updatedNode;
- return updatedNode as 'id' extends keyof T ? Node : Node[];
+ if (!n) this.nodes.set(opts.id, updatedNode);
+ else this.nodes.set(opts.id, updatedNode);
+ return updatedNode as 'id' extends keyof T ? Node : Collection<string, Node>;
} else {
for (const node of request.result as DB_Node[]) {
- const index = this.nodes.findIndex(d => d.id == node.id);
- if (index == -1) this.nodes.push({ ...node, partial: true, shared: false, permissions: [] });
- else this.nodes[index] = { ...node, partial: true, shared: false, permissions: [] };
+ const n = this.nodes.get(node.id);
+ if (!n) this.nodes.set(node.id, { ...node, partial: true, shared: false, permissions: [] });
+ else this.nodes.set(node.id, { ...node, partial: true, shared: false, permissions: [] });
}
this.recomputeTags();
- return this.nodes as 'id' extends keyof T ? Node : Node[];
+ return this.nodes as 'id' extends keyof T ? Node : Collection<string, Node>;
}
} else throw request;
},
@@ -192,17 +190,16 @@ export const useNodesStore = defineStore('nodes', {
return fetchedDoc;
} else return undefined;
},
- async fetchShared(): Promise<Node[]> {
+ async fetchShared(): Promise<Collection<string, Node>> {
console.log(`[store/nodes] Fetching shared nodes`);
- if (this.nodes.length) return this.nodes;
+ if (this.nodes.size) return this.nodes;
const request = await makeRequest(`nodes/shared/@me`, 'GET', {});
if (request.status === 'success') {
for (const node of request.result as DB_Node[]) {
- const index = this.nodes.findIndex(d => d.id == node.id);
- if (index == -1) this.nodes.push({ ...node, partial: true, shared: true, permissions: node.permissions || [] });
+ if (!this.nodes.has(node.id)) this.nodes.set(node.id, { ...node, partial: true, shared: true, permissions: node.permissions || [] });
else {
- const state = this.nodes[index];
- this.nodes[index] = { ...node, partial: true, shared: state?.shared ?? true, permissions: node.permissions || [] };
+ const state = this.nodes.get(node.id);
+ this.nodes.set(node.id, { ...node, partial: true, shared: state?.shared ?? true, permissions: node.permissions || [] });
}
}
return this.nodes;
@@ -243,7 +240,7 @@ export const useNodesStore = defineStore('nodes', {
async post(node: Partial<Node>): Promise<DB_Node> {
const request = await makeRequest('nodes', 'POST', node);
if (request.status == 'success') {
- this.nodes.push({ ...(request.result as DB_Node), partial: false, shared: false, permissions: [] });
+ this.nodes.set((request.result as DB_Node).id, { ...(request.result as DB_Node), partial: false, shared: false, permissions: [] });
return request.result as DB_Node;
} else throw request.message;
},
@@ -256,8 +253,10 @@ export const useNodesStore = defineStore('nodes', {
node = mergeNode(node, full_node);
}
const request = await makeRequest(`nodes/${node.id}`, 'PUT', node);
- if (request.status == 'success') return (this.nodes = this.nodes.map(d => (d.id == node.id ? node : d)));
- else throw request.message;
+ if (request.status == 'success') {
+ this.nodes.set(node.id, node);
+ return this.nodes;
+ } else throw request.message;
},
async delete(id: string) {
const request = await makeRequest(`nodes/${id}`, 'DELETE', {});