Lots of work trying to use the new core db_save_ae_obj_li__ae_obj() function.
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
import { marked } from 'marked';
|
||||
|
||||
import type { key_val } from '$lib/ae_stores';
|
||||
import { api } from '$lib/api';
|
||||
|
||||
import { db_save_ae_obj_li__ae_obj } from "$lib/ae_core/core__idb_dexie";
|
||||
import { db_journals } from "$lib/ae_journals/db_journals";
|
||||
import { marked } from 'marked';
|
||||
|
||||
import { load_ae_obj_li__journal_entry } from "$lib/ae_journals/ae_journals__journal_entry";
|
||||
|
||||
@@ -50,15 +52,37 @@ export async function load_ae_obj_id__journal(
|
||||
params: params,
|
||||
log_lvl: log_lvl
|
||||
})
|
||||
.then(function (journal_obj_get_result) {
|
||||
.then(async function (journal_obj_get_result) {
|
||||
if (journal_obj_get_result) {
|
||||
if (try_cache) {
|
||||
// This is expecting a list
|
||||
db_save_ae_obj_li__journal({
|
||||
obj_type: 'journal',
|
||||
// Process the results first
|
||||
let processed_obj_li = await process_ae_obj__journal_props({
|
||||
obj_li: [journal_obj_get_result],
|
||||
log_lvl: log_lvl
|
||||
log_lvl: log_lvl,
|
||||
});
|
||||
if (log_lvl) {
|
||||
console.log('Processed object list:', processed_obj_li);
|
||||
}
|
||||
// Save the updated results list to the database
|
||||
if (log_lvl) {
|
||||
console.log('Saving to DB...');
|
||||
}
|
||||
await db_save_ae_obj_li__ae_obj({
|
||||
db_instance: db_journals,
|
||||
table_name: 'journal',
|
||||
obj_li: processed_obj_li,
|
||||
properties_to_save: properties_to_save,
|
||||
log_lvl: log_lvl,
|
||||
});
|
||||
if (log_lvl) {
|
||||
console.log('DB save completed.');
|
||||
}
|
||||
// // This is expecting a list
|
||||
// db_save_ae_obj_li__journal({
|
||||
// obj_type: 'journal',
|
||||
// obj_li: [journal_obj_get_result],
|
||||
// log_lvl: log_lvl
|
||||
// });
|
||||
}
|
||||
return journal_obj_get_result;
|
||||
} else {
|
||||
@@ -179,14 +203,36 @@ export async function load_ae_obj_li__journal(
|
||||
params: params,
|
||||
log_lvl: log_lvl
|
||||
})
|
||||
.then(function (journal_obj_li_get_result) {
|
||||
.then(async function (journal_obj_li_get_result) {
|
||||
if (journal_obj_li_get_result) {
|
||||
if (try_cache) {
|
||||
db_save_ae_obj_li__journal({
|
||||
obj_type: 'journal',
|
||||
// Process the results first
|
||||
let processed_obj_li = await process_ae_obj__journal_props({
|
||||
obj_li: journal_obj_li_get_result,
|
||||
log_lvl: log_lvl
|
||||
log_lvl: log_lvl,
|
||||
});
|
||||
if (log_lvl) {
|
||||
console.log('Processed object list:', processed_obj_li);
|
||||
}
|
||||
// Save the updated results list to the database
|
||||
if (log_lvl) {
|
||||
console.log('Saving to DB...');
|
||||
}
|
||||
await db_save_ae_obj_li__ae_obj({
|
||||
db_instance: db_journals,
|
||||
table_name: 'journal',
|
||||
obj_li: processed_obj_li,
|
||||
properties_to_save: properties_to_save,
|
||||
log_lvl: log_lvl,
|
||||
});
|
||||
if (log_lvl) {
|
||||
console.log('DB save completed.');
|
||||
}
|
||||
// db_save_ae_obj_li__journal({
|
||||
// obj_type: 'journal',
|
||||
// obj_li: journal_obj_li_get_result,
|
||||
// log_lvl: log_lvl
|
||||
// });
|
||||
}
|
||||
return journal_obj_li_get_result;
|
||||
} else {
|
||||
@@ -277,15 +323,37 @@ export async function create_ae_obj__journal(
|
||||
return_obj: true,
|
||||
log_lvl: log_lvl
|
||||
})
|
||||
.then(function (journal_obj_create_result) {
|
||||
.then(async function (journal_obj_create_result) {
|
||||
if (journal_obj_create_result) {
|
||||
if (try_cache) {
|
||||
db_save_ae_obj_li__journal(
|
||||
{
|
||||
obj_type: 'journal',
|
||||
obj_li: [journal_obj_create_result],
|
||||
log_lvl: log_lvl
|
||||
// Process the results first
|
||||
let processed_obj_li = await process_ae_obj__journal_props({
|
||||
obj_li: [journal_obj_create_result],
|
||||
log_lvl: log_lvl,
|
||||
});
|
||||
if (log_lvl) {
|
||||
console.log('Processed object list:', processed_obj_li);
|
||||
}
|
||||
// Save the updated results list to the database
|
||||
if (log_lvl) {
|
||||
console.log('Saving to DB...');
|
||||
}
|
||||
await db_save_ae_obj_li__ae_obj({
|
||||
db_instance: db_journals,
|
||||
table_name: 'journal',
|
||||
obj_li: processed_obj_li,
|
||||
properties_to_save: properties_to_save,
|
||||
log_lvl: log_lvl,
|
||||
});
|
||||
if (log_lvl) {
|
||||
console.log('DB save completed.');
|
||||
}
|
||||
// db_save_ae_obj_li__journal(
|
||||
// {
|
||||
// obj_type: 'journal',
|
||||
// obj_li: [journal_obj_create_result],
|
||||
// log_lvl: log_lvl
|
||||
// });
|
||||
}
|
||||
return journal_obj_create_result;
|
||||
} else {
|
||||
@@ -339,12 +407,12 @@ export async function delete_ae_obj_id__journal(
|
||||
.catch(function (error) {
|
||||
console.log('No results returned or failed.', error);
|
||||
})
|
||||
.finally(function () {
|
||||
.finally(async function () {
|
||||
if (try_cache) {
|
||||
if (log_lvl) {
|
||||
console.log(`Attempting to remove IDB entry for journal_id=${journal_id}`);
|
||||
}
|
||||
db_journals.journal.delete(journal_id);
|
||||
await db_journals.journal.delete(journal_id);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -376,6 +444,8 @@ export async function update_ae_obj__journal({
|
||||
console.log(`*** update_ae_obj__journal() *** journal_id=${journal_id}`, data_kv);
|
||||
}
|
||||
|
||||
log_lvl = 1;
|
||||
|
||||
// Perform the API update
|
||||
const result = await api.update_ae_obj_id_crud({
|
||||
api_cfg: api_cfg,
|
||||
@@ -391,13 +461,33 @@ export async function update_ae_obj__journal({
|
||||
// Handle the result
|
||||
if (result) {
|
||||
if (try_cache) {
|
||||
console.log('Saving to DB...');
|
||||
await db_save_ae_obj_li__journal({
|
||||
obj_type: 'journal',
|
||||
// Process the results first
|
||||
let processed_obj_li = await process_ae_obj__journal_props({
|
||||
obj_li: [result],
|
||||
log_lvl: log_lvl,
|
||||
});
|
||||
if (log_lvl) {
|
||||
console.log('Processed object list:', processed_obj_li);
|
||||
}
|
||||
// Save the updated results list to the database
|
||||
if (log_lvl) {
|
||||
console.log('Saving to DB...');
|
||||
}
|
||||
await db_save_ae_obj_li__ae_obj({
|
||||
db_instance: db_journals,
|
||||
table_name: 'journal',
|
||||
obj_li: processed_obj_li,
|
||||
properties_to_save: properties_to_save,
|
||||
log_lvl: log_lvl,
|
||||
});
|
||||
console.log('DB save completed.');
|
||||
if (log_lvl) {
|
||||
console.log('DB save completed.');
|
||||
}
|
||||
// await db_save_ae_obj_li__journal({
|
||||
// obj_type: 'journal',
|
||||
// obj_li: [result],
|
||||
// log_lvl: log_lvl,
|
||||
// });
|
||||
}
|
||||
return result;
|
||||
} else {
|
||||
@@ -506,12 +596,36 @@ export async function qry__journal(
|
||||
params: params,
|
||||
log_lvl: log_lvl
|
||||
})
|
||||
.then(function (journal_obj_li_get_result) {
|
||||
.then(async function (journal_obj_li_get_result) {
|
||||
if (journal_obj_li_get_result) {
|
||||
db_save_ae_obj_li__journal({
|
||||
obj_type: 'journal',
|
||||
obj_li: journal_obj_li_get_result
|
||||
});
|
||||
if (try_cache) {
|
||||
// Process the results first
|
||||
let processed_obj_li = await process_ae_obj__journal_props({
|
||||
obj_li: journal_obj_li_get_result,
|
||||
log_lvl: log_lvl,
|
||||
});
|
||||
if (log_lvl) {
|
||||
console.log('Processed object list:', processed_obj_li);
|
||||
}
|
||||
// Save the updated results list to the database
|
||||
if (log_lvl) {
|
||||
console.log('Saving to DB...');
|
||||
}
|
||||
db_save_ae_obj_li__ae_obj({
|
||||
db_instance: db_journals,
|
||||
table_name: 'journal',
|
||||
obj_li: processed_obj_li,
|
||||
properties_to_save: properties_to_save,
|
||||
log_lvl: log_lvl,
|
||||
});
|
||||
if (log_lvl) {
|
||||
console.log('DB save completed.');
|
||||
}
|
||||
}
|
||||
// db_save_ae_obj_li__journal({
|
||||
// obj_type: 'journal',
|
||||
// obj_li: journal_obj_li_get_result
|
||||
// });
|
||||
return journal_obj_li_get_result;
|
||||
} else {
|
||||
return [];
|
||||
@@ -670,3 +784,195 @@ export async function db_save_ae_obj_li__journal(
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Updated 2025-05-09
|
||||
let properties_to_save = [
|
||||
|
||||
'id',
|
||||
'journal_id',
|
||||
|
||||
'code',
|
||||
|
||||
'for_type',
|
||||
'for_id',
|
||||
'type_code',
|
||||
|
||||
'account_id',
|
||||
'person_id',
|
||||
|
||||
'name',
|
||||
'short_name',
|
||||
'summary',
|
||||
'outline',
|
||||
|
||||
'description',
|
||||
'description_md_html', // Use the markdown parser to generate HTML
|
||||
'description_html',
|
||||
'description_json',
|
||||
|
||||
// start_datetime: obj.start_datetime,
|
||||
// end_datetime: obj.end_datetime,
|
||||
'timezone',
|
||||
|
||||
'alert',
|
||||
'alert_msg',
|
||||
|
||||
'sort_by',
|
||||
'sort_by_desc',
|
||||
|
||||
'cfg_json',
|
||||
|
||||
// ux_mode: obj.ux_mode,
|
||||
|
||||
// This only allows for basic access to the data.
|
||||
'passcode_read', // For LLM (AI) generated summary...???
|
||||
'passcode_read_expire',
|
||||
'passcode_write',
|
||||
'passcode_write_expire',
|
||||
|
||||
'passcode', // For Journal Entry encryption password
|
||||
'passcode_timeout',
|
||||
|
||||
'auth_key', // For Journal authorization without sign in
|
||||
|
||||
'enable',
|
||||
'hide',
|
||||
'priority',
|
||||
'sort',
|
||||
'group',
|
||||
'notes',
|
||||
'created_on',
|
||||
'updated_on',
|
||||
|
||||
// Generated fields for sorting locally only
|
||||
'tmp_sort_1',
|
||||
'tmp_sort_2',
|
||||
'tmp_sort_3',
|
||||
// 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',
|
||||
|
||||
// A key value list of the others
|
||||
// journal_other_kv
|
||||
// journal_other_li
|
||||
];
|
||||
|
||||
|
||||
// Updated 2025-05-09
|
||||
export async function process_ae_obj__journal_props(
|
||||
{
|
||||
// obj_type,
|
||||
obj_li,
|
||||
log_lvl = 0,
|
||||
}: {
|
||||
// obj_type: string;
|
||||
obj_li: any[];
|
||||
log_lvl?: number;
|
||||
}
|
||||
) {
|
||||
if (log_lvl) {
|
||||
console.log(`*** process_ae_obj__journal_props() ***`, obj_li);
|
||||
}
|
||||
|
||||
if (!obj_li || obj_li.length === 0) {
|
||||
if (log_lvl) {
|
||||
console.log('No objects to process.');
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
const processed_obj_li = [];
|
||||
|
||||
for (const obj of obj_li) {
|
||||
// const processed_obj = { ...obj };
|
||||
|
||||
// Process the properties as needed
|
||||
let description = obj.description ?? '';
|
||||
// remove the most common zerowidth characters from the start of the file
|
||||
let description_cleaned: string = description.replace(/^[\u200B\u200C\u200D\u200E\u200F\uFEFF]/,"");
|
||||
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 processed_obj = {
|
||||
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, // For Journal Entry encryption password
|
||||
passcode_timeout: obj.passcode_timeout,
|
||||
|
||||
auth_key: obj.auth_key, // For Journal authorization without sign in
|
||||
|
||||
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 ?? '0'}_${obj.priority ? 1 : 0}_${obj.sort ?? '0'}_${obj.updated_on}_${obj.created_on}`,
|
||||
tmp_sort_2: `${obj.group ?? '0'}_${obj.priority ? 1 : 0}_${obj.sort ?? '0'}_${obj.updated_on ?? obj.created_on}`,
|
||||
tmp_sort_3: `${obj.group ?? '0'}_${obj.priority ? 1 : 0}_${obj.sort ?? '0'}_${obj.name}_${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,
|
||||
};
|
||||
|
||||
processed_obj_li.push(processed_obj);
|
||||
}
|
||||
|
||||
return processed_obj_li;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user