Wrapping up for the night at 4 AM. Made lots of progress with the Journals module. Should have saved more often.
This commit is contained in:
@@ -126,11 +126,6 @@ export async function load_ae_obj_li__archive(
|
||||
console.log(`*** load_ae_obj_li__archive() *** for_obj_type=${for_obj_type} for_obj_id=${for_obj_id}`);
|
||||
}
|
||||
|
||||
// let enabled: string = (params.qry__enabled ?? 'enabled'); // all, disabled, enabled
|
||||
// let hidden: string = (params.qry__hidden ?? 'not_hidden'); // all, hidden, not_hidden
|
||||
// let limit: number = (params.qry__limit ?? 99); // 99
|
||||
// let offset: number = (params.qry__offset ?? 0); // 0
|
||||
|
||||
let params_json: key_val = {};
|
||||
|
||||
// console.log('params_json:', params_json);
|
||||
|
||||
@@ -377,6 +377,7 @@ export async function db_save_ae_obj_li__archive_content(
|
||||
created_on: obj.created_on,
|
||||
updated_on: obj.updated_on,
|
||||
|
||||
// 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}`,
|
||||
|
||||
|
||||
589
src/lib/ae_journals/ae_journals__journal.ts
Normal file
589
src/lib/ae_journals/ae_journals__journal.ts
Normal file
@@ -0,0 +1,589 @@
|
||||
import type { key_val } from '$lib/ae_stores';
|
||||
import { api } from '$lib/api';
|
||||
|
||||
import { db_journals } from "$lib/ae_journals/db_journals";
|
||||
|
||||
import { load_ae_obj_li__journal_entry } from "$lib/ae_journals/ae_journals__journal_entry";
|
||||
|
||||
let ae_promises: key_val = {};
|
||||
|
||||
|
||||
// Updated 2025-03-15
|
||||
export async function load_ae_obj_id__journal(
|
||||
{
|
||||
api_cfg,
|
||||
journal_id,
|
||||
inc_entry_li = false,
|
||||
try_cache = true,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
api_cfg: any,
|
||||
journal_id: string,
|
||||
inc_entry_li?: boolean,
|
||||
try_cache?: boolean,
|
||||
log_lvl?: number
|
||||
}
|
||||
) {
|
||||
if (log_lvl) {
|
||||
console.log(`*** load_ae_obj_id__journal() *** journal_id=${journal_id}`);
|
||||
}
|
||||
|
||||
let params = {};
|
||||
|
||||
ae_promises.load__journal_obj = await api.get_ae_obj_id_crud({
|
||||
api_cfg: api_cfg,
|
||||
obj_type: 'journal',
|
||||
obj_id: journal_id, // NOTE: This is the FQDN, not normally the ID.
|
||||
use_alt_table: true, // NOTE: This will use the table_name_alt value instead of the table_name value in the API config.
|
||||
use_alt_base: false, // NOTE: This will use the base_name_alt value instead of the base_name value in the API config.
|
||||
params: params,
|
||||
log_lvl: log_lvl
|
||||
})
|
||||
.then(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',
|
||||
obj_li: [journal_obj_get_result]
|
||||
});
|
||||
}
|
||||
return journal_obj_get_result;
|
||||
} else {
|
||||
console.log('No results returned.');
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.log('No results returned or failed.', error);
|
||||
});
|
||||
|
||||
if (log_lvl) {
|
||||
console.log('ae_promises.load__journal_obj:', ae_promises.load__journal_obj);
|
||||
}
|
||||
|
||||
if (inc_entry_li) {
|
||||
// Load the entries for the journal
|
||||
if (log_lvl) {
|
||||
console.log(`Need to load the entry list for the journal now`);
|
||||
}
|
||||
let load_journal_entry_obj_li = load_ae_obj_li__journal_entry({
|
||||
api_cfg: api_cfg,
|
||||
for_obj_type: 'journal',
|
||||
for_obj_id: journal_id,
|
||||
params: {qry__enabled: 'all', qry__limit: 99},
|
||||
try_cache: try_cache,
|
||||
log_lvl: log_lvl
|
||||
})
|
||||
.then((journal_entry_obj_li) => {
|
||||
if (log_lvl) {
|
||||
console.log(`journal_entry_obj_li = `, journal_entry_obj_li);
|
||||
}
|
||||
return journal_entry_obj_li;
|
||||
});
|
||||
|
||||
if (log_lvl) {
|
||||
console.log(`journal_entry_obj_li = `, load_journal_entry_obj_li);
|
||||
}
|
||||
ae_promises.load__journal_obj.journal_entry_li = load_journal_entry_obj_li;
|
||||
}
|
||||
|
||||
return ae_promises.load__journal_obj;
|
||||
}
|
||||
|
||||
|
||||
// Updated 2025-03-15
|
||||
export async function load_ae_obj_li__journal(
|
||||
{
|
||||
api_cfg,
|
||||
for_obj_type = 'account',
|
||||
for_obj_id,
|
||||
inc_entry_li = false,
|
||||
enabled = 'enabled',
|
||||
hidden = 'not_hidden',
|
||||
limit = 99,
|
||||
offset = 0,
|
||||
order_by_li = {'priority': 'DESC', 'sort': 'DESC', 'name': 'ASC', 'updated_on': 'DESC', 'created_on': 'DESC'},
|
||||
params = {},
|
||||
try_cache = true,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
api_cfg: any,
|
||||
for_obj_type: string,
|
||||
for_obj_id: string,
|
||||
inc_entry_li?: boolean,
|
||||
enabled?: string, // all, disabled, enabled
|
||||
hidden?: string, // all, hidden, not_hidden
|
||||
limit?: number,
|
||||
offset?: number,
|
||||
order_by_li?: key_val,
|
||||
params?: key_val,
|
||||
try_cache?: boolean,
|
||||
log_lvl?: number
|
||||
}
|
||||
) {
|
||||
if (log_lvl) {
|
||||
console.log(`*** load_ae_obj_li__journal() *** for_obj_type=${for_obj_type} for_obj_id=${for_obj_id}`);
|
||||
}
|
||||
|
||||
let params_json: key_val = {};
|
||||
|
||||
// console.log('params_json:', params_json);
|
||||
|
||||
ae_promises.load__journal_obj_li = await api.get_ae_obj_li_for_obj_id_crud_v2({
|
||||
api_cfg: api_cfg,
|
||||
obj_type: 'journal',
|
||||
for_obj_type: for_obj_type,
|
||||
for_obj_id: for_obj_id,
|
||||
use_alt_tbl: false,
|
||||
use_alt_mdl: false,
|
||||
use_alt_exp: false,
|
||||
enabled: enabled,
|
||||
hidden: hidden,
|
||||
order_by_li: order_by_li,
|
||||
limit: limit,
|
||||
offset: offset,
|
||||
params_json: params_json,
|
||||
params: params,
|
||||
log_lvl: log_lvl
|
||||
})
|
||||
.then(function (journal_obj_li_get_result) {
|
||||
if (journal_obj_li_get_result) {
|
||||
if (try_cache) {
|
||||
db_save_ae_obj_li__journal({
|
||||
obj_type: 'journal',
|
||||
obj_li: journal_obj_li_get_result
|
||||
});
|
||||
}
|
||||
return journal_obj_li_get_result;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
});
|
||||
|
||||
if (log_lvl) {
|
||||
console.log('ae_promises.load__journal_obj_li:', ae_promises.load__journal_obj_li);
|
||||
}
|
||||
|
||||
if (inc_entry_li) {
|
||||
// Load the entries for the journals
|
||||
if (log_lvl) {
|
||||
console.log(`Need to load the entry list for each journal now`);
|
||||
}
|
||||
for (let i = 0; i < ae_promises.load__journal_obj_li.length; i++) {
|
||||
let journal_obj = ae_promises.load__journal_obj_li[i];
|
||||
let journal_id = journal_obj.journal_id_random;
|
||||
|
||||
let load_journal_entry_obj_li = load_ae_obj_li__journal_entry({
|
||||
api_cfg: api_cfg,
|
||||
for_obj_type: 'journal',
|
||||
for_obj_id: journal_id,
|
||||
params: params,
|
||||
try_cache: try_cache,
|
||||
log_lvl: log_lvl
|
||||
})
|
||||
.then((journal_entry_obj_li) => {
|
||||
if (log_lvl) {
|
||||
console.log(`journal_entry_obj_li = `, journal_entry_obj_li);
|
||||
}
|
||||
|
||||
return journal_entry_obj_li;
|
||||
});
|
||||
|
||||
if (log_lvl) {
|
||||
console.log(`load_journal_entry_obj_li = `, load_journal_entry_obj_li);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ae_promises.load__journal_obj_li;
|
||||
}
|
||||
|
||||
|
||||
// Updated 2025-03-15
|
||||
export async function create_ae_obj__journal(
|
||||
{
|
||||
api_cfg,
|
||||
account_id,
|
||||
data_kv,
|
||||
params = {},
|
||||
try_cache = true,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
api_cfg: any,
|
||||
account_id: string,
|
||||
data_kv: key_val,
|
||||
params?: key_val,
|
||||
try_cache?: boolean,
|
||||
log_lvl?: number
|
||||
}
|
||||
) {
|
||||
if (log_lvl) {
|
||||
console.log(`*** create_ae_obj__journal() *** account_id=${account_id}`);
|
||||
}
|
||||
|
||||
ae_promises.create__journal = await api.create_ae_obj_crud({
|
||||
api_cfg: api_cfg,
|
||||
obj_type: 'journal',
|
||||
fields: {
|
||||
account_id_random: account_id,
|
||||
...data_kv
|
||||
},
|
||||
key: api_cfg.api_crud_super_key,
|
||||
params: params,
|
||||
return_obj: true,
|
||||
log_lvl: log_lvl
|
||||
})
|
||||
.then(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]
|
||||
});
|
||||
}
|
||||
return journal_obj_create_result;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.log('No results returned or failed.', error);
|
||||
})
|
||||
.finally(function () {
|
||||
});
|
||||
|
||||
if (log_lvl) {
|
||||
console.log('ae_promises.create__journal:', ae_promises.create__journal);
|
||||
}
|
||||
return ae_promises.create__journal;
|
||||
}
|
||||
|
||||
|
||||
// Updated 2025-03-15
|
||||
export async function delete_ae_obj_id__journal(
|
||||
{
|
||||
api_cfg,
|
||||
journal_id,
|
||||
method = 'delete', // 'delete', 'disable', 'hide'
|
||||
params = {},
|
||||
try_cache = true,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
api_cfg: any,
|
||||
journal_id: string,
|
||||
method?: string,
|
||||
params?: key_val,
|
||||
try_cache?: boolean,
|
||||
log_lvl?: number
|
||||
}
|
||||
) {
|
||||
if (log_lvl) {
|
||||
console.log(`*** delete_ae_obj_id__journal() *** journal_id=${journal_id}`);
|
||||
}
|
||||
|
||||
ae_promises.delete__journal_obj = await api.delete_ae_obj_id_crud({
|
||||
api_cfg: api_cfg,
|
||||
obj_type: 'journal',
|
||||
obj_id: journal_id,
|
||||
key: api_cfg.api_crud_super_key,
|
||||
params: params,
|
||||
method: method,
|
||||
log_lvl: log_lvl
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.log('No results returned or failed.', error);
|
||||
})
|
||||
.finally(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);
|
||||
}
|
||||
});
|
||||
|
||||
if (log_lvl) {
|
||||
console.log('ae_promises.delete__journal_obj:', ae_promises.delete__journal_obj);
|
||||
}
|
||||
|
||||
return ae_promises.delete__journal_obj;
|
||||
}
|
||||
|
||||
|
||||
// Updated 2025-03-15
|
||||
export async function update_ae_obj__journal(
|
||||
{
|
||||
api_cfg,
|
||||
journal_id,
|
||||
data_kv,
|
||||
params = {},
|
||||
try_cache = true,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
api_cfg: any,
|
||||
journal_id: string,
|
||||
data_kv: key_val,
|
||||
params?: key_val,
|
||||
try_cache?: boolean,
|
||||
log_lvl?: number
|
||||
}
|
||||
) {
|
||||
if (log_lvl) {
|
||||
console.log(`*** update_ae_obj__journal() *** journal_id=${journal_id}`, data_kv);
|
||||
}
|
||||
ae_promises.update__journal_obj = await api.update_ae_obj_id_crud({
|
||||
api_cfg: api_cfg,
|
||||
obj_type: 'journal',
|
||||
obj_id: journal_id,
|
||||
fields: data_kv,
|
||||
key: api_cfg.api_crud_super_key,
|
||||
params: params,
|
||||
return_obj: true,
|
||||
log_lvl: log_lvl
|
||||
})
|
||||
.then(function (journal_obj_update_result) {
|
||||
if (journal_obj_update_result) {
|
||||
if (try_cache) {
|
||||
db_save_ae_obj_li__journal({
|
||||
obj_type: 'journal', obj_li: [journal_obj_update_result]
|
||||
});
|
||||
}
|
||||
return journal_obj_update_result;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.log('No results returned or failed.', error);
|
||||
})
|
||||
.finally(function () {
|
||||
});
|
||||
|
||||
if (log_lvl) {
|
||||
console.log('ae_promises.update__journal_obj:', ae_promises.update__journal_obj);
|
||||
}
|
||||
return ae_promises.update__journal_obj;
|
||||
}
|
||||
|
||||
|
||||
// This new function is using CRUD v2. This should allow for more flexibility in the queries.
|
||||
// Updated 2025-03-15
|
||||
export async function qry__journal(
|
||||
{
|
||||
api_cfg,
|
||||
journal_id,
|
||||
qry_str,
|
||||
qry_files,
|
||||
qry_start_datetime, // Example greater than: '2024-10-24'
|
||||
enabled = 'enabled',
|
||||
hidden = 'not_hidden',
|
||||
limit = 50,
|
||||
offset = 0,
|
||||
params = {},
|
||||
try_cache = true,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
api_cfg: any,
|
||||
journal_id: any,
|
||||
qry_str?: string,
|
||||
qry_files?: null|boolean,
|
||||
qry_start_datetime?: null|string, // Greater than this datetime
|
||||
enabled?: string, // all, disabled, enabled
|
||||
hidden?: string, // all, hidden, not_hidden
|
||||
limit?: number,
|
||||
offset?: number,
|
||||
params?: any,
|
||||
try_cache?: boolean,
|
||||
log_lvl?: number
|
||||
}
|
||||
) {
|
||||
if (log_lvl) {
|
||||
console.log(`*** qry__journal() *** journal_id=${journal_id} enabled=${enabled} hidden=${hidden} limit=${limit} offset=${offset}`);
|
||||
}
|
||||
|
||||
// let enabled: string = (params.qry__enabled ?? 'enabled'); // all, disabled, enabled
|
||||
// let hidden: string = (params.qry__hidden ?? 'not_hidden'); // all, hidden, not_hidden
|
||||
// let limit: number = (params.qry__limit ?? 25); // 99
|
||||
// let offset: number = (params.qry__offset ?? 0); // 0
|
||||
|
||||
let params_json: key_val = {};
|
||||
|
||||
// if (qry_str && qry_str.length > 2) {
|
||||
// params_json['ft_qry'] = {};
|
||||
// params_json['ft_qry']['default_qry_str'] = qry_str;
|
||||
// }
|
||||
|
||||
params_json['qry'] = [];
|
||||
|
||||
if (qry_files === true) {
|
||||
let qry_param =
|
||||
{
|
||||
type: "AND",
|
||||
field: "file_count_all",
|
||||
operator: ">",
|
||||
value: 0
|
||||
};
|
||||
params_json['qry'].push(qry_param);
|
||||
} else if (qry_files === false) {
|
||||
let qry_param =
|
||||
{
|
||||
type: "AND",
|
||||
field: "file_count_all",
|
||||
operator: "IS",
|
||||
value: null
|
||||
};
|
||||
params_json['qry'].push(qry_param);
|
||||
}
|
||||
|
||||
if (qry_start_datetime) {
|
||||
let qry_param =
|
||||
{
|
||||
type: "AND",
|
||||
field: "start_datetime",
|
||||
operator: ">",
|
||||
value: qry_start_datetime
|
||||
};
|
||||
params_json['qry'].push(qry_param);
|
||||
}
|
||||
|
||||
let order_by_li = {'priority': 'DESC', 'sort': 'DESC', 'start_datetime': 'ASC', 'name': 'ASC', 'updated_on': 'DESC', 'created_on': 'DESC'};
|
||||
|
||||
ae_promises.load__journal_obj_li = await api.get_ae_obj_li_for_obj_id_crud_v2({
|
||||
api_cfg: api_cfg,
|
||||
obj_type: 'journal',
|
||||
for_obj_type: 'account',
|
||||
for_obj_id: journal_id,
|
||||
use_alt_tbl: true, // NOTE: We want to use the alt table for journal searching
|
||||
use_alt_mdl: false,
|
||||
use_alt_exp: false,
|
||||
enabled: enabled,
|
||||
hidden: hidden,
|
||||
order_by_li: order_by_li,
|
||||
limit: limit,
|
||||
offset: offset,
|
||||
params_json: params_json,
|
||||
params: params,
|
||||
log_lvl: log_lvl
|
||||
})
|
||||
.then(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
|
||||
});
|
||||
return journal_obj_li_get_result;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
});
|
||||
|
||||
if (log_lvl) {
|
||||
console.log('ae_promises.load__journal_obj_li:', ae_promises.load__journal_obj_li);
|
||||
}
|
||||
return ae_promises.load__journal_obj_li;
|
||||
}
|
||||
|
||||
|
||||
// This function will loop through the journal_obj_li and save each one to the DB.
|
||||
// Updated 2025-03-15
|
||||
export function db_save_ae_obj_li__journal(
|
||||
{
|
||||
obj_type,
|
||||
obj_li,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
obj_type: string,
|
||||
obj_li: any,
|
||||
log_lvl?: number
|
||||
}
|
||||
) {
|
||||
if (log_lvl) {
|
||||
console.log(`*** db_save_ae_obj_li__journal() ***`);
|
||||
}
|
||||
|
||||
if (obj_li && obj_li.length) {
|
||||
obj_li.forEach(async function (obj: any) {
|
||||
if (log_lvl) {
|
||||
console.log(`ae_obj ${obj_type}:`, obj);
|
||||
}
|
||||
|
||||
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,
|
||||
summary: obj.summary,
|
||||
outline: obj.outline,
|
||||
|
||||
description: obj.description,
|
||||
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,
|
||||
|
||||
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.original_datetime}_${obj.group}_${obj.priority}_${obj.sort}`,
|
||||
// tmp_sort_2: `${obj.group}_${obj.original_datetime}_${obj.priority}_${obj.sort}`,
|
||||
|
||||
// From SQL view
|
||||
// journal_other_count: obj.journal_other_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}`);
|
||||
} catch (error) {
|
||||
let status = `Failed to put ${obj.journal_id_random}: ${error}`;
|
||||
console.log(status);
|
||||
}
|
||||
|
||||
// const id_random = await db_journals.journal.put(obj);
|
||||
// console.log(`Put obj with ID: ${obj.journal_id_random}`);
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
425
src/lib/ae_journals/ae_journals__journal_entry.ts
Normal file
425
src/lib/ae_journals/ae_journals__journal_entry.ts
Normal file
@@ -0,0 +1,425 @@
|
||||
import type { key_val } from '$lib/ae_stores';
|
||||
import { api } from '$lib/api';
|
||||
|
||||
import { db_journals } from "$lib/ae_journals/db_journals";
|
||||
|
||||
let ae_promises: key_val = {};
|
||||
|
||||
|
||||
// Updated 2025-03-15
|
||||
export async function load_ae_obj_id__journal_entry(
|
||||
{
|
||||
api_cfg,
|
||||
journal_entry_id,
|
||||
try_cache = true,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
api_cfg: any,
|
||||
journal_entry_id: string,
|
||||
try_cache?: boolean,
|
||||
log_lvl?: number
|
||||
}
|
||||
) {
|
||||
if (log_lvl) {
|
||||
console.log(`*** load_ae_obj_id__journal_entry() *** journal_entry_id=${journal_entry_id}`);
|
||||
}
|
||||
|
||||
let params = {};
|
||||
|
||||
ae_promises.load__journal_entry_obj = await api.get_ae_obj_id_crud({
|
||||
api_cfg: api_cfg,
|
||||
obj_type: 'journal_entry',
|
||||
obj_id: journal_entry_id, // NOTE: This is the FQDN, not normally the ID.
|
||||
use_alt_table: true, // NOTE: This will use the table_name_alt value instead of the table_name value in the API config.
|
||||
use_alt_base: false, // NOTE: This will use the base_name_alt value instead of the base_name value
|
||||
params: params,
|
||||
log_lvl: log_lvl
|
||||
})
|
||||
.then(async function (journal_entry_obj_get_result) {
|
||||
if (journal_entry_obj_get_result) {
|
||||
if (try_cache) {
|
||||
// This is expecting a list
|
||||
await db_save_ae_obj_li__journal_entry({
|
||||
obj_type: 'journal_entry',
|
||||
obj_li: [journal_entry_obj_get_result]
|
||||
|
||||
});
|
||||
}
|
||||
return journal_entry_obj_get_result;
|
||||
} else {
|
||||
console.log('No results returned.');
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.log('No results returned or failed.', error);
|
||||
});
|
||||
|
||||
return ae_promises.load__journal_entry_obj;
|
||||
}
|
||||
|
||||
|
||||
// Updated 2025-03-15
|
||||
export async function load_ae_obj_li__journal_entry(
|
||||
{
|
||||
api_cfg,
|
||||
for_obj_type = 'journal',
|
||||
for_obj_id,
|
||||
enabled = 'enabled',
|
||||
hidden = 'not_hidden',
|
||||
limit = 99,
|
||||
offset = 0,
|
||||
order_by_li = {'priority': 'DESC', 'sort': 'DESC', 'name': 'ASC', 'updated_on': 'DESC', 'created_on': 'DESC'},
|
||||
params = {},
|
||||
try_cache = true,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
api_cfg: any,
|
||||
for_obj_type: string,
|
||||
for_obj_id: string,
|
||||
enabled?: string,
|
||||
hidden?: string,
|
||||
limit?: number,
|
||||
offset?: number,
|
||||
order_by_li?: key_val,
|
||||
params?: key_val,
|
||||
try_cache?: boolean,
|
||||
log_lvl?: number
|
||||
}
|
||||
) {
|
||||
if (log_lvl) {
|
||||
console.log(`*** load_ae_obj_li__journal_entry() *** for_obj_type=${for_obj_type} for_obj_id=${for_obj_id}`);
|
||||
}
|
||||
|
||||
// let enabled: string = (params.qry__enabled ?? 'enabled'); // all, disabled, enabled
|
||||
// let hidden: string = (params.qry__hidden ?? 'not_hidden'); // all, hidden, not_hidden
|
||||
// let limit: number = (params.qry__limit ?? 99); // 99
|
||||
// let offset: number = (params.qry__offset ?? 0); // 0
|
||||
|
||||
let params_json: key_val = {};
|
||||
|
||||
// console('params_json:', params_json);
|
||||
|
||||
ae_promises.load__journal_entry_obj_li = await api.get_ae_obj_li_for_obj_id_crud_v2({
|
||||
api_cfg: api_cfg,
|
||||
obj_type: 'journal_entry',
|
||||
for_obj_type: for_obj_type,
|
||||
for_obj_id: for_obj_id,
|
||||
use_alt_tbl: false,
|
||||
use_alt_mdl: false,
|
||||
use_alt_exp: false,
|
||||
enabled: enabled,
|
||||
hidden: hidden,
|
||||
order_by_li: order_by_li,
|
||||
limit: limit,
|
||||
offset: offset,
|
||||
params_json: params_json,
|
||||
params: params,
|
||||
log_lvl: log_lvl
|
||||
})
|
||||
.then(async function (journal_entry_obj_li_get_result) {
|
||||
if (journal_entry_obj_li_get_result) {
|
||||
if (try_cache) {
|
||||
await db_save_ae_obj_li__journal_entry({
|
||||
obj_type: 'journal_entry', obj_li: journal_entry_obj_li_get_result
|
||||
});
|
||||
}
|
||||
return journal_entry_obj_li_get_result;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.log('No results returned or failed.', error);
|
||||
});
|
||||
|
||||
if (log_lvl) {
|
||||
console.log('ae_promises.load__journal_entry_obj_li:', ae_promises.load__journal_entry_obj_li);
|
||||
}
|
||||
|
||||
return ae_promises.load__journal_entry_obj_li;
|
||||
}
|
||||
|
||||
|
||||
// Updated 2025-03-15
|
||||
export async function create_ae_obj__journal_entry(
|
||||
{
|
||||
api_cfg,
|
||||
journal_id,
|
||||
data_kv,
|
||||
params={},
|
||||
try_cache = true,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
api_cfg: any,
|
||||
journal_id: string,
|
||||
data_kv: key_val,
|
||||
params?: key_val,
|
||||
try_cache?: boolean,
|
||||
log_lvl?: number
|
||||
}
|
||||
) {
|
||||
if (log_lvl) {
|
||||
console.log(`*** create_ae_obj__journal_entry() *** journal_id=${journal_id}`);
|
||||
}
|
||||
|
||||
ae_promises.create__journal_entry = await api.create_ae_obj_crud({
|
||||
api_cfg: api_cfg,
|
||||
obj_type: 'journal_entry',
|
||||
fields: {
|
||||
journal_id_random: journal_id,
|
||||
...data_kv
|
||||
},
|
||||
key: api_cfg.api_crud_super_key,
|
||||
params: params,
|
||||
return_obj: true,
|
||||
log_lvl: log_lvl
|
||||
})
|
||||
.then(async function (journal_entry_obj_create_result) {
|
||||
if (journal_entry_obj_create_result) {
|
||||
if (try_cache) {
|
||||
await db_save_ae_obj_li__journal_entry(
|
||||
{
|
||||
obj_type: 'journal_entry',
|
||||
obj_li: [journal_entry_obj_create_result]
|
||||
});
|
||||
}
|
||||
return journal_entry_obj_create_result;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.log('No results returned or failed.', error);
|
||||
});
|
||||
|
||||
if (log_lvl) {
|
||||
console.log('ae_promises.create__journal_entry:', ae_promises.create__journal_entry);
|
||||
}
|
||||
return ae_promises.create__journal_entry;
|
||||
}
|
||||
|
||||
|
||||
// Updated 2025-03-15
|
||||
export async function delete_ae_obj_id__journal_entry(
|
||||
{
|
||||
api_cfg,
|
||||
journal_entry_id,
|
||||
method = 'delete', // 'delete', 'disable', 'hide'
|
||||
params = {},
|
||||
try_cache = true,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
api_cfg: any,
|
||||
journal_entry_id: string,
|
||||
method?: string,
|
||||
params?: key_val,
|
||||
try_cache?: boolean,
|
||||
log_lvl?: number
|
||||
}
|
||||
) {
|
||||
if (log_lvl) {
|
||||
console.log(`*** delete_ae_obj_id__journal_entry() *** journal_entry_id=${journal_entry_id}`);
|
||||
}
|
||||
|
||||
ae_promises.delete__journal_entry_obj = await api.delete_ae_obj_id_crud({
|
||||
api_cfg: api_cfg,
|
||||
obj_type: 'journal_entry',
|
||||
obj_id: journal_entry_id,
|
||||
key: api_cfg.api_crud_super_key,
|
||||
params: params,
|
||||
method: method,
|
||||
log_lvl: log_lvl
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.log('No results returned or failed.', error);
|
||||
})
|
||||
.finally(function () {
|
||||
if (try_cache) {
|
||||
if (log_lvl) {
|
||||
console.log(`Attempting to remove IDB entry for journal_entry_id=${journal_entry_id}`);
|
||||
}
|
||||
db_journals.journal_entry.delete(journal_entry_id); // Delete from the DB no matter what.
|
||||
}
|
||||
});
|
||||
|
||||
if (log_lvl) {
|
||||
console.log('ae_promises.delete__journal_entry_obj:', ae_promises.delete__journal_entry_obj);
|
||||
}
|
||||
|
||||
return ae_promises.delete__journal_entry_obj;
|
||||
}
|
||||
|
||||
|
||||
// Updated 2025-03-15
|
||||
export async function update_ae_obj__journal_entry(
|
||||
{
|
||||
api_cfg,
|
||||
journal_entry_id,
|
||||
data_kv,
|
||||
params = {},
|
||||
try_cache = true,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
api_cfg: any,
|
||||
journal_entry_id: string,
|
||||
data_kv: key_val,
|
||||
params?: key_val,
|
||||
try_cache?: boolean,
|
||||
log_lvl?: number
|
||||
}
|
||||
) {
|
||||
if (log_lvl) {
|
||||
console.log(`*** update_ae_obj__journal_entry() *** journal_entry_id=${journal_entry_id}`, data_kv);
|
||||
}
|
||||
ae_promises.update__journal_entry_obj = await api.update_ae_obj_id_crud({
|
||||
api_cfg: api_cfg,
|
||||
obj_type: 'journal_entry',
|
||||
obj_id: journal_entry_id,
|
||||
fields: data_kv,
|
||||
key: api_cfg.api_crud_super_key,
|
||||
params: params,
|
||||
return_obj: true,
|
||||
log_lvl: log_lvl
|
||||
})
|
||||
.then(async function (journal_entry_obj_update_result) {
|
||||
if (journal_entry_obj_update_result) {
|
||||
if (try_cache) {
|
||||
await db_save_ae_obj_li__journal_entry({
|
||||
obj_type: 'journal_entry', obj_li: [journal_entry_obj_update_result]
|
||||
});
|
||||
}
|
||||
return journal_entry_obj_update_result;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.log('No results returned or failed.', error);
|
||||
})
|
||||
.finally(function () {
|
||||
});
|
||||
|
||||
if (log_lvl) {
|
||||
console.log('ae_promises.update__journal_entry_obj:', ae_promises.update__journal_entry_obj);
|
||||
}
|
||||
return ae_promises.update__journal_entry_obj;
|
||||
}
|
||||
|
||||
|
||||
// This function will loop through the journal_entry_obj_li and save each one to the DB.
|
||||
// Updated 2025-03-15
|
||||
export async function db_save_ae_obj_li__journal_entry(
|
||||
{
|
||||
obj_type,
|
||||
obj_li,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
obj_type: string,
|
||||
obj_li: any,
|
||||
log_lvl?: number
|
||||
}
|
||||
) {
|
||||
if (log_lvl) {
|
||||
console.log(`*** db_save_ae_obj_li__journal_entry() ***`);
|
||||
}
|
||||
|
||||
if (obj_li && obj_li.length) {
|
||||
obj_li.forEach(async function (obj: any) {
|
||||
if (log_lvl) {
|
||||
console.log(`ae_obj ${obj_type}:`, obj);
|
||||
}
|
||||
|
||||
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,
|
||||
|
||||
name: obj.name,
|
||||
summary: obj.summary,
|
||||
outline: obj.outline,
|
||||
// description: obj.description,
|
||||
|
||||
content: obj.content,
|
||||
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.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}`);
|
||||
} catch (error) {
|
||||
let status = `Failed to put ${obj.journal_entry_id_random}: ${error}`;
|
||||
console.log(status);
|
||||
}
|
||||
|
||||
// const id_random = await db_journals.journal_entry.put(obj);
|
||||
// console.log(`Put obj with ID: ${obj.journal_entry_id_random}`);
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
21
src/lib/ae_journals/ae_journals_functions.ts
Normal file
21
src/lib/ae_journals/ae_journals_functions.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
// This file is used to export all the functions that are used for Aether Journals related functions.
|
||||
|
||||
import * as journal from "$lib/ae_journals/ae_journals__journal";
|
||||
import * as journal_entry from "$lib/ae_journals/ae_journals__journal_entry";
|
||||
|
||||
|
||||
let export_obj = {
|
||||
load_ae_obj_id__journal: journal.load_ae_obj_id__journal,
|
||||
load_ae_obj_li__journal: journal.load_ae_obj_li__journal,
|
||||
create_ae_obj__journal: journal.create_ae_obj__journal,
|
||||
delete_ae_obj_id__journal: journal.delete_ae_obj_id__journal,
|
||||
update_ae_obj__journal: journal.update_ae_obj__journal,
|
||||
db_save_ae_obj_li__journal: journal.db_save_ae_obj_li__journal,
|
||||
load_ae_obj_id__journal_entry: journal_entry.load_ae_obj_id__journal_entry,
|
||||
load_ae_obj_li__journal_entry: journal_entry.load_ae_obj_li__journal_entry,
|
||||
create_ae_obj__journal_entry: journal_entry.create_ae_obj__journal_entry,
|
||||
delete_ae_obj_id__journal_entry: journal_entry.delete_ae_obj_id__journal_entry,
|
||||
update_ae_obj__journal_entry: journal_entry.update_ae_obj__journal_entry,
|
||||
db_save_ae_obj_li__journal_entry: journal_entry.db_save_ae_obj_li__journal_entry,
|
||||
};
|
||||
export let journals_func = export_obj;
|
||||
104
src/lib/ae_journals/ae_journals_stores.ts
Normal file
104
src/lib/ae_journals/ae_journals_stores.ts
Normal file
@@ -0,0 +1,104 @@
|
||||
import { localStorageStore } from '@skeletonlabs/skeleton';
|
||||
import { writable } from 'svelte/store';
|
||||
import type { Writable } from 'svelte/store';
|
||||
|
||||
import type { key_val } from '$lib/ae_stores';
|
||||
|
||||
|
||||
/* *** BEGIN *** Initialize journals_local_data_struct */
|
||||
// This is for longer term or sticky app data. This should be stored to *local* storage.
|
||||
// Updated 2024-08-20
|
||||
let journals_local_data_struct: key_val = {
|
||||
ver: '2024-08-20_19',
|
||||
// Shared
|
||||
name: 'Aether - Journals (SvelteKit 2.x Svelte 4.x)',
|
||||
title: `OSIT's Æ Journals`, // Æ
|
||||
|
||||
mode__edit: false,
|
||||
mode__debug: false,
|
||||
|
||||
qry__enabled: 'enabled', // all, disabled, enabled
|
||||
qry__hidden: 'not_hidden', // all, hidden, not_hidden
|
||||
qry__limit: 20,
|
||||
qry__order_by_li: {
|
||||
// 'created_on': 'desc',
|
||||
// 'updated_on': 'desc',
|
||||
},
|
||||
qry__offset: 0,
|
||||
qry__journal_id: null,
|
||||
|
||||
};
|
||||
// console.log(`AE Stores - App Journals Local Storage Data:`, journals_local_data_struct);
|
||||
|
||||
// This works and uses *local* storage:
|
||||
export let journals_loc: Writable<key_val> = localStorageStore('ae_journals_loc', journals_local_data_struct);
|
||||
// console.log(`AE Stores - App Local Storage Data:`, get(ae_loc));
|
||||
|
||||
|
||||
|
||||
/* *** BEGIN *** Initialize journals_session_data_struct */
|
||||
// Temporary app data. This is lost if the page is refreshed or using different tabs/windows. This should be stored to *session* storage.
|
||||
// Updated 2024-08-20
|
||||
let journals_session_data_struct: key_val = {
|
||||
ver: '2024-08-20_19',
|
||||
log_lvl: 1,
|
||||
|
||||
// Shared Triggers
|
||||
trigger: null,
|
||||
trigger__journal_id: null,
|
||||
// trigger__journal_li: null,
|
||||
|
||||
show__modal_edit__journal_id: false,
|
||||
show__modal_view__journal_id: null,
|
||||
show_list__journal_entry_li_group: true,
|
||||
show__modal_view__journal_entry_id: null,
|
||||
show__modal_edit__journal_entry_id: null,
|
||||
};
|
||||
// console.log(`AE Stores - App Journals Session Storage Data:`, journals_session_data_struct);
|
||||
export let journals_sess = writable(journals_session_data_struct);
|
||||
|
||||
|
||||
|
||||
/* *** BEGIN *** Initialize journals_slct and journals_trig */
|
||||
/* The slct and slct_trigger variable should not be stored in local storage. Only use session storage because browser tabs can be open to different journals, badges, exhibits, etc. */
|
||||
|
||||
// Intended for temporary session storage.
|
||||
// Updated 2024-08-20
|
||||
let journals_slct_obj_template: key_val = {
|
||||
// Top level
|
||||
'journal_id': null,
|
||||
'journal_obj': {},
|
||||
'journal_obj_li': [],
|
||||
|
||||
'lq__journal_obj': {}, // Testing passing a LiveQuery object around...
|
||||
};
|
||||
// console.log(`AE Stores - Selected Journals Objects:`, journals_slct_obj_template);
|
||||
|
||||
// This works, and uses *session* (not local) storage:
|
||||
export let journals_slct = writable(journals_slct_obj_template);
|
||||
|
||||
|
||||
/* *** BEGIN *** Initialize journals_trig */
|
||||
// Intended for temporary session storage.
|
||||
// Updated 2025-03-16
|
||||
let journals_trig_template: key_val = {
|
||||
archive_id: false,
|
||||
archive_content_li: false,
|
||||
event_id: false,
|
||||
post_id: false,
|
||||
};
|
||||
export let journals_trig: any = writable(journals_trig_template);
|
||||
// console.log(`AE Journals Stores - Journals Trigger:`, journals_trig);
|
||||
|
||||
|
||||
/* *** BEGIN *** Initialize journals_prom */
|
||||
// Intended for temporary session storage.
|
||||
// Updated 2025-03-16
|
||||
let journals_prom_template: key_val = {
|
||||
archive_id: false,
|
||||
archive_content_li: false,
|
||||
event_id: false,
|
||||
post_id: false,
|
||||
};
|
||||
export let journals_prom: any = writable(journals_prom_template);
|
||||
// console.log(`AE Journals Stores - Journals Trigger:`, journals_prom);
|
||||
274
src/lib/ae_journals/db_journals.ts
Normal file
274
src/lib/ae_journals/db_journals.ts
Normal file
@@ -0,0 +1,274 @@
|
||||
import Dexie, { type Table } from 'dexie';
|
||||
|
||||
import type { key_val } from '../ae_stores';
|
||||
|
||||
// li = list
|
||||
// kv = key value list
|
||||
// json = JSON string
|
||||
// ux = user experience (mode)
|
||||
// LLM = Large Language Model (AI)
|
||||
// Updated 2025-03-15
|
||||
|
||||
|
||||
export interface Journal {
|
||||
id: string; // actually "id_random"
|
||||
journal_id: string;
|
||||
|
||||
// Essentially this is a change log of journals
|
||||
snapshot_id?: string; // This is the original journal ID. If deleted, then delete all children journals.
|
||||
previous_id?: null|string; // This is the old or parent journal ID
|
||||
next_id?: null|string; // This is the new or child journal ID
|
||||
|
||||
external_id?: null|string;
|
||||
import_id?: null|string;
|
||||
code?: null|string;
|
||||
|
||||
for_type?: null|string;
|
||||
for_id?: null|string;
|
||||
|
||||
type_code?: null|string;
|
||||
|
||||
account_id?: null|string; // Owner account of the journal
|
||||
person_id?: null|string; // Owner person of the journal
|
||||
// event_id?: null|string; // Assign to an event???
|
||||
// location_id?: null|string; // Assign to a location???
|
||||
|
||||
name: string; // or the title
|
||||
summary?: null|string; // LLM (AI) generated summary...???
|
||||
outline?: null|string; // LLM (AI) generated outline...???
|
||||
|
||||
description?: null|string;
|
||||
description_html?: null|string;
|
||||
description_json?: null|string;
|
||||
|
||||
start_datetime?: null|Date;
|
||||
end_datetime?: null|Date;
|
||||
timezone?: null|string;
|
||||
|
||||
alert?: null|boolean; // LLM (AI) generated summary...???
|
||||
alert_msg?: null|string; // LLM (AI) generated summary...???
|
||||
|
||||
sort_by?: null|string; // This is the sort by field
|
||||
sort_by_desc?: null|string; // This is the sort by field description
|
||||
|
||||
cfg_json?: null|key_val; // This is the configuration JSON for the journal
|
||||
|
||||
data_json?: null|string; // We always need to store something extra...
|
||||
|
||||
ux_mode?: null|string; // 'mobile' or 'desktop'
|
||||
|
||||
// This only allows for basic access to the data.
|
||||
passcode_read?: null|string; // For LLM (AI) generated summary...???
|
||||
passcode_read_expire?: null|Date;
|
||||
passcode_write?: null|string;
|
||||
passcode_write_expire?: null|Date
|
||||
|
||||
enable: null|boolean;
|
||||
hide?: null|boolean;
|
||||
priority?: null|boolean
|
||||
sort?: null|number;
|
||||
group?: null|string;
|
||||
notes?: null|string;
|
||||
created_on: Date;
|
||||
updated_on?: null|Date;
|
||||
|
||||
// Additional fields for convenience (database views)
|
||||
file_count?: null|number; // Only files directly under a journal
|
||||
journal_file_id_li_json?: null|string;
|
||||
|
||||
// One person
|
||||
person__given_name?: null|string;
|
||||
person__family_name?: null|string;
|
||||
person__full_name?: null|string;
|
||||
person__primary_email?: null|string;
|
||||
person__passcode?: null|string;
|
||||
|
||||
// JSON formatted key value pairs for multiple people: {id: name, email, etc.}
|
||||
person__kv_json?: null|string;
|
||||
|
||||
journal_name?: null|string;
|
||||
|
||||
journal_location_code?: null|string;
|
||||
journal_location_name?: null|string;
|
||||
|
||||
// A key value list of the entries
|
||||
journal_entry_kv?: null|key_val;
|
||||
journal_entry_li?: null|[];
|
||||
// A key value list of the files
|
||||
journal_file_kv?: null|key_val;
|
||||
journal_file_li?: null|[];
|
||||
|
||||
// journal_collection_id?: null|string; // For a collection of journals?
|
||||
|
||||
// Future standard fields!!!
|
||||
obj_id?: null|string;
|
||||
obj_ext_uid?: null|string; // Probably not needed for journals
|
||||
obj_ext_id?: null|string; // Probably not needed for journals
|
||||
obj_import_id?: null|string; // Probably not needed for journals
|
||||
obj_code?: null|string;
|
||||
obj_account_id?: null|string;
|
||||
obj_passcode?: null|string;
|
||||
obj_type?: null|string; // Should always be 'journal' in this case
|
||||
obj_type_ver_id?: null|string; // The ID from the table for the object type
|
||||
obj_name?: null|string;
|
||||
obj_summary?: null|string; // LLM (AI) generated summary...???
|
||||
obj_outline?: null|string; // LLM (AI) generated outline...???
|
||||
obj_description?: null|string; // Probably not needed for journals
|
||||
obj_enable?: null|boolean;
|
||||
obj_enable_on?: null|Date;
|
||||
obj_archive_on?: null|Date;
|
||||
obj_hide?: null|boolean;
|
||||
obj_priority?: null|number;
|
||||
obj_sort?: null|number;
|
||||
obj_group?: null|string;
|
||||
obj_cfg_json?: null|string;
|
||||
obj_notes?: null|string;
|
||||
obj_created_on?: Date;
|
||||
obj_updated_on?: null|Date;
|
||||
}
|
||||
|
||||
|
||||
// Updated 2025-03-15
|
||||
export interface Journal_Entry {
|
||||
id: string; // actually "id_random"
|
||||
journal_entry_id: string;
|
||||
|
||||
journal_id: string; // This is the parent journal ID. If deleted, then delete all children journal entries.
|
||||
|
||||
// Essentially this is a change log of journal entries
|
||||
snapshot_id?: string; // This is the original journal ID. If deleted, then delete all children journal entries.
|
||||
previous_id?: null|string; // This is the old or parent journal ID
|
||||
next_id?: null|string; // This is the new or child journal ID
|
||||
|
||||
external_id?: null|string;
|
||||
import_id?: null|string;
|
||||
code?: null|string;
|
||||
|
||||
for_type?: null|string;
|
||||
for_id?: null|string;
|
||||
|
||||
type_code?: null|string;
|
||||
journal_entry_type?: null|string; // This is the type of journal entry
|
||||
|
||||
account_id?: null|string; // Owner account of the journal
|
||||
person_id?: null|string; // Owner person of the journal
|
||||
// event_id?: null|string; // Assign to an event???
|
||||
// location_id?: null|string; // Assign to a location???
|
||||
|
||||
name: string; // or the title
|
||||
summary?: null|string; // LLM (AI) generated summary...???
|
||||
outline?: null|string; // LLM (AI) generated outline...???
|
||||
// description?: null|string; // This is the description of the journal entry
|
||||
|
||||
content?: null|string;
|
||||
content_html?: null|string;
|
||||
content_json?: null|string;
|
||||
|
||||
start_datetime?: null|Date;
|
||||
end_datetime?: null|Date;
|
||||
timezone?: null|string;
|
||||
|
||||
alert?: null|boolean; // LLM (AI) generated summary...???
|
||||
alert_msg?: null|string; // LLM (AI) generated summary...???
|
||||
|
||||
// cfg_json?: null|key_val; // This is the configuration JSON for the journal entry
|
||||
data_json?: null|string; // We always need to store something extra...
|
||||
|
||||
// This only allows for basic access to the content.
|
||||
passcode_read?: null|string; // For LLM (AI) generated summary...???
|
||||
passcode_read_expire?: null|Date;
|
||||
passcode_write?: null|string;
|
||||
passcode_write_expire?: null|Date
|
||||
|
||||
enable: null|boolean;
|
||||
hide?: null|boolean;
|
||||
priority?: null|boolean
|
||||
sort?: null|number;
|
||||
group?: null|string;
|
||||
notes?: null|string;
|
||||
created_on: Date;
|
||||
updated_on?: null|Date;
|
||||
|
||||
// Additional fields for convenience (database views)
|
||||
file_count?: null|number; // Only files directly under a journal
|
||||
journal_file_id_li_json?: null|string;
|
||||
|
||||
journal_code?: null|string; // This is the code for the journal entry
|
||||
journal_name?: null|string; // This is the name for the journal entry
|
||||
|
||||
// One person
|
||||
person__given_name?: null|string;
|
||||
person__family_name?: null|string;
|
||||
person__full_name?: null|string;
|
||||
person__primary_email?: null|string;
|
||||
person__passcode?: null|string;
|
||||
|
||||
// JSON formatted key value pairs for multiple people: {id: name, email, etc.}
|
||||
person__kv_json?: null|string;
|
||||
|
||||
// A key value list of the files
|
||||
journal_file_kv?: null|key_val;
|
||||
journal_file_li?: null|[];
|
||||
|
||||
// journal_collection_id?: null|string; // For a collection of journal entries?
|
||||
|
||||
// Future standard fields!!!
|
||||
obj_id?: null|string;
|
||||
obj_ext_uid?: null|string; // Probably not needed for journal entries
|
||||
obj_ext_id?: null|string; // Probably not needed for journal entries
|
||||
obj_import_id?: null|string; // Probably not needed for journal entries
|
||||
obj_code?: null|string;
|
||||
obj_account_id?: null|string;
|
||||
obj_passcode?: null|string;
|
||||
obj_type?: null|string; // Should always be 'journal' in this case
|
||||
obj_type_ver_id?: null|string; // The ID from the table for the object type
|
||||
obj_name?: null|string;
|
||||
obj_summary?: null|string; // LLM (AI) generated summary...???
|
||||
obj_outline?: null|string; // LLM (AI) generated outline...???
|
||||
obj_description?: null|string; // Probably not needed for journal entries
|
||||
obj_enable?: null|boolean;
|
||||
obj_enable_on?: null|Date;
|
||||
obj_archive_on?: null|Date;
|
||||
obj_hide?: null|boolean;
|
||||
obj_priority?: null|number;
|
||||
obj_sort?: null|number;
|
||||
obj_group?: null|string;
|
||||
obj_cfg_json?: null|string;
|
||||
obj_notes?: null|string;
|
||||
obj_created_on?: Date;
|
||||
obj_updated_on?: null|Date;
|
||||
}
|
||||
|
||||
|
||||
// Updated 2024-06-10
|
||||
export class MySubClassedDexie extends Dexie {
|
||||
// We just tell the typing system this is the case
|
||||
journal!: Table<Journal>;
|
||||
journal_entry!: Table<Journal_Entry>;
|
||||
|
||||
constructor() {
|
||||
super('ae_journals_db');
|
||||
this.version(1).stores({
|
||||
journal: `
|
||||
id, journal_id,
|
||||
code,
|
||||
account_id,
|
||||
conference, type,
|
||||
name,
|
||||
start_datetime, end_datetime,
|
||||
timezone,
|
||||
enable, hide, priority, sort, group, notes, created_on, updated_on`,
|
||||
journal_entry: `
|
||||
id, journal_entry_id,
|
||||
journal_id,
|
||||
code,
|
||||
account_id,
|
||||
name,
|
||||
start_datetime, end_datetime,
|
||||
timezone,
|
||||
enable, hide, priority, sort, group, notes, created_on, updated_on`,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export const db_journals = new MySubClassedDexie();
|
||||
@@ -1,706 +0,0 @@
|
||||
import type { key_val } from '$lib/ae_stores';
|
||||
import { api } from '$lib/api';
|
||||
|
||||
import { db_notes } from "$lib/ae_notes/db_notes";
|
||||
|
||||
// import { load_ae_obj_li__note_other } from "$lib/ae_notes__note_other";
|
||||
|
||||
let ae_promises: key_val = {};
|
||||
|
||||
|
||||
// Updated 2024-09-25
|
||||
export async function load_ae_obj_id__note(
|
||||
{
|
||||
api_cfg,
|
||||
note_id,
|
||||
// inc_other_li = false,
|
||||
try_cache = true,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
api_cfg: any,
|
||||
note_id: string,
|
||||
// inc_other_li?: boolean,
|
||||
try_cache?: boolean,
|
||||
log_lvl?: number
|
||||
}
|
||||
) {
|
||||
console.log(`*** load_ae_obj_id__note() *** note_id=${note_id}`);
|
||||
|
||||
let params = {};
|
||||
|
||||
ae_promises.load__note_obj = await api.get_ae_obj_id_crud({
|
||||
api_cfg: api_cfg,
|
||||
obj_type: 'note',
|
||||
obj_id: note_id, // NOTE: This is the FQDN, not normally the ID.
|
||||
use_alt_table: true, // NOTE: This will use the table_name_alt value instead of the table_name value in the API config.
|
||||
use_alt_base: false, // NOTE: This will use the base_name_alt value instead of the base_name value in the API config.
|
||||
params: params,
|
||||
log_lvl: log_lvl
|
||||
})
|
||||
.then(function (note_obj_get_result) {
|
||||
if (note_obj_get_result) {
|
||||
if (try_cache) {
|
||||
// This is expecting a list
|
||||
db_save_ae_obj_li__note({
|
||||
obj_type: 'note',
|
||||
obj_li: [note_obj_get_result]
|
||||
});
|
||||
}
|
||||
return note_obj_get_result;
|
||||
} else {
|
||||
console.log('No results returned.');
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.log('No results returned or failed.', error);
|
||||
});
|
||||
|
||||
if (log_lvl) {
|
||||
console.log('ae_promises.load__note_obj:', ae_promises.load__note_obj);
|
||||
}
|
||||
|
||||
// if (inc_other_li) {
|
||||
// // Load the others for the note
|
||||
// if (log_lvl) {
|
||||
// console.log(`Need to load the other list for the note now`);
|
||||
// }
|
||||
// let load_note_other_obj_li = load_ae_obj_li__note_other({
|
||||
// api_cfg: api_cfg,
|
||||
// for_obj_type: 'note',
|
||||
// for_obj_id: note_id,
|
||||
// inc_other_li: inc_other_li,
|
||||
// params: {qry__enabled: 'all', qry__limit: 25},
|
||||
// try_cache: try_cache,
|
||||
// log_lvl: log_lvl
|
||||
// })
|
||||
// .then((note_other_obj_li) => {
|
||||
// if (log_lvl) {
|
||||
// console.log(`note_other_obj_li = `, note_other_obj_li);
|
||||
// }
|
||||
// return note_other_obj_li;
|
||||
// });
|
||||
|
||||
// if (log_lvl) {
|
||||
// console.log(`note_other_obj_li = `, load_note_other_obj_li);
|
||||
// }
|
||||
// ae_promises.load__note_obj.note_other_li = load_note_other_obj_li;
|
||||
// }
|
||||
|
||||
return ae_promises.load__note_obj;
|
||||
}
|
||||
|
||||
|
||||
// Updated 2024-09-25
|
||||
export async function load_ae_obj_li__note(
|
||||
{
|
||||
api_cfg,
|
||||
for_obj_type = 'account',
|
||||
for_obj_id,
|
||||
// inc_other_li = false,
|
||||
enabled = 'enabled',
|
||||
hidden = 'not_hidden',
|
||||
limit = 99,
|
||||
offset = 0,
|
||||
order_by_li = {'priority': 'DESC', 'sort': 'DESC', 'name': 'ASC', 'updated_on': 'DESC', 'created_on': 'DESC'},
|
||||
params = {},
|
||||
try_cache = true,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
api_cfg: any,
|
||||
for_obj_type: string,
|
||||
for_obj_id: string,
|
||||
// inc_other_li?: boolean,
|
||||
enabled?: string, // all, disabled, enabled
|
||||
hidden?: string, // all, hidden, not_hidden
|
||||
limit?: number,
|
||||
offset?: number,
|
||||
order_by_li?: key_val,
|
||||
params?: key_val,
|
||||
try_cache?: boolean,
|
||||
log_lvl?: number
|
||||
}
|
||||
) {
|
||||
console.log(`*** load_ae_obj_li__note() *** for_obj_type=${for_obj_type} for_obj_id=${for_obj_id}`);
|
||||
|
||||
let params_json: key_val = {};
|
||||
|
||||
// console.log('params_json:', params_json);
|
||||
|
||||
ae_promises.load__note_obj_li = await api.get_ae_obj_li_for_obj_id_crud({
|
||||
api_cfg: api_cfg,
|
||||
obj_type: 'note',
|
||||
for_obj_type: for_obj_type,
|
||||
for_obj_id: for_obj_id,
|
||||
use_alt_table: true, // NOTE: This will use the table_name_alt value instead of the table_name value in the API config.
|
||||
use_alt_base: false, // NOTE: This will use the base_name_alt value instead of the base_name value
|
||||
enabled: enabled,
|
||||
hidden: hidden,
|
||||
order_by_li: order_by_li,
|
||||
limit: limit,
|
||||
offset: offset,
|
||||
params_json: params_json,
|
||||
params: params,
|
||||
log_lvl: log_lvl
|
||||
})
|
||||
.then(function (note_obj_li_get_result) {
|
||||
if (note_obj_li_get_result) {
|
||||
if (try_cache) {
|
||||
db_save_ae_obj_li__note({
|
||||
obj_type: 'note',
|
||||
obj_li: note_obj_li_get_result
|
||||
});
|
||||
}
|
||||
return note_obj_li_get_result;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.log('No results returned or failed.', error);
|
||||
});
|
||||
|
||||
if (log_lvl) {
|
||||
console.log('ae_promises.load__note_obj_li:', ae_promises.load__note_obj_li);
|
||||
}
|
||||
|
||||
// if (inc_other_li) {
|
||||
// // Load the others for the notes
|
||||
// if (log_lvl) {
|
||||
// console.log(`Need to load the other list for each note now`);
|
||||
// }
|
||||
// for (let i = 0; i < ae_promises.load__note_obj_li.length; i++) {
|
||||
// let note_obj = ae_promises.load__note_obj_li[i];
|
||||
// let note_id = note_obj.note_id_random;
|
||||
|
||||
// let load_note_other_obj_li = load_ae_obj_li__note_other({
|
||||
// api_cfg: api_cfg,
|
||||
// for_obj_type: 'note',
|
||||
// for_obj_id: note_id,
|
||||
// params: {qry__enabled: enabled, qry__limit: limit},
|
||||
// try_cache: try_cache,
|
||||
// log_lvl: log_lvl
|
||||
// })
|
||||
// .then((note_other_obj_li) => {
|
||||
// if (log_lvl) {
|
||||
// console.log(`note_other_obj_li = `, note_other_obj_li);
|
||||
// }
|
||||
|
||||
// return note_other_obj_li;
|
||||
// });
|
||||
|
||||
// if (log_lvl) {
|
||||
// console.log(`load_note_other_obj_li = `, load_note_other_obj_li);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
return ae_promises.load__note_obj_li;
|
||||
}
|
||||
|
||||
|
||||
// Updated 2024-10-08
|
||||
export async function create_ae_obj__note(
|
||||
{
|
||||
api_cfg,
|
||||
account_id,
|
||||
data_kv,
|
||||
params = {},
|
||||
try_cache = true,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
api_cfg: any,
|
||||
account_id: string,
|
||||
data_kv: key_val,
|
||||
params?: key_val,
|
||||
try_cache?: boolean,
|
||||
log_lvl?: number
|
||||
}
|
||||
) {
|
||||
if (log_lvl) {
|
||||
console.log(`*** create_ae_obj__note() *** account_id=${account_id}`);
|
||||
}
|
||||
|
||||
ae_promises.create__note = await api.create_ae_obj_crud({
|
||||
api_cfg: api_cfg,
|
||||
obj_type: 'note',
|
||||
fields: {
|
||||
account_id_random: account_id,
|
||||
...data_kv
|
||||
},
|
||||
key: api_cfg.api_crud_super_key,
|
||||
params: params,
|
||||
return_obj: true,
|
||||
log_lvl: log_lvl
|
||||
})
|
||||
.then(function (note_obj_create_result) {
|
||||
if (note_obj_create_result) {
|
||||
if (try_cache) {
|
||||
db_save_ae_obj_li__note(
|
||||
{
|
||||
obj_type: 'note',
|
||||
obj_li: [note_obj_create_result]
|
||||
});
|
||||
}
|
||||
return note_obj_create_result;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.log('No results returned or failed.', error);
|
||||
})
|
||||
.finally(function () {
|
||||
});
|
||||
|
||||
if (log_lvl) {
|
||||
console.log('ae_promises.create__note:', ae_promises.create__note);
|
||||
}
|
||||
return ae_promises.create__note;
|
||||
}
|
||||
|
||||
|
||||
// Updated 2024-11-08
|
||||
export async function delete_ae_obj_id__note(
|
||||
{
|
||||
api_cfg,
|
||||
note_id,
|
||||
method = 'delete', // 'delete', 'disable', 'hide'
|
||||
params = {},
|
||||
try_cache = true,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
api_cfg: any,
|
||||
note_id: string,
|
||||
method?: string,
|
||||
params?: key_val,
|
||||
try_cache?: boolean,
|
||||
log_lvl?: number
|
||||
}
|
||||
) {
|
||||
if (log_lvl) {
|
||||
console.log(`*** delete_ae_obj_id__note() *** note_id=${note_id}`);
|
||||
}
|
||||
|
||||
ae_promises.delete__note_obj = await api.delete_ae_obj_id_crud({
|
||||
api_cfg: api_cfg,
|
||||
obj_type: 'note',
|
||||
obj_id: note_id,
|
||||
key: api_cfg.api_crud_super_key,
|
||||
params: params,
|
||||
method: method,
|
||||
log_lvl: log_lvl
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.log('No results returned or failed.', error);
|
||||
})
|
||||
.finally(function () {
|
||||
if (try_cache) {
|
||||
if (log_lvl) {
|
||||
console.log(`Attempting to remove IDB entry for note_id=${note_id}`);
|
||||
}
|
||||
db_notes.note.delete(note_id);
|
||||
}
|
||||
});
|
||||
|
||||
if (log_lvl) {
|
||||
console.log('ae_promises.delete__note_obj:', ae_promises.delete__note_obj);
|
||||
}
|
||||
|
||||
return ae_promises.delete__note_obj;
|
||||
}
|
||||
|
||||
|
||||
// Updated 2024-09-25
|
||||
export async function update_ae_obj__note(
|
||||
{
|
||||
api_cfg,
|
||||
note_id,
|
||||
data_kv,
|
||||
params = {},
|
||||
try_cache = true,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
api_cfg: any,
|
||||
note_id: string,
|
||||
data_kv: key_val,
|
||||
params?: key_val,
|
||||
try_cache?: boolean,
|
||||
log_lvl?: number
|
||||
}
|
||||
) {
|
||||
if (log_lvl) {
|
||||
console.log(`*** update_ae_obj__note() *** note_id=${note_id}`, data_kv);
|
||||
}
|
||||
ae_promises.update__note_obj = await api.update_ae_obj_id_crud({
|
||||
api_cfg: api_cfg,
|
||||
obj_type: 'note',
|
||||
obj_id: note_id,
|
||||
fields: data_kv,
|
||||
key: api_cfg.api_crud_super_key,
|
||||
params: params,
|
||||
return_obj: true,
|
||||
log_lvl: log_lvl
|
||||
})
|
||||
.then(function (note_obj_update_result) {
|
||||
if (note_obj_update_result) {
|
||||
if (try_cache) {
|
||||
db_save_ae_obj_li__note({
|
||||
obj_type: 'note', obj_li: [note_obj_update_result]
|
||||
});
|
||||
}
|
||||
return note_obj_update_result;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.log('No results returned or failed.', error);
|
||||
})
|
||||
.finally(function () {
|
||||
});
|
||||
|
||||
if (log_lvl) {
|
||||
console.log('ae_promises.update__note_obj:', ae_promises.update__note_obj);
|
||||
}
|
||||
return ae_promises.update__note_obj;
|
||||
}
|
||||
|
||||
|
||||
// This new function is using CRUD v2. This should allow for more flexibility in the queries.
|
||||
// Updated 2024-09-25
|
||||
export async function qry__note(
|
||||
{
|
||||
api_cfg,
|
||||
note_id,
|
||||
qry_str,
|
||||
qry_files,
|
||||
qry_start_datetime, // Example greater than: '2024-10-24'
|
||||
enabled = 'enabled',
|
||||
hidden = 'not_hidden',
|
||||
limit = 50,
|
||||
offset = 0,
|
||||
params = {},
|
||||
try_cache = true,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
api_cfg: any,
|
||||
note_id: any,
|
||||
qry_str?: string,
|
||||
qry_files?: null|boolean,
|
||||
qry_start_datetime?: null|string, // Greater than this datetime
|
||||
enabled?: string, // all, disabled, enabled
|
||||
hidden?: string, // all, hidden, not_hidden
|
||||
limit?: number,
|
||||
offset?: number,
|
||||
params?: any,
|
||||
try_cache?: boolean,
|
||||
log_lvl?: number
|
||||
}
|
||||
) {
|
||||
console.log(`*** qry__note() *** note_id=${note_id} qry_str=${qry_str}`);
|
||||
|
||||
// let enabled: string = (params.qry__enabled ?? 'enabled'); // all, disabled, enabled
|
||||
// let hidden: string = (params.qry__hidden ?? 'not_hidden'); // all, hidden, not_hidden
|
||||
// let limit: number = (params.qry__limit ?? 25); // 99
|
||||
// let offset: number = (params.qry__offset ?? 0); // 0
|
||||
|
||||
let params_json: key_val = {};
|
||||
|
||||
// if (qry_str && qry_str.length > 2) {
|
||||
// params_json['ft_qry'] = {};
|
||||
// params_json['ft_qry']['default_qry_str'] = qry_str;
|
||||
// }
|
||||
|
||||
params_json['qry'] = [];
|
||||
|
||||
if (qry_files === true) {
|
||||
let qry_param =
|
||||
{
|
||||
type: "AND",
|
||||
field: "file_count_all",
|
||||
operator: ">",
|
||||
value: 0
|
||||
};
|
||||
params_json['qry'].push(qry_param);
|
||||
} else if (qry_files === false) {
|
||||
let qry_param =
|
||||
{
|
||||
type: "AND",
|
||||
field: "file_count_all",
|
||||
operator: "IS",
|
||||
value: null
|
||||
};
|
||||
params_json['qry'].push(qry_param);
|
||||
}
|
||||
|
||||
if (qry_start_datetime) {
|
||||
let qry_param =
|
||||
{
|
||||
type: "AND",
|
||||
field: "start_datetime",
|
||||
operator: ">",
|
||||
value: qry_start_datetime
|
||||
};
|
||||
params_json['qry'].push(qry_param);
|
||||
}
|
||||
|
||||
let order_by_li = {'priority': 'DESC', 'sort': 'DESC', 'start_datetime': 'ASC', 'name': 'ASC', 'updated_on': 'DESC', 'created_on': 'DESC'};
|
||||
|
||||
ae_promises.load__note_obj_li = await api.get_ae_obj_li_for_obj_id_crud_v2({
|
||||
api_cfg: api_cfg,
|
||||
obj_type: 'note',
|
||||
for_obj_type: 'account',
|
||||
for_obj_id: note_id,
|
||||
use_alt_tbl: true, // NOTE: We want to use the alt table for note searching
|
||||
use_alt_mdl: false,
|
||||
use_alt_exp: false,
|
||||
enabled: enabled,
|
||||
hidden: hidden,
|
||||
order_by_li: order_by_li,
|
||||
limit: limit,
|
||||
offset: offset,
|
||||
params_json: params_json,
|
||||
params: params,
|
||||
log_lvl: log_lvl
|
||||
})
|
||||
.then(function (note_obj_li_get_result) {
|
||||
if (note_obj_li_get_result) {
|
||||
db_save_ae_obj_li__note({
|
||||
obj_type: 'note',
|
||||
obj_li: note_obj_li_get_result
|
||||
});
|
||||
return note_obj_li_get_result;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
});
|
||||
|
||||
if (log_lvl) {
|
||||
console.log('ae_promises.load__note_obj_li:', ae_promises.load__note_obj_li);
|
||||
}
|
||||
return ae_promises.load__note_obj_li;
|
||||
}
|
||||
|
||||
|
||||
// Updated 2024-09-25
|
||||
// export async function search__note(
|
||||
// {
|
||||
// api_cfg,
|
||||
// account_id,
|
||||
// poc_agree = null,
|
||||
// fulltext_search_qry_str,
|
||||
// ft_other_search_qry_str,
|
||||
// like_search_qry_str = null,
|
||||
// file_count = false, // If true then only show those that have a file count
|
||||
// person_name = null,
|
||||
// params = {},
|
||||
// try_cache = true,
|
||||
// log_lvl = 0
|
||||
// }: {
|
||||
// api_cfg: any,
|
||||
// account_id: any,
|
||||
// poc_agree?: null|boolean,
|
||||
// fulltext_search_qry_str?: null|string,
|
||||
// ft_other_search_qry_str?: null|string,
|
||||
// like_search_qry_str?: null|string,
|
||||
// file_count?: boolean,
|
||||
// person_name?: null|string,
|
||||
// params?: any,
|
||||
// try_cache?: boolean,
|
||||
// log_lvl?: number
|
||||
// }
|
||||
// ) {
|
||||
// console.log(`*** search__note() *** account_id=${account_id}`);
|
||||
|
||||
// let enabled: string = (params.qry__enabled ?? 'enabled'); // all, disabled, enabled
|
||||
// let hidden: string = (params.qry__hidden ?? 'not_hidden'); // all, hidden, not_hidden
|
||||
// let limit: number = (params.qry__limit ?? 25); // 99
|
||||
// let offset: number = (params.qry__offset ?? 0); // 0
|
||||
|
||||
// let params_json: key_val = {};
|
||||
|
||||
// // if (!fulltext_search_qry_str && !like_search_qry_str) {
|
||||
// // console.log('No search string provided!!!');
|
||||
// // return false; // Returning false instead of [] because no search was performed.
|
||||
// // }
|
||||
|
||||
// if (fulltext_search_qry_str || ft_other_search_qry_str) {
|
||||
// params_json['ft_qry'] = {};
|
||||
// if (fulltext_search_qry_str && fulltext_search_qry_str.length > 2) {
|
||||
// params_json['ft_qry']['default_qry_str'] = fulltext_search_qry_str;
|
||||
// }
|
||||
|
||||
// if (ft_other_search_qry_str && ft_other_search_qry_str.length > 2) {
|
||||
// params_json['ft_qry']['note_other_li_qry_str'] = ft_other_search_qry_str;
|
||||
// }
|
||||
// }
|
||||
|
||||
// // Use the AND (AND LIKE) query
|
||||
// // if (like_search_qry_str || like_other_search_qry_str) {
|
||||
// // params_json['and_like'] = {};
|
||||
// // if (like_search_qry_str && like_search_qry_str.length > 2) {
|
||||
// // params_json['and_like']['default_qry_str'] = like_search_qry_str;
|
||||
// // }
|
||||
// // if (like_other_search_qry_str && like_other_search_qry_str.length > 2) {
|
||||
// // params_json['and_like']['note_other_li_qry_str'] = like_other_search_qry_str;
|
||||
// // }
|
||||
// // }
|
||||
|
||||
// // Use the AND (OR LIKE) query
|
||||
// if (like_search_qry_str || like_other_search_qry_str || like_other_search_qry_str) {
|
||||
// params_json['or_like'] = {};
|
||||
// if (like_search_qry_str && like_search_qry_str.length > 2) {
|
||||
// params_json['or_like']['default_qry_str'] = like_search_qry_str;
|
||||
// }
|
||||
// if (like_other_search_qry_str && like_other_search_qry_str.length > 2) {
|
||||
// params_json['or_like']['note_other_li_qry_str'] = like_other_search_qry_str;
|
||||
// }
|
||||
// if (like_other_search_qry_str && like_other_search_qry_str.length > 2) {
|
||||
// params_json['or_like']['note_other_li_qry_str'] = like_other_search_qry_str;
|
||||
// }
|
||||
// }
|
||||
|
||||
// params_json['and_qry'] = {};
|
||||
|
||||
// if (poc_agree) {
|
||||
// params_json['and_qry']['poc_agree'] = poc_agree;
|
||||
// }
|
||||
|
||||
// if (file_count) {
|
||||
// params_json['and_qry']['file_count'] = file_count;
|
||||
// }
|
||||
|
||||
// // This should be using a like with surrounded by %'s
|
||||
// if (person_name) {
|
||||
// params_json['and_qry']['note_full_name'] = person_name;
|
||||
// }
|
||||
|
||||
// let order_by_li = {'priority': 'DESC', 'sort': 'DESC', 'name': 'ASC', 'updated_on': 'DESC', 'created_on': 'DESC'};
|
||||
|
||||
// ae_promises.load__note_obj_li = await api.get_ae_obj_li_for_obj_id_crud({
|
||||
// api_cfg: api_cfg,
|
||||
// obj_type: 'note',
|
||||
// for_obj_type: 'account',
|
||||
// for_obj_id: account_id,
|
||||
// use_alt_table: true, // NOTE: We want to use the alt table for note searching
|
||||
// use_alt_base: false,
|
||||
// enabled: enabled,
|
||||
// hidden: hidden,
|
||||
// order_by_li: order_by_li,
|
||||
// limit: limit,
|
||||
// offset: offset,
|
||||
// params_json: params_json,
|
||||
// params: params,
|
||||
// log_lvl: log_lvl
|
||||
// })
|
||||
// .then(function (note_obj_li_get_result) {
|
||||
// if (note_obj_li_get_result) {
|
||||
// if (try_cache) {
|
||||
// db_save_ae_obj_li__note({
|
||||
// obj_type: 'note',
|
||||
// obj_li: note_obj_li_get_result
|
||||
// });
|
||||
// }
|
||||
// return note_obj_li_get_result;
|
||||
// } else {
|
||||
// return [];
|
||||
// }
|
||||
// })
|
||||
// .catch(function (error) {
|
||||
// console.log('No results returned or failed.', error);
|
||||
// })
|
||||
// .finally(function () {
|
||||
// });
|
||||
|
||||
// if (log_lvl) {
|
||||
// console.log('ae_promises.load__note_obj_li:', ae_promises.load__note_obj_li);
|
||||
// }
|
||||
// return ae_promises.load__note_obj_li;
|
||||
// }
|
||||
|
||||
|
||||
// This function will loop through the note_obj_li and save each one to the DB.
|
||||
// Updated 2024-09-25
|
||||
export function db_save_ae_obj_li__note(
|
||||
{
|
||||
obj_type,
|
||||
obj_li,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
obj_type: string,
|
||||
obj_li: any,
|
||||
log_lvl?: number
|
||||
}
|
||||
) {
|
||||
if (log_lvl) {
|
||||
console.log(`*** db_save_ae_obj_li__note() ***`);
|
||||
}
|
||||
|
||||
if (obj_li && obj_li.length) {
|
||||
obj_li.forEach(async function (obj: any) {
|
||||
if (log_lvl) {
|
||||
console.log(`ae_obj ${obj_type}:`, obj);
|
||||
}
|
||||
|
||||
try {
|
||||
const id_random = await db_notes.note.put({
|
||||
id: obj.note_id_random,
|
||||
note_id: obj.note_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,
|
||||
summary: obj.summary,
|
||||
outline: obj.outline,
|
||||
|
||||
// note: obj.note,
|
||||
note_html: obj.note_html,
|
||||
note_json: obj.note_json,
|
||||
|
||||
start_datetime: obj.start_datetime,
|
||||
end_datetime: obj.end_datetime,
|
||||
timezone: obj.timezone,
|
||||
|
||||
alert: obj.alert,
|
||||
alert_msg: obj.alert_msg,
|
||||
|
||||
data_json: obj.data_json,
|
||||
|
||||
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,
|
||||
|
||||
// From SQL view
|
||||
// note_other_count: obj.note_other_count,
|
||||
|
||||
// A key value list of the others
|
||||
// note_other_kv: obj.note_other_kv,
|
||||
// note_other_li: obj.note_other_li,
|
||||
});
|
||||
// console.log(`Put obj with ID: ${obj.note_id_random} or ${id_random}`);
|
||||
} catch (error) {
|
||||
let status = `Failed to put ${obj.note_id_random}: ${error}`;
|
||||
console.log(status);
|
||||
}
|
||||
|
||||
// const id_random = await db_notes.note.put(obj);
|
||||
// console.log(`Put obj with ID: ${obj.note_id_random}`);
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
// This file is used to export all the functions that are used for Aether Events related functions.
|
||||
|
||||
import * as note from "$lib/ae_notes/ae_notes__note";
|
||||
|
||||
|
||||
let export_obj = {
|
||||
load_ae_obj_id__note: note.load_ae_obj_id__note,
|
||||
load_ae_obj_li__note: note.load_ae_obj_li__note,
|
||||
create_ae_obj__note: note.create_ae_obj__note,
|
||||
delete_ae_obj_id__note: note.delete_ae_obj_id__note,
|
||||
update_ae_obj__note: note.update_ae_obj__note,
|
||||
db_save_ae_obj_li__note: note.db_save_ae_obj_li__note,
|
||||
};
|
||||
export let notes_func = export_obj;
|
||||
@@ -1,70 +0,0 @@
|
||||
import { localStorageStore } from '@skeletonlabs/skeleton';
|
||||
import { writable } from 'svelte/store';
|
||||
import type { Writable } from 'svelte/store';
|
||||
|
||||
import type { key_val } from '$lib/ae_stores';
|
||||
|
||||
|
||||
/* *** BEGIN *** Initialize notes_local_data_struct */
|
||||
// This is for longer term or sticky app data. This should be stored to *local* storage.
|
||||
// Updated 2024-08-20
|
||||
let notes_local_data_struct: key_val = {
|
||||
ver: '2024-08-20_19',
|
||||
// Shared
|
||||
name: 'Aether - Notes (SvelteKit 2.x Svelte 4.x)',
|
||||
title: `OSIT's Æ Notes`, // Æ
|
||||
|
||||
mode__edit: false,
|
||||
mode__debug: false,
|
||||
|
||||
};
|
||||
// console.log(`AE Stores - App Notes Local Storage Data:`, notes_local_data_struct);
|
||||
|
||||
// This works and uses *local* storage:
|
||||
export let notes_loc: Writable<key_val> = localStorageStore('ae_notes_loc', notes_local_data_struct);
|
||||
// console.log(`AE Stores - App Local Storage Data:`, get(ae_loc));
|
||||
|
||||
|
||||
|
||||
/* *** BEGIN *** Initialize notes_session_data_struct */
|
||||
// Temporary app data. This is lost if the page is refreshed or using different tabs/windows. This should be stored to *session* storage.
|
||||
// Updated 2024-08-20
|
||||
let notes_session_data_struct: key_val = {
|
||||
ver: '2024-08-20_19',
|
||||
log_lvl: 1,
|
||||
|
||||
// Shared Triggers
|
||||
trigger: null,
|
||||
trigger__note_id: null,
|
||||
// trigger__note_li: null,
|
||||
};
|
||||
// console.log(`AE Stores - App Notes Session Storage Data:`, notes_session_data_struct);
|
||||
export let notes_sess = writable(notes_session_data_struct);
|
||||
|
||||
|
||||
|
||||
/* *** BEGIN *** Initialize notes_slct and notes_trigger */
|
||||
/* The slct and slct_trigger variable should not be stored in local storage. Only use session storage because browser tabs can be open to different notes, badges, exhibits, etc. */
|
||||
|
||||
// Intended for temporary session storage.
|
||||
// Updated 2024-08-20
|
||||
let notes_slct_obj_template: key_val = {
|
||||
// Top level
|
||||
'note_id': null,
|
||||
'note_obj': {},
|
||||
'note_obj_li': [],
|
||||
|
||||
'lq__note_obj': {}, // Testing passing a LiveQuery object around...
|
||||
};
|
||||
// console.log(`AE Stores - Selected Notes Objects:`, notes_slct_obj_template);
|
||||
|
||||
// This works, and uses *session* (not local) storage:
|
||||
export let notes_slct = writable(notes_slct_obj_template);
|
||||
|
||||
|
||||
|
||||
/* *** BEGIN *** Initialize notes_trigger */
|
||||
// Intended for temporary session storage.
|
||||
// Updated 2024-08-20
|
||||
export let notes_trigger: any = writable(null);
|
||||
// console.log(`AE Notes Stores - Notes Trigger:`, notes_trigger);
|
||||
@@ -1,148 +0,0 @@
|
||||
import Dexie, { type Table } from 'dexie';
|
||||
|
||||
import type { key_val } from '../ae_stores';
|
||||
|
||||
// li = list
|
||||
// kv = key value list
|
||||
// json = JSON string
|
||||
// ux = user experience (mode)
|
||||
// LLM = Large Language Model (AI)
|
||||
|
||||
// Updated 2024-08-20
|
||||
export interface Note {
|
||||
id: string; // actually "id_random"
|
||||
note_id: string;
|
||||
|
||||
// Essentially this is a change log of notes
|
||||
snapshot_id?: string; // This is the original note ID. If deleted, then delete all children notes.
|
||||
previous_id?: null|string; // This is the old or parent note ID
|
||||
next_id?: null|string; // This is the new or child note ID
|
||||
|
||||
external_id?: null|string;
|
||||
import_id?: null|string;
|
||||
code?: null|string;
|
||||
|
||||
for_type?: null|string;
|
||||
for_id?: null|string;
|
||||
|
||||
type_code?: null|string;
|
||||
|
||||
account_id?: null|string; // Owner account of the note
|
||||
person_id?: null|string; // Owner person of the note
|
||||
// event_id?: null|string; // Assign to an event???
|
||||
// location_id?: null|string; // Assign to a location???
|
||||
|
||||
name: string; // or the title
|
||||
summary?: null|string; // LLM (AI) generated summary...???
|
||||
outline?: null|string; // LLM (AI) generated outline...???
|
||||
|
||||
note?: null|string;
|
||||
note_html?: null|string;
|
||||
note_json?: null|string;
|
||||
|
||||
start_datetime?: null|Date;
|
||||
end_datetime?: null|Date;
|
||||
timezone?: null|string;
|
||||
|
||||
hide_event_launcher?: null|boolean;
|
||||
|
||||
alert?: null|boolean; // LLM (AI) generated summary...???
|
||||
alert_msg?: null|string; // LLM (AI) generated summary...???
|
||||
|
||||
data_json?: null|string; // We always need to store something extra...
|
||||
|
||||
ux_mode?: null|string; // 'mobile' or 'desktop'
|
||||
|
||||
// This only allows for basic access to the content.
|
||||
passcode_read?: null|string; // For LLM (AI) generated summary...???
|
||||
passcode_read_expire?: null|Date;
|
||||
passcode_write?: null|string;
|
||||
passcode_write_expire?: null|Date
|
||||
|
||||
enable: null|boolean;
|
||||
hide?: null|boolean;
|
||||
priority?: null|boolean
|
||||
sort?: null|number;
|
||||
group?: null|string;
|
||||
notes?: null|string;
|
||||
created_on: Date;
|
||||
updated_on?: null|Date;
|
||||
|
||||
// Additional fields for convenience (database views)
|
||||
file_count?: null|number; // Only files directly under a note
|
||||
note_file_id_li_json?: null|string;
|
||||
|
||||
// One person
|
||||
person__given_name?: null|string;
|
||||
person__family_name?: null|string;
|
||||
person__full_name?: null|string;
|
||||
person__primary_email?: null|string;
|
||||
person__passcode?: null|string;
|
||||
|
||||
// JSON formatted key value pairs for multiple people: {id: name, email, etc.}
|
||||
person__kv_json?: null|string;
|
||||
|
||||
note_name?: null|string;
|
||||
|
||||
note_location_code?: null|string;
|
||||
note_location_name?: null|string;
|
||||
|
||||
// A key value list of the presentations
|
||||
note_presentation_kv?: null|key_val;
|
||||
note_presentation_li?: null|[];
|
||||
// A key value list of the files
|
||||
note_file_kv?: null|key_val;
|
||||
note_file_li?: null|[];
|
||||
|
||||
// note_collection_id?: null|string; // For a collection of notes?
|
||||
|
||||
// Future standard fields!!!
|
||||
obj_id?: null|string;
|
||||
obj_ext_uid?: null|string; // Probably not needed for notes
|
||||
obj_ext_id?: null|string; // Probably not needed for notes
|
||||
obj_import_id?: null|string; // Probably not needed for notes
|
||||
obj_code?: null|string;
|
||||
obj_account_id?: null|string;
|
||||
obj_passcode?: null|string;
|
||||
obj_type?: null|string; // Should always be 'note' in this case
|
||||
obj_type_ver_id?: null|string; // The ID from the table for the object type
|
||||
obj_name?: null|string;
|
||||
obj_summary?: null|string; // LLM (AI) generated summary...???
|
||||
obj_outline?: null|string; // LLM (AI) generated outline...???
|
||||
obj_description?: null|string; // Probably not needed for notes
|
||||
obj_enable?: null|boolean;
|
||||
obj_enable_on?: null|Date;
|
||||
obj_archive_on?: null|Date;
|
||||
obj_hide?: null|boolean;
|
||||
obj_priority?: null|number;
|
||||
obj_sort?: null|number;
|
||||
obj_group?: null|string;
|
||||
obj_cfg_json?: null|string;
|
||||
obj_notes?: null|string; // Not the same as the "note" in the object type named "Note".
|
||||
obj_created_on?: Date;
|
||||
obj_updated_on?: null|Date;
|
||||
}
|
||||
|
||||
|
||||
// Updated 2024-06-10
|
||||
export class MySubClassedDexie extends Dexie {
|
||||
// We just tell the typing system this is the case
|
||||
note!: Table<Note>;
|
||||
|
||||
constructor() {
|
||||
super('ae_notes_db');
|
||||
this.version(1).stores({
|
||||
note: `
|
||||
id, note_id,
|
||||
code,
|
||||
account_id,
|
||||
conference, type,
|
||||
name,
|
||||
start_datetime, end_datetime,
|
||||
timezone,
|
||||
enable, hide, priority, sort, group, notes, created_on, updated_on`,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export const db_notes = new MySubClassedDexie();
|
||||
Reference in New Issue
Block a user