Making the code easier to read and more consistent.
This commit is contained in:
@@ -1,86 +1,112 @@
|
||||
<script lang="ts">
|
||||
interface Props {
|
||||
person_id: string;
|
||||
display_mode?: string; // 'default', 'compact', 'minimal', 'launcher'
|
||||
log_lvl?: number;
|
||||
interface Props {
|
||||
person_id: string;
|
||||
display_mode?: string; // 'default', 'compact', 'minimal', 'launcher'
|
||||
log_lvl?: number;
|
||||
}
|
||||
|
||||
let { person_id, display_mode = 'default', log_lvl = 0 }: Props = $props();
|
||||
|
||||
console.log(`ae_core person_view.svelte`);
|
||||
|
||||
import { liveQuery } from 'dexie';
|
||||
|
||||
import type { key_val } from '$lib/stores/ae_stores';
|
||||
import { ae_util } from '$lib/ae_utils/ae_utils';
|
||||
import Element_ae_obj_field_editor from '$lib/elements/element_ae_obj_field_editor.svelte';
|
||||
import { api } from '$lib/api/api';
|
||||
|
||||
import { core_func } from '$lib/ae_core/ae_core_functions';
|
||||
import {
|
||||
ae_snip,
|
||||
ae_loc,
|
||||
ae_sess,
|
||||
ae_api,
|
||||
ae_trig,
|
||||
slct,
|
||||
slct_trigger
|
||||
} from '$lib/stores/ae_stores';
|
||||
import { db_core } from '$lib/ae_core/db_core';
|
||||
import {
|
||||
Archive,
|
||||
BookOpen,
|
||||
Building2,
|
||||
Check,
|
||||
Eye,
|
||||
EyeOff,
|
||||
Fingerprint,
|
||||
IdCard,
|
||||
Key,
|
||||
LoaderCircle,
|
||||
Mail,
|
||||
Save,
|
||||
Star,
|
||||
Tag,
|
||||
ToggleLeft,
|
||||
ToggleRight,
|
||||
TriangleAlert,
|
||||
User,
|
||||
UserRound
|
||||
} from '@lucide/svelte';
|
||||
// import { db_events } from "$lib/db_events";
|
||||
// import { events_loc, events_sess, events_slct, events_trigger } from '$lib/stores/ae_events_stores';
|
||||
// import { events_func } from '$lib/ae_events/ae_events_functions';
|
||||
|
||||
let ae_placeholder_li: key_val = {};
|
||||
let ae_promises: key_val = $state({}); // Promise<any>;
|
||||
let ae_tmp: key_val = $state({});
|
||||
|
||||
$effect(() => {
|
||||
if (log_lvl) {
|
||||
console.log(`person_id:`, person_id);
|
||||
}
|
||||
});
|
||||
|
||||
let { person_id, display_mode = 'default', log_lvl = 0 }: Props = $props();
|
||||
let lq__person_obj = $derived(
|
||||
liveQuery(async () => {
|
||||
let results = await db_core.person.get(person_id);
|
||||
return results;
|
||||
})
|
||||
);
|
||||
|
||||
console.log(`ae_core person_view.svelte`);
|
||||
ae_tmp.value__data_json = null;
|
||||
$effect(() => {
|
||||
if ($lq__person_obj?.data_json && ae_tmp.value__data_json === null) {
|
||||
ae_tmp.value__data_json = JSON.stringify(
|
||||
$lq__person_obj.data_json,
|
||||
null,
|
||||
4
|
||||
);
|
||||
// ae_tmp.value__data_json = JSON.parse(JSON.stringify($lq__person_obj.data_json));
|
||||
// JSON.stringify(jsObj, null, 4);
|
||||
}
|
||||
});
|
||||
|
||||
import { liveQuery } from 'dexie';
|
||||
ae_tmp.valid__data_json = null;
|
||||
$effect(() => {
|
||||
if (ae_tmp.value__data_json && ae_tmp.value__data_json.length) {
|
||||
console.log(
|
||||
`ae_tmp.value__data_json.length:`,
|
||||
ae_tmp.value__data_json.length
|
||||
);
|
||||
|
||||
import type { key_val } from '$lib/stores/ae_stores';
|
||||
import { ae_util } from '$lib/ae_utils/ae_utils';
|
||||
import Element_ae_obj_field_editor from '$lib/elements/element_ae_obj_field_editor.svelte';
|
||||
import { api } from '$lib/api/api';
|
||||
|
||||
import { core_func } from '$lib/ae_core/ae_core_functions';
|
||||
import {
|
||||
ae_snip,
|
||||
ae_loc,
|
||||
ae_sess,
|
||||
ae_api,
|
||||
ae_trig,
|
||||
slct,
|
||||
slct_trigger
|
||||
} from '$lib/stores/ae_stores';
|
||||
import { db_core } from '$lib/ae_core/db_core';
|
||||
import { Archive, BookOpen, Building2, Check, Eye, EyeOff, Fingerprint, IdCard, Key, LoaderCircle, Mail, Save, Star, Tag, ToggleLeft, ToggleRight, TriangleAlert, User, UserRound } from '@lucide/svelte';
|
||||
// import { db_events } from "$lib/db_events";
|
||||
// import { events_loc, events_sess, events_slct, events_trigger } from '$lib/stores/ae_events_stores';
|
||||
// import { events_func } from '$lib/ae_events/ae_events_functions';
|
||||
|
||||
let ae_placeholder_li: key_val = {};
|
||||
let ae_promises: key_val = $state({}); // Promise<any>;
|
||||
let ae_tmp: key_val = $state({});
|
||||
|
||||
|
||||
$effect(() => {
|
||||
if (log_lvl) {
|
||||
console.log(`person_id:`, person_id);
|
||||
try {
|
||||
JSON.parse(ae_tmp.value__data_json);
|
||||
ae_tmp.valid__data_json = true;
|
||||
} catch (e) {
|
||||
ae_tmp.valid__data_json = false;
|
||||
console.error(`JSON.parse error:`, e);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
let lq__person_obj = $derived(
|
||||
liveQuery(async () => {
|
||||
let results = await db_core.person.get(person_id);
|
||||
return results;
|
||||
})
|
||||
);
|
||||
|
||||
ae_tmp.value__data_json = null;
|
||||
$effect(() => {
|
||||
if ($lq__person_obj?.data_json && ae_tmp.value__data_json === null) {
|
||||
ae_tmp.value__data_json = JSON.stringify($lq__person_obj.data_json, null, 4);
|
||||
// ae_tmp.value__data_json = JSON.parse(JSON.stringify($lq__person_obj.data_json));
|
||||
// JSON.stringify(jsObj, null, 4);
|
||||
}
|
||||
});
|
||||
|
||||
ae_tmp.valid__data_json = null;
|
||||
$effect(() => {
|
||||
if (ae_tmp.value__data_json && ae_tmp.value__data_json.length) {
|
||||
console.log(`ae_tmp.value__data_json.length:`, ae_tmp.value__data_json.length);
|
||||
|
||||
try {
|
||||
JSON.parse(ae_tmp.value__data_json);
|
||||
ae_tmp.valid__data_json = true;
|
||||
} catch (e) {
|
||||
ae_tmp.valid__data_json = false;
|
||||
console.error(`JSON.parse error:`, e);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// let tmp_agree = false;
|
||||
// let tmp_opt_out: key_val = {
|
||||
// audio: false,
|
||||
// video: false,
|
||||
// transcription_and_publication: false,
|
||||
// publication_in_app: false
|
||||
// };
|
||||
// let tmp_agree = false;
|
||||
// let tmp_opt_out: key_val = {
|
||||
// audio: false,
|
||||
// video: false,
|
||||
// transcription_and_publication: false,
|
||||
// publication_in_app: false
|
||||
// };
|
||||
</script>
|
||||
|
||||
{#if $lq__person_obj}
|
||||
@@ -100,8 +126,12 @@
|
||||
field_type={'text'}
|
||||
current_value={$lq__person_obj.external_id}
|
||||
allow_null={true}
|
||||
on_success={() => core_func.load_ae_obj_id__person({ api_cfg: $ae_api, person_id: $lq__person_obj?.person_id_random, log_lvl: 1 })}
|
||||
>
|
||||
on_success={() =>
|
||||
core_func.load_ae_obj_id__person({
|
||||
api_cfg: $ae_api,
|
||||
person_id: $lq__person_obj?.person_id_random,
|
||||
log_lvl: 1
|
||||
})}>
|
||||
<IdCard size="1em" />
|
||||
External ID:
|
||||
<span class="font-bold">
|
||||
@@ -117,12 +147,17 @@
|
||||
field_type={'text'}
|
||||
current_value={$lq__person_obj.external_sys_id}
|
||||
allow_null={true}
|
||||
on_success={() => core_func.load_ae_obj_id__person({ api_cfg: $ae_api, person_id: $lq__person_obj?.person_id_random, log_lvl: 1 })}
|
||||
>
|
||||
on_success={() =>
|
||||
core_func.load_ae_obj_id__person({
|
||||
api_cfg: $ae_api,
|
||||
person_id: $lq__person_obj?.person_id_random,
|
||||
log_lvl: 1
|
||||
})}>
|
||||
<Fingerprint size="1em" />
|
||||
External System ID:
|
||||
<span class="font-bold">
|
||||
{@html $lq__person_obj.external_sys_id ?? ae_snip.html__not_set}
|
||||
{@html $lq__person_obj.external_sys_id ??
|
||||
ae_snip.html__not_set}
|
||||
</span>
|
||||
</Element_ae_obj_field_editor>
|
||||
</li>
|
||||
@@ -136,8 +171,12 @@
|
||||
field_name={'given_name'}
|
||||
field_type={'text'}
|
||||
current_value={$lq__person_obj.given_name}
|
||||
on_success={() => core_func.load_ae_obj_id__person({ api_cfg: $ae_api, person_id: $lq__person_obj?.person_id_random, log_lvl: 1 })}
|
||||
>
|
||||
on_success={() =>
|
||||
core_func.load_ae_obj_id__person({
|
||||
api_cfg: $ae_api,
|
||||
person_id: $lq__person_obj?.person_id_random,
|
||||
log_lvl: 1
|
||||
})}>
|
||||
<span class="font-bold">
|
||||
{@html $lq__person_obj.given_name ?? ae_snip.html__not_set}
|
||||
</span>
|
||||
@@ -148,8 +187,12 @@
|
||||
field_name={'family_name'}
|
||||
field_type={'text'}
|
||||
current_value={$lq__person_obj.family_name}
|
||||
on_success={() => core_func.load_ae_obj_id__person({ api_cfg: $ae_api, person_id: $lq__person_obj?.person_id_random, log_lvl: 1 })}
|
||||
>
|
||||
on_success={() =>
|
||||
core_func.load_ae_obj_id__person({
|
||||
api_cfg: $ae_api,
|
||||
person_id: $lq__person_obj?.person_id_random,
|
||||
log_lvl: 1
|
||||
})}>
|
||||
<span class="font-bold">
|
||||
{@html $lq__person_obj.family_name ?? ae_snip.html__not_set}
|
||||
</span>
|
||||
@@ -163,17 +206,21 @@
|
||||
field_type={'text'}
|
||||
current_value={$lq__person_obj.primary_email}
|
||||
allow_null={true}
|
||||
on_success={() => core_func.load_ae_obj_id__person({ api_cfg: $ae_api, person_id: $lq__person_obj?.person_id_random, log_lvl: 1 })}
|
||||
>
|
||||
on_success={() =>
|
||||
core_func.load_ae_obj_id__person({
|
||||
api_cfg: $ae_api,
|
||||
person_id: $lq__person_obj?.person_id_random,
|
||||
log_lvl: 1
|
||||
})}>
|
||||
<Mail size="1em" />
|
||||
<span class="font-bold">
|
||||
{#if $lq__person_obj.primary_email}
|
||||
<a
|
||||
href="mailto:{$lq__person_obj?.primary_email}"
|
||||
class="text-blue-500 underline hover:text-blue-800"
|
||||
title="Person's primary email address"
|
||||
>
|
||||
{@html $lq__person_obj.primary_email ?? 'email' + ae_snip.html__not_set}
|
||||
title="Person's primary email address">
|
||||
{@html $lq__person_obj.primary_email ??
|
||||
'email' + ae_snip.html__not_set}
|
||||
</a>
|
||||
{:else}
|
||||
email {@html ae_snip.html__not_set}
|
||||
@@ -189,11 +236,16 @@
|
||||
field_type={'text'}
|
||||
current_value={$lq__person_obj.affiliations}
|
||||
allow_null={true}
|
||||
on_success={() => core_func.load_ae_obj_id__person({ api_cfg: $ae_api, person_id: $lq__person_obj?.person_id_random, log_lvl: 1 })}
|
||||
>
|
||||
on_success={() =>
|
||||
core_func.load_ae_obj_id__person({
|
||||
api_cfg: $ae_api,
|
||||
person_id: $lq__person_obj?.person_id_random,
|
||||
log_lvl: 1
|
||||
})}>
|
||||
<Building2 size="1em" />
|
||||
<span class="font-bold">
|
||||
{@html $lq__person_obj.affiliations ?? 'affiliations' + ae_snip.html__not_set}
|
||||
{@html $lq__person_obj.affiliations ??
|
||||
'affiliations' + ae_snip.html__not_set}
|
||||
</span>
|
||||
</Element_ae_obj_field_editor>
|
||||
</li>
|
||||
@@ -205,8 +257,12 @@
|
||||
field_type={'text'}
|
||||
current_value={$lq__person_obj.professional_title}
|
||||
allow_null={true}
|
||||
on_success={() => core_func.load_ae_obj_id__person({ api_cfg: $ae_api, person_id: $lq__person_obj?.person_id_random, log_lvl: 1 })}
|
||||
>
|
||||
on_success={() =>
|
||||
core_func.load_ae_obj_id__person({
|
||||
api_cfg: $ae_api,
|
||||
person_id: $lq__person_obj?.person_id_random,
|
||||
log_lvl: 1
|
||||
})}>
|
||||
<Tag size="1em" />
|
||||
<span class="font-bold">
|
||||
{@html $lq__person_obj.professional_title &&
|
||||
@@ -224,12 +280,17 @@
|
||||
field_type={'text'}
|
||||
current_value={$lq__person_obj.passcode}
|
||||
allow_null={true}
|
||||
on_success={() => core_func.load_ae_obj_id__person({ api_cfg: $ae_api, person_id: $lq__person_obj?.person_id_random, log_lvl: 1 })}
|
||||
>
|
||||
on_success={() =>
|
||||
core_func.load_ae_obj_id__person({
|
||||
api_cfg: $ae_api,
|
||||
person_id: $lq__person_obj?.person_id_random,
|
||||
log_lvl: 1
|
||||
})}>
|
||||
<UserRound size="1em" />
|
||||
Passcode:
|
||||
<span class="font-bold">
|
||||
{@html $lq__person_obj.passcode ?? 'passcode' + ae_snip.html__not_set}
|
||||
{@html $lq__person_obj.passcode ??
|
||||
'passcode' + ae_snip.html__not_set}
|
||||
</span>
|
||||
</Element_ae_obj_field_editor>
|
||||
</li>
|
||||
@@ -237,16 +298,25 @@
|
||||
<li hidden={!$ae_loc.trusted_access}>
|
||||
<!-- Show/Hide -->
|
||||
{#if $ae_loc.trusted_access}
|
||||
<span class="text-sm">{$lq__person_obj?.hide ? 'Hidden' : 'Not Hidden'}</span>
|
||||
<span class="text-sm"
|
||||
>{$lq__person_obj?.hide ? 'Hidden' : 'Not Hidden'}</span>
|
||||
{/if}
|
||||
<button
|
||||
type="button"
|
||||
onclick={async () => {
|
||||
await api.update_ae_obj({ api_cfg: $ae_api, obj_type: 'person', obj_id: $lq__person_obj?.person_id_random, fields: { hide: !$lq__person_obj?.hide } });
|
||||
core_func.load_ae_obj_id__person({ api_cfg: $ae_api, person_id: $lq__person_obj?.person_id_random, log_lvl: 1 });
|
||||
await api.update_ae_obj({
|
||||
api_cfg: $ae_api,
|
||||
obj_type: 'person',
|
||||
obj_id: $lq__person_obj?.person_id_random,
|
||||
fields: { hide: !$lq__person_obj?.hide }
|
||||
});
|
||||
core_func.load_ae_obj_id__person({
|
||||
api_cfg: $ae_api,
|
||||
person_id: $lq__person_obj?.person_id_random,
|
||||
log_lvl: 1
|
||||
});
|
||||
}}
|
||||
class="btn btn-sm preset-tonal-warning"
|
||||
>
|
||||
class="btn btn-sm preset-tonal-warning">
|
||||
{#if $ae_loc.trusted_access}
|
||||
{#if $lq__person_obj?.hide}
|
||||
<Eye size="1em" class="m-1" /> Unhide?
|
||||
@@ -261,43 +331,61 @@
|
||||
|
||||
<!-- Enable/Disable -->
|
||||
{#if $ae_loc.trusted_access}
|
||||
<span class="text-sm">{$lq__person_obj?.enable ? 'Enabled' : 'Disabled'}</span>
|
||||
<span class="text-sm"
|
||||
>{$lq__person_obj?.enable ? 'Enabled' : 'Disabled'}</span>
|
||||
{/if}
|
||||
<button
|
||||
type="button"
|
||||
onclick={async () => {
|
||||
await api.update_ae_obj({ api_cfg: $ae_api, obj_type: 'person', obj_id: $lq__person_obj?.person_id_random, fields: { enable: !$lq__person_obj?.enable } });
|
||||
core_func.load_ae_obj_id__person({ api_cfg: $ae_api, person_id: $lq__person_obj?.person_id_random, log_lvl: 1 });
|
||||
await api.update_ae_obj({
|
||||
api_cfg: $ae_api,
|
||||
obj_type: 'person',
|
||||
obj_id: $lq__person_obj?.person_id_random,
|
||||
fields: { enable: !$lq__person_obj?.enable }
|
||||
});
|
||||
core_func.load_ae_obj_id__person({
|
||||
api_cfg: $ae_api,
|
||||
person_id: $lq__person_obj?.person_id_random,
|
||||
log_lvl: 1
|
||||
});
|
||||
}}
|
||||
class="btn btn-sm preset-tonal-warning"
|
||||
>
|
||||
class="btn btn-sm preset-tonal-warning">
|
||||
{#if $ae_loc.trusted_access}
|
||||
{#if $lq__person_obj?.enable}
|
||||
<ToggleRight size="1em" class="m-1" /> Disable?
|
||||
{:else}
|
||||
<ToggleLeft size="1em" class="m-1" /> Enable?
|
||||
{/if}
|
||||
{:else if $lq__person_obj?.enable}
|
||||
<ToggleRight size="1em" class="m-1" /> Disable
|
||||
{:else}
|
||||
{#if $lq__person_obj?.enable}
|
||||
<ToggleRight size="1em" class="m-1" /> Disable
|
||||
{:else}
|
||||
<ToggleLeft size="1em" class="m-1" /> Enable
|
||||
{/if}
|
||||
<ToggleLeft size="1em" class="m-1" /> Enable
|
||||
{/if}
|
||||
</button>
|
||||
|
||||
<!-- Priority/Not -->
|
||||
{#if $ae_loc.trusted_access}
|
||||
<span class="text-sm">{$lq__person_obj?.priority ? 'Priority' : 'Not Priority'}</span>
|
||||
<span class="text-sm"
|
||||
>{$lq__person_obj?.priority
|
||||
? 'Priority'
|
||||
: 'Not Priority'}</span>
|
||||
{/if}
|
||||
<button
|
||||
type="button"
|
||||
onclick={async () => {
|
||||
await api.update_ae_obj({ api_cfg: $ae_api, obj_type: 'person', obj_id: $lq__person_obj?.person_id_random, fields: { priority: !$lq__person_obj?.priority } });
|
||||
core_func.load_ae_obj_id__person({ api_cfg: $ae_api, person_id: $lq__person_obj?.person_id_random, log_lvl: 1 });
|
||||
await api.update_ae_obj({
|
||||
api_cfg: $ae_api,
|
||||
obj_type: 'person',
|
||||
obj_id: $lq__person_obj?.person_id_random,
|
||||
fields: { priority: !$lq__person_obj?.priority }
|
||||
});
|
||||
core_func.load_ae_obj_id__person({
|
||||
api_cfg: $ae_api,
|
||||
person_id: $lq__person_obj?.person_id_random,
|
||||
log_lvl: 1
|
||||
});
|
||||
}}
|
||||
class="btn btn-sm preset-tonal-warning"
|
||||
>
|
||||
class="btn btn-sm preset-tonal-warning">
|
||||
<Star size="1em" class="m-1" />
|
||||
{#if $ae_loc.trusted_access}
|
||||
{$lq__person_obj?.priority ? 'Not Priority?' : 'Priority?'}
|
||||
@@ -308,21 +396,38 @@
|
||||
|
||||
<!-- Allow Auth Key/Not -->
|
||||
{#if $ae_loc.trusted_access}
|
||||
<span class="text-sm">{$lq__person_obj?.allow_auth_key ? 'Allow Auth Key' : 'Not Allow Auth Key'}</span>
|
||||
<span class="text-sm"
|
||||
>{$lq__person_obj?.allow_auth_key
|
||||
? 'Allow Auth Key'
|
||||
: 'Not Allow Auth Key'}</span>
|
||||
{/if}
|
||||
<button
|
||||
type="button"
|
||||
onclick={async () => {
|
||||
await api.update_ae_obj({ api_cfg: $ae_api, obj_type: 'person', obj_id: $lq__person_obj?.person_id_random, fields: { allow_auth_key: !$lq__person_obj?.allow_auth_key } });
|
||||
core_func.load_ae_obj_id__person({ api_cfg: $ae_api, person_id: $lq__person_obj?.person_id_random, log_lvl: 1 });
|
||||
await api.update_ae_obj({
|
||||
api_cfg: $ae_api,
|
||||
obj_type: 'person',
|
||||
obj_id: $lq__person_obj?.person_id_random,
|
||||
fields: {
|
||||
allow_auth_key: !$lq__person_obj?.allow_auth_key
|
||||
}
|
||||
});
|
||||
core_func.load_ae_obj_id__person({
|
||||
api_cfg: $ae_api,
|
||||
person_id: $lq__person_obj?.person_id_random,
|
||||
log_lvl: 1
|
||||
});
|
||||
}}
|
||||
class="btn btn-sm preset-tonal-warning"
|
||||
>
|
||||
class="btn btn-sm preset-tonal-warning">
|
||||
<Key size="1em" class="m-1" />
|
||||
{#if $ae_loc.trusted_access}
|
||||
{$lq__person_obj?.allow_auth_key ? 'Not Allow Auth Key?' : 'Allow Auth Key?'}
|
||||
{$lq__person_obj?.allow_auth_key
|
||||
? 'Not Allow Auth Key?'
|
||||
: 'Allow Auth Key?'}
|
||||
{:else}
|
||||
{$lq__person_obj?.allow_auth_key ? 'Not Allow Auth Key' : 'Allow Auth Key'}
|
||||
{$lq__person_obj?.allow_auth_key
|
||||
? 'Not Allow Auth Key'
|
||||
: 'Allow Auth Key'}
|
||||
{/if}
|
||||
</button>
|
||||
</li>
|
||||
@@ -332,7 +437,9 @@
|
||||
<label for="person__data_json" class="label">
|
||||
<BookOpen size="1em" />
|
||||
Person JSON Data
|
||||
<span class="text-sm text-gray-500"> (no character limit) </span>
|
||||
<span class="text-sm text-gray-500">
|
||||
(no character limit)
|
||||
</span>
|
||||
</label>
|
||||
|
||||
<textarea
|
||||
@@ -348,8 +455,7 @@
|
||||
rows="8"
|
||||
cols="70"
|
||||
bind:value={ae_tmp.value__data_json}
|
||||
placeholder="Enter data_json here"
|
||||
></textarea>
|
||||
placeholder="Enter data_json here"></textarea>
|
||||
<!-- {/if} -->
|
||||
</div>
|
||||
|
||||
@@ -393,8 +499,7 @@
|
||||
// console.log(update_result);
|
||||
// return update_result;
|
||||
});
|
||||
}}
|
||||
>
|
||||
}}>
|
||||
{#await ae_promises.update__person_obj}
|
||||
<LoaderCircle size="1em" class="animate-spin mx-1" />
|
||||
{:then}
|
||||
|
||||
Reference in New Issue
Block a user