Work on Dexie liveQuery for Journals

This commit is contained in:
Scott Idem
2025-04-09 12:40:00 -04:00
parent 10c3e34b38
commit e1848dddb5
4 changed files with 226 additions and 186 deletions

2
package-lock.json generated
View File

@@ -17,7 +17,7 @@
"@tiptap/extension-paragraph": "^2.10.2",
"axios": "^1.7.0",
"dayjs": "^1.11.10",
"dexie": "^4.0.1-beta.14",
"dexie": "^4.0.11",
"flowbite-svelte": "^0.48.00",
"html5-qrcode": "^2.3.8",
"lucide-svelte": "^0.483.0",

View File

@@ -95,7 +95,7 @@
"@tiptap/extension-paragraph": "^2.10.2",
"axios": "^1.7.0",
"dayjs": "^1.11.10",
"dexie": "^4.0.1-beta.14",
"dexie": "^4.0.11",
"flowbite-svelte": "^0.48.00",
"html5-qrcode": "^2.3.8",
"lucide-svelte": "^0.483.0",

View File

@@ -543,86 +543,106 @@ export function db_save_ae_obj_li__journal(
let description_md_html: null|string = await marked.parse(description_cleaned ?? '') ?? null;
// let description_md_html_alt: null|string = await marked.parse(description_cleaned ?? '', { gfm: false }) ?? null;
let obj_record = {
id: obj.journal_id_random,
journal_id: obj.journal_id_random,
code: obj.code,
for_type: obj.for_type,
for_id: obj.for_id,
type_code: obj.type_code,
account_id: obj.account_id_random,
person_id: obj.person_id_random,
name: obj.name,
short_name: obj.short_name,
summary: obj.summary,
outline: obj.outline,
description: obj.description,
description_md_html: description_md_html, // Use the markdown parser to generate HTML
description_html: obj.description_html,
description_json: obj.description_json,
// start_datetime: obj.start_datetime,
// end_datetime: obj.end_datetime,
timezone: obj.timezone,
alert: obj.alert,
alert_msg: obj.alert_msg,
sort_by: obj.sort_by,
sort_by_desc: obj.sort_by_desc,
cfg_json: obj.cfg_json ?? {},
data_json: obj.data_json ?? {},
// ux_mode: obj.ux_mode,
// This only allows for basic access to the data.
passcode_read: obj.passcode_read, // For LLM (AI) generated summary...???
passcode_read_expire: obj.passcode_read_expire,
passcode_write: obj.passcode_write,
passcode_write_expire: obj.passcode_write_expire,
passcode: obj.passcode,
passcode_timeout: obj.passcode_timeout,
enable: obj.enable,
hide: obj.hide,
priority: obj.priority,
sort: obj.sort,
group: obj.group,
notes: obj.notes,
created_on: obj.created_on,
updated_on: obj.updated_on,
// Generated fields for sorting locally only
tmp_sort_1: `${obj.group}_${obj.priority}_${obj.sort}_${obj.updated_on}_${obj.created_on}`,
tmp_sort_2: `${obj.group}_${obj.priority}_${obj.sort}_${obj.updated_on ?? obj.created_on}`,
// tmp_sort_1: `${obj.original_datetime}_${obj.group}_${obj.priority}_${obj.sort}`,
// tmp_sort_2: `${obj.group}_${obj.original_datetime}_${obj.priority}_${obj.sort}`,
// From SQL view
journal_entry_count: obj.journal_entry_count,
// A key value list of the others
// journal_other_kv: obj.journal_other_kv,
// journal_other_li: obj.journal_other_li,
};
let id_random = null;
try {
const id_random = await db_journals.journal.put({
id: obj.journal_id_random,
journal_id: obj.journal_id_random,
code: obj.code,
for_type: obj.for_type,
for_id: obj.for_id,
type_code: obj.type_code,
account_id: obj.account_id_random,
person_id: obj.person_id_random,
name: obj.name,
short_name: obj.short_name,
summary: obj.summary,
outline: obj.outline,
description: obj.description,
description_md_html: description_md_html, // Use the markdown parser to generate HTML
description_html: obj.description_html,
description_json: obj.description_json,
// start_datetime: obj.start_datetime,
// end_datetime: obj.end_datetime,
timezone: obj.timezone,
alert: obj.alert,
alert_msg: obj.alert_msg,
sort_by: obj.sort_by,
sort_by_desc: obj.sort_by_desc,
cfg_json: obj.cfg_json ?? {},
data_json: obj.data_json ?? {},
// ux_mode: obj.ux_mode,
// This only allows for basic access to the data.
passcode_read: obj.passcode_read, // For LLM (AI) generated summary...???
passcode_read_expire: obj.passcode_read_expire,
passcode_write: obj.passcode_write,
passcode_write_expire: obj.passcode_write_expire,
passcode: obj.passcode,
passcode_timeout: obj.passcode_timeout,
enable: obj.enable,
hide: obj.hide,
priority: obj.priority,
sort: obj.sort,
group: obj.group,
notes: obj.notes,
created_on: obj.created_on,
updated_on: obj.updated_on,
// Generated fields for sorting locally only
tmp_sort_1: `${obj.group}_${obj.priority}_${obj.sort}_${obj.updated_on}_${obj.created_on}`,
tmp_sort_2: `${obj.group}_${obj.priority}_${obj.sort}_${obj.updated_on ?? obj.created_on}`,
// tmp_sort_1: `${obj.original_datetime}_${obj.group}_${obj.priority}_${obj.sort}`,
// tmp_sort_2: `${obj.group}_${obj.original_datetime}_${obj.priority}_${obj.sort}`,
// From SQL view
journal_entry_count: obj.journal_entry_count,
// A key value list of the others
// journal_other_kv: obj.journal_other_kv,
// journal_other_li: obj.journal_other_li,
});
// console.log(`Put obj with ID: ${obj.journal_id_random} or ${id_random}`);
id_random = await db_journals.journal.update(obj_record.id, obj_record);
} catch (error) {
let status = `Failed to put ${obj.journal_id_random}: ${error}`;
console.log(status);
console.log(`Error: Failed to update ${obj_record.id}: ${error}`);
}
if (!id_random) {
if (log_lvl) {
console.log(`Failed to update record with ID: ${obj_record.id}. Trying put...`);
}
try {
id_random = await db_journals.journal.put(obj_record);
} catch (error) {
console.log(`Error: Failed to put ${obj.journal_id_random}: ${error}`);
}
} else {
if (log_lvl) {
console.log(`Updated record with ID: ${obj_record.id}`);
}
}
if (!id_random) {
console.log(`Failed to save record with ID: ${obj_record.id}`);
} else {
if (log_lvl) {
console.log(`Saved record with ID: ${obj_record.id}`);
}
}
// const id_random = await db_journals.journal.put(obj);
// console.log(`Put obj with ID: ${obj.journal_id_random}`);
});
return true;

