Wrapping up for the night. Things are working better. There are still API request misses or something.

This commit is contained in:
Scott Idem
2024-03-05 20:35:38 -05:00
parent bed4f4a0f2
commit e71cdab353
10 changed files with 261 additions and 139 deletions

View File

@@ -9,6 +9,7 @@ import { ae_util } from '$lib/ae_utils';
import type { key_val } from '$lib/ae_stores';
export let ds_code: string;
export let ds_name: string;
export let ds_type: string = 'text';
export let for_type: string;
export let for_id: string;
@@ -26,7 +27,9 @@ export let show_delete_btn: boolean = false;
export let debug: boolean = false;
let ae_promises: key_val = {}; // Promise<any>;
let data_store_results: Promise<any>|key_val;
let ds_get_results: Promise<any>|key_val;
let ds_loading_status: string = 'starting...';
let ds_submit_results: Promise<any>|key_val;
let val_json: key_val;
let val_html: key_val;
@@ -40,13 +43,13 @@ let ds_code_obj =
id: null,
account_id: null,
code: ds_code,
name: ds_name,
type: ds_type,
for_type: null, // for_type
for_id: null, // for_id
access_read: null, // 'super', 'administrator', 'trusted', 'anonymous'
access_write: null, // 'super', 'administrator', 'trusted', 'anonymous'
access_delete: null, // 'super', 'administrator', 'trusted', 'anonymous'
name: null,
html: null,
json: null,
md: null,
@@ -57,34 +60,36 @@ let ds_code_obj =
let ae_ds_loc: Writable<key_val> = localStorageStore(`ae_ds__${ds_code}`, ds_code_obj);
console.log(`ae_ Data Store ${ds_code} = `, $ae_ds_loc);
if (!$ae_ds_loc.id) {
ds_loading_status = '-- loading --';
}
$ae_sess.ds.submit_status = null;
$ae_sess.ds.create_status = null;
$ae_sess.ds.update_status = null;
$slct_trigger = 'load__ds__code';
let trigger: null|string = 'load__ds__code';
onMount(() => {
console.log('Element: Data Store element_data_store.svelte');
if (ds_code && ds_type) {
$slct_trigger = 'load__ds__code';
}
// if (ds_code && ds_type) {
// trigger = 'load__ds__code';
// $slct_trigger = 'load__ds__code';
// }
});
// let ds_code_li = {}; //: key_val; // = ae_loc_tmp.ds;
// console.log(`ae_ ds_code_li = `, ds_code_li);
$: if ($slct_trigger == 'load__ds__code' && ds_code && ds_type) {
$slct_trigger = null;
$: if (trigger == 'load__ds__code' && ds_code && ds_type) {
trigger = null;
load_data_store({
code: ds_code,
type: ds_type,
for_type: for_type,
for_id: for_id,
store: store,
display: display,
class_li: class_li,
try_cache: try_cache
});
}
@@ -97,24 +102,8 @@ async function load_data_store({
try_cache=true
}) {
// if ($ae_ds_loc) {
// console.log(`ae_ Data Store ${code} = `, $ae_ds_loc);
// // ds_code_val = ae_ds_loc;
// // if (type == 'html') {
// // val_html = $ae_ds_loc.text;
// // } else if (type == 'json') {
// // val_json = $ae_ds_loc.json;
// // } else if (type == 'md') {
// // val_md = $ae_ds_loc.text;
// // } else if (type == 'sql') {
// // val_sql = $ae_ds_loc.text;
// // } else {
// // val_text = $ae_ds_loc.text;
// // }
// }
let ds_code_val = await api.get_data_store_obj_w_code({
// let ds_code_val = await api.get_data_store_obj_w_code({
ds_get_results = api.get_data_store_obj_w_code({
api_cfg: $ae_api,
data_store_code: code,
data_type: type,
@@ -154,11 +143,14 @@ async function load_data_store({
val_text = ds_results.text;
return ds_results.text;
}
} else {
ds_loading_status = '-- not found --';
}
})
.catch(function (error) {
console.log(`Something went wrong. for code ${code}`);
console.log(error);
ds_loading_status = '-- error --';
return false;
});
// .finally(function (ds_val_result) {
@@ -209,14 +201,20 @@ async function handle_submit_form(event) {
if (typeof data_store_di.ds_code !== 'undefined') {
data_store_do['code'] = data_store_di.ds_code;
} else {
data_store_do['code'] = ds_code;
}
if (typeof data_store_di.ds_name !== 'undefined') {
data_store_do['name'] = data_store_di.ds_name;
} else {
data_store_do['name'] = ds_name;
}
if (typeof data_store_di.ds_type !== 'undefined') {
data_store_do['type'] = data_store_di.ds_type;
} else {
data_store_do['type'] = ds_type;
}
if (typeof data_store_di.ds_for_type !== 'undefined' && data_store_di.ds_for_type) {
@@ -268,7 +266,7 @@ async function handle_submit_form(event) {
if (!$ae_ds_loc.id) {
// Create
console.log(`ae_ Data Store Create:`, data_store_do);
data_store_results = handle_create__data_store({
ds_submit_results = handle_create__data_store({
obj_type: 'data_store',
data: data_store_do
})
@@ -294,7 +292,7 @@ async function handle_submit_form(event) {
} else {
// Update
console.log(`ae_ Data Store Update:`, data_store_do);
data_store_results = handle_update__data_store({
ds_submit_results = handle_update__data_store({
obj_type: 'data_store',
obj_id: $ae_ds_loc.id,
data: data_store_do
@@ -437,7 +435,7 @@ async function handle_update__data_store({
value={$ae_ds_loc.id}
/>
{#if $ae_loc.administrator_access}
{#if $ae_loc.trusted_access}
<label for="ds_use_account_id" class="label text-xs inline">Use Account ID
<input
type="checkbox"
@@ -447,6 +445,8 @@ async function handle_update__data_store({
checked={$ae_ds_loc.account_id ? true : false}
/>
</label>
{/if}
{#if $ae_loc.administrator_access}
<input
type="text"
name="ds_account_id"
@@ -455,7 +455,6 @@ async function handle_update__data_store({
value={$ae_ds_loc.account_id}
/>
<input
type="text"
name="ds_code"
@@ -464,6 +463,8 @@ async function handle_update__data_store({
value={$ae_ds_loc.code}
required
/>
{/if}
{#if $ae_loc.trusted_access}
<input
type="text"
name="ds_name"
@@ -472,6 +473,8 @@ async function handle_update__data_store({
value={$ae_ds_loc.name}
required
/>
{/if}
{#if $ae_loc.administrator_access}
<input
type="text"
name="ds_type"
@@ -515,6 +518,10 @@ async function handle_update__data_store({
placeholder="Access delete"
value={$ae_ds_loc.access_delete}
/>
{:else}
Code: {$ae_ds_loc.code}
<!-- Name: {$ae_ds_loc.name} -->
Type: {$ae_ds_loc.type}
{/if}
{#if $ae_ds_loc.type == 'html' || $ae_ds_loc.type == null}
@@ -541,7 +548,8 @@ async function handle_update__data_store({
class="btn variant-soft-warning"
on:click={() => {
if (confirm('Are you sure you want to delete this data store?')) {
$slct_trigger = 'delete__ds__code';
trigger = 'delete__ds__code';
// $slct_trigger = 'delete__ds__code';
}
show_edit = false;
show_view = true;
@@ -560,30 +568,31 @@ async function handle_update__data_store({
}}
>
<span class="fas fa-times mx-1"></span>
Cancel
Close
</button>
<button
type="submit"
class="btn variant-soft-primary"
disabled={data_store_results instanceof Promise}
disabled={ds_submit_results instanceof Promise}
on:click={() => {
$slct_trigger = 'save__ds__code';
trigger = 'save__ds__code';
// $slct_trigger = 'save__ds__code';
}}
>
<span class="fas fa-save mx-1"></span>
Save
</button>
{#await data_store_results}
{#await ds_submit_results}
<div class="modal-loading">
<span class="fas fa-spinner fa-spin"></span>
<span class="loading-text">
Saving...
</span>
</div>
{:then data_store_results}
{#if data_store_results}
{:then ds_submit_results}
{#if ds_submit_results}
<span class="fas fa-check text-green-500"></span>
<span class="saved-text">
Saved
@@ -625,6 +634,7 @@ async function handle_update__data_store({
{/if}
<button
type="button"
class="ae_btn_edit__ds btn hover:variant-glass-warning text-xs absolute top-0 right-0 opacity-75 hover:opacity-100 transition delay-700 hover:delay-200 m-1 p-1"
on:click={() => {
show_edit = true;
@@ -636,6 +646,7 @@ async function handle_update__data_store({
</button>
<!-- {/if} -->
{:else}
{/if}
@@ -650,6 +661,17 @@ async function handle_update__data_store({
{val_json}
</pre> -->
{#await ds_get_results}
<div class="modal-loading">
<span class="fas fa-spinner fa-spin"></span>
<span class="loading-text">
Loading...
</span>
</div>
{/await}
<!-- {ds_loading_status} -->
</div>