379 lines
12 KiB
TypeScript
379 lines
12 KiB
TypeScript
import { localStorageStore } from '@skeletonlabs/skeleton';
|
|
import { readable, writable } from 'svelte/store';
|
|
import type { Readable, Writable } from 'svelte/store';
|
|
|
|
|
|
import { PUBLIC_TESTING, PUBLIC_AE_API_PROTOCOL, PUBLIC_AE_API_SERVER, PUBLIC_AE_API_BAK_SERVER, PUBLIC_AE_API_PORT, PUBLIC_AE_API_PATH, PUBLIC_AE_API_SECRET_KEY, PUBLIC_AE_API_CRUD_SUPER_KEY, PUBLIC_AE_NO_ACCOUNT_ID, PUBLIC_AE_NO_ACCOUNT_ID_TOKEN, PUBLIC_AE_ACCOUNT_ID, PUBLIC_AE_EVENT_ID, PUBLIC_AE_SPONSORSHIP_CFG_ID } from '$env/static/public';
|
|
console.log(`AE Stores - PUBLIC_TESTING:`, PUBLIC_TESTING);
|
|
|
|
const api_server_fqdn = PUBLIC_AE_API_SERVER; // 'api.oneskyit.com'
|
|
const api_base_url = `${PUBLIC_AE_API_PROTOCOL}://${PUBLIC_AE_API_SERVER}:${PUBLIC_AE_API_PORT}${PUBLIC_AE_API_PATH}`;
|
|
const api_base_url_bak = `${PUBLIC_AE_API_PROTOCOL}://${PUBLIC_AE_API_BAK_SERVER}:${PUBLIC_AE_API_PORT}${PUBLIC_AE_API_PATH}`;
|
|
|
|
const api_secret_key = PUBLIC_AE_API_SECRET_KEY;
|
|
const api_crud_super_key = PUBLIC_AE_API_CRUD_SUPER_KEY;
|
|
|
|
// const ae_account_id = PUBLIC_AE_ACCOUNT_ID;
|
|
let ae_account_id: null|string = null;
|
|
const ae_no_account_id = PUBLIC_AE_NO_ACCOUNT_ID;
|
|
const ae_no_account_id_token = PUBLIC_AE_NO_ACCOUNT_ID_TOKEN;
|
|
const ae_event_id = PUBLIC_AE_EVENT_ID;
|
|
const ae_sponsorship_cfg_id = PUBLIC_AE_SPONSORSHIP_CFG_ID;
|
|
|
|
// import { getStores, navigating, page, updated } from '$app/stores';
|
|
// import { assets, base, resolveRoute } from '$app/paths';
|
|
// console.log(page.path); // Everything after the domain name
|
|
|
|
// console.log(import.meta.env.MODE);
|
|
// console.log(import.meta.env.BASE_URL);
|
|
|
|
|
|
// Export the key_val type for use in other files.
|
|
export type key_val = {
|
|
[key: string]: any; // variable key
|
|
// name: string;
|
|
};
|
|
// export type key_val = key_val;
|
|
|
|
|
|
// import { html__not_set, classes__events_pres_mgmt_menu } from './ae_string_snippets';
|
|
import {string_snippets} from './ae_string_snippets';
|
|
export let ae_snip = string_snippets;
|
|
|
|
// export let ae_snip =
|
|
// {
|
|
// 'not_set': html__not_set,
|
|
// 'classes__events_pres_mgmt_menu': classes__events_pres_mgmt_menu
|
|
// };
|
|
|
|
// Set the version for the app data. Changing this should force a notification and ask the user to clear and reload the page.
|
|
let ver = '2024-08-21_1736';
|
|
let ver_idb = '2024-10-16_1540';
|
|
|
|
// *** BEGIN *** Longer-term app data. This should be stored to local storage.
|
|
export let ae_app_local_data_struct: key_val = {
|
|
last_idb_reload: null,
|
|
ver: '2024-10-16_1540',
|
|
ver_idb: '2024-10-16_1540', // Clear if date IndexedDB version
|
|
name: 'Aether - App Hub (SvelteKit 2.x Svelte 4.x)',
|
|
theme: 'light',
|
|
iframe: false,
|
|
title: `OSIT's Æ`, // - Dev SvelteKit`, // Æ
|
|
|
|
debug: false, // A simple flag to know if we should show debug information.
|
|
edit_mode: false, // A simple flag to know if we should show edit mode options.
|
|
sync_local_config: true, // A simple flag to know if we should sync local config with the remote API server.
|
|
|
|
'account_id': ae_account_id, // OSIT Demo _XY7DXtc9MY
|
|
'account_code': 'not_set',
|
|
'account_name': 'Account Name Not Set',
|
|
'allow_access': true, // Set to key site key was used, otherwise set to true.
|
|
'site_domain': null, // https://example.com, https://dev.example.com, etc.
|
|
'site_access_key': null, // This is the general site access key
|
|
'site_domain_access_key': null, // This is specific to a (sub)domain.
|
|
'site_cfg_json': {
|
|
slct__event_id: null,
|
|
slct__event_badge_template_id: null,
|
|
slct__sponsorship_cfg_id: null,
|
|
header_image_path: null,
|
|
},
|
|
|
|
// The site access codes can be pulled from the site records for an account.
|
|
'site_access_code_kv': {
|
|
// 'manager': '10240',
|
|
'administrator': null,
|
|
'trusted': null,
|
|
'public': 'public1980',
|
|
'authenticated': 'auth1980'
|
|
},
|
|
// 'manager_passcode': '10240',
|
|
// 'administrator_passcode': '11500',
|
|
// 'trusted_passcode': '19111',
|
|
// 'authenticated_passcode': 'auth2024',
|
|
|
|
'access_type': 'anonymous',
|
|
'administrator_access': false,
|
|
'trusted_access': false,
|
|
'public_access': false,
|
|
'authenticated_access': false,
|
|
'anonymous_access': true,
|
|
|
|
'user_email': null, // Currently used with Sponsorships only?
|
|
|
|
'qry__enabled': 'enabled', // all, disabled, enabled
|
|
'qry__hidden': 'not_hidden', // all, hidden, not_hidden
|
|
'qry__limit': 20,
|
|
'qry__offset': 0,
|
|
|
|
qr_scanner_version: 'one',
|
|
|
|
'admin': {
|
|
show_element__sql_qry: false,
|
|
show_element__sql_qry_results: false,
|
|
},
|
|
|
|
files: {
|
|
processed_file_kv: {},
|
|
uploaded_file_kv: {},
|
|
video_clip_file_kv: {},
|
|
},
|
|
|
|
'ds': {},
|
|
'hub': {
|
|
'show_element__cfg': true,
|
|
'show_element__cfg_detail': false,
|
|
'show_element__access_type': true,
|
|
'theme_mode': 'light',
|
|
'theme_name': 'wintry', // wintry
|
|
|
|
'classes__form': 'border border-surface-200 p-4 space-y-4 rounded-container-token',
|
|
|
|
'qr': {},
|
|
},
|
|
'mod': {
|
|
'archives': {},
|
|
|
|
'events': {
|
|
'event_id': null,
|
|
|
|
show_edit__event_presenter_obj: false,
|
|
show_list__event_presenter_obj_li: true,
|
|
show_view__event_presenter_obj: false,
|
|
|
|
submit_status: null, // 'saving', 'created', 'updated'
|
|
|
|
// Badge Printing
|
|
|
|
// Lead Retrievals
|
|
|
|
// Presentation Management
|
|
|
|
// Speakers Management
|
|
'default_session_id': null, // Assign to presenters by default
|
|
|
|
// other
|
|
},
|
|
|
|
'journals': {},
|
|
|
|
'posts': {},
|
|
|
|
'sponsorships': {
|
|
'cfg_id': ae_sponsorship_cfg_id,
|
|
|
|
for_type: null,
|
|
for_id: null,
|
|
|
|
level_guest_max_li: {
|
|
0: 0,
|
|
1: 4, // CHOW 2024 - Friend
|
|
2: 8, // CHOW 2024 - Supporter
|
|
3: 8, // CHOW 2024 - Advocate
|
|
4: 8, // CHOW 2024 - Champion
|
|
5: 8, // CHOW 2024 - Presenting Partner
|
|
6: 16, // CHOW 2024 - Signature Partner
|
|
7: 16, // CHOW 2024 - Premier Partner
|
|
},
|
|
|
|
show_edit__sponsorship_obj: false,
|
|
show_list__sponsorship_obj_li: true,
|
|
show_view__sponsorship_obj: false,
|
|
|
|
show_question__accommodations: false,
|
|
|
|
submit_status: null, // 'saving', 'created', 'updated'
|
|
},
|
|
|
|
'testing': {},
|
|
},
|
|
|
|
'person': {
|
|
show_content__person_page_help: false,
|
|
},
|
|
|
|
test: true,
|
|
}
|
|
// console.log(`AE Stores - App Local Storage Data:`, ae_app_local_data_struct);
|
|
|
|
// This works, but does not uses local storage:
|
|
// export let ae_loc = writable(ae_app_local_data_struct);
|
|
|
|
// This works and uses local storage:
|
|
export let ae_loc: Writable<key_val> = localStorageStore('ae_loc', ae_app_local_data_struct);
|
|
// console.log(`AE Stores - App Local Storage Data:`, get(ae_loc));
|
|
|
|
|
|
// *** BEGIN *** Temporary app data. This should be stored to session storage.
|
|
export let ae_app_session_data_struct: key_val = {
|
|
'ver': '2024-10-16_1540',
|
|
// ver_idb: ver_idb,
|
|
log_lvl: 0,
|
|
|
|
// 'name': 'Aether App Template',
|
|
// 'theme': 'light',
|
|
// 'account_id': ae_account_id,
|
|
'ds': {
|
|
'submit_status': null,
|
|
},
|
|
'ds_loaded': {
|
|
},
|
|
|
|
'files': {
|
|
disable_submit__hosted_file_obj: false,
|
|
processed_file_kv: {},
|
|
uploaded_file_kv: {},
|
|
video_clip_file_kv: {},
|
|
processed_file_list: [],
|
|
// uploaded_file_list: [],
|
|
video_clip_file_list: [],
|
|
submit_status: null, // 'saving', 'created', 'updated', 'saved'
|
|
clip_complete: null,
|
|
},
|
|
|
|
'hub': {
|
|
'show_xyz': null,
|
|
},
|
|
'mod': {
|
|
'archives': {},
|
|
'events': {
|
|
// Badge Printing
|
|
|
|
// Lead Retrievals
|
|
|
|
// Presentation Management
|
|
|
|
// Speakers Management
|
|
|
|
// other
|
|
},
|
|
'journals': {},
|
|
'posts': {},
|
|
'sponsorships': {
|
|
disable_submit__sponsorship_obj: false,
|
|
slct__level_num: 0,
|
|
show_question__accommodations: false,
|
|
submit_status: null, // 'saving', 'created', 'updated', 'saved'
|
|
},
|
|
'testing': {},
|
|
},
|
|
|
|
'person': {
|
|
show_report__person_li: false,
|
|
|
|
qry_limit__people: 100,
|
|
},
|
|
|
|
|
|
'download': {},
|
|
// For API download and upload progress status per file.
|
|
'api_download_kv': {},
|
|
// Example: {example_file_id: {status: 'downloading', endpoint: '/event/file/abc123/download', filename: 'example_file_name.ext', size_total: 0, size_loaded: 0, percent_completed: 0}}
|
|
'api_upload_kv': {}, // {example_temp_id: {status: 'uploading', endpoint: '/event/file/abc123/upload', filename: 'example_file_name.ext', size_total: 0, size_loaded: 0, percent_completed: 0}}
|
|
|
|
test: true,
|
|
};
|
|
// console.log(`AE Stores - App Session Storage Data:`, ae_app_session_data_struct);
|
|
export let ae_sess = writable(ae_app_session_data_struct);
|
|
|
|
|
|
// *** BEGIN *** Temporary API data. This should be stored to session storage.
|
|
export let ae_api_data_struct: key_val = {
|
|
'ver': '2024-08-11_11',
|
|
'fqdn': api_server_fqdn,
|
|
'base_url': api_base_url,
|
|
'base_url_bak': api_base_url_bak,
|
|
'api_secret_key': api_secret_key, // 'YOUR_API_SECRET_KEY',
|
|
'api_secret_key_bak': api_secret_key, // 'YOUR_API_SECRET_KEY',
|
|
'api_crud_super_key': api_crud_super_key, // 'YOUR_SUPER_KEY' 'zp5PtX4zUsI'
|
|
'headers': {},
|
|
'account_id': ae_account_id,
|
|
};
|
|
|
|
let ae_api_headers: key_val = {};
|
|
ae_api_headers['Access-Control-Allow-Origin'] = '*';
|
|
ae_api_headers['content-type'] = 'application/json';
|
|
ae_api_headers['x-aether-api-key'] = ae_api_data_struct.api_secret_key;
|
|
ae_api_headers['x-aether-api-token'] = 'fake-temp-token';
|
|
ae_api_headers['x-aether-api-expire-on'] = '';
|
|
if (ae_account_id) {
|
|
ae_api_headers['x-account-id'] = ae_account_id;
|
|
} else {
|
|
// ae_api_headers['x-account-id'] = ;
|
|
}
|
|
if (ae_no_account_id) {
|
|
ae_api_headers['x-no-account-id'] = ae_no_account_id;
|
|
}
|
|
ae_api_data_struct['headers'] = ae_api_headers;
|
|
|
|
// console.log(`AE Stores - API Data:`, ae_api_data_struct);
|
|
export let ae_api = writable(ae_api_data_struct);
|
|
|
|
// *** BEGIN *** Trigger to update the slct variables and other things.
|
|
let ae_trig_template: key_val = {};
|
|
export let ae_trig = writable(ae_trig_template);
|
|
|
|
|
|
/* *** BEGIN *** Initialize slct and slct_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 accounts, events, sponsorships, etc. */
|
|
|
|
// Intended for temporary session storage.
|
|
// Updated 2024-03-15
|
|
let slct_obj_template: key_val = {
|
|
'account_id': ae_account_id,
|
|
'account_obj': {},
|
|
'event_id': null,
|
|
'event_obj': {},
|
|
'event_obj_li': [],
|
|
// 'event_exhibit_id': null,
|
|
// 'event_exhibit_obj': {},
|
|
// 'event_exhibit_obj_li': [],
|
|
'event_presentation_id': null,
|
|
'event_presentation_obj': {},
|
|
'event_presentation_obj_li': [],
|
|
'event_presenter_id': null,
|
|
'event_presenter_obj': {},
|
|
'event_presenter_obj_li': [],
|
|
'event_session_id': null,
|
|
'event_session_obj': {},
|
|
'event_session_obj_li': [],
|
|
'sponsorship_id': null,
|
|
'sponsorship_obj': {},
|
|
'sponsorship_obj_li': [],
|
|
'sponsorship_cfg_id': ae_sponsorship_cfg_id,
|
|
'sponsorship_cfg_obj': {},
|
|
'sponsorship_cfg_obj_li': [],
|
|
'post_id': null,
|
|
'post_obj': {},
|
|
'post_obj_li': [],
|
|
'post_comment_id': null,
|
|
'post_comment_obj': {},
|
|
'post_comment_obj_li': []
|
|
};
|
|
// console.log(`AE Stores - Selected Objects:`, slct_obj_template);
|
|
|
|
// This works, and uses *session* (not local) storage:
|
|
export let slct = writable(slct_obj_template);
|
|
|
|
// This works and uses *local* storage:
|
|
// export let slct: Writable<key_val> = localStorageStore('ae_slct', slct_obj_template);
|
|
|
|
|
|
/* *** BEGIN *** Initialize slct_trigger */
|
|
// Intended for temporary session storage.
|
|
// Updated 2024-02-27
|
|
export let slct_trigger: any = writable(null);
|
|
// console.log(`AE Stores - Selected Trigger:`, slct_trigger);
|
|
|
|
|
|
/* *** BEGIN *** Create time variable */
|
|
// Updated 2020
|
|
export const time = readable(new Date(), function start(set) {
|
|
const interval = setInterval(() => {
|
|
set(new Date());
|
|
}, 1000);
|
|
|
|
return function stop() {
|
|
clearInterval(interval);
|
|
};
|
|
});
|