More work on new CRUD element. Now able to update the session location in the list.

This commit is contained in:
Scott Idem
2025-09-29 18:58:54 -04:00
parent 22d7c4728d
commit 0c01eed5c8
3 changed files with 194 additions and 145 deletions

View File

@@ -489,6 +489,7 @@ let events_session_data_struct: key_val = {
show__session_poc_profile: false,
show_modal__session_poc_agree: false,
hide__edit_location: {},
show__edit_location: {},
status_rpt: {

View File

@@ -6,7 +6,7 @@ interface Props {
trigger_patch?: any;
patch_status?: string; // '', processing, complete, error
patch_complete?: boolean|null; // null = not started, true = complete/success, false = error
patch_complete?: boolean|null|string; // null = not started, true = complete/success, false = error
patch_result?: boolean|null|key_val; // Result of the patch operation
object_type: string;
@@ -20,12 +20,14 @@ interface Props {
new_field_value?: any;
allow_null?: boolean;
select_option_li?: key_val;
select_option_kv?: key_val;
val_empty_is_null?: boolean; // This was added to help with a select option list. If the value is empty (''), it will be set to null.
edit_label?: string;
display_inline?: boolean;
display_block_edit?: boolean;
display_block?: boolean; // If true, the element will be displayed as a block element.
// display_inline?: boolean;
display_absolute_edit?: boolean; // If true, the edit form will be displayed in the top right corner of the element.
// display_block_edit?: boolean;
textarea_cols?: number;
textarea_rows?: number;
@@ -33,7 +35,8 @@ interface Props {
hide_element?: boolean;
hide_edit_btn?: boolean;
hide_edit_form?: boolean;
// hide_edit_form?: boolean;
show_edit_form?: boolean;
outline_element?: boolean;
@@ -49,7 +52,7 @@ let {
trigger_patch = null,
patch_status = '',
patch_complete = null,
patch_complete = $bindable(null), // null = not started, true = complete/success, false = error
patch_result = null,
object_type,
@@ -60,21 +63,24 @@ let {
previous_field_value = $bindable(null),
current_field_value = null,
new_field_value = $bindable(null),
new_field_value = current_field_value,
allow_null = false,
select_option_li = $bindable({}),
select_option_kv = $bindable({}),
val_empty_is_null = false, // If the value is empty (''), it will be set to null.
edit_label = 'Edit',
display_inline = false,
display_block_edit = false,
display_block = false,
// display_inline = false,
display_absolute_edit = false,
// display_block_edit = false,
textarea_cols = 80,
textarea_rows = 5,
hide_element = $bindable(false),
hide_edit_btn = false,
hide_edit_form = true,
// hide_edit_form = $bindable(true),
show_edit_form = $bindable(),
outline_element = $bindable(false),
@@ -113,6 +119,12 @@ $effect(() => {
// ; Super Key: ${api_crud_super_key}
}
}
if (select_option_kv) {
console.log(select_option_kv);
}
if (trigger_patch === true) {
@@ -199,7 +211,8 @@ async function handle_obj_field_patch(new_field_value: any) {
patch_complete = false;
patch_result = false;
} else {
patch_complete = true;
// patch_complete = true;
patch_complete = object_id; // Return the object ID that was patched
patch_result = {
'type': object_type,
'id': object_id,
@@ -222,10 +235,13 @@ async function handle_obj_field_patch(new_field_value: any) {
class="{class_li} ae_crud
font-normal
transition-all duration-300 ease-in-out
relative
z-20
"
class:hidden={hide_element}
class:inline={display_inline}
class:block={display_block}
class:inline-block={!display_block}
class:outline_element
>
@@ -239,7 +255,7 @@ async function handle_obj_field_patch(new_field_value: any) {
<button
type="button"
class:hidden={hide_edit_btn}
class:hidden={show_edit_form || hide_edit_btn}
class="
btn btn-icon
text-xs
@@ -248,11 +264,11 @@ async function handle_obj_field_patch(new_field_value: any) {
preset-outlined-warning-100-900 hover:preset-outlined-warning-600-400
opacity-50 hover:opacity-100
transition-all
inline
"
ondblclick={() => {
hide_edit_btn = true;
hide_edit_form = false;
// hide_edit_btn = true;
// hide_edit_form = false;
show_edit_form = true;
}}
title="Double click to edit property"
>
@@ -263,14 +279,31 @@ async function handle_obj_field_patch(new_field_value: any) {
<!-- class:display_block={display_block} -->
<div
class:hidden={hide_edit_form}
class:hidden={!show_edit_form}
class:absolute={display_absolute_edit}
class:top-0={display_absolute_edit}
class:right-0={display_absolute_edit}
class="field_editing_wrapper
min-w-content w-100 max-w-full
class:drop-shadow-2xl={display_absolute_edit}
class="field_editing_wrapper_v2
border-2 border-dashed hover:border-solid
border-pink-400 dark:border-pink-600
rounded-md
min-w-fit w-full max-w-fit
z-20
p-1 m-0
bg-pink-50/90 dark:bg-pink-900/90
hover:bg-pink-50 hover:dark:bg-pink-900
flex flex-col md:flex-row flex-wrap gap-1
items-center justify-center
space-y-2
transition-all duration-300 ease-in-out
"
>
<!-- <span class="grow flex flex-row items-center justify-between"> -->
<span class="hidden">
<span class="grow flex flex-row items-center justify-between">
<span class="hidden md:inline font-semibold text-lg">
{edit_label}
</span>
@@ -278,18 +311,23 @@ async function handle_obj_field_patch(new_field_value: any) {
type="button"
class="btn btn-md ae_btn_surface_outlined m-1"
onclick={() => {
hide_edit_btn = false;
hide_edit_form = true;
// hide_edit_btn = false;
// hide_edit_form = true;
show_edit_form = false;
}}
title="Close field editing. This does not save any changes."
>
<span class="fas fa-window-close"></span>
<span class="hidden sm:inline">Close</span>
</button>
<!-- </span> -->
</span>
<span
class="field_value grow min-w-content max-w-full"
class="field_value
grow
min-w-fit w-full max-w-fit
flex flex-row flex-wrap items-center justify-center gap-1
"
>
{#if field_type == 'template'}
@@ -300,13 +338,18 @@ async function handle_obj_field_patch(new_field_value: any) {
{:else if field_type == 'select'}
<select
bind:value={new_field_value}
class="select"
class="
select
p-1
min-w-fit w-full
border border-gray-300 dark:border-gray-600
"
>
{#if select_option_li && Object.keys(select_option_li).length == 0}
{#if select_option_kv && Object.keys(select_option_kv).length == 0}
<option value="">-- not set --</option>
{:else if select_option_li && Object.keys(select_option_li).length > 0}
{#each Object.keys(select_option_li) as option}
<option value={option}>{select_option_li[option]}</option>
{:else if select_option_kv && Object.keys(select_option_kv).length > 0}
{#each Object.keys(select_option_kv) as option}
<option value={option}>{select_option_kv[option]}</option>
{/each}
{:else}
<option value="">-- no list --</option>
@@ -346,15 +389,18 @@ async function handle_obj_field_patch(new_field_value: any) {
</span>
<button
class="btn btn-lg ae_btn_warning_outlined m-1"
disabled={new_field_value == current_field_value}
class="
ae_btn_warning_outlined
btn btn-lg
m-1
"
disabled={new_field_value === current_field_value}
onclick={async () => {
handle_obj_field_patch(new_field_value);
}}
title="Save new field value"
>
{#if new_field_value == current_field_value}
{#if new_field_value === current_field_value}
{#if (btn_label)}
{@html btn_label}
{:else}

View File

@@ -60,8 +60,39 @@ import { events_func } from '$lib/ae_events_functions';
// let ae_promises: key_val = {};
let ae_tmp: key_val = $state({});
let ae_triggers: key_val = $state({});
let trigger_reload_session_id: string = $state('');
// *** Functions and Logic
$effect(() => {
// if (ae_triggers.session_obj_id_reload) {
// console.log(`ae_triggers.session_obj_id_reload changed: ${ae_triggers.session_obj_id_reload}`);
// reload_session_id(ae_triggers.session_obj_id_reload);
// }
if (trigger_reload_session_id) {
console.log(`trigger_reload_session_id changed: ${trigger_reload_session_id}`);
reload_event_session_id(trigger_reload_session_id);
trigger_reload_session_id = '';
}
});
function reload_event_session_id(event_session_id_random: string) {
console.log(`Reloading session ID: ${event_session_id_random}`);
events_func.load_ae_obj_id__event_session({
api_cfg: $ae_api,
event_session_id: event_session_id_random,
log_lvl: log_lvl
})
.then(function (load_results) {
console.log(`Loaded session:`, load_results);
});
}
</script>
<!-- xs:max-w-sm lg:max-w-100 -->
@@ -268,152 +299,123 @@ let ae_triggers: key_val = $state({});
{/if}
{#if $ae_loc.edit_mode}
<!-- $slct.location_obj_kv -->
<Element_ae_crud_v2
api_cfg={$ae_api}
trigger_patch={ae_triggers.update_location}
bind:patch_complete={trigger_reload_session_id}
object_type={'event_session'}
object_id={session_obj?.event_session_id_random}
field_name={'event_location_id_random'}
field_type={'button'}
field_type={'select'}
current_field_value={session_obj?.event_location_id_random}
allow_null={true}
select_option_li={$slct.location_obj_kv}
select_option_kv={$slct.event_location_obj_kv}
hide_element={!$ae_loc.edit_mode}
hide_edit_btn={true}
hide_edit_form={$events_sess.pres_mgmt.show__edit_location[session_obj?.event_session_id_random] !== true}
bind:show_edit_form={$events_sess.pres_mgmt.show__edit_location[session_obj?.event_session_id_random]}
outline_element={false}
display_inline={true}
display_block={false}
display_absolute_edit={true}
class_li={'m-1'}
>
{#await $slct.location_obj_li}
<span class="fas fa-spinner fa-spin mx-1"></span>
{:then location_obj_li}
{#if location_obj_li && location_obj_li.length > 0}
<label class="text-sm">Location:
<select
bind:value={ae_tmp[session_obj.event_session_id_random].event_location_id_random}
class="select min-w-fit max-w-md text-sm"
>
<option value="">-- No location --</option>
{#each location_obj_li as location_obj}
<option
value={location_obj.event_location_id_random}
selected={location_obj.event_location_id_random == session_obj?.event_location_id_random}
>
{location_obj.name}
({location_obj.event_location_id_random})
</option>
{/each}
</select>
</label>
<button
type="button"
disabled={ae_tmp[session_obj.event_session_id_random].event_location_id_random == session_obj?.event_location_id_random}
onclick={() => {
console.log('Save the location for the session.');
let location_id = ae_tmp[session_obj.event_session_id_random].event_location_id_random;
console.log('Selected location ID:', location_id);
ae_triggers.update_location = true;
}}
class="btn btn-sm preset-tonal-warning hover:preset-tonal-warning border border-warning
"
>
<span class="fas fa-save mx-1"></span>
Save
</button>
{/if}
{/await}
</Element_ae_crud_v2>
{/if}
{#if ae_tmp?.show__edit_location}
{#if $events_sess.pres_mgmt.show__edit_location[session_obj?.event_session_id_random]}
{#await $slct.event_location_obj_li}
<span class="fas fa-spinner fa-spin mx-1"></span>
{:then event_location_obj_li}
<!-- {#if event_location_obj_li && event_location_obj_li.length > 0}
<!-- {#await $slct.event_location_obj_li}
<span class="fas fa-spinner fa-spin mx-1"></span>
{/await}
{/if} -->
{/await}
<button
type="button"
onclick={() => {
console.log('Cancel editing the location for the session.');
<button
type="button"
onclick={() => {
console.log('Cancel editing the location for the session.');
ae_tmp.event_location_id = null;
ae_tmp.show__edit_event_location = false;
ae_tmp.event_location_id = null;
ae_tmp.show__edit_event_location = false;
$events_sess.pres_mgmt.show__edit_location[session_obj?.event_session_id_random] = false;
}}
class="btn btn-sm preset-tonal-warning hover:preset-tonal-warning border border-warning-500"
>
<span class="fas fa-times mx-1"></span>
Cancel
</button> -->
$events_sess.pres_mgmt.show__edit_location[session_obj?.event_session_id_random] = false;
}}
class="btn btn-sm preset-tonal-warning hover:preset-tonal-warning border border-warning-500"
>
<span class="fas fa-times mx-1"></span>
Cancel
</button>
{:else if $ae_loc.edit_mode}
<button
type="button"
ondblclick={() => {
console.log('Edit the location for the session.');
{:else}
<button
type="button"
onclick={() => {
console.log('Edit the location for the session.');
let params = {
qry__limit: 50,
}
let params = {
qry__limit: 50,
}
// $slct.event_location_obj_li = await core_func.load_ae_obj_li__event_location({api_cfg: $ae_api, account_id: $slct.account_id, params: params});
// $slct.event_location_obj_li = await core_func.load_ae_obj_li__event_location({api_cfg: $ae_api, account_id: $slct.account_id, params: params});
$slct.event_location_obj_li = events_func.load_ae_obj_li__event_location({
api_cfg: $ae_api,
for_obj_type: 'event',
for_obj_id: session_obj?.event_id_random,
params: params,
log_lvl: log_lvl
})
.then(function (load_results) {
console.log(`Loaded event_location_obj_li:`, load_results);
// We need to make this ready for the select option list. Convert the list to a key value pair with the event_location_id_random as the key. We also need to set the option text value to: name (room)
if (load_results) {
let event_location_obj_li = load_results;
let event_location_obj_kv = {}; //: key_val = {};
event_location_obj_kv[''] = '-- Select a location --';
event_location_obj_li.forEach((event_location_obj) => {
let option_text = `${event_location_obj.name} (${event_location_obj.code})`;
event_location_obj_kv[event_location_obj.event_location_id_random] = option_text;
});
$slct.event_location_obj_kv = event_location_obj_kv;
}
// $slct.event_location_obj_kv = $slct.event_location_obj_kv;
console.log(`$slct.event_location_obj_kv = `, $slct.event_location_obj_kv);
return load_results;
$slct.event_location_obj_li = events_func.load_ae_obj_li__event_location({
api_cfg: $ae_api,
for_obj_type: 'event',
for_obj_id: session_obj?.event_id_random,
params: params,
log_lvl: log_lvl
})
.finally(function () {
console.log(`Finally...`);
ae_tmp.event_location_id = session_obj?.event_location_id_random;
ae_tmp.show__edit_event_location = true;
.then(function (load_results) {
console.log(`Loaded event_location_obj_li:`, load_results);
$events_sess.pres_mgmt.show__edit_location[session_obj?.event_session_id_random] = true;
// We need to make this ready for the select option list. Convert the list to a key value pair with the event_location_id_random as the key. We also need to set the option text value to: name (room)
if (load_results) {
let event_location_obj_li = load_results;
let event_location_obj_kv = {}; //: key_val = {};
event_location_obj_kv[''] = '-- Select a location --';
event_location_obj_li.forEach((event_location_obj) => {
let option_text = `${event_location_obj.name} (${event_location_obj.code})`;
event_location_obj_kv[event_location_obj.event_location_id_random] = option_text;
});
$slct.event_location_obj_kv = event_location_obj_kv;
}
// $slct.event_location_obj_kv = $slct.event_location_obj_kv;
console.log(`$slct.event_location_obj_kv = `, $slct.event_location_obj_kv);
});
}}
class="btn btn-sm preset-tonal-warning group"
>
<span class="fas fa-edit m-0.75"></span>
<span class="hidden group-hover:inline">Edit</span>
</button>
return load_results;
})
.finally(function () {
console.log(`Finally...`);
ae_tmp.event_location_id = session_obj?.event_location_id_random;
ae_tmp.show__edit_event_location = true;
{/if}
$events_sess.pres_mgmt.show__edit_location[session_obj?.event_session_id_random] = true;
});
}}
class="
btn btn-icon
text-xs
m-0 px-0.5
preset-tonal-warning hover:preset-tonal-error
preset-outlined-warning-100-900 hover:preset-outlined-warning-600-400
opacity-50 hover:opacity-100
transition-all
"
>
<span class="fas fa-edit m-0.75"></span>
<!-- group-hover:inline -->
<span class="hidden">Edit</span>
</button>
{/if}
</td>