Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@
"overview": "Overview",
"feed": "Feeds",
"library": "Knowledge Base",
"trash": "Recycle Bin",
"papers": "Paper Library",
"calendar": "Calendar",
"attributes": "Manage Attributes",
Expand Down Expand Up @@ -599,6 +600,90 @@
"page-fit": "Fit page"
}
},
"table": {
"sort": "Sort",
"group": "Group",
"ungroup": "Remove grouping",
"field": "Field",
"operator": "Operator",
"value": "Value",
"searchOptions": "Search options",
"addCondition": "Add condition",
"removeCondition": "Remove condition",
"addValue": "Add value",
"removeValue": "Remove value",
"direction": "Direction",
"ascending": "Ascending",
"descending": "Descending",
"sortLevel": "Sort level {{level}}",
"moveSort": "Reorder sort level",
"addSort": "Add sort",
"removeSort": "Remove sort",
"granularity": "Date granularity",
"granularities": {
"day": "Day",
"week": "Week",
"month": "Month",
"year": "Year"
},
"noGroupValue": "No {{name}}",
"openTrash": "Open Recycle Bin",
"editTitle": "Edit title",
"valueSeparator": ", ",
"dateMode": "Date mode",
"absolute": "Absolute",
"relativeMode": "Relative",
"days": "Days",
"from": "Start",
"to": "End",
"operators": {
"contains": "Contains",
"not-contains": "Does not contain",
"equals": "Is",
"not-equals": "Is not",
"numberEquals": "=",
"numberNotEquals": "≠",
"empty": "Is empty",
"not-empty": "Is not empty",
"greater": ">",
"greater-or-equal": "≥",
"less": "<",
"less-or-equal": "≤",
"in": "Is any of",
"not-in": "Is none of",
"any": "Contains any of",
"all": "Contains all of",
"none": "Contains none of",
"before": "Before",
"after": "After",
"on-or-after": "On or after",
"on-or-before": "On or before",
"between": "Between",
"incomplete": "Is incomplete",
"complete": "Is complete"
},
"relative": {
"today": "Today",
"yesterday": "Yesterday",
"tomorrow": "Tomorrow",
"this-week": "This week",
"last-week": "Last week",
"next-week": "Next week",
"this-month": "This month",
"last-month": "Last month",
"next-month": "Next month",
"past-days": "Past {{count}} days",
"next-days": "Next {{count}} days",
"past-days_one": "Past {{count}} day",
"past-days_other": "Past {{count}} days",
"next-days_one": "Next {{count}} day",
"next-days_other": "Next {{count}} days"
},
"relativeOptions": {
"past-days": "Past N days",
"next-days": "Next N days"
}
},
"library": {
"scope": "Scope",
"all": "All Pages",
Expand Down
85 changes: 85 additions & 0 deletions locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@
"overview": "总览",
"feed": "订阅",
"library": "知识库",
"trash": "回收站",
"papers": "文献库",
"calendar": "日历",
"attributes": "属性管理",
Expand Down Expand Up @@ -599,6 +600,90 @@
"page-fit": "适合页面"
}
},
"table": {
"sort": "排序",
"group": "分组",
"ungroup": "取消分组",
"field": "字段",
"operator": "运算符",
"value": "值",
"searchOptions": "搜索选项",
"addCondition": "添加条件",
"removeCondition": "删除条件",
"addValue": "添加值",
"removeValue": "删除值",
"direction": "方向",
"ascending": "升序",
"descending": "降序",
"sortLevel": "第{{level}}级排序",
"moveSort": "拖动调整排序顺序",
"addSort": "添加排序",
"removeSort": "删除排序",
"granularity": "时间粒度",
"granularities": {
"day": "日",
"week": "周",
"month": "月",
"year": "年"
},
"noGroupValue": "无({{name}})",
"openTrash": "打开回收站",
"editTitle": "编辑标题",
"valueSeparator": "、",
"dateMode": "日期模式",
"absolute": "绝对日期",
"relativeMode": "相对日期",
"days": "天数",
"from": "起始值",
"to": "结束值",
"operators": {
"contains": "包含",
"not-contains": "不包含",
"equals": "是",
"not-equals": "不是",
"numberEquals": "=",
"numberNotEquals": "≠",
"empty": "为空",
"not-empty": "不为空",
"greater": ">",
"greater-or-equal": "≥",
"less": "<",
"less-or-equal": "≤",
"in": "是其中之一",
"not-in": "不是其中任何一个",
"any": "包含其中之一",
"all": "全部包含",
"none": "不包含其中任何一个",
"before": "早于",
"after": "晚于",
"on-or-after": "不早于",
"on-or-before": "不晚于",
"between": "介于",
"incomplete": "属于未完成",
"complete": "属于已完成"
},
"relative": {
"today": "今天",
"yesterday": "昨天",
"tomorrow": "明天",
"this-week": "本周",
"last-week": "上周",
"next-week": "下周",
"this-month": "本月",
"last-month": "上月",
"next-month": "下月",
"past-days": "过去{{count}}天",
"next-days": "未来{{count}}天",
"past-days_one": "过去{{count}}天",
"next-days_one": "未来{{count}}天",
"past-days_other": "过去{{count}}天",
"next-days_other": "未来{{count}}天"
},
"relativeOptions": {
"past-days": "过去N天",
"next-days": "未来N天"
}
},
"library": {
"scope": "范围",
"all": "全部页面",
Expand Down
25 changes: 19 additions & 6 deletions main/knowledge/edits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,22 @@ function putBlock(block: ContentBlock): void {
plan.putBlock(block);
plan.persist();
}
export function create(source: HistorySource, title = "", initial: Record<string, AttributeValue> = {}, parentId?: string, kind: "editable" | "paper" = "editable"): PageRecord {
export function validateInitial(initial: Record<string, AttributeValue>): void {
workspace.requireWorkspace();
if (!record(initial)) throw new LabloomError({ kind: "page-invalid-attributes" });
for (const id of Object.keys(initial)) if (attributes.definition(id).readonly || id === "deleted") throw new LabloomError({ kind: "page-create-readonly" });
return createPage(kind, title, initial, parentId, source);
}

type CreationIdentity = { id: string; writeId: string };
export function create(source: HistorySource, title = "", initial: Record<string, AttributeValue> = {}, parentId?: string, kind: PageKind = "editable",
identity?: CreationIdentity): PageRecord {
validateInitial(initial);
return createPage(kind, title, kind === "annotation" && !parentId ? { independent: true, ...initial } : initial, parentId, source, identity);
}

export function rename(pageId: string, title: string, source: HistorySource, confirmation?: string): CommitResult {
const { titleBlockId } = data.writable(pageId);
return commitEdit({ pageId, batch: 0, blocks: [{ id: titleBlockId, type: "title", payload: payload("title", title), children: [] }] }, source, confirmation);
}
function planEdit(input: EditCommit): EditChanges {
if (!record(input) || !Number.isSafeInteger(input.batch) || input.batch < 0 || !Array.isArray(input.blocks) || !record(input.attributes ?? {}) ||
Expand Down Expand Up @@ -301,18 +312,20 @@ function createPageRows(plan: EditChanges, id: string, kind: PageKind, title: st
return [titleId, ...children];
}

export function createPage(kind: PageKind = "editable", title = "", initial: Record<string, AttributeValue> = {}, parentId?: string, history?: HistorySource): PageRecord {
export function createPage(kind: PageKind = "editable", title = "", initial: Record<string, AttributeValue> = {}, parentId?: string,
history?: HistorySource, identity?: CreationIdentity): PageRecord {
workspace.requireWorkspace();
if (!pageKinds.includes(kind) || typeof title !== "string" || !record(initial)) throw new LabloomError({ kind: "page-invalid-create" });
if (!pageKinds.includes(kind) || typeof title !== "string" || !record(initial) || identity && !validUUID(identity.id))
throw new LabloomError({ kind: "page-invalid-create" });
const changed = { pages: [] as string[], blocks: [] as string[] };
const page = commit.run({ history }, context => {
const page = commit.run({ history, writeId: identity?.writeId }, context => {
if (parentId) data.writable(parentId);
if (kind === "annotation" && initial.annotation_file != null) {
if (!parentId || data.header(parentId).kind !== "paper") throw new LabloomError({ kind: "annotation-paper-required" });
const files = data.get(parentId).attributes.paper_files as string[];
if (!files.includes(String(initial.annotation_file))) throw new LabloomError({ kind: "paper-file-removed" });
}
const id = randomUUID(), plan = new EditChanges();
const id = identity?.id ?? randomUUID(), plan = new EditChanges();
const created = createPageRows(plan, id, kind, title, parentId ? { ...initial, independent: false } : initial);
if (parentId && kind === "annotation") {
if (data.header(parentId).kind !== "paper") throw new LabloomError({ kind: "annotation-paper-required" });
Expand Down
5 changes: 3 additions & 2 deletions main/knowledge/papers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export function attachImported(ids: string[], pageId: string, attributeId: strin
});
}

export function importPrepared(ids: string[], source?: HistorySource, pageId?: string): string[] {
export function importPrepared(ids: string[], source?: HistorySource, pageId?: string, initial: Record<string, AttributeValue> = {}): string[] {
workspace.requireWorkspace();
if (!ids.length) return [];
if (pageId) {
Expand All @@ -204,8 +204,9 @@ export function importPrepared(ids: string[], source?: HistorySource, pageId?: s
}
const files = requiredFiles(ids);
if (files.some(file => file.mediaType !== "application/pdf")) throw new LabloomError({ kind: "import-pdf-only" });
edits.validateInitial(initial);
return files.map(file => edits.createPage("paper", basename(file.originalName, extname(file.originalName)), {
paper_files: [file.id], source_snapshot: { originalName: file.originalName }
...initial, paper_files: [file.id], source_snapshot: { originalName: file.originalName }
}, undefined, source).id);
}

Expand Down
Loading
Loading