Moving files around. Breaking links to sessions and other things.
This commit is contained in:
@@ -539,10 +539,15 @@ export function db_save_ae_obj_li__event_file(
|
||||
for_id: obj.for_id_id_random,
|
||||
for_id_random: obj.for_id_random,
|
||||
|
||||
event_id: obj.event_id_random,
|
||||
event_id_random: obj.event_id_random,
|
||||
event_session_id: obj.event_session_id_random,
|
||||
event_session_id_random: obj.event_session_id_random,
|
||||
event_presentation_id: obj.event_presentation_id_random,
|
||||
event_presentation_id_random: obj.event_presentation_id_random,
|
||||
event_presenter_id: obj.event_presenter_id_random,
|
||||
event_presenter_id_random: obj.event_presenter_id_random,
|
||||
event_location_id: obj.event_location_id_random,
|
||||
event_location_id_random: obj.event_location_id_random,
|
||||
|
||||
filename: obj.filename,
|
||||
|
||||
@@ -1,17 +1,22 @@
|
||||
// Import external files first. Eventually this will be broken up in to smaller files.
|
||||
import { clean_filename, format_bytes, guess_file_name, guess_file_extension, get_file_hash } from './ae_utils__files';
|
||||
import { get_obj_li_w_match_prop} from './ae_utils__get_obj_li_w_match_prop';
|
||||
import { file_extension_icon } from './ae_utils__file_extension_icon';
|
||||
import { process_permission_checks } from './ae_utils__perm_checks';
|
||||
import { iso_datetime_formatter } from './ae_utils__datetime_format';
|
||||
import { is_datetime_recent } from './ae_utils__is_datetime_recent';
|
||||
import { clean_filename, format_bytes, guess_file_name, guess_file_extension, get_file_hash } from './ae_utils__files';
|
||||
import { get_obj_li_w_match_prop} from './ae_utils__get_obj_li_w_match_prop';
|
||||
import { extract_prefixed_form_data } from './ae_utils__extract_prefixed_form_data';
|
||||
import { to_title_case } from './ae_utils__to_title_case';
|
||||
import { process_data_string } from './ae_utils__process_data_string';
|
||||
import { set_obj_prop_display_name } from './ae_utils__set_obj_prop_display_name';
|
||||
import { return_obj_type_path } from './ae_utils__return_obj_type_path';
|
||||
|
||||
|
||||
type key_str = {
|
||||
export type key_str = {
|
||||
[key: string]: string;
|
||||
};
|
||||
|
||||
type key_val = {
|
||||
export type key_val = {
|
||||
[key: string]: any;
|
||||
};
|
||||
|
||||
@@ -22,106 +27,14 @@ function number_w_commas(x) {
|
||||
}
|
||||
|
||||
|
||||
/* This utility function processes specific data string.
|
||||
* MECARD
|
||||
* OBJ = OBJ:ot:example,oi:asdf1234
|
||||
* ot = Aether object type; oi = Aether object ID random
|
||||
* KV = KV:"key":"value"
|
||||
* JS = {"id":123,"name":"example name"}
|
||||
* http or https?
|
||||
* Common short keys used:
|
||||
* bdg: Badge ID Random
|
||||
* reg: Registration ID Random
|
||||
* exid: External ID
|
||||
* gn: Given First Name
|
||||
* fn: Family Last Name
|
||||
* em: Email Address
|
||||
*/
|
||||
// Updated 2022-02-11
|
||||
export let process_data_string = function process_data_string(data_string: string) {
|
||||
console.log('*** process_data_string() ***');
|
||||
// console.log(data_string);
|
||||
|
||||
if (!data_string || data_string.length < 1) {
|
||||
console.log('No data string found.');
|
||||
return false;
|
||||
}
|
||||
|
||||
let obj: key_val = {};
|
||||
|
||||
let colon_index = data_string.indexOf(':')
|
||||
if (colon_index) {
|
||||
let data_string_type = data_string.slice(0, colon_index);
|
||||
console.log(data_string_type);
|
||||
|
||||
obj['qr_type'] = data_string_type;
|
||||
|
||||
if (data_string_type == 'MECARD') {
|
||||
let mecard_str = data_string.slice(colon_index+1);
|
||||
console.log(mecard_str);
|
||||
|
||||
obj['str'] = mecard_str;
|
||||
} else if (data_string_type == 'OBJ') {
|
||||
let key_value_str = data_string.slice(colon_index+1);
|
||||
console.log(key_value_str);
|
||||
let key_value_array = key_value_str.split(',');
|
||||
// console.log(key_value_array);
|
||||
|
||||
let ot_colon_index = key_value_array[0].indexOf(':')
|
||||
let obj_type = key_value_array[0].slice(ot_colon_index+1);
|
||||
// console.log(obj_type);
|
||||
|
||||
let oi_colon_index = key_value_array[1].indexOf(':')
|
||||
let obj_id = key_value_array[1].slice(oi_colon_index+1);
|
||||
// console.log(obj_id);
|
||||
|
||||
obj['type'] = obj_type;
|
||||
obj['id'] = obj_id;
|
||||
} else if (data_string_type == 'JSON') {
|
||||
let partial_json_str = data_string.slice(colon_index+1);
|
||||
console.log(partial_json_str);
|
||||
let json_str = `{${partial_json_str}}`;
|
||||
console.log(json_str);
|
||||
|
||||
obj['json'] = JSON.parse(json_str);
|
||||
} else if (data_string_type == 'STR') {
|
||||
let str = data_string.slice(colon_index+1);
|
||||
console.log(str);
|
||||
|
||||
obj['str'] = str;
|
||||
} else if (data_string_type == 'http' || data_string_type == 'https') {
|
||||
console.log(`http or https: ${data_string}`);
|
||||
|
||||
obj['type'] = 'url';
|
||||
obj['url'] = data_string;
|
||||
} else {
|
||||
console.log('The unknown data string type was found. Returning the string part.')
|
||||
let unknown_str = data_string.slice(colon_index+1);
|
||||
console.log(unknown_str);
|
||||
|
||||
obj['str'] = unknown_str;
|
||||
}
|
||||
} else {
|
||||
console.log('The data string type was not found. Returning the entire string.')
|
||||
console.log(data_string);
|
||||
|
||||
obj['qr_type'] = 'UNKNOWN';
|
||||
obj['str'] = data_string;
|
||||
// return false;
|
||||
}
|
||||
|
||||
console.log(obj);
|
||||
return obj; // Returns an object
|
||||
}
|
||||
|
||||
|
||||
|
||||
// This function will update the URL and send a message to the parent window (iframe).
|
||||
// The name should be something like "example_id".
|
||||
// Svelte specific:
|
||||
// WARNING: Avoid using `history.pushState(...)` and `history.replaceState(...)` as these will conflict with SvelteKit's router. Use the `pushState` and `replaceState` imports from `$app/navigation` instead.
|
||||
// Updated 2024-03-02
|
||||
import { pushState, replaceState } from '$app/navigation';
|
||||
// import { pushState, replaceState } from '$app/navigation';
|
||||
|
||||
|
||||
|
||||
function handle_url_and_message(name: string, value: null|string) {
|
||||
console.log(`*** handle_url_and_message() *** name=${name} value=${value}`);
|
||||
@@ -225,62 +138,15 @@ function count_words(text: string) {
|
||||
}
|
||||
|
||||
|
||||
/* Adapted from: To Title Case © 2018 David Gouch | https://github.com/gouch/to-title-case */
|
||||
|
||||
// eslint-disable-next-line no-extend-native
|
||||
function to_title_case (text_string) {
|
||||
// console.log('*** to_title_case() ***');
|
||||
|
||||
let smallWords = /^(a|an|and|as|at|but|by|en|for|if|in|nor|of|on|or|per|the|to|v.?|vs.?|via)$/i
|
||||
let alphanumericPattern = /([A-Za-z0-9\u00C0-\u00FF])/
|
||||
let wordSeparators = /([ :–—-])/
|
||||
|
||||
return text_string.split(wordSeparators)
|
||||
.map(function (current, index, array) {
|
||||
if (
|
||||
/* Check for small words */
|
||||
current.search(smallWords) > -1 &&
|
||||
/* Skip first and last word */
|
||||
index !== 0 &&
|
||||
index !== array.length - 1 &&
|
||||
/* Ignore title end and subtitle start */
|
||||
array[index - 3] !== ':' &&
|
||||
array[index + 1] !== ':' &&
|
||||
/* Ignore small words that start a hyphenated phrase */
|
||||
(array[index + 1] !== '-' ||
|
||||
(array[index - 1] === '-' && array[index + 1] === '-'))
|
||||
) {
|
||||
return current.toLowerCase()
|
||||
}
|
||||
|
||||
/* Ignore intentional capitalization */
|
||||
if (current.substr(1).search(/[A-Z]|\../) > -1) {
|
||||
return current
|
||||
}
|
||||
|
||||
/* Ignore URLs */
|
||||
if (array[index + 1] === ':' && array[index + 2] !== '') {
|
||||
return current
|
||||
}
|
||||
|
||||
/* Capitalize the first letter */
|
||||
return current.replace(alphanumericPattern, function (match) {
|
||||
return match.toUpperCase()
|
||||
})
|
||||
})
|
||||
.join('')
|
||||
}
|
||||
|
||||
|
||||
// Updated 2024-06-19
|
||||
// This function behaves weirdly. It needs to be reviewed and updated.
|
||||
export let shorten_string = function shorten_string(
|
||||
{
|
||||
string,
|
||||
max_length=45,
|
||||
begin_length=15,
|
||||
end_length=5,
|
||||
wildcard_length=3
|
||||
max_length = 45,
|
||||
begin_length = 15,
|
||||
end_length = 5,
|
||||
wildcard_length = 3
|
||||
}: {
|
||||
string: undefined|string,
|
||||
max_length?: number,
|
||||
@@ -336,9 +202,9 @@ export let shorten_string = function shorten_string(
|
||||
function shorten_filename(
|
||||
{
|
||||
filename,
|
||||
max_length=20,
|
||||
slice_end_at=15,
|
||||
max_end_length=5
|
||||
max_length = 20,
|
||||
slice_end_at = 15,
|
||||
max_end_length = 5
|
||||
}: {
|
||||
filename: string,
|
||||
max_length?: number,
|
||||
@@ -373,235 +239,6 @@ function shorten_filename(
|
||||
}
|
||||
|
||||
|
||||
// Updated 2024-6-19
|
||||
function file_extension_icon(
|
||||
extension: string
|
||||
) {
|
||||
// console.log('*** file_extension_icon() ***');
|
||||
|
||||
let file_icons: key_str = {
|
||||
'file': 'file',
|
||||
'3gp': 'file-video',
|
||||
'7z': 'file-archive',
|
||||
'aac': 'file-audio',
|
||||
'ac3': 'file-audio',
|
||||
'aif': 'file-audio',
|
||||
'aiff': 'file-audio',
|
||||
'avi': 'file-video',
|
||||
'bmp': 'file-image',
|
||||
'csv': 'file-csv',
|
||||
'doc': 'file-word',
|
||||
'docx': 'file-word',
|
||||
'eps': 'file-image',
|
||||
'flac': 'file-audio',
|
||||
'gif': 'file-image',
|
||||
'htm': 'file-code',
|
||||
'html': 'file-code',
|
||||
'jpeg': 'file-image',
|
||||
'jpg': 'file-image',
|
||||
'key': 'file-powerpoint',
|
||||
'mkv': 'file-video',
|
||||
'mov': 'file-video',
|
||||
'mp3': 'file-audio',
|
||||
'mp4': 'file-video',
|
||||
'odp': 'file-powerpoint',
|
||||
'pdf': 'file-pdf',
|
||||
'png': 'file-image',
|
||||
'ppt': 'file-powerpoint',
|
||||
'pptx': 'file-powerpoint',
|
||||
'txt': 'file-alt',
|
||||
'wav': 'file-audio',
|
||||
'webp': 'file-image',
|
||||
'xls': 'file-excel',
|
||||
'xlsx': 'file-excel',
|
||||
'zip': 'file-archive'
|
||||
};
|
||||
|
||||
if (file_icons[extension]) {
|
||||
return file_icons[extension];
|
||||
} else {
|
||||
// return null;
|
||||
return file_icons['file'];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Updated 2023-08-18
|
||||
function set_obj_prop_display_name({prop_name, obj_type=null, prefix_w_obj_type=true, prefix_all_w_obj_type=false, replace_underscores=true, title_case=true, override=null}) {
|
||||
console.log('*** set_obj_prop_display_name() ***');
|
||||
|
||||
if (override) {
|
||||
return override;
|
||||
}
|
||||
|
||||
let known_obj_type_li = ['account', 'address', 'contact', 'event_badge', 'event_exhibit', 'event_file', 'event_location', 'event_person', 'event_presentation', 'event_presenter', 'event_registration', 'event_session', 'event', 'hosted_file', 'order_line', 'order', 'person', 'user'];
|
||||
|
||||
|
||||
let known_obj_type_li_dict = [
|
||||
{name: 'account', display: 'Account'},
|
||||
{name: 'address', display: 'Address'},
|
||||
{name: 'contact', display: 'Contact'},
|
||||
{name: 'event_badge', display: 'Event Badge'},
|
||||
{name: 'event_exhibit', display: 'Event Exhibit'},
|
||||
{name: 'event_file', display: 'Event File'},
|
||||
{name: 'event_location', display: 'Event Location'},
|
||||
{name: 'event_person', display: 'Event Person'},
|
||||
{name: 'event_presentation', display: 'Event Presentation'},
|
||||
{name: 'event_presenter', display: 'Event Presenter'},
|
||||
{name: 'event_registration', display: 'Event Registration'},
|
||||
{name: 'event_session', display: 'Event Session'},
|
||||
{name: 'event', display: 'Event'},
|
||||
{name: 'hosted_file', display: 'Hosted File'},
|
||||
{name: 'order_line', display: 'Order Line'},
|
||||
{name: 'order', display: 'Order'},
|
||||
{name: 'person', display: 'Person'},
|
||||
{name: 'user', display: 'User'},
|
||||
];
|
||||
|
||||
let prop_display_name = prop_name;
|
||||
|
||||
if (!prefix_w_obj_type) {
|
||||
if (obj_type) {
|
||||
prop_display_name = prop_name.replace(obj_type, '');
|
||||
} else {
|
||||
for (let i = 0; i < known_obj_type_li_dict.length; i++) {
|
||||
// console.log(known_obj_type_li_dict[i]);
|
||||
|
||||
if (prop_name.startsWith(known_obj_type_li_dict[i].name)) {
|
||||
// console.log(`Found ${known_obj_type_li_dict[i].name}`);
|
||||
prop_display_name = prop_name.replace(known_obj_type_li_dict[i].name, '');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// for (let i = 0; i < known_obj_type_li.length; i++) {
|
||||
// // console.log(known_obj_type_li[i]);
|
||||
|
||||
// if (prop_name.startsWith(known_obj_type_li[i])) {
|
||||
// console.log(`Found ${known_obj_type_li[i]}`);
|
||||
// prop_display_name = prop_name.replace(known_obj_type_li[i], '');
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
} else {
|
||||
if (!prefix_all_w_obj_type) {
|
||||
for (let i = 0; i < known_obj_type_li.length; i++) {
|
||||
// console.log(known_obj_type_li[i]);
|
||||
|
||||
let found_obj_type = null;
|
||||
|
||||
if (prop_name.startsWith(known_obj_type_li_dict[i].name)) {
|
||||
// if (prop_name.startsWith(known_obj_type_li[i])) {
|
||||
// console.log(`Found ${known_obj_type_li_dict[i].name}`);
|
||||
found_obj_type = known_obj_type_li_dict[i].name;
|
||||
if (found_obj_type == obj_type) {
|
||||
prop_display_name = prop_name.replace(known_obj_type_li_dict[i].name, '');
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// if (obj_type) {
|
||||
// prop_display_name = prop_name.replace(obj_type, '');
|
||||
// } else {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// console.log(prop_display_name);
|
||||
|
||||
if (prop_display_name.search('ID')) {
|
||||
|
||||
}
|
||||
prop_display_name = prop_display_name.replace('id_random', 'ID');
|
||||
|
||||
if (replace_underscores) {
|
||||
prop_display_name = prop_display_name.replaceAll('_', ' ');
|
||||
}
|
||||
|
||||
if (title_case) {
|
||||
prop_display_name = to_title_case(prop_display_name);
|
||||
}
|
||||
|
||||
// console.log(prop_display_name);
|
||||
|
||||
return prop_display_name;
|
||||
}
|
||||
|
||||
|
||||
function return_obj_type_path({obj_type=null, obj_type_prop_name=null}) {
|
||||
console.log('*** set_obj_prop_display_name() ***');
|
||||
|
||||
let obj_type_path = null;
|
||||
|
||||
let known_obj_type_li = ['account', 'address', 'archive', 'archive_content', 'contact', 'event_badge', 'event_exhibit', 'event_file', 'event_location', 'event_person', 'event_presentation', 'event_presenter', 'event_registration', 'event_session', 'event', 'hosted_file', 'order_line', 'order', 'person', 'post', 'post_comment', 'user'];
|
||||
|
||||
let known_obj_type_li_dict = [
|
||||
{name: 'account', display: 'Account', path: 'account'},
|
||||
{name: 'archive', display: 'Archive', path: 'archive'},
|
||||
{name: 'address', display: 'Address', path: 'address'},
|
||||
{name: 'archive', display: 'Archive', path: 'archive'},
|
||||
{name: 'archive_content', display: 'Archive Content', path: 'archive/content'},
|
||||
{name: 'contact', display: 'Contact', path: 'contact'},
|
||||
{name: 'data_store', display: 'Data Store', path: 'data_store'},
|
||||
{name: 'event_abstract', display: 'Event Abstract', path: 'event/abstract'},
|
||||
{name: 'event_badge', display: 'Event Badge', path: 'event/badge'},
|
||||
{name: 'event_device', display: 'Event Device', path: 'event/device'},
|
||||
{name: 'event_exhibit', display: 'Event Exhibit', path: 'event/exhibit'},
|
||||
{name: 'event_file', display: 'Event File', path: 'event/file'},
|
||||
{name: 'event_location', display: 'Event Location', path: 'event/location'},
|
||||
{name: 'event_person', display: 'Event Person', path: 'event/person'},
|
||||
{name: 'event_presentation', display: 'Event Presentation', path: 'event/'},
|
||||
{name: 'event_presenter', display: 'Event Presenter', path: 'event/presenter'},
|
||||
{name: 'event_registration', display: 'Event Registration', path: 'event/registration'},
|
||||
{name: 'event_session', display: 'Event Session', path: 'event/session'},
|
||||
{name: 'event', display: 'Event', path: 'event'},
|
||||
{name: 'hosted_file', display: 'Hosted File', path: 'hosted_file'},
|
||||
{name: 'journal', display: 'Journal', path: 'journal'},
|
||||
{name: 'journal_entry', display: 'Journal Entry', path: 'journal/entry'},
|
||||
{name: 'order_line', display: 'Order Line', path: 'order/line'},
|
||||
{name: 'order', display: 'Order', path: 'order'},
|
||||
{name: 'person', display: 'Person', path: 'person'},
|
||||
{name: 'post', display: 'Archive', path: 'post'},
|
||||
{name: 'post_comment', display: 'Archive Content', path: 'post/comment'},
|
||||
{name: 'user', display: 'User', path: 'user'},
|
||||
];
|
||||
|
||||
if (obj_type) {
|
||||
// Need to loop through known for safety?
|
||||
obj_type_path = obj_type_prop_name.replaceAll('_', '/');
|
||||
|
||||
} else if (obj_type_prop_name) {
|
||||
let found_obj_type_name = null;
|
||||
let found_obj_type_path = null;
|
||||
|
||||
for (let i = 0; i < known_obj_type_li_dict.length; i++) {
|
||||
// console.log(known_obj_type_li_dict[i]);
|
||||
|
||||
// let guessed_obj_type = prop_name.startsWith(known_obj_type_li_dict[i]
|
||||
|
||||
|
||||
if (obj_type_prop_name.startsWith(known_obj_type_li_dict[i].name)) {
|
||||
console.log(`Found ${known_obj_type_li_dict[i].name}`);
|
||||
found_obj_type_name = known_obj_type_li_dict[i].name;
|
||||
found_obj_type_path = known_obj_type_li_dict[i].path;
|
||||
// obj_type_path = obj_type_prop_name.replaceAll('_', '/');
|
||||
obj_type_path = found_obj_type_path;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
console.log('Missing required parameters');
|
||||
return false;
|
||||
}
|
||||
|
||||
return obj_type_path;
|
||||
}
|
||||
|
||||
|
||||
export let ae_util = {
|
||||
is_datetime_recent: is_datetime_recent,
|
||||
process_permission_checks: process_permission_checks,
|
||||
|
||||
51
src/lib/ae_utils/ae_utils__file_extension_icon.ts
Normal file
51
src/lib/ae_utils/ae_utils__file_extension_icon.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import type { key_str } from "./ae_utils";
|
||||
|
||||
// Updated 2024-06-19
|
||||
export function file_extension_icon(
|
||||
extension: string) {
|
||||
// console.log('*** file_extension_icon() ***');
|
||||
let file_icons: key_str = {
|
||||
'file': 'file',
|
||||
'3gp': 'file-video',
|
||||
'7z': 'file-archive',
|
||||
'aac': 'file-audio',
|
||||
'ac3': 'file-audio',
|
||||
'aif': 'file-audio',
|
||||
'aiff': 'file-audio',
|
||||
'avi': 'file-video',
|
||||
'bmp': 'file-image',
|
||||
'csv': 'file-csv',
|
||||
'doc': 'file-word',
|
||||
'docx': 'file-word',
|
||||
'eps': 'file-image',
|
||||
'flac': 'file-audio',
|
||||
'gif': 'file-image',
|
||||
'htm': 'file-code',
|
||||
'html': 'file-code',
|
||||
'jpeg': 'file-image',
|
||||
'jpg': 'file-image',
|
||||
'key': 'file-powerpoint',
|
||||
'mkv': 'file-video',
|
||||
'mov': 'file-video',
|
||||
'mp3': 'file-audio',
|
||||
'mp4': 'file-video',
|
||||
'odp': 'file-powerpoint',
|
||||
'pdf': 'file-pdf',
|
||||
'png': 'file-image',
|
||||
'ppt': 'file-powerpoint',
|
||||
'pptx': 'file-powerpoint',
|
||||
'txt': 'file-alt',
|
||||
'wav': 'file-audio',
|
||||
'webp': 'file-image',
|
||||
'xls': 'file-excel',
|
||||
'xlsx': 'file-excel',
|
||||
'zip': 'file-archive'
|
||||
};
|
||||
|
||||
if (file_icons[extension]) {
|
||||
return file_icons[extension];
|
||||
} else {
|
||||
// return null;
|
||||
return file_icons['file'];
|
||||
}
|
||||
}
|
||||
91
src/lib/ae_utils/ae_utils__process_data_string.ts
Normal file
91
src/lib/ae_utils/ae_utils__process_data_string.ts
Normal file
@@ -0,0 +1,91 @@
|
||||
import type { key_val } from "./ae_utils";
|
||||
|
||||
/* This utility function processes specific data string.
|
||||
* MECARD
|
||||
* OBJ = OBJ:ot:example,oi:asdf1234
|
||||
* ot = Aether object type; oi = Aether object ID random
|
||||
* KV = KV:"key":"value"
|
||||
* JS = {"id":123,"name":"example name"}
|
||||
* http or https?
|
||||
* Common short keys used:
|
||||
* bdg: Badge ID Random
|
||||
* reg: Registration ID Random
|
||||
* exid: External ID
|
||||
* gn: Given First Name
|
||||
* fn: Family Last Name
|
||||
* em: Email Address
|
||||
*/
|
||||
// Updated 2022-02-11
|
||||
|
||||
|
||||
export let process_data_string = function process_data_string(data_string: string) {
|
||||
console.log('*** process_data_string() ***');
|
||||
// console.log(data_string);
|
||||
if (!data_string || data_string.length < 1) {
|
||||
console.log('No data string found.');
|
||||
return false;
|
||||
}
|
||||
|
||||
let obj: key_val = {};
|
||||
|
||||
let colon_index = data_string.indexOf(':');
|
||||
if (colon_index) {
|
||||
let data_string_type = data_string.slice(0, colon_index);
|
||||
console.log(data_string_type);
|
||||
|
||||
obj['qr_type'] = data_string_type;
|
||||
|
||||
if (data_string_type == 'MECARD') {
|
||||
let mecard_str = data_string.slice(colon_index + 1);
|
||||
console.log(mecard_str);
|
||||
|
||||
obj['str'] = mecard_str;
|
||||
} else if (data_string_type == 'OBJ') {
|
||||
let key_value_str = data_string.slice(colon_index + 1);
|
||||
console.log(key_value_str);
|
||||
let key_value_array = key_value_str.split(',');
|
||||
// console.log(key_value_array);
|
||||
let ot_colon_index = key_value_array[0].indexOf(':');
|
||||
let obj_type = key_value_array[0].slice(ot_colon_index + 1);
|
||||
// console.log(obj_type);
|
||||
let oi_colon_index = key_value_array[1].indexOf(':');
|
||||
let obj_id = key_value_array[1].slice(oi_colon_index + 1);
|
||||
// console.log(obj_id);
|
||||
obj['type'] = obj_type;
|
||||
obj['id'] = obj_id;
|
||||
} else if (data_string_type == 'JSON') {
|
||||
let partial_json_str = data_string.slice(colon_index + 1);
|
||||
console.log(partial_json_str);
|
||||
let json_str = `{${partial_json_str}}`;
|
||||
console.log(json_str);
|
||||
|
||||
obj['json'] = JSON.parse(json_str);
|
||||
} else if (data_string_type == 'STR') {
|
||||
let str = data_string.slice(colon_index + 1);
|
||||
console.log(str);
|
||||
|
||||
obj['str'] = str;
|
||||
} else if (data_string_type == 'http' || data_string_type == 'https') {
|
||||
console.log(`http or https: ${data_string}`);
|
||||
|
||||
obj['type'] = 'url';
|
||||
obj['url'] = data_string;
|
||||
} else {
|
||||
console.log('The unknown data string type was found. Returning the string part.');
|
||||
let unknown_str = data_string.slice(colon_index + 1);
|
||||
console.log(unknown_str);
|
||||
|
||||
obj['str'] = unknown_str;
|
||||
}
|
||||
} else {
|
||||
console.log('The data string type was not found. Returning the entire string.');
|
||||
console.log(data_string);
|
||||
|
||||
obj['qr_type'] = 'UNKNOWN';
|
||||
obj['str'] = data_string;
|
||||
// return false;
|
||||
}
|
||||
|
||||
console.log(obj);
|
||||
return obj; // Returns an object
|
||||
};
|
||||
66
src/lib/ae_utils/ae_utils__return_obj_type_path.ts
Normal file
66
src/lib/ae_utils/ae_utils__return_obj_type_path.ts
Normal file
@@ -0,0 +1,66 @@
|
||||
export function return_obj_type_path({ obj_type = null, obj_type_prop_name = null }) {
|
||||
console.log('*** return_obj_type_path() ***');
|
||||
|
||||
let obj_type_path = null;
|
||||
|
||||
let known_obj_type_li = ['account', 'address', 'archive', 'archive_content', 'contact', 'event_badge', 'event_exhibit', 'event_file', 'event_location', 'event_person', 'event_presentation', 'event_presenter', 'event_registration', 'event_session', 'event', 'hosted_file', 'order_line', 'order', 'person', 'post', 'post_comment', 'user'];
|
||||
|
||||
let known_obj_type_li_dict = [
|
||||
{ name: 'account', display: 'Account', path: 'account' },
|
||||
{ name: 'archive', display: 'Archive', path: 'archive' },
|
||||
{ name: 'address', display: 'Address', path: 'address' },
|
||||
{ name: 'archive', display: 'Archive', path: 'archive' },
|
||||
{ name: 'archive_content', display: 'Archive Content', path: 'archive/content' },
|
||||
{ name: 'contact', display: 'Contact', path: 'contact' },
|
||||
{ name: 'data_store', display: 'Data Store', path: 'data_store' },
|
||||
{ name: 'event_abstract', display: 'Event Abstract', path: 'event/abstract' },
|
||||
{ name: 'event_badge', display: 'Event Badge', path: 'event/badge' },
|
||||
{ name: 'event_device', display: 'Event Device', path: 'event/device' },
|
||||
{ name: 'event_exhibit', display: 'Event Exhibit', path: 'event/exhibit' },
|
||||
{ name: 'event_file', display: 'Event File', path: 'event/file' },
|
||||
{ name: 'event_location', display: 'Event Location', path: 'event/location' },
|
||||
{ name: 'event_person', display: 'Event Person', path: 'event/person' },
|
||||
{ name: 'event_presentation', display: 'Event Presentation', path: 'event/' },
|
||||
{ name: 'event_presenter', display: 'Event Presenter', path: 'event/presenter' },
|
||||
{ name: 'event_registration', display: 'Event Registration', path: 'event/registration' },
|
||||
{ name: 'event_session', display: 'Event Session', path: 'event/session' },
|
||||
{ name: 'event', display: 'Event', path: 'event' },
|
||||
{ name: 'hosted_file', display: 'Hosted File', path: 'hosted_file' },
|
||||
{ name: 'journal', display: 'Journal', path: 'journal' },
|
||||
{ name: 'journal_entry', display: 'Journal Entry', path: 'journal/entry' },
|
||||
{ name: 'order_line', display: 'Order Line', path: 'order/line' },
|
||||
{ name: 'order', display: 'Order', path: 'order' },
|
||||
{ name: 'person', display: 'Person', path: 'person' },
|
||||
{ name: 'post', display: 'Archive', path: 'post' },
|
||||
{ name: 'post_comment', display: 'Archive Content', path: 'post/comment' },
|
||||
{ name: 'user', display: 'User', path: 'user' },
|
||||
];
|
||||
|
||||
if (obj_type) {
|
||||
// Need to loop through known for safety?
|
||||
obj_type_path = obj_type_prop_name.replaceAll('_', '/');
|
||||
|
||||
} else if (obj_type_prop_name) {
|
||||
let found_obj_type_name = null;
|
||||
let found_obj_type_path = null;
|
||||
|
||||
for (let i = 0; i < known_obj_type_li_dict.length; i++) {
|
||||
// console.log(known_obj_type_li_dict[i]);
|
||||
// let guessed_obj_type = prop_name.startsWith(known_obj_type_li_dict[i]
|
||||
if (obj_type_prop_name.startsWith(known_obj_type_li_dict[i].name)) {
|
||||
console.log(`Found ${known_obj_type_li_dict[i].name}`);
|
||||
found_obj_type_name = known_obj_type_li_dict[i].name;
|
||||
found_obj_type_path = known_obj_type_li_dict[i].path;
|
||||
// obj_type_path = obj_type_prop_name.replaceAll('_', '/');
|
||||
obj_type_path = found_obj_type_path;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
console.log('Missing required parameters');
|
||||
return false;
|
||||
}
|
||||
|
||||
return obj_type_path;
|
||||
}
|
||||
98
src/lib/ae_utils/ae_utils__set_obj_prop_display_name.ts
Normal file
98
src/lib/ae_utils/ae_utils__set_obj_prop_display_name.ts
Normal file
@@ -0,0 +1,98 @@
|
||||
import { to_title_case } from "./ae_utils__to_title_case";
|
||||
|
||||
// Updated 2023-08-18
|
||||
export function set_obj_prop_display_name({ prop_name, obj_type = null, prefix_w_obj_type = true, prefix_all_w_obj_type = false, replace_underscores = true, title_case = true, override = null }) {
|
||||
console.log('*** set_obj_prop_display_name() ***');
|
||||
|
||||
if (override) {
|
||||
return override;
|
||||
}
|
||||
|
||||
let known_obj_type_li = ['account', 'address', 'contact', 'event_badge', 'event_exhibit', 'event_file', 'event_location', 'event_person', 'event_presentation', 'event_presenter', 'event_registration', 'event_session', 'event', 'hosted_file', 'order_line', 'order', 'person', 'user'];
|
||||
|
||||
|
||||
let known_obj_type_li_dict = [
|
||||
{ name: 'account', display: 'Account' },
|
||||
{ name: 'address', display: 'Address' },
|
||||
{ name: 'contact', display: 'Contact' },
|
||||
{ name: 'event_badge', display: 'Event Badge' },
|
||||
{ name: 'event_exhibit', display: 'Event Exhibit' },
|
||||
{ name: 'event_file', display: 'Event File' },
|
||||
{ name: 'event_location', display: 'Event Location' },
|
||||
{ name: 'event_person', display: 'Event Person' },
|
||||
{ name: 'event_presentation', display: 'Event Presentation' },
|
||||
{ name: 'event_presenter', display: 'Event Presenter' },
|
||||
{ name: 'event_registration', display: 'Event Registration' },
|
||||
{ name: 'event_session', display: 'Event Session' },
|
||||
{ name: 'event', display: 'Event' },
|
||||
{ name: 'hosted_file', display: 'Hosted File' },
|
||||
{ name: 'order_line', display: 'Order Line' },
|
||||
{ name: 'order', display: 'Order' },
|
||||
{ name: 'person', display: 'Person' },
|
||||
{ name: 'user', display: 'User' },
|
||||
];
|
||||
|
||||
let prop_display_name = prop_name;
|
||||
|
||||
if (!prefix_w_obj_type) {
|
||||
if (obj_type) {
|
||||
prop_display_name = prop_name.replace(obj_type, '');
|
||||
} else {
|
||||
for (let i = 0; i < known_obj_type_li_dict.length; i++) {
|
||||
// console.log(known_obj_type_li_dict[i]);
|
||||
if (prop_name.startsWith(known_obj_type_li_dict[i].name)) {
|
||||
// console.log(`Found ${known_obj_type_li_dict[i].name}`);
|
||||
prop_display_name = prop_name.replace(known_obj_type_li_dict[i].name, '');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// for (let i = 0; i < known_obj_type_li.length; i++) {
|
||||
// // console.log(known_obj_type_li[i]);
|
||||
// if (prop_name.startsWith(known_obj_type_li[i])) {
|
||||
// console.log(`Found ${known_obj_type_li[i]}`);
|
||||
// prop_display_name = prop_name.replace(known_obj_type_li[i], '');
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
} else {
|
||||
if (!prefix_all_w_obj_type) {
|
||||
for (let i = 0; i < known_obj_type_li.length; i++) {
|
||||
// console.log(known_obj_type_li[i]);
|
||||
let found_obj_type = null;
|
||||
|
||||
if (prop_name.startsWith(known_obj_type_li_dict[i].name)) {
|
||||
// if (prop_name.startsWith(known_obj_type_li[i])) {
|
||||
// console.log(`Found ${known_obj_type_li_dict[i].name}`);
|
||||
found_obj_type = known_obj_type_li_dict[i].name;
|
||||
if (found_obj_type == obj_type) {
|
||||
prop_display_name = prop_name.replace(known_obj_type_li_dict[i].name, '');
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// if (obj_type) {
|
||||
// prop_display_name = prop_name.replace(obj_type, '');
|
||||
// } else {
|
||||
}
|
||||
}
|
||||
|
||||
// console.log(prop_display_name);
|
||||
if (prop_display_name.search('ID')) {
|
||||
}
|
||||
prop_display_name = prop_display_name.replace('id_random', 'ID');
|
||||
|
||||
if (replace_underscores) {
|
||||
prop_display_name = prop_display_name.replaceAll('_', ' ');
|
||||
}
|
||||
|
||||
if (title_case) {
|
||||
prop_display_name = to_title_case(prop_display_name);
|
||||
}
|
||||
|
||||
// console.log(prop_display_name);
|
||||
return prop_display_name;
|
||||
}
|
||||
42
src/lib/ae_utils/ae_utils__to_title_case.ts
Normal file
42
src/lib/ae_utils/ae_utils__to_title_case.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
/* Adapted from: To Title Case © 2018 David Gouch | https://github.com/gouch/to-title-case */
|
||||
// eslint-disable-next-line no-extend-native
|
||||
export function to_title_case(text_string) {
|
||||
// console.log('*** to_title_case() ***');
|
||||
let smallWords = /^(a|an|and|as|at|but|by|en|for|if|in|nor|of|on|or|per|the|to|v.?|vs.?|via)$/i;
|
||||
let alphanumericPattern = /([A-Za-z0-9\u00C0-\u00FF])/;
|
||||
let wordSeparators = /([ :–—-])/;
|
||||
|
||||
return text_string.split(wordSeparators)
|
||||
.map(function (current, index, array) {
|
||||
if (
|
||||
/* Check for small words */
|
||||
current.search(smallWords) > -1 &&
|
||||
/* Skip first and last word */
|
||||
index !== 0 &&
|
||||
index !== array.length - 1 &&
|
||||
/* Ignore title end and subtitle start */
|
||||
array[index - 3] !== ':' &&
|
||||
array[index + 1] !== ':' &&
|
||||
/* Ignore small words that start a hyphenated phrase */
|
||||
(array[index + 1] !== '-' ||
|
||||
(array[index - 1] === '-' && array[index + 1] === '-'))) {
|
||||
return current.toLowerCase();
|
||||
}
|
||||
|
||||
/* Ignore intentional capitalization */
|
||||
if (current.substr(1).search(/[A-Z]|\../) > -1) {
|
||||
return current;
|
||||
}
|
||||
|
||||
/* Ignore URLs */
|
||||
if (array[index + 1] === ':' && array[index + 2] !== '') {
|
||||
return current;
|
||||
}
|
||||
|
||||
/* Capitalize the first letter */
|
||||
return current.replace(alphanumericPattern, function (match) {
|
||||
return match.toUpperCase();
|
||||
});
|
||||
})
|
||||
.join('');
|
||||
}
|
||||
@@ -305,10 +305,15 @@ export interface File {
|
||||
for_id?: string;
|
||||
for_id_random?: string;
|
||||
|
||||
event_id: string;
|
||||
event_id_random: string;
|
||||
event_session_id?: string;
|
||||
event_session_id_random?: string;
|
||||
event_presentation_id?: string;
|
||||
event_presentation_id_random?: string;
|
||||
event_presenter_id?: string;
|
||||
event_presenter_id_random?: string;
|
||||
event_location_id?: string;
|
||||
event_location_id_random?: string;
|
||||
|
||||
filename: string;
|
||||
|
||||
@@ -184,7 +184,7 @@ function dispatch_edit_mode_changed() {
|
||||
Sessions:
|
||||
<ul>
|
||||
{#each Object.entries($events_loc.auth__kv.session) as [key, value]}
|
||||
<li><a href="/events_pres_mgmt/session/{key}">
|
||||
<li><a href="/events/{event_id}/session/{key}">
|
||||
{key}
|
||||
</a></li>
|
||||
{/each}
|
||||
|
||||
Reference in New Issue
Block a user