Can now save and delete archive content. This includes the hosted file. It still needs some work though. The content delete should also remove the hosted file.

This commit is contained in:
Scott Idem
2024-11-08 11:25:19 -05:00
parent b93cacdfcc
commit abcd5c54c2
7 changed files with 170 additions and 189 deletions

View File

@@ -6,6 +6,9 @@ import { db_archives } from "$lib/db_archives";
let ae_promises: key_val = {};
// TESTING NOTE: I changed these to all use async and await. Not sure if this helps or hurts things. Mainly this is related to the Dexie DB changes. 2024-11-08
// Updated 2024-09-25
export async function load_ae_obj_id__archive_content(
{
@@ -135,12 +138,14 @@ export async function create_ae_obj__archive_content(
archive_id,
data_kv,
params={},
try_cache = true,
log_lvl=0
}: {
api_cfg: any,
archive_id: string,
data_kv: key_val,
params?: key_val,
try_cache?: boolean,
log_lvl?: number
}
) {
@@ -160,11 +165,13 @@ export async function create_ae_obj__archive_content(
})
.then(async function (archive_content_obj_create_result) {
if (archive_content_obj_create_result) {
await db_save_ae_obj_li__archive_content(
{
obj_type: 'archive_content',
obj_li: [archive_content_obj_create_result]
});
if (try_cache) {
await db_save_ae_obj_li__archive_content(
{
obj_type: 'archive_content',
obj_li: [archive_content_obj_create_result]
});
}
return archive_content_obj_create_result;
} else {
return null;
@@ -183,6 +190,59 @@ export async function create_ae_obj__archive_content(
}
// Updated 2024-11-08
export async function delete_ae_obj_id__archive_content(
{
api_cfg,
archive_content_id,
method = 'delete', // 'delete', 'disable', 'hide'
params = {},
try_cache = true,
log_lvl = 0
}: {
api_cfg: any,
archive_content_id: string,
method?: string,
params?: key_val,
try_cache?: boolean,
log_lvl?: number
}
) {
if (log_lvl) {
console.log(`*** delete_ae_obj_id__archive_content() *** archive_content_id=${archive_content_id}`);
}
ae_promises.delete__archive_content_obj = await api.delete_ae_obj_id_crud({
api_cfg: api_cfg,
obj_type: 'archive_content',
obj_id: archive_content_id,
key: api_cfg.api_crud_super_key,
params: params,
method: method,
log_lvl: log_lvl
})
.then(function (archive_content_obj_delete_result) {
// if (archive_content_obj_delete_result) {
// return archive_content_obj_delete_result;
// } else {
// return null;
// }
})
.catch(function (error) {
console.log('No results returned or failed.', error);
})
.finally(function () {
db_archives.content.delete(archive_content_id); // Delete from the DB no matter what.
});
if (log_lvl) {
console.log('ae_promises.delete__archive_content_obj:', ae_promises.delete__archive_content_obj);
}
return ae_promises.delete__archive_content_obj;
}
// Updated 2024-09-25
export async function update_ae_obj__archive_content(
{

View File

@@ -14,6 +14,7 @@ import {
load_ae_obj_id__archive_content,
load_ae_obj_li__archive_content,
create_ae_obj__archive_content,
delete_ae_obj_id__archive_content,
update_ae_obj__archive_content,
// qry__archive_content,
db_save_ae_obj_li__archive_content,
@@ -30,6 +31,7 @@ let export_obj = {
load_ae_obj_id__archive_content: load_ae_obj_id__archive_content,
load_ae_obj_li__archive_content: load_ae_obj_li__archive_content,
create_ae_obj__archive_content: create_ae_obj__archive_content,
delete_ae_obj_id__archive_content: delete_ae_obj_id__archive_content,
update_ae_obj__archive_content: update_ae_obj__archive_content,
db_save_ae_obj_li__archive_content: db_save_ae_obj_li__archive_content,
};

View File

@@ -215,7 +215,7 @@ export async function delete_ae_obj_id__event_presenter(
ae_promises.delete__event_presenter_obj = await api.delete_ae_obj_id_crud({
api_cfg: api_cfg,
obj_type: 'event_presenter',
obj_id: event_presenter_id, // NOTE: This is the FQDN, not normally the ID.
obj_id: event_presenter_id,
key: api_cfg.api_crud_super_key,
params: params,
method: method,

View File

@@ -26,7 +26,7 @@ let upload__hosted_file_obj_promise: any;
let prom_api__archive_content_obj: any;
let prom_api__archive_content_obj__hosted_file: any;
let disable_submit_btn = true;
let disable_submit_btn = false;
if ($idaa_slct.archive_content_id) {
console.log(`Archive Content ID selected: ${$idaa_slct.archive_content_id}`);
@@ -127,12 +127,11 @@ async function handle_submit_form(event) {
let archive_content_do: key_val = {};
if (!$idaa_slct.archive_content_id) {
archive_content_do['account_id_random'] = $ae_loc.account_id;
archive_content_do['archive_id_random'] = $idaa_slct.archive_id;
// archive_content_do['enable'] = true;
}
archive_content_do['name'] = archive_content_di.name;
// Check if the description_new_html exists and is a string
if (typeof $idaa_slct.archive_content_obj.description_new_html === 'string') {
console.log('New description is a string');
@@ -148,11 +147,11 @@ async function handle_submit_form(event) {
archive_content_do['archive_content_type'] = null;
}
archive_content_do['enable_for_public'] = !!!archive_content_di.enable_for_public;
// archive_content_do['enable_for_public'] = !!!archive_content_di.enable_for_public;
archive_content_do['file_path'] = archive_content_di.file_path;
archive_content_do['filename'] = archive_content_di.filename.trim();
archive_content_do['file_extension'] = archive_content_di.file_extension.trim();
// archive_content_do['file_path'] = archive_content_di.file_path;
archive_content_do['filename'] = archive_content_di?.filename?.trim() ?? null;
archive_content_do['file_extension'] = archive_content_di?.file_extension?.trim() ?? null;
let date_time_str = null;
let date_part = archive_content_di.original_datetime_date.trim();
@@ -184,11 +183,8 @@ async function handle_submit_form(event) {
archive_content_do['group'] = null;
}
// Check if the enable exists and is a string
console.log(`archive_content_di.enable = ${archive_content_di.enable}`);
// if (typeof archive_content_di.enable !== 'undefined') {
archive_content_do['enable'] = !!archive_content_di.enable;
// }
// console.log(`archive_content_di.enable = ${archive_content_di.enable}`);
archive_content_do['enable'] = !!archive_content_di.enable;
// Check if the notes_new_html exists and is a string
if (typeof $idaa_slct.archive_content_obj.notes_new_html === 'string') {
@@ -202,12 +198,11 @@ async function handle_submit_form(event) {
console.log(archive_content_do);
if (!$idaa_slct.archive_content_id) {
create_archive_content_obj_promise = api.create_ae_obj_crud({
prom_api__archive_content_obj = archives_func.create_ae_obj__archive_content({
api_cfg: $ae_api,
obj_type: 'archive_content',
fields: archive_content_do,
key: $ae_api.api_crud_super_key,
log_lvl: 1
archive_id: $idaa_slct.archive_id,
data_kv: archive_content_do,
log_lvl: 2
})
.then(async function (archive_content_obj_create_result) {
if (!archive_content_obj_create_result) {
@@ -216,78 +211,17 @@ async function handle_submit_form(event) {
}
$idaa_slct.archive_content_id = archive_content_obj_create_result.obj_id_random;
$idaa_slct.archive_content_obj = archive_content_obj_create_result;
// Get ready to upload the file now that we have a new archive_content_id.
const form_data = new FormData();
form_data.append('account_id', $ae_loc.account_id);
form_data.append('link_to_type', 'archive_content');
form_data.append('link_to_id', $idaa_slct.archive_content_id);
for (let i = 0; i < event.target.file_list.files.length; i++) {
form_data.append(`file_list`, event.target.archive_content_file_upload_list.files[i]);
}
let params = null;
let endpoint = '/hosted_file/upload_files';
console.log(form_data);
params = null;
// Uncomment and the post_promise is not seen by the "await" below
// post_promise = await api.post_object({api_cfg: $cfg.api, endpoint: endpoint, params: params, data:form_data});
// Uncomment so that the post_promise is not seen by the "await" below
upload__hosted_file_obj_promise = await api.post_object({api_cfg: $ae_api, endpoint: endpoint, params: params, form_data: form_data});
console.log(upload__hosted_file_obj_promise);
let hosted_file_id = upload__hosted_file_obj_promise[0].hosted_file_id_random;
archive_content_do = {};
archive_content_do['hosted_file_id_random'] = hosted_file_id;
archive_content_do['file_path'] = `/hosted_file/download/${hosted_file_id}?filename=${archive_content_di.filename.trim()}`;
archive_content_do['archive_content_type'] = 'hosted_file';
update_archive_content_obj_promise = await api.update_ae_obj_id_crud({
api_cfg: $ae_api,
obj_type: 'archive_content',
obj_id: $idaa_slct.archive_content_id,
fields: archive_content_do,
key: $ae_api.api_crud_super_key,
log_lvl: 1
})
.then(function (archive_content_obj_update_result) {
if (!archive_content_obj_update_result) {
console.log('The result was null or false.');
return false;
}
return archive_content_obj_update_result;
})
.catch(function (error) {
console.log('Something went wrong.');
console.log(error);
return false;
});
// update_archive_content_obj_promise = await update_archive_content_obj({archive_content_id: $idaa_slct.archive_content_id, data: archive_content_do})
// console.log(update_archive_content_obj_promise);
return update_archive_content_obj_promise
})
.then(function (archive_content_obj_create_result) {
// dispatch(
// 'created__archive_content_obj',
// {
// archive_content_id: $idaa_slct.archive_content_id,
// }
// );
return archive_content_obj_create_result;
})
.catch(function (error) {
console.log('Something went wrong.');
console.log(error);
return false;
})
.finally(() => {
disable_submit_btn = false;
});
return create_archive_content_obj_promise;
@@ -313,46 +247,16 @@ async function handle_submit_form(event) {
return false;
})
.finally(() => {
// We need to do this since the comment has changed and the idaa_slct object does automatically update (yet...???).
$idaa_slct.archive_content_obj = $lq__archive_content_obj;
disable_submit_btn = false;
// $idaa_sess.archives.show__modal_edit__archive_content_id = false;
// 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_content_obj = await $lq__archive_content_obj;
$idaa_slct.archive_content_id = null;
$idaa_slct.archive_content_obj = {};
$idaa_sess.archives.show__modal_edit__archive_content_id = false;
});
return prom_api__archive_content_obj;
}
// update_archive_content_obj_promise = api.update_ae_obj_id_crud({
// api_cfg: $ae_api,
// obj_type: 'archive_content',
// obj_id: $idaa_slct.archive_content_id,
// fields: archive_content_do,
// key: $ae_api.api_crud_super_key,
// log_lvl: 1
// })
// .then(function (archive_content_obj_update_result) {
// if (!archive_content_obj_update_result) {
// console.log('The result was null or false.');
// return false;
// }
// // dispatch(
// // 'updated__archive_content_obj',
// // {
// // archive_content_id: $idaa_slct.archive_content_id,
// // }
// // );
// return archive_content_obj_update_result;
// })
// .catch(function (error) {
// console.log('Something went wrong.');
// console.log(error);
// return false;
// });
// return update_archive_content_obj_promise;
// }
}
$: if ($idaa_slct.archive_content_obj.upload_complete && $idaa_slct.archive_content_obj.hosted_file_id_li?.length && $idaa_slct.archive_content_obj.hosted_file_obj_li?.length) {
@@ -441,7 +345,7 @@ async function handle_hosted_files_uploaded(hosted_file_id_li: string[], hosted_
<select
id="archive_content_type"
name="archive_content_type"
value={$idaa_slct.archive_content_obj.archive_content_type}
bind:value={$idaa_slct.archive_content_obj.archive_content_type}
class="select w-52"
>
<option value="">-- None --</option>
@@ -476,51 +380,42 @@ async function handle_hosted_files_uploaded(hosted_file_id_li: string[], hosted_
>
</label>
</fieldset> -->
</section>
<h3>File?</h3>
<section
class="ae_section archive_content__hosted_file border border-gray-200 rounded p-2 space-y-2"
class:hidden={$idaa_slct.archive_content_obj.archive_content_type !== 'hosted_file' && !$idaa_slct.archive_content_id}
>
{#if $ae_loc.trusted_access && $idaa_slct.archive_content_id}
<Comp_hosted_files_upload
class_li="border border-gray-300 rounded-md p-2 bg-gray-100 hover:bg-gray-200"
link_to_type="archive_content"
link_to_id={$idaa_slct.archive_content_obj.archive_content_id}
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}
>
<span slot="label">
<div>
<span class="fas fa-upload"></span>
<strong class="bg-green-100 p-1">Upload archive files</strong>
</div>
<span class="text-sm text-gray-600 dark:text-gray-400 italic">
<strong>Aether hosted files only</strong><br>
Recommended: PowerPoint (pptx) or Keynote (key) or Adobe PDF<br>
Media: Audio (mp3, m4a) and videos (mp4, mkv)<br>
Supplemental files: Word Doc, Excel, txt, etc
</span>
</span>
</Comp_hosted_files_upload>
{/if}
<!-- {$idaa_slct.archive_content_obj.hosted_file_id_li?.length ? $idaa_slct.archive_content_obj.hosted_file_id_li.length : 'waiting...'} -->
<!-- {$idaa_slct.archive_content_obj.upload_complete ? 'Upload complete' : 'Upload not complete'} -->
<h3 class="h3">Upload/Manage Hosted File</h3>
{#if !$idaa_slct.archive_content_obj.hosted_file_id}
No file uploaded yet.
<!-- FILE INPUT GOES HERE -->
<!-- <Element_input_file_hashing
multiple = {false}
required = {true}
accept = {''}
element_id = {'archive_content_file_upload_list'}
on:input_file_list_updated = {handle_input_file_list_updated}
use_selected_file_table={true}
/> -->
<!-- bind:input_file_list = {$idaa_loc.archives.form_file_upload_list} -->
{#if $ae_loc.trusted_access}
<Comp_hosted_files_upload
class_li="border border-gray-300 rounded-md p-2 bg-gray-100 hover:bg-gray-200"
link_to_type="archive_content"
link_to_id={$idaa_slct.archive_content_obj.archive_content_id}
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}
>
<span slot="label">
<div>
<span class="fas fa-upload"></span>
<strong class="bg-green-100 p-1">Upload archive files</strong>
</div>
<span class="text-sm text-gray-600 dark:text-gray-400 italic">
<strong>Aether hosted files only</strong><br>
Recommended: PowerPoint (pptx) or Keynote (key) or Adobe PDF<br>
Media: Audio (mp3, m4a) and videos (mp4, mkv)<br>
Supplemental files: Word Doc, Excel, txt, etc
</span>
</span>
</Comp_hosted_files_upload>
{/if}
{:else}
@@ -557,7 +452,8 @@ async function handle_hosted_files_uploaded(hosted_file_id_li: string[], hosted_
log_lvl: log_lvl
})
.then(function (archive_content_obj_update_result) {
// ???
// 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_content_obj = $lq__archive_content_obj;
})
.catch(function (error) {
console.log('Something went wrong.');
@@ -571,15 +467,11 @@ async function handle_hosted_files_uploaded(hosted_file_id_li: string[], hosted_
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_content_obj.hosted_file_id = null;
$idaa_slct.archive_content_obj.file_path = null;
$idaa_slct.archive_content_obj.filename = null;
$idaa_slct.archive_content_obj.file_extension = null;
// We need to do this since the comment has changed and the idaa_slct object does automatically update (yet...???).
$idaa_slct.archive_content_obj = $lq__archive_content_obj;
// disable_submit_btn = false;
// $idaa_sess.archives.show__modal_edit__archive_content_id = false;
});
@@ -812,27 +704,55 @@ async function handle_hosted_files_uploaded(hosted_file_id_li: string[], hosted_
</label>
{/if}
<div class="text-sm text-gray-600 dark:text-gray-400">
{$lq__archive_content_obj?.updated_on ? `DB Updated on: ${$lq__archive_content_obj?.updated_on}` : ''}
{$idaa_slct.archive_content_obj?.updated_on ? `SLCT Updated on: ${$idaa_slct.archive_content_obj?.updated_on}` : ''}
</div>
</section> <!-- END: section post__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">
<span class="fas fa-check m-1"></span> Save Archive Content
<button
type="submit"
disabled={disable_submit_btn}
class="btn btn-md variant-ghost-primary"
>
<span class="fas fa-check m-1"></span>
Save Archive Content
</button>
{#if $idaa_slct.archive_content_id}
{#if $idaa_slct.archive_content_id && !$idaa_slct.archive_content_obj.hosted_file_id}
<button
type="button"
on:click={() => {
if (!confirm('Are you sure you want to delete this archive content?')) {return false;}
handle_delete_archive_content_obj({archive_content_id: $idaa_slct.archive_content_id, hosted_file_id: $idaa_slct.archive_content_obj.hosted_file_id_random});
prom_api__archive_content_obj = archives_func.delete_ae_obj_id__archive_content({
api_cfg: $ae_api,
archive_content_id: $idaa_slct.archive_content_id,
method: 'disable',
log_lvl: log_lvl
});
$idaa_slct.archive_content_id = null;
$idaa_slct.archive_content_obj = {};
$idaa_sess.archives.show__modal_edit__archive_content_id = false;
}}
class="btn btn-sm variant-soft-warning" type="button">
<span class="fas fa-minus m-1"></span> Delete
class="btn btn-sm variant-soft-warning"
title="Disable this archive content"
>
<span class="fas fa-minus m-1"></span>
Delete
{#if $ae_loc.administrator_access}
(Disable)
{/if}
</button>
{:else if $idaa_slct.archive_content_obj.hosted_file_id}
{#if $ae_loc.administrator_access}
Can not delete. Remove hosted file first.
{/if}
{/if}
</section>

View File

@@ -134,7 +134,7 @@ onMount(() => {
$idaa_sess.archives.show__modal_edit__archive_content_id = $idaa_slct.archive_content_id;
}}
class="btn btn-sm variant-glass-warning hover:variant-filled-warning transition"
title={`Edit archive: ${idaa_archive_content_obj?.name}`}
title={`Edit archive content: ${idaa_archive_content_obj?.name}`}
>
<span class="fas fa-edit m-1"></span> Edit Content
</button>

View File

@@ -70,13 +70,15 @@ onMount(() => {
{#if $ae_loc.trusted_access}
<div class="ae_options">
{#if $ae_loc.trusted_access || $lq__archive_obj?.external_person_id === $idaa_loc.novi_uuid}
{#if $ae_loc.trusted_access}
<button
disabled={$ae_loc.administrator_access}
disabled={!$ae_loc.trusted_access}
on:click={() => {
$slct.archive_content_id = null;
$slct.archive_content_obj = {};
$idaa_sess.archives.show_edit__archive_content_id = true;
$idaa_slct.archive_content_id = null;
$idaa_slct.archive_content_obj = {};
$idaa_sess.archives.show__modal_view__archive_content_id = false;
$idaa_sess.archives.show__modal_edit__archive_content_id = true;
}}
class="btn btn-sm variant-glass-warning"
title={`Add content for: ${$lq__archive_obj?.name}`}
@@ -85,9 +87,9 @@ onMount(() => {
</button>
<button
disabled={$ae_loc.administrator_access}
disabled={!$ae_loc.administrator_access}
on:click={() => {
// $slct.archive_id = $lq__archive_obj?.archive_id_random;
// $idaa_slct.archive_id = $lq__archive_obj?.archive_id_random;
// $lq__archive_obj? = $lq__archive_obj?;
$idaa_slct.archive_obj = $lq__archive_obj;

View File

@@ -81,11 +81,8 @@ async function handle_submit_form(event: any) {
post_do['group'] = null;
}
// Check if the enable exists and is a string
console.log(`post_di.enable = ${post_di.enable}`);
// if (typeof post_di.enable !== 'undefined') {
post_do['enable'] = !!post_di.enable;
// }
// console.log(`post_di.enable = ${post_di.enable}`);
post_do['enable'] = !!post_di.enable;
// Check if the notes_new_html exists and is a string
if (typeof $idaa_slct.post_obj.notes_new_html === 'string') {