Lots of little fixes. Can now save archives.

This commit is contained in:
Scott Idem
2024-11-08 15:43:47 -05:00
parent e6a9a5ceab
commit f4538720b2
10 changed files with 377 additions and 157 deletions

View File

@@ -49,7 +49,7 @@ $idaa_slct.archive_id = ae_acct.slct.archive_id;
$: lq__archive_obj = liveQuery(async () => {
console.log(`lq__archive_obj: archive_id = ${$idaa_slct?.archive_id}`);
let results = await db_archives.archive
.get($idaa_slct?.archive_id);
.get($idaa_slct?.archive_id ?? ''); // null or undefined does not reset things like '' does
return results;
});
@@ -57,7 +57,7 @@ $: lq__archive_obj = liveQuery(async () => {
$: lq__archive_content_obj_li = liveQuery(async () => {
let results = await db_archives.content
.where('archive_id')
.equals($idaa_slct?.archive_id)
.equals($idaa_slct?.archive_id ?? '') // null or undefined does not reset things like '' does
.reverse()
.sortBy('updated_on');
// .sortBy('title');
@@ -67,7 +67,7 @@ $: lq__archive_content_obj_li = liveQuery(async () => {
$: lq__archive_content_obj = liveQuery(async () => {
let results = await db_archives.content
.get($idaa_slct.archive_content_id);
.get($idaa_slct.archive_content_id ?? ''); // null or undefined does not reset things like '' does
return results;
});
@@ -180,7 +180,7 @@ if (browser) {
<!-- Modal: Archive Content edit ID -->
<Modal
title="{$lq__archive_content_obj?.name} - {$lq__archive_content_obj?.id}"
title="{$lq__archive_content_obj?.name ?? 'New Archive Content'} - {$lq__archive_content_obj?.id ?? 'Not Saved Yet'}"
bind:open={$idaa_sess.archives.show__modal_edit__archive_content_id}
autoclose={false}
placement="top-center"
@@ -191,30 +191,30 @@ if (browser) {
<svelte:fragment slot="header">
<div class="flex flex-row items-center justify-between w-full">
<h3 class="text-lg font-semibold">
{#if $ae_loc.trusted_access}
<!-- <div class="ae_options"> -->
<button
on:click={() => {
// const url = new URL(location);
// url.searchParams.set('event_id', $lq__archive_content_obj?.event_id_random);
// history.pushState({}, '', url);
{#if $ae_loc.trusted_access}
<!-- <div class="ae_options"> -->
<button
on:click={() => {
// const url = new URL(location);
// url.searchParams.set('event_id', $lq__archive_content_obj?.event_id_random);
// history.pushState({}, '', url);
$idaa_sess.archives.show__modal_view__archive_content_id = $idaa_slct.archive_content_id;
$idaa_sess.archives.show__modal_edit__archive_content_id = false;
}}
class="btn btn-sm variant-ghost-warning hover:variant-filled-warning transition"
title={`View meeting: ${$lq__archive_content_obj?.name}`}
>
<span class="fas fa-eye m-1"></span> View
</button>
<!-- </div> -->
{/if}
$idaa_sess.archives.show__modal_view__archive_content_id = $idaa_slct.archive_content_id;
$idaa_sess.archives.show__modal_edit__archive_content_id = false;
}}
class="btn btn-sm variant-ghost-warning hover:variant-filled-warning transition"
title={`View meeting: ${$lq__archive_content_obj?.name}`}
>
<span class="fas fa-eye m-1"></span> View
</button>
<!-- </div> -->
{/if}
<span class="text-sm text-gray-500">
Edit Archive Content:
</span>
{$lq__archive_content_obj?.name}
</h3>
<span class="text-sm text-gray-500">
Edit Archive Content:
</span>
{$lq__archive_content_obj?.name ?? 'New Archive Content'}
</h3>
</div>
</svelte:fragment>
@@ -248,6 +248,7 @@ if (browser) {
title="{$lq__archive_content_obj?.name} - {$lq__archive_content_obj?.archive_content_id}"
bind:open={$idaa_sess.archives.show__modal_view__archive_content_id}
autoclose={false}
outsideclose={true}
placement="top-center"
size="xl"
class="top-center bg-white dark:bg-gray-800 text-gray-800 dark:text-gray-200 rounded-lg border-gray-200 dark:border-gray-700 divide-gray-200 dark:divide-gray-700 shadow-md relative flex flex-col mx-auto w-full divide-y"

View File

@@ -3,13 +3,11 @@ export let log_lvl = 1;
// *** Import Svelte core
import { onMount } from 'svelte';
import { fade } from 'svelte/transition';
import { Spinner } from 'flowbite-svelte';
// *** Import Aether core variables and functions
import type { key_val } from '$lib/ae_stores';
import { ae_util } from '$lib/ae_utils/ae_utils';
import { core_func } from '$lib/ae_core/ae_core_functions';
import { api } from '$lib/api';
import { ae_snip, ae_loc, ae_sess, ae_api, ae_trig, slct, slct_trigger } from '$lib/ae_stores';
import { idaa_loc, idaa_sess, idaa_slct } from '$lib/ae_idaa_stores';
import { archives_func } from '$lib/ae_archives/ae_archives_functions';
@@ -101,6 +99,7 @@ if (lu_time_zone_list && lu_time_zone_list.length > 0) {
});
}
onMount(() => {
console.log('** Component Mounted: ** ID - Archive Content Obj - Edit');
});
@@ -400,7 +399,7 @@ async function handle_hosted_files_uploaded(hosted_file_id_li: string[], hosted_
bind:hosted_file_id_li={$idaa_slct.archive_content_obj.hosted_file_id_li}
bind:hosted_file_obj_li={$idaa_slct.archive_content_obj.hosted_file_obj_li}
bind:upload_complete={$idaa_slct.archive_content_obj.upload_complete}
log_lvl={2}
log_lvl={log_lvl}
>
<span slot="label">
<div>
@@ -717,7 +716,7 @@ async function handle_hosted_files_uploaded(hosted_file_id_li: string[], hosted_
<button
type="submit"
disabled={disable_submit_btn}
class="btn btn-md variant-ghost-primary"
class="btn btn-md variant-ghost-primary hover:variant-filled-primary transition"
>
<span class="fas fa-check m-1"></span>
Save Archive Content

View File

@@ -3,15 +3,14 @@ export let log_lvl = 1;
// *** Import Svelte core
import { onMount } from 'svelte';
import { fade } from 'svelte/transition';
import { Spinner } from 'flowbite-svelte';
// *** Import Aether core variables and functions
import type { key_val } from '$lib/ae_stores';
import { ae_util } from '$lib/ae_utils/ae_utils';
import { core_func } from '$lib/ae_core/ae_core_functions';
import { api } from '$lib/api';
import { ae_snip, ae_loc, ae_sess, ae_api, ae_trig, slct, slct_trigger } from '$lib/ae_stores';
import { idaa_loc, idaa_sess, idaa_slct } from '$lib/ae_idaa_stores';
import { archives_func } from '$lib/ae_archives/ae_archives_functions';
import Tiptap_editor from '$lib/element_tiptap_editor.svelte';
@@ -21,6 +20,8 @@ let create_archive_obj_promise: any;
let delete_archive_obj_promise: any;
let update_archive_obj_promise: any;
let upload__hosted_file_obj_promise: any;
let prom_api__archive_obj: any;
let prom_api__archive_obj__hosted_file: any;
let disable_submit_btn = true;
@@ -66,7 +67,6 @@ if (lu_time_zone_list && lu_time_zone_list.length > 0) {
}
onMount(() => {
console.log('** Component Mounted: ** ID - Archive Obj - Edit');
});
@@ -74,39 +74,40 @@ onMount(() => {
async function handle_submit_form(event) {
console.log('*** handle_submit_form() ***');
if (log_lvl > 1) {
console.log('*** handle_submit_form() ***');
console.log(event.target);
}
disable_submit_btn = true;
let form_data = new FormData(event.target);
console.log(form_data);
let form_archive_data = ae_util.extract_prefixed_form_data({prefix: null, form_data: form_data, trim_values: true, bool_tf_str: true, log_lvl: 0});
console.log(form_archive_data);
let archive_di = ae_util.extract_prefixed_form_data({prefix: null, form_data: form_data, trim_values: true, bool_tf_str: true, log_lvl: 0});
console.log(archive_di);
let archive_data: key_val = {};
let archive_do: key_val = {};
if (!$idaa_slct.archive_id) {
archive_data['account_id_random'] = $ae_loc.account_id;
archive_data['enable'] = true;
archive_do['account_id_random'] = $ae_loc.account_id;
// archive_do['enable'] = true;
}
archive_data['name'] = form_archive_data.name;
if (tinyMCE.get('description')) {
archive_data['description'] = tinyMCE.get('description').getContent();
} else {
archive_data['description'] = form_archive_data.description;
}
archive_do['name'] = archive_di.name;
if (tinyMCE.get('content_html')) {
archive_data['content_html'] = tinyMCE.get('content_html').getContent();
// Check if the description_new_html exists and is a string
if (typeof $idaa_slct.archive_obj.description_new_html === 'string') {
console.log('New description is a string');
archive_do['description'] = $idaa_slct.archive_obj.description_new_html;
} else {
archive_data['content_html'] = form_archive_data.content_html;
console.log('New description is not a string. Do nothing.');
// archive_do['description'] = event_meeting_fd.description;
}
let date_time_str = null;
let date_part = form_archive_data.original_datetime_date.trim();
let time_part = form_archive_data.original_datetime_time.trim();
let date_part = archive_di.original_datetime_date.trim();
let time_part = archive_di.original_datetime_time.trim();
if (date_part && time_part) {
date_time_str = `${date_part} ${time_part}`;
} else if (date_part) {
@@ -115,81 +116,77 @@ async function handle_submit_form(event) {
// date_time_str = `${time_part}`;
date_time_str = false;
}
archive_data['original_datetime'] = date_time_str;
archive_do['original_datetime'] = date_time_str;
archive_data['original_timezone'] = form_archive_data.original_timezone;
archive_do['original_timezone'] = archive_di.original_timezone;
archive_data['original_location'] = form_archive_data.original_location;
archive_do['original_location'] = archive_di.original_location;
archive_data['original_url'] = form_archive_data.original_url;
archive_data['original_url_text'] = form_archive_data.original_url_text;
archive_do['original_url'] = archive_di.original_url;
archive_do['original_url_text'] = archive_di.original_url_text;
archive_data['hide'] = !!form_archive_data.hide;
archive_data['priority'] = !!form_archive_data.priority;
if (form_archive_data.sort) {
archive_data['sort'] = Number(form_archive_data.sort);
archive_do['hide'] = archive_di.hide;
archive_do['priority'] = archive_di.priority;
if (archive_di.sort) {
archive_do['sort'] = Number(archive_di.sort);
} else {
archive_data['sort'] = null;
archive_do['sort'] = null;
}
if (form_archive_data.group) {
archive_data['group'] = form_archive_data.group;
if (archive_di.group) {
archive_do['group'] = archive_di.group;
} else {
archive_data['group'] = null;
archive_do['group'] = null;
}
if (form_archive_data.enable) {
archive_data['enable'] = !!form_archive_data.enable;
}
// console.log(`archive_di.enable = ${archive_di.enable}`);
archive_do['enable'] = !!archive_di.enable;
if (tinyMCE.get('notes')) {
archive_data['notes'] = tinyMCE.get('notes').getContent();
// Check if the notes_new_html exists and is a string
if (typeof $idaa_slct.archive_obj.notes_new_html === 'string') {
console.log('New notes is a string');
archive_do['notes'] = $idaa_slct.archive_obj.notes_new_html;
} else {
archive_data['notes'] = form_archive_data.notes;
console.log('New notes is not a string. Do nothing.');
// archive_do['notes'] = event_meeting_fd.notes;
}
console.log(archive_data);
console.log(archive_do);
if (!$idaa_slct.archive_id) {
create_archive_obj_promise = api.create_ae_obj_crud({
prom_api__archive_obj = archives_func.create_ae_obj__archive({
api_cfg: $ae_api,
obj_type: 'archive',
fields: archive_data,
key: $ae_api.api_crud_super_key,
log_lvl: 1
archive_id: $idaa_slct.archive_id,
data_kv: archive_do,
log_lvl: log_lvl
})
.then(function (archive_obj_create_result) {
.then(async function (archive_obj_create_result) {
if (!archive_obj_create_result) {
console.log('The result was null or false.');
return false;
}
$idaa_slct.archive_id = archive_obj_create_result.obj_id_random;
$idaa_slct.archive_obj = archive_obj_create_result;
dispatch(
'created__archive_obj',
{
archive_id: $idaa_slct.archive_id,
}
);
return archive_obj_create_result;
return update_archive_obj_promise
})
.catch(function (error) {
console.log('Something went wrong.');
console.log(error);
return false;
})
.finally(() => {
disable_submit_btn = false;
});
return create_archive_obj_promise;
} else {
update_archive_obj_promise = api.update_ae_obj_id_crud({
prom_api__archive_obj = archives_func.update_ae_obj__archive({
api_cfg: $ae_api,
obj_type: 'archive',
obj_id: $idaa_slct.archive_id,
fields: archive_data,
key: $ae_api.api_crud_super_key,
log_lvl: 1
archive_id: $idaa_slct.archive_id,
data_kv: archive_do,
log_lvl: log_lvl
})
.then(function (archive_obj_update_result) {
if (!archive_obj_update_result) {
@@ -197,22 +194,23 @@ async function handle_submit_form(event) {
return false;
}
dispatch(
'updated__archive_obj',
{
archive_id: $idaa_slct.archive_id,
}
);
return archive_obj_update_result;
})
.catch(function (error) {
console.log('Something went wrong.');
console.log(error);
return false;
})
.finally(() => {
// We need to do all of this since the DB object has changed and the SLCT object does automatically update (yet...??? Svelte 5?).
// $idaa_slct.archive_obj = await $lq__archive_obj;
// $idaa_slct.archive_id = null;
// $idaa_slct.archive_obj = {};
$idaa_sess.archives.show__modal_edit__archive_id = false;
});
return update_archive_obj_promise;
return prom_api__archive_obj;
}
}
@@ -383,60 +381,117 @@ async function handle_submit_form(event) {
{$idaa_loc.archives.show__admin_options ? 'Hide' : 'Show'} Admin
</button>
<!-- BEGIN: section post__admin_options -->
<section
class="ae_section archive__admin_options border border-gray-200 rounded p-2 space-y-2"
class="ae_section archive__admin_options border border-gray-200 rounded p-2 space-y-2 bg-red-100"
class:hidden={!$idaa_loc.archives.show__admin_options}
> <!-- BEGIN: section archive__admin_options -->
<!-- <div
class="border border-gray-200 rounded p-2"
class:hidden={!$idaa_loc.archives.show__admin_options}
> -->
>
<h3 class="h3">
Admin Options
</h3>
<label>Hide
<input
type="checkbox"
name="hide"
id="hide"
bind:checked={$idaa_slct.archive_obj.hide}
class="checkbox"
<span
class="flex flex-col md:flex-row flex-wrap gap-2 items-center justify-center md:justify-stretch w-full"
>
<span
class="flex flex-row flex-wrap gap-2 items-center justify-evenly grow"
>
<!-- <input type="checkbox" name="hide" value={$idaa_slct.archive_obj.hide} /> -->
</label>
<fieldset class="flex flex-row gap-1 items-center justify-center">
<legend class="legend text-sm font-semibold">Hide</legend>
<div>
<input
type="radio"
id="hide_yes"
name="hide"
value={true}
bind:group={$idaa_slct.archive_obj.hide}
class="radio"
>
<label for="hide_yes">Yes</label>
</div>
<div>
<input
type="radio"
id="hide_no"
name="hide"
value={false}
bind:group={$idaa_slct.archive_obj.hide}
class="radio"
>
<label for="hide_no">No</label>
</div>
</fieldset>
<label>Priority
<input
type="checkbox"
name="priority"
id="priority"
bind:checked={$idaa_slct.archive_obj.priority}
class="checkbox"
>
<!-- <input type="checkbox" name="priority" value={$idaa_slct.archive_obj.priority} /> -->
</label>
<fieldset class="flex flex-row gap-2">
<legend class="legend text-sm font-semibold">Priority</legend>
<div>
<input
type="radio"
id="priority_yes"
name="priority"
value={true}
bind:group={$idaa_slct.archive_obj.priority}
class="radio"
>
<label for="priority_yes">Yes</label>
</div>
<div>
<input
type="radio"
id="priority_no"
name="priority"
value={false}
bind:group={$idaa_slct.archive_obj.priority}
class="radio"
>
<label for="priority_no">No</label>
</div>
</fieldset>
</span>
<label>Sort <input type="number" name="sort" value={$idaa_slct.archive_obj.sort} class="input w-24" /></label>
<span class="flex flex-row flex-wrap gap-1 items-center justify-evenly grow">
<label class="legend text-sm font-semibold">Sort <input type="number" name="sort" value={$idaa_slct.archive_obj.sort} class="input w-24" /></label>
<label>Group <input type="text" name="group" value={$idaa_slct.archive_obj.group} max="100" class="input w-48" /></label>
<label class="legend text-sm font-semibold">Group <input type="text" name="group" value={$idaa_slct.archive_obj.group ?? ''} max="100" class="input w-40" /></label>
</span>
{#if $ae_loc.administrator_access}
<label>Enable
<input
type="checkbox"
name="enable"
id="enable"
bind:checked={$idaa_slct.archive_obj.enable}
class="checkbox"
>
<!-- <input type="checkbox" name="enable" value={$idaa_slct.archive_obj.enable} checked={$idaa_slct.archive_obj.enable} /> -->
</label>
{/if}
{#if $ae_loc.administrator_access}
<span class="flex flex-row flex-wrap gap-1 items-center justify-evenly grow">
<fieldset class="flex flex-row gap-2">
<legend class="legend text-sm font-semibold">Enable</legend>
<div>
<input
type="radio"
id="enable_yes"
name="enable"
value={true}
bind:group={$idaa_slct.archive_obj.enable}
class="radio"
>
<label for="enable_yes">Yes</label>
</div>
<div>
<input
type="radio"
id="enable_no"
name="enable"
value={false}
bind:group={$idaa_slct.archive_obj.enable}
class="radio"
>
<label for="enable_no">No</label>
</div>
</fieldset>
</span>
{/if}
</span>
<label for="notes">
Internal Staff Notes
{#if $ae_loc.trusted_access}
<label
for="notes"
>
<span class="legend text-sm font-semibold">Internal Staff Notes</span>
<Tiptap_editor
default_minimal={true}
bind:html_text={$idaa_slct.archive_obj.notes}
@@ -444,16 +499,30 @@ async function handle_submit_form(event) {
bind:new_html={$idaa_slct.archive_obj.notes_new_html}
/>
</label>
{/if}
<div class="text-sm text-gray-600 dark:text-gray-400">
{$lq__archive_obj?.updated_on ? `DB Updated on: ${$lq__archive_obj?.updated_on}` : ''}
{$idaa_slct.archive_obj?.updated_on ? `SLCT Updated on: ${$idaa_slct.archive_obj?.updated_on}` : ''}
</div>
</section> <!-- END: section archive__admin_options -->
{/if}
<section class="ae_section ae_options flex flex-row gap-1 items-center justify-center">
<button type="submit" class="btn btn-md variant-ghost-primary hover:variant-filled-primary transition"><span class="fas fa-check m-1"></span> Save Archive</button>
<button
type="submit"
class="btn btn-md variant-ghost-primary hover:variant-filled-primary transition"
>
<span class="fas fa-check m-1"></span>
Save Archive
</button>
{#if $idaa_slct.archive_id}
<button
disabled={$ae_loc.administrator_access}
type="button"
on:click={() => {
if (!confirm('Are you sure you want to delete this archive?')) {return false;}
handle_delete_archive_obj({archive_id: $idaa_slct.archive_id});
@@ -461,7 +530,8 @@ async function handle_submit_form(event) {
$idaa_slct.archive_id = null;
$idaa_slct.archive_obj = {};
}}
class="btn btn-sm variant-soft-warning" type="button">
class="btn btn-sm variant-soft-warning"
>
<span class="fas fa-minus m-1"></span> Delete
</button>
{/if}

View File

@@ -76,6 +76,9 @@ onMount(() => {
<button
disabled={!$ae_loc.trusted_access}
on:click={() => {
if (!confirm('Create new archive content?')) {
return false;
}
$idaa_slct.archive_content_id = null;
$idaa_slct.archive_content_obj = {};