A lot of code clean up. Also making things look better.
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
import dayjs from 'dayjs';
|
||||
// Import external files first. Eventually this will be broken up in to smaller files.
|
||||
import { process_permission_checks } from './ae_utils__perm_checks';
|
||||
import { iso_datetime_formatter } from './ae_utils__datetime_format';
|
||||
|
||||
|
||||
type key_str = {
|
||||
[key: string]: string;
|
||||
@@ -8,135 +11,6 @@ type key_val = {
|
||||
[key: string]: any;
|
||||
};
|
||||
|
||||
export let iso_datetime_formatter = function iso_datetime_formatter(
|
||||
raw_datetime: null|string|Date = null,
|
||||
named_format: string = 'datetime_iso_no_seconds', // date_iso, datetime_iso_no_seconds
|
||||
) {
|
||||
// console.log('*** iso_datetime_formatter() ***');
|
||||
|
||||
// https://en.wikipedia.org/wiki/ISO_8601
|
||||
// https://day.js.org/docs/en/display/format
|
||||
// ISO 8601-1:2019 includes the T before the time portion
|
||||
// ISO 8601-1:2019 midnight may only be referred to as "00:00", corresponding to the beginning of a calendar day
|
||||
// and "24:00" is no longer allowed corresponding to the end of a day
|
||||
// 60 is only used to denote an added leap second
|
||||
|
||||
// ISO 8601 UTC: 2021-03-04T19:04:44+00:00
|
||||
// ISO 8601 UTC: 2021-03-04T19:04:44Z
|
||||
// ISO 8601 UTC: 20210304T190444Z
|
||||
|
||||
//datetime_iso 'YYYY-MM-DD HH:mm:ss'
|
||||
//datetime_iso_12 'YYYY-MM-DD hh:mm:ss A'
|
||||
//datetime_iso_12_short 'YY-MM-DD hh:mm A'
|
||||
//datetime_iso_tz 'YYYY-MM-DD HH:mm:ss'
|
||||
|
||||
//datetime_long 'dddd, MMMM D, YYYY hh:mm:ss A'
|
||||
//datetime_medium 'ddd, MMM D, YYYY hh:mm:ss A'
|
||||
//datetime_short 'MMM D, YY hh:mm A'
|
||||
|
||||
//date_iso 'YYYY-MM-DD'
|
||||
|
||||
//date_long 'dddd, MMMM D, YYYY'
|
||||
//date_medium 'ddd, MMM D, YYYY'
|
||||
//date_short 'MMM D, YY'
|
||||
|
||||
//time_iso 'HH:mm:ss'
|
||||
//time_iso_12 'hh:mm:ss A'
|
||||
|
||||
//time_long 'hh:mm:ss A'
|
||||
//time_medium 'h:m:s A'
|
||||
//time_short 'hh:mm A'
|
||||
|
||||
//dayjs(raw_datetime).format('dddd, MMMM D, YYYY hh:mm:ss A');
|
||||
|
||||
if (!raw_datetime) {
|
||||
raw_datetime = new Date(); // Get the current datetime if one was not passed.
|
||||
}
|
||||
|
||||
let datetime_string = null;
|
||||
|
||||
switch (named_format) {
|
||||
case 'datetime_iso':
|
||||
datetime_string = dayjs(raw_datetime).format('YYYY-MM-DD HH:mm:ss');
|
||||
break;
|
||||
case 'datetime_iso_no_seconds':
|
||||
datetime_string = dayjs(raw_datetime).format('YYYY-MM-DD HH:mm');
|
||||
break;
|
||||
case 'datetime_iso_12_short':
|
||||
datetime_string = dayjs(raw_datetime).format('YY-MM-DD hh:mm A');
|
||||
break;
|
||||
case 'datetime_iso_12_short_month':
|
||||
datetime_string = dayjs(raw_datetime).format('MM-DD hh:mm A');
|
||||
break;
|
||||
case 'datetime_short':
|
||||
datetime_string = dayjs(raw_datetime).format('MMM D, YY hh:mm A');
|
||||
break;
|
||||
case 'datetime_medium':
|
||||
datetime_string = dayjs(raw_datetime).format('MMM D, YYYY h:mm A');
|
||||
break;
|
||||
case 'datetime_long':
|
||||
datetime_string = dayjs(raw_datetime).format('MMMM D, YYYY hh:mm A');
|
||||
break;
|
||||
case 'datetime_short_month':
|
||||
datetime_string = dayjs(raw_datetime).format('MMM D hh:mm A');
|
||||
break;
|
||||
case 'datetime_long_month':
|
||||
datetime_string = dayjs(raw_datetime).format('MMMM D hh:mm A');
|
||||
break;
|
||||
case 'datetime_short_day':
|
||||
datetime_string = dayjs(raw_datetime).format('D hh:mm A');
|
||||
break;
|
||||
case 'date_iso':
|
||||
datetime_string = dayjs(raw_datetime).format('YYYY-MM-DD');
|
||||
break;
|
||||
case 'date_long_month_day':
|
||||
datetime_string = dayjs(raw_datetime).format('MMMM D');
|
||||
break;
|
||||
case 'date_short':
|
||||
datetime_string = dayjs(raw_datetime).format('MMM D, YY');
|
||||
break;
|
||||
case 'date_short_no_year':
|
||||
datetime_string = dayjs(raw_datetime).format('MMM D');
|
||||
break;
|
||||
case 'date_long':
|
||||
datetime_string = dayjs(raw_datetime).format('MMMM D, YYYY');
|
||||
break;
|
||||
case 'date_full':
|
||||
datetime_string = dayjs(raw_datetime).format('dddd, MMMM D, YYYY');
|
||||
break;
|
||||
case 'date_full_no_year':
|
||||
datetime_string = dayjs(raw_datetime).format('dddd, MMMM D');
|
||||
break;
|
||||
case 'time_iso':
|
||||
datetime_string = dayjs(raw_datetime).format('HH:mm:ss');
|
||||
break;
|
||||
case 'time_long':
|
||||
datetime_string = dayjs(raw_datetime).format('hh:mm:ss A');
|
||||
break;
|
||||
case 'time_short':
|
||||
datetime_string = dayjs(raw_datetime).format('hh:mm A');
|
||||
break;
|
||||
case 'time_short_no_leading':
|
||||
datetime_string = dayjs(raw_datetime).format('h:mm A');
|
||||
break;
|
||||
case 'week_long':
|
||||
datetime_string = dayjs(raw_datetime).format('dddd');
|
||||
break;
|
||||
case 'week_medium':
|
||||
datetime_string = dayjs(raw_datetime).format('ddd');
|
||||
break;
|
||||
case 'week_short':
|
||||
datetime_string = dayjs(raw_datetime).format('dd');
|
||||
break;
|
||||
default:
|
||||
console.log(`The named format passed (${named_format}) did not match a common name. Trying to format with the named format value.`);
|
||||
datetime_string = dayjs(raw_datetime).format(named_format);
|
||||
// datetime_string = dayjs(raw_datetime).format('YYYY-MM-DD HH:mm:ss');
|
||||
}
|
||||
return datetime_string;
|
||||
}
|
||||
|
||||
|
||||
function format_bytes(
|
||||
bytes: number,
|
||||
decimals: number = 2
|
||||
@@ -282,11 +156,16 @@ export let extract_prefixed_form_data = function extract_prefixed_form_data({pre
|
||||
* em: Email Address
|
||||
*/
|
||||
// Updated 2022-02-11
|
||||
export let process_data_string = function process_data_string(data_string) {
|
||||
export let process_data_string = function process_data_string(data_string: string) {
|
||||
console.log('*** process_data_string() ***');
|
||||
// console.log(data_string);
|
||||
|
||||
let obj = {};
|
||||
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) {
|
||||
@@ -354,172 +233,6 @@ export let process_data_string = function process_data_string(data_string) {
|
||||
}
|
||||
|
||||
|
||||
// NOTE: I know there is a better more efficient way to do this, but I don't have time for that right now.
|
||||
export let process_permission_checks = function process_permission_checks(access_type: string) {
|
||||
// let access_checks = { 'access_type': null, 'super_check': null };
|
||||
let access_checks: key_val = {};
|
||||
|
||||
if (access_type == 'super') {
|
||||
access_checks.access_type = 'super';
|
||||
|
||||
access_checks.super_check = true;
|
||||
access_checks.manager_check = false;
|
||||
access_checks.administrator_check = false;
|
||||
access_checks.support_check = false;
|
||||
access_checks.assistant_check = false;
|
||||
access_checks.trusted_check = false;
|
||||
access_checks.verified_check = false;
|
||||
access_checks.provisional_check = false;
|
||||
access_checks.public_check = false;
|
||||
access_checks.authenticated_check = true;
|
||||
access_checks.anonymous_check = false;
|
||||
|
||||
access_checks.super_access = true;
|
||||
access_checks.manager_access = true;
|
||||
access_checks.administrator_access = true;
|
||||
access_checks.support_access = true;
|
||||
access_checks.assistant_access = true;
|
||||
access_checks.trusted_access = true;
|
||||
access_checks.verified_access = true;
|
||||
access_checks.provisional_access = true;
|
||||
access_checks.public_access = true;
|
||||
access_checks.authenticated_access = true;
|
||||
access_checks.anonymous_access = true;
|
||||
} else if (access_type == 'manager') {
|
||||
access_checks.access_type = 'manager';
|
||||
|
||||
access_checks.super_check = false;
|
||||
access_checks.manager_check = true;
|
||||
access_checks.administrator_check = false;
|
||||
access_checks.support_check = false;
|
||||
access_checks.assistant_check = false;
|
||||
access_checks.trusted_check = false;
|
||||
access_checks.verified_check = false;
|
||||
access_checks.provisional_check = false;
|
||||
access_checks.public_check = false;
|
||||
access_checks.authenticated_check = true;
|
||||
access_checks.anonymous_check = false;
|
||||
|
||||
access_checks.super_access = false;
|
||||
access_checks.manager_access = true;
|
||||
access_checks.administrator_access = true;
|
||||
access_checks.support_access = true;
|
||||
access_checks.assistant_access = true;
|
||||
access_checks.trusted_access = true;
|
||||
access_checks.verified_access = true;
|
||||
access_checks.provisional_access = true;
|
||||
access_checks.public_access = true;
|
||||
access_checks.authenticated_access = true;
|
||||
access_checks.anonymous_access = true;
|
||||
} else if (access_type == 'administrator') {
|
||||
access_checks.access_type = 'administrator';
|
||||
|
||||
access_checks.super_check = false;
|
||||
access_checks.manager_check = false;
|
||||
access_checks.administrator_check = true;
|
||||
access_checks.support_check = false;
|
||||
access_checks.assistant_check = false;
|
||||
access_checks.trusted_check = false;
|
||||
access_checks.verified_check = false;
|
||||
access_checks.provisional_check = false;
|
||||
access_checks.public_check = false;
|
||||
access_checks.authenticated_check = false;
|
||||
access_checks.anonymous_check = false;
|
||||
|
||||
access_checks.super_access = false;
|
||||
access_checks.manager_access = false;
|
||||
access_checks.administrator_access = true;
|
||||
access_checks.support_access = true;
|
||||
access_checks.assistant_access = true;
|
||||
access_checks.trusted_access = true;
|
||||
access_checks.verified_access = true;
|
||||
access_checks.provisional_access = true;
|
||||
access_checks.public_access = true;
|
||||
access_checks.authenticated_access = true;
|
||||
access_checks.anonymous_access = true;
|
||||
} else if (access_type == 'trusted') {
|
||||
access_checks.access_type = 'trusted';
|
||||
|
||||
access_checks.super_check = false;
|
||||
access_checks.manager_check = false;
|
||||
access_checks.administrator_check = false;
|
||||
access_checks.support_check = false;
|
||||
access_checks.assistant_check = false;
|
||||
access_checks.trusted_check = true;
|
||||
access_checks.verified_check = false;
|
||||
access_checks.provisional_check = false;
|
||||
access_checks.public_check = false;
|
||||
access_checks.authenticated_check = true;
|
||||
access_checks.anonymous_check = false;
|
||||
|
||||
access_checks.super_access = false;
|
||||
access_checks.manager_access = false;
|
||||
access_checks.administrator_access = false;
|
||||
access_checks.support_access = false;
|
||||
access_checks.assistant_access = false;
|
||||
access_checks.trusted_access = true;
|
||||
access_checks.verified_access = true;
|
||||
access_checks.provisional_access = true;
|
||||
access_checks.public_access = true;
|
||||
access_checks.authenticated_access = true;
|
||||
access_checks.anonymous_access = true;
|
||||
} else if (access_type == 'authenticated') {
|
||||
access_checks.access_type = 'authenticated';
|
||||
|
||||
access_checks.super_check = false;
|
||||
access_checks.manager_check = false;
|
||||
access_checks.administrator_check = false;
|
||||
access_checks.support_check = false;
|
||||
access_checks.assistant_check = false;
|
||||
access_checks.trusted_check = false;
|
||||
access_checks.verified_check = false;
|
||||
access_checks.provisional_check = false;
|
||||
access_checks.public_check = false;
|
||||
access_checks.authenticated_check = true;
|
||||
access_checks.anonymous_check = false;
|
||||
|
||||
access_checks.super_access = false;
|
||||
access_checks.manager_access = false;
|
||||
access_checks.administrator_access = false;
|
||||
access_checks.support_access = false;
|
||||
access_checks.assistant_access = false;
|
||||
access_checks.trusted_access = false;
|
||||
access_checks.verified_access = false;
|
||||
access_checks.provisional_access = false;
|
||||
access_checks.public_access = false;
|
||||
access_checks.authenticated_access = true;
|
||||
access_checks.anonymous_access = true;
|
||||
} else {
|
||||
access_checks.access_type = 'anonymous';
|
||||
|
||||
access_checks.super_check = false;
|
||||
access_checks.manager_check = false;
|
||||
access_checks.administrator_check = false;
|
||||
access_checks.support_check = false;
|
||||
access_checks.assistant_check = false;
|
||||
access_checks.trusted_check = false;
|
||||
access_checks.verified_check = false;
|
||||
access_checks.provisional_check = false;
|
||||
access_checks.public_check = false;
|
||||
access_checks.authenticated_check = false;
|
||||
access_checks.anonymous_check = true;
|
||||
|
||||
access_checks.super_access = false;
|
||||
access_checks.manager_access = false;
|
||||
access_checks.administrator_access = false;
|
||||
access_checks.support_access = false;
|
||||
access_checks.assistant_access = false;
|
||||
access_checks.trusted_access = false;
|
||||
access_checks.verified_access = false;
|
||||
access_checks.provisional_access = false;
|
||||
access_checks.public_access = false;
|
||||
access_checks.authenticated_access = false;
|
||||
access_checks.anonymous_access = true;
|
||||
}
|
||||
|
||||
return access_checks;
|
||||
}
|
||||
|
||||
|
||||
// This function will update the URL and send a message to the parent window (iframe).
|
||||
// The name should be something like "example_id".
|
||||
@@ -1006,14 +719,13 @@ function return_obj_type_path({obj_type=null, obj_type_prop_name=null}) {
|
||||
|
||||
|
||||
|
||||
|
||||
export let ae_util = {
|
||||
process_permission_checks: process_permission_checks,
|
||||
iso_datetime_formatter: iso_datetime_formatter,
|
||||
format_bytes: format_bytes,
|
||||
number_w_commas: number_w_commas,
|
||||
extract_prefixed_form_data: extract_prefixed_form_data,
|
||||
process_data_string: process_data_string,
|
||||
process_permission_checks: process_permission_checks,
|
||||
handle_url_and_message: handle_url_and_message,
|
||||
create_a_element: create_a_element,
|
||||
create_img_element: create_img_element,
|
||||
@@ -1026,4 +738,3 @@ export let ae_util = {
|
||||
set_obj_prop_display_name: set_obj_prop_display_name,
|
||||
return_obj_type_path: return_obj_type_path,
|
||||
};
|
||||
// export default ae_util;
|
||||
Reference in New Issue
Block a user