import type { key_val } from '$lib/ae_stores'; import { api } from '$lib/api'; import { db_events } from "$lib/db_events"; let ae_promises: key_val = {}; // Updated 2024-09-25 export async function load_ae_obj_id__event( { api_cfg, event_id, inc_file_li = false, inc_location_li = false, inc_presentation_li = false, inc_presenter_li = false, inc_session_li = false, try_cache = true, log_lvl = 0 }: { api_cfg: any, event_id: string, inc_file_li?: boolean, inc_location_li?: boolean, inc_presentation_li?: boolean, inc_presenter_li?: boolean, inc_session_li?: boolean, try_cache?: boolean, log_lvl?: number } ) { console.log(`*** load_ae_obj_id__event() *** event_id=${event_id}`); let params = {}; // $events_sess.badges.status_load__event_obj = 'loading'; ae_promises.load__event_obj = await api.get_ae_obj_id_crud({ api_cfg: api_cfg, obj_type: 'event', obj_id: event_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 (event_obj_get_result) { if (event_obj_get_result) { if (try_cache) { // This is expecting a list db_save_ae_obj_li__event({ obj_type: 'event', obj_li: [event_obj_get_result] }); } return event_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__event_obj; } // Updated 2024-09-27 export async function load_ae_obj_li__event( { api_cfg, for_obj_type = 'account', for_obj_id, qry_conference = true, qry_str = null, inc_file_li = false, inc_location_li = false, inc_presentation_li = false, inc_presenter_li = false, inc_session_li = false, order_by_li = {'start_datetime': 'DESC', 'name': 'ASC', 'updated_on': 'DESC', 'created_on': 'DESC'}, params_json = null, params = {}, try_cache = true, log_lvl = 0 }: { api_cfg: any, for_obj_type: string, for_obj_id: string, qry_conference?: null|boolean, qry_str?: null|string, inc_file_li?: boolean, inc_location_li?: boolean, inc_presentation_li?: boolean, inc_presenter_li?: boolean, inc_session_li?: boolean, order_by_li?: key_val, params_json?: null|key_val, params?: key_val, try_cache?: boolean, log_lvl?: number } ) { console.log(`*** load_ae_obj_li__event() *** 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 // There is probably a better way to handle this. I don't want to just start a new object if it is not passed. However, the qry_conference and qry_str are sort of a special case. -2024-10-01 if (!params_json) { params_json = {}; } if (qry_conference) { if (!params_json['and_qry']) { params_json['and_qry'] = {}; } params_json['and_qry']['conference'] = qry_conference; } else if (qry_conference === false) { if (!params_json['and_qry']) { params_json['and_qry'] = {}; } console.log('qry_conference is false!'); params_json['and_qry']['conference'] = qry_conference; } if (qry_str) { if (!params_json['ft_qry']) { params_json['ft_qry'] = {}; } params_json['ft_qry'] = {}; params_json['ft_qry']['default_qry_str'] = qry_str; params_json['ft_qry']['location_address_json_ext'] = qry_str; params_json['ft_qry']['contact_li_json_ext'] = qry_str; } // console.log('params_json:', params_json); // ae_promises.load__event_obj_li = await api.get_ae_obj_li_for_obj_id_crud({ // api_cfg: api_cfg, // obj_type: 'event', // 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 // }) ae_promises.load__event_obj_li = await api.get_ae_obj_li_for_obj_id_crud_v2({ api_cfg: api_cfg, obj_type: 'event', for_obj_type: for_obj_type, for_obj_id: for_obj_id, use_alt_tbl: true, // NOTE: This will use the table_name_alt value instead of the table_name value in the API config. // use_alt_mdl: 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 (event_obj_li_get_result) { if (event_obj_li_get_result) { if (try_cache) { db_save_ae_obj_li__event({obj_type: 'event', obj_li: event_obj_li_get_result}); } return event_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__event_obj_li:', ae_promises.load__event_obj_li); } return ae_promises.load__event_obj_li; } // The qry_ae_obj_li__event() is essentially a wrapper for the load_ae_obj_li__event() function. This should process the query strings and related before calling the load_ae_obj_li__event() function. // Updated 2024-10-01 export async function qry_ae_obj_li__event( { api_cfg, for_obj_type = 'account', for_obj_id, qry_conference = true, qry_physical = null, qry_virtual = null, qry_type = null, qry_str = null, inc_file_li = false, inc_location_li = false, inc_presentation_li = false, inc_presenter_li = false, inc_session_li = false, order_by_li = {'start_datetime': '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, qry_conference?: null|boolean, qry_physical?: null|boolean, qry_virtual?: null|boolean, qry_type?: null|string, qry_str?: null|string, inc_file_li?: boolean, inc_location_li?: boolean, inc_presentation_li?: boolean, inc_presenter_li?: boolean, inc_session_li?: boolean, order_by_li?: key_val, params?: key_val, try_cache?: boolean, log_lvl?: number } ) { console.log(`*** qry_ae_obj_li__event() *** 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 // Build the params_json object. This needs to be documented better! -2024-10-01 let params_json: key_val = {}; params_json['and_qry'] = {}; // This is handled in the actual load_ae_obj_li__event() function. For now...? // if (qry_conference) { // params_json['and_qry']['conference'] = qry_conference; // } else if (qry_conference === false) { // console.log('qry_conference is false!'); // params_json['and_qry']['conference'] = qry_conference; // } if (qry_physical && qry_virtual) { // Ignore both if both are set to true. } else if (qry_physical || qry_virtual) { if (qry_physical) { params_json['and_qry']['physical'] = qry_physical; } if (qry_virtual) { params_json['and_qry']['virtual'] = qry_virtual; } } if (qry_type) { params_json['and_qry']['type'] = qry_type; } if (qry_str) { params_json['ft_qry'] = {}; params_json['ft_qry']['default_qry_str'] = qry_str; params_json['ft_qry']['location_address_json_ext'] = qry_str; params_json['ft_qry']['contact_li_json_ext'] = qry_str; } if (log_lvl) { console.log('params_json:', params_json); } ae_promises.qry__event_obj_li = await load_ae_obj_li__event({ api_cfg: api_cfg, for_obj_type: for_obj_type, for_obj_id: for_obj_id, qry_conference: qry_conference, qry_str: qry_str, inc_file_li: inc_file_li, inc_location_li: inc_location_li, inc_presentation_li: inc_presentation_li, inc_presenter_li: inc_presenter_li, inc_session_li: inc_session_li, order_by_li: order_by_li, params_json: params_json, params: params, try_cache: try_cache, log_lvl: log_lvl }); return ae_promises.qry__event_obj_li; } // Updated 2024-09-25 export async function create_ae_obj__event( { api_cfg, account_id, data_kv, params={}, log_lvl=0 }: { api_cfg: any, account_id: string, data_kv: key_val, params?: key_val, log_lvl?: number } ) { console.log(`*** create_ae_obj__event() *** account_id=${account_id}`); ae_promises.create__event = await api.create_ae_obj_crud({ api_cfg: api_cfg, obj_type: 'event', 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 (event_obj_create_result) { if (event_obj_create_result) { db_save_ae_obj_li__event( { obj_type: 'event', obj_li: [event_obj_create_result] }); return event_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__event:', ae_promises.create__event); } return ae_promises.create__event; } // Updated 2024-09-25 export async function update_ae_obj__event( { api_cfg, event_id, data_kv, params = {}, try_cache = true, log_lvl = 0 }: { api_cfg: any, event_id: string, data_kv: key_val, params?: key_val, try_cache?: boolean, log_lvl?: number } ) { if (log_lvl) { console.log(`*** update_ae_obj__event() *** event_id=${event_id}`, data_kv); } // ae_promises.update__event_obj = 'test'; ae_promises.update__event_obj = await api.update_ae_obj_id_crud({ api_cfg: api_cfg, obj_type: 'event', obj_id: event_id, fields: data_kv, key: api_cfg.api_crud_super_key, params: params, return_obj: true, log_lvl: log_lvl }) .then(function (event_obj_update_result) { if (event_obj_update_result) { if (try_cache) { db_save_ae_obj_li__event({ obj_type: 'event', obj_li: [event_obj_update_result] }); } return event_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__event_obj:', ae_promises.update__event_obj); } return ae_promises.update__event_obj; } // This function will loop through the event_obj_li and save each one to the DB. export function db_save_ae_obj_li__event( { 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__event() ***`); } 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_events.events.put({ id: obj.event_id_random, // id_random: obj.event_id_random, event_id: obj.event_id_random, event_id_random: obj.event_id_random, code: obj.event_code, account_id: obj.account_id_random, account_id_random: obj.account_id_random, conference: obj.conference, type: obj.type, name: obj.name, summary: obj.summary, description: obj.description, start_datetime: obj.start_datetime, end_datetime: obj.end_datetime, timezone: obj.timezone, location_address_json: obj.location_address_json, mod_abstracts_json: obj.mod_abstracts_json, mod_badges_json: obj.mod_badges_json, mod_exhibits_json: obj.mod_exhibits_json, mod_pres_mgmt_json: obj.mod_pres_mgmt_json, cfg_json: obj.cfg_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, // IDAA Recovery Meetings contact_li_json: obj.contact_li_json, external_person_id: obj.external_person_id, physical: obj.physical, virtual: obj.virtual, weekday_sunday: obj.weekday_sunday, weekday_monday: obj.weekday_monday, weekday_tuesday: obj.weekday_tuesday, weekday_wednesday: obj.weekday_wednesday, weekday_thursday: obj.weekday_thursday, weekday_friday: obj.weekday_friday, weekday_saturday: obj.weekday_saturday, recurring_start_time: obj.recurring_start_time, // From SQL view file_count: obj.file_count, file_count_all: obj.file_count_all, internal_use_count: obj.internal_use_count, event_file_id_li_json: obj.event_file_id_li_json, }); // console.log(`Put obj with ID: ${obj.event_id_random} or ${id_random}`); } catch (error) { let status = `Failed to put ${obj.event_id_random}: ${error}`; console.log(status); } // const id_random = await db_events.events.put(obj); // console.log(`Put obj with ID: ${obj.event_id_random}`); }); return true; } } // This function will process the event config, specifically for presentation management. export function sync_config__event_pres_mgmt( { pres_mgmt_cfg_remote, // This is the remote config that will be compared. pres_mgmt_cfg_local, // This is the local config that will be updated. log_lvl = 0 }: { pres_mgmt_cfg_remote: key_val, pres_mgmt_cfg_local: key_val, log_lvl?: number } ) { if (log_lvl) { console.log(`*** sync_config__event_pres_mgmt() *** pres_mgmt_cfg_remote:`, pres_mgmt_cfg_remote); } // Deal with things that can not be overridden first: // Labels: pres_mgmt_cfg_local.label__presenter_external_id = pres_mgmt_cfg_remote?.label__presenter_external_id ?? 'External ID'; pres_mgmt_cfg_local.label__session_poc_type = pres_mgmt_cfg_remote?.label__session_poc_type ?? 'poc'; pres_mgmt_cfg_local.label__session_poc_name = pres_mgmt_cfg_remote?.label__session_poc_name_short ?? 'POC'; pres_mgmt_cfg_local.label__session_poc_name = pres_mgmt_cfg_remote?.label__session_poc_name ?? 'Point of Contact'; // Hide content: pres_mgmt_cfg_local.hide__session_poc = pres_mgmt_cfg_remote?.hide__session_poc ?? false; // pres_mgmt_cfg_local.hide__report_kv = pres_mgmt_cfg_remote?.hide__report_kv ?? null; // pres_mgmt_cfg_local.limit__navigation = pres_mgmt_cfg_remote?.limit__navigation ?? false; // pres_mgmt_cfg_local.limit__options = pres_mgmt_cfg_remote?.limit__options ?? false; // Required fields or options (agreements): pres_mgmt_cfg_local.require__presenter_agree = pres_mgmt_cfg_remote?.require__presenter_agree ?? false; // In use pres_mgmt_cfg_local.require__session_agree = pres_mgmt_cfg_remote?.require__session_agree ?? false; // New and in progress // Show content: // pres_mgmt_cfg_local.show__navigation = pres_mgmt_cfg_remote?.show__navigation ?? false; pres_mgmt_cfg_local.file_purpose_option_kv = pres_mgmt_cfg_remote?.file_purpose_option_kv ?? null; // Deal with things that can be overridden: // Locking the config is targeted at the trusted staff level and below. It is more or less ignored at the global manager and super levels. It may be enforced at the staff admin level? // pres_mgmt_cfg_local.lock_config = pres_mgmt_cfg_remote?.lock_config ? true : false; // This disables the sync local config button and options. if (pres_mgmt_cfg_local.lock_config) { console.log(`The config should be locked! Forcing the sync!`); // This is to forcibly sync the local config with the remote config. pres_mgmt_cfg_local.sync_local_config = true; } else { // Do not override the preference for syncing the local config with the remote config. console.log(`The config is not locked. Currently set to sync? ${pres_mgmt_cfg_local.sync_local_config}`); // Check if the sync_local_config is undefined versus just false. // if (pres_mgmt_cfg_local?.sync_local_config) { // pres_mgmt_cfg_local.sync_local_config = true; // } else { // pres_mgmt_cfg_local.sync_local_config = pres_mgmt_cfg_remote?.sync_local_config ?? false; // } } if (pres_mgmt_cfg_local?.sync_local_config) { if (log_lvl) { console.log(`Syncing the local config with the remote config!!!`); } // Hide content: pres_mgmt_cfg_local.hide__location_code = pres_mgmt_cfg_remote?.hide__location_code ?? false; pres_mgmt_cfg_local.hide__presentation_code = pres_mgmt_cfg_remote?.hide__presentation_code ?? false; pres_mgmt_cfg_local.hide__presenter_code = pres_mgmt_cfg_remote?.hide__presenter_code ?? false; pres_mgmt_cfg_local.hide__presenter_biography = pres_mgmt_cfg_remote?.hide__presenter_biography ?? false; pres_mgmt_cfg_local.hide__session_code = pres_mgmt_cfg_remote?.hide__session_code ?? false; pres_mgmt_cfg_local.hide__session_description = pres_mgmt_cfg_remote?.hide__session_description ?? false; pres_mgmt_cfg_local.hide__session_location = pres_mgmt_cfg_remote?.hide__session_location ?? false; pres_mgmt_cfg_local.hide__session_msg = pres_mgmt_cfg_remote?.hide__session_msg ?? false; // pres_mgmt_cfg_local.hide__session_li_poc_field = pres_mgmt_cfg_remote?.hide__session_li_poc_field ?? false; // This should still allow the POC name to be shown. pres_mgmt_cfg_local.hide__session_poc_profile = pres_mgmt_cfg_remote?.hide__session_poc_profile ?? false; // This should still allow the POC name to be shown. pres_mgmt_cfg_local.hide__session_poc_biography = pres_mgmt_cfg_remote?.hide__session_poc_biography ?? false; // New and in progress pres_mgmt_cfg_local.hide__session_poc_profile_pic = pres_mgmt_cfg_remote?.hide__session_poc_profile_pic ?? false; // New and in progress pres_mgmt_cfg_local.show__copy_access_link = pres_mgmt_cfg_remote?.show__copy_access_link ?? false; pres_mgmt_cfg_local.show__email_access_link = pres_mgmt_cfg_remote?.show__email_access_link ?? false; pres_mgmt_cfg_local.show__launcher_link = pres_mgmt_cfg_remote?.show__launcher_link ?? false; pres_mgmt_cfg_local.show__launcher_link_legacy = pres_mgmt_cfg_remote?.show__launcher_link_legacy ?? false; } if (log_lvl) { console.log(`pres_mgmt_cfg_local:`, pres_mgmt_cfg_local); } return pres_mgmt_cfg_local; }