View File

@@ -344,116 +344,136 @@ export async function db_save_ae_obj_li__journal_entry(
let content_md_html: null|string = await marked.parse(content_cleaned ?? '') ?? null;
// let content_md_html_alt: null|string = await marked.parse(content_cleaned ?? '', { gfm: false }) ?? null;
let obj_record = {
id: obj.journal_entry_id_random,
journal_entry_id: obj.journal_entry_id_random,
journal_id: obj.journal_id_random,
code: obj.code,
for_type: obj.for_type,
for_id: obj.for_id,
journal_entry_type: obj.journal_entry_type,
person_id: obj.person_id_random,
template: obj.template ?? null, // Allow for a template to be used, otherwise null
activity_code: obj.activity_code,
category_code: obj.category_code,
type_code: obj.type_code,
topic_code: obj.topic_code,
tags: obj.tags,
public: obj.public,
private: obj.private,
personal: obj.personal,
professional: obj.professional,
name: obj.name,
short_name: obj.short_name ?? null,
summary: obj.summary,
outline: obj.outline,
// description: obj.description,
content: obj.content,
content_md_html: content_md_html,
// content_md_html_alt: content_md_html_alt,
content_html: obj.content_html,
content_json: obj.content_json,
// url: obj.url,
// url_text: obj.url_text,
// hosted_file_id: obj.hosted_file_id_random,
// file_path: obj.file_path,
// filename: obj.filename,
// file_extension: obj.file_extension,
// start_datetime: obj.start_datetime,
// end_datetime: obj.end_datetime,
// timezone: obj.timezone,
// original_datetime: obj.original_datetime,
// original_timezone: obj.original_timezone,
// original_location: obj.original_location,
// original_url: obj.original_url,
// original_url_text: obj.original_url_text,
// enable_for_public: obj.enable_for_public,
alert: obj.alert,
alert_msg: obj.alert_msg,
// cfg_json: obj.cfg_json ?? {},
data_json: obj.data_json ?? {},
// This only allows for basic access to the data.
// passcode_read: obj.passcode_read, // For LLM (AI) generated summary...???
// passcode_read_expire: obj.passcode_read_expire,
// passcode_write: obj.passcode_write,
// passcode_write_expire: obj.passcode_write_expire,
enable: obj.enable,
hide: obj.hide,
priority: obj.priority,
sort: obj.sort,
group: obj.group,
notes: obj.notes,
created_on: obj.created_on,
updated_on: obj.updated_on,
// Generated fields for sorting locally only
tmp_sort_1: `${obj.group}_${obj.priority}_${obj.sort}_${obj.updated_on}_${obj.created_on}`,
tmp_sort_2: `${obj.group}_${obj.priority}_${obj.sort}_${obj.updated_on ?? obj.created_on}`,
// tmp_sort_1: `${obj.original_datetime}_${obj.group}_${obj.priority}_${obj.sort}`,
// tmp_sort_2: `${obj.group}_${obj.original_datetime}_${obj.priority}_${obj.sort}`,
// Generated fields for sorting locally only
// tmp_sort_1: `${obj.original_datetime}_${obj.group}_${obj.priority}_${obj.sort}`,
// tmp_sort_2: `${obj.group}_${obj.original_datetime}_${obj.priority}_${obj.sort}`,
// From SQL view
journal_code: obj.journal_code,
journal_name: obj.journal_name,
// A key value list of the others
// journal_other_kv: obj.journal_other_kv,
// journal_other_li: obj.journal_other_li,
};
let id_random = null;
try {
const id_random = await db_journals.journal_entry.put({
id: obj.journal_entry_id_random,
journal_entry_id: obj.journal_entry_id_random,
journal_id: obj.journal_id_random,
code: obj.code,
for_type: obj.for_type,
for_id: obj.for_id,
journal_entry_type: obj.journal_entry_type,
person_id: obj.person_id_random,
template: obj.template ?? null, // Allow for a template to be used, otherwise null
activity_code: obj.activity_code,
category_code: obj.category_code,
type_code: obj.type_code,
topic_code: obj.topic_code,
tags: obj.tags,
public: obj.public,
private: obj.private,
personal: obj.personal,
professional: obj.professional,
name: obj.name,
short_name: obj.short_name ?? null,
summary: obj.summary,
outline: obj.outline,
// description: obj.description,
content: obj.content,
content_md_html: content_md_html,
// content_md_html_alt: content_md_html_alt,
content_html: obj.content_html,
content_json: obj.content_json,
// url: obj.url,
// url_text: obj.url_text,
// hosted_file_id: obj.hosted_file_id_random,
// file_path: obj.file_path,
// filename: obj.filename,
// file_extension: obj.file_extension,
// start_datetime: obj.start_datetime,
// end_datetime: obj.end_datetime,
// timezone: obj.timezone,
// original_datetime: obj.original_datetime,
// original_timezone: obj.original_timezone,
// original_location: obj.original_location,
// original_url: obj.original_url,
// original_url_text: obj.original_url_text,
// enable_for_public: obj.enable_for_public,
alert: obj.alert,
alert_msg: obj.alert_msg,
// cfg_json: obj.cfg_json ?? {},
data_json: obj.data_json ?? {},
// This only allows for basic access to the data.
// passcode_read: obj.passcode_read, // For LLM (AI) generated summary...???
// passcode_read_expire: obj.passcode_read_expire,
// passcode_write: obj.passcode_write,
// passcode_write_expire: obj.passcode_write_expire,
enable: obj.enable,
hide: obj.hide,
priority: obj.priority,
sort: obj.sort,
group: obj.group,
notes: obj.notes,
created_on: obj.created_on,
updated_on: obj.updated_on,
// Generated fields for sorting locally only
tmp_sort_1: `${obj.group}_${obj.priority}_${obj.sort}_${obj.updated_on}_${obj.created_on}`,
tmp_sort_2: `${obj.group}_${obj.priority}_${obj.sort}_${obj.updated_on ?? obj.created_on}`,
// tmp_sort_1: `${obj.original_datetime}_${obj.group}_${obj.priority}_${obj.sort}`,
// tmp_sort_2: `${obj.group}_${obj.original_datetime}_${obj.priority}_${obj.sort}`,
// Generated fields for sorting locally only
// tmp_sort_1: `${obj.original_datetime}_${obj.group}_${obj.priority}_${obj.sort}`,
// tmp_sort_2: `${obj.group}_${obj.original_datetime}_${obj.priority}_${obj.sort}`,
// From SQL view
journal_code: obj.journal_code,
journal_name: obj.journal_name,
// A key value list of the others
// journal_other_kv: obj.journal_other_kv,
// journal_other_li: obj.journal_other_li,
});
// console.log(`Put obj with ID: ${obj.journal_entry_id_random} or ${id_random}`);
id_random = await db_journals.journal_entry.update(obj_record.id, obj_record);
} catch (error) {
let status = `Failed to put ${obj.journal_entry_id_random}: ${error}`;
console.log(status);
console.log(`Error: Failed to update ${obj_record.id}: ${error}`);
}
if (!id_random) {
if (log_lvl) {
console.log(`Failed to update record with ID: ${obj_record.id}. Trying put...`);
}
try {
id_random = await db_journals.journal_entry.put(obj_record);
} catch (error) {
console.log(`Error: Failed to put ${obj.journal_entry_id_random}: ${error}`);
}
} else {
if (log_lvl) {
console.log(`Updated record with ID: ${obj_record.id}`);
}
}
if (!id_random) {
console.log(`Failed to save record with ID: ${obj_record.id}`);
} else {
if (log_lvl) {
console.log(`Saved record with ID: ${obj_record.id}`);
}
}
// const id_random = await db_journals.journal_entry.put(obj);
// console.log(`Put obj with ID: ${obj.journal_entry_id_random}`);
});
return true;