Wrapping up for the day. File uploads and deletes pretty much work now. Need to figure out whey the form does not refresh or just ignore?

This commit is contained in:
Scott Idem
2024-11-07 19:34:57 -05:00
parent 079ec80fbd
commit b93cacdfcc
9 changed files with 540 additions and 27 deletions

View File

@@ -15,6 +15,7 @@ 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';
import Comp_hosted_files_upload from '$lib/ae_core/ae_comp__hosted_files_upload.svelte';
export let lq__archive_content_obj: any;
@@ -22,7 +23,8 @@ let create_archive_content_obj_promise: any;
let delete_archive_content_obj_promise: any;
let update_archive_content_obj_promise: any;
let upload__hosted_file_obj_promise: any;
let prom_api__archive_content_obj_v2: any;
let prom_api__archive_content_obj: any;
let prom_api__archive_content_obj__hosted_file: any;
let disable_submit_btn = true;
@@ -291,7 +293,7 @@ async function handle_submit_form(event) {
return create_archive_content_obj_promise;
} else {
prom_api__archive_content_obj_v2 = archives_func.update_ae_obj__archive_content({
prom_api__archive_content_obj = archives_func.update_ae_obj__archive_content({
api_cfg: $ae_api,
archive_content_id: $idaa_slct.archive_content_id,
data_kv: archive_content_do,
@@ -317,7 +319,7 @@ async function handle_submit_form(event) {
// $idaa_sess.archives.show__modal_edit__archive_content_id = false;
});
return prom_api__archive_content_obj_v2;
return prom_api__archive_content_obj;
}
// update_archive_content_obj_promise = api.update_ae_obj_id_crud({
@@ -353,6 +355,36 @@ async function handle_submit_form(event) {
// }
}
$: 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) {
handle_hosted_files_uploaded($idaa_slct.archive_content_obj.hosted_file_id_li, $idaa_slct.archive_content_obj.hosted_file_obj_li);
}
async function handle_hosted_files_uploaded(hosted_file_id_li: string[], hosted_file_obj_li: any[]) {
console.log(`*** handle_hosted_files_uploaded() *** ${hosted_file_id_li}`);
// We need to update the archive_content_obj with the new file (for now just the first one).
prom_api__archive_content_obj = archives_func.update_ae_obj__archive_content({
api_cfg: $ae_api,
archive_content_id: $idaa_slct.archive_content_id,
data_kv: {
hosted_file_id_random: hosted_file_obj_li[0].hosted_file_id_random,
// file_path: hosted_file_obj_li[0].file_path,
filename: hosted_file_obj_li[0].filename,
file_extension: hosted_file_obj_li[0].extension,
archive_content_type: 'hosted_file',
},
log_lvl: log_lvl
})
.then(function (archive_content_obj_update_result) {
$idaa_slct.archive_content_obj = $lq__archive_content_obj;
})
.catch(function (error) {
console.log('Something went wrong.');
console.log(error);
return false;
});
}
</script>
@@ -446,9 +478,39 @@ async function handle_submit_form(event) {
</fieldset> -->
<h3>File?</h3>
{#if !$idaa_slct.archive_content_id}
FILE INPUT GOES HERE
{#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'} -->
{#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}
@@ -462,7 +524,80 @@ async function handle_submit_form(event) {
{:else}
<label for="file_path">File Path
<button
disabled={!$ae_loc.administrator_access}
type="button"
on:click={() => {
if (confirm('Are you sure you want to remove the file?')) {
// First - Attempt to delete the hosted file
prom_api__archive_content_obj__hosted_file = core_func.delete_ae_obj_id__hosted_file({
api_cfg: $ae_api,
hosted_file_id: $idaa_slct.archive_content_obj.hosted_file_id,
link_to_type: 'archive_content',
link_to_id: $idaa_slct.archive_content_id,
rm_orphan: true,
fake_delete: false,
log_lvl: log_lvl
})
.then(function (delete_result) {
// Second - If deleted, then update the archive_content_obj
console.log(`File removed. Now update the archive_content_obj`);
prom_api__archive_content_obj = archives_func.update_ae_obj__archive_content({
api_cfg: $ae_api,
archive_content_id: $idaa_slct.archive_content_id,
data_kv: {
hosted_file_id_random: null,
file_path: null,
filename: null,
file_extension: null,
archive_content_type: null,
},
log_lvl: log_lvl
})
.then(function (archive_content_obj_update_result) {
// ???
})
.catch(function (error) {
console.log('Something went wrong.');
console.log(error);
return false;
});
})
.catch(function (error) {
console.log('Something went wrong.');
console.log(error);
return false;
})
.finally(() => {
$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;
});
}
}}
class="btn btn-sm variant-soft-error float-right"
>
{#await prom_api__archive_content_obj__hosted_file}
<span class="fas fa-spinner fa-spin m-1"></span>
{:then}
<span class="fas fa-trash-alt m-1"></span>
Remove File
{/await}
<!-- <span class="fas fa-trash-alt m-1"></span>
Remove File -->
</button>
<!-- <label for="file_path">File Path
{#if !$ae_loc.administrator_access}
<span class="fas fa-lock" title="Field is locked"></span>
{:else}
@@ -476,10 +611,10 @@ async function handle_submit_form(event) {
readonly={!$ae_loc.administrator_access}
class="input w-full"
>
</label>
</label> -->
<label for="filename">Filename
<input type="text" id="filename" name="filename" value={($idaa_slct.archive_content_obj.filename ? $idaa_slct.archive_content_obj.filename : $idaa_loc.archives.input_filename)} class="input w-full">
<input type="text" id="filename" name="filename" value={($idaa_slct.archive_content_obj.filename ? $idaa_slct.archive_content_obj.filename : 'unknown')} class="input w-full">
</label>
<label for="file_extension">File Extension
@@ -492,7 +627,7 @@ async function handle_submit_form(event) {
type="text"
id="file_extension"
name="file_extension"
value={($idaa_slct.archive_content_obj.file_extension ? $idaa_slct.archive_content_obj.file_extension : $idaa_loc.archives.input_file_extension)}
value={($idaa_slct.archive_content_obj.file_extension ? $idaa_slct.archive_content_obj.file_extension : 'ext')}
readonly={!$ae_loc.administrator_access}
class="input w-24"
>

View File

@@ -125,7 +125,7 @@ onMount(() => {
{#if $ae_loc.trusted_access}
<button
disabled={!$ae_loc.administrator_access}
disabled={!$ae_loc.trusted_access}
on:click={() => {
$idaa_slct.archive_content_id = idaa_archive_content_obj.archive_content_id;
$idaa_slct.archive_content_obj = idaa_archive_content_obj;
@@ -146,9 +146,9 @@ onMount(() => {
<div
class="archive_content__description ae_description"
>
<div class="ae_label archive_content__description">Description:</div>
<div class="ae_label archive_content__description text-sm">Description:</div>
<div class="ae_value archive_content__description">
{idaa_archive_content_obj?.description}
{@html idaa_archive_content_obj?.description}
</div>
</div>
{/if}
@@ -157,7 +157,7 @@ onMount(() => {
<div
class="archive_content__content_html ae_content_html"
>
<div class="ae_label archive_content__content_html">Content:</div>
<div class="ae_label archive_content__content_html text-sm">Content:</div>
<div class="ae_value archive_content__content_html">
{@html idaa_archive_content_obj?.content_html}
</div>
@@ -168,13 +168,13 @@ onMount(() => {
class="ae_group"
class:hidden={!idaa_archive_content_obj?.original_datetime && !idaa_archive_content_obj?.original_timezone}
>
<span class="ae_label">Original date/time:</span>
<span class="ae_label text-sm">Original date/time:</span>
{#if idaa_archive_content_obj.original_datetime}
<span class="ae_value ae_prop prop_original_datetime fs_smaller">{ae_util.iso_datetime_formatter(idaa_archive_content_obj.original_datetime, 'datetime_12_long')}</span>
<span class="ae_value ae_prop prop_original_datetime font-semibold">{ae_util.iso_datetime_formatter(idaa_archive_content_obj.original_datetime, 'datetime_12_long')}</span>
{/if}
{#if idaa_archive_content_obj.original_timezone}
<span class="ae_label">Timezone:</span>
<span class="ae_value">{idaa_archive_content_obj.original_timezone}</span>
<span class="ae_label text-sm">Timezone:</span>
<span class="ae_value font-semibold">{idaa_archive_content_obj.original_timezone}</span>
{/if}
</div>

View File

@@ -72,6 +72,7 @@ onMount(() => {
<div class="ae_options">
{#if $ae_loc.trusted_access || $lq__archive_obj?.external_person_id === $idaa_loc.novi_uuid}
<button
disabled={$ae_loc.administrator_access}
on:click={() => {
$slct.archive_content_id = null;
$slct.archive_content_obj = {};
@@ -84,6 +85,7 @@ onMount(() => {
</button>
<button
disabled={$ae_loc.administrator_access}
on:click={() => {
// $slct.archive_id = $lq__archive_obj?.archive_id_random;
// $lq__archive_obj? = $lq__archive_obj?;

View File

@@ -94,7 +94,7 @@ onMount(() => {
{#if $idaa_slct.archive_content_obj.description}
<div class="archive_content__description">
{$idaa_slct.archive_content_obj.description}
{@html $idaa_slct.archive_content_obj.description}
</div>
{/if}