Using the hosted file select method is 90% working. It still needs to create a new hosted_file_link record.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
<script lang="ts">
|
||||
export let log_lvl: number = 0;
|
||||
import { run, preventDefault } from 'svelte/legacy';
|
||||
|
||||
// *** Import Svelte core
|
||||
import { onMount } from 'svelte';
|
||||
import { fade } from 'svelte/transition';
|
||||
@@ -14,17 +15,25 @@ 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';
|
||||
import Element_manage_hosted_file_li_wrap from '$lib/element_manage_hosted_file_li_all.svelte';
|
||||
|
||||
export let lq__archive_content_obj: any;
|
||||
interface Props {
|
||||
log_lvl?: number;
|
||||
lq__archive_content_obj: any;
|
||||
}
|
||||
|
||||
let { log_lvl = 0, lq__archive_content_obj }: Props = $props();
|
||||
|
||||
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: any;
|
||||
let prom_api__archive_content_obj__hosted_file: any;
|
||||
let prom_api__archive_content_obj: any = $state();
|
||||
let prom_api__archive_content_obj__hosted_file: any = $state();
|
||||
|
||||
let disable_submit_btn = false;
|
||||
let disable_submit_btn = $state(false);
|
||||
|
||||
let slct_hosted_file_kv: key_val = $state({});
|
||||
|
||||
if ($idaa_slct.archive_content_id) {
|
||||
console.log(`Archive Content ID selected: ${$idaa_slct.archive_content_id}`);
|
||||
@@ -58,7 +67,7 @@ if ($idaa_slct.archive_content_id) {
|
||||
console.log(`Archive Content Object started: ${$idaa_slct.archive_content_obj}`)
|
||||
}
|
||||
|
||||
let lu_time_zone_list:any = localStorage.getItem('lu_time_zone_list') ? JSON.parse(localStorage.getItem('lu_time_zone_list')) : [];
|
||||
let lu_time_zone_list:any = $state(localStorage.getItem('lu_time_zone_list') ? JSON.parse(localStorage.getItem('lu_time_zone_list')) : []);
|
||||
$ae_loc.lu_time_zone_list = [];
|
||||
// $ae_loc.lu_time_zone_list = [];
|
||||
if (lu_time_zone_list && lu_time_zone_list.length > 0) {
|
||||
@@ -105,8 +114,6 @@ onMount(() => {
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
async function handle_submit_form(event) {
|
||||
if (log_lvl > 1) {
|
||||
console.log('*** handle_submit_form() ***');
|
||||
@@ -265,10 +272,6 @@ 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}`);
|
||||
@@ -297,6 +300,44 @@ async function handle_hosted_files_uploaded(hosted_file_id_li: string[], hosted_
|
||||
});
|
||||
}
|
||||
|
||||
run(() => {
|
||||
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);
|
||||
}
|
||||
});
|
||||
|
||||
let slct_hosted_file_id: any = $state(null);
|
||||
let slct_hosted_file_obj: any = $state(null);
|
||||
$effect(() => {
|
||||
if (slct_hosted_file_id && slct_hosted_file_obj) {
|
||||
console.log(`*** handle_hosted_file_selected() *** ${slct_hosted_file_id}`);
|
||||
// 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: slct_hosted_file_id,
|
||||
// file_path: hosted_file_obj_li[0].file_path,
|
||||
filename: slct_hosted_file_obj.filename,
|
||||
file_extension: slct_hosted_file_obj.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;
|
||||
$idaa_slct.archive_content_obj = archive_content_obj_update_result;
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.log('Something went wrong.');
|
||||
console.log(error);
|
||||
return false;
|
||||
});
|
||||
|
||||
slct_hosted_file_id = null;
|
||||
slct_hosted_file_obj = null;
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<section
|
||||
@@ -305,7 +346,7 @@ async function handle_hosted_files_uploaded(hosted_file_id_li: string[], hosted_
|
||||
>
|
||||
<!-- bind:clientHeight={ae_iframe_height} -->
|
||||
|
||||
<form on:submit|preventDefault={handle_submit_form} class="space-y-2">
|
||||
<form onsubmit={preventDefault(handle_submit_form)} class="space-y-2">
|
||||
|
||||
{#await prom_api__archive_content_obj}
|
||||
<div class="awaiting alert_msg_pulse" out:fade={{ duration: 2000 }}>Saving...</div>
|
||||
@@ -402,6 +443,26 @@ async function handle_hosted_files_uploaded(hosted_file_id_li: string[], hosted_
|
||||
No file uploaded yet.
|
||||
|
||||
{#if $ae_loc.trusted_access}
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-sm variant-ghost-warning hover:variant-filled-warning float-right"
|
||||
title="Toggle between Upload and Select from Hosted Files"
|
||||
onclick={() => {
|
||||
if ($ae_sess.files.add_to_use_files_method == 'upload') {
|
||||
$ae_sess.files.add_to_use_files_method = 'select';
|
||||
} else {
|
||||
$ae_sess.files.add_to_use_files_method = 'upload';
|
||||
}
|
||||
}}
|
||||
>
|
||||
<span class="fas fa-exchange-alt m-1"></span>
|
||||
Upload/Select
|
||||
</button>
|
||||
|
||||
<div
|
||||
class:hidden={$ae_sess.files.add_to_use_files_method != 'upload'}
|
||||
class="upload"
|
||||
>
|
||||
<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"
|
||||
@@ -411,19 +472,38 @@ async function handle_hosted_files_uploaded(hosted_file_id_li: string[], hosted_
|
||||
bind:upload_complete={$idaa_slct.archive_content_obj.upload_complete}
|
||||
log_lvl={log_lvl}
|
||||
>
|
||||
<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 video (mp4, mkv)<br>
|
||||
Supplemental files: Word Doc, Excel, txt, etc
|
||||
{#snippet label()}
|
||||
<span >
|
||||
<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 video (mp4, mkv)<br>
|
||||
Supplemental files: Word Doc, Excel, txt, etc
|
||||
</span>
|
||||
</span>
|
||||
</span>
|
||||
{/snippet}
|
||||
</Comp_hosted_files_upload>
|
||||
</div>
|
||||
|
||||
<div
|
||||
class:hidden={$ae_sess.files.add_to_use_files_method != 'select'}
|
||||
class=""
|
||||
>
|
||||
<Element_manage_hosted_file_li_wrap
|
||||
link_to_type={'account'}
|
||||
link_to_id={$ae_loc?.account_id}
|
||||
allow_basic={true}
|
||||
allow_moderator={true}
|
||||
class_li={''}
|
||||
bind:slct_hosted_file_kv={slct_hosted_file_kv}
|
||||
bind:slct_hosted_file_id={slct_hosted_file_id}
|
||||
bind:slct_hosted_file_obj={slct_hosted_file_obj}
|
||||
/>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{:else}
|
||||
@@ -431,7 +511,7 @@ async function handle_hosted_files_uploaded(hosted_file_id_li: string[], hosted_
|
||||
<button
|
||||
disabled={!$ae_loc.administrator_access}
|
||||
type="button"
|
||||
on:click={() => {
|
||||
onclick={() => {
|
||||
if (confirm('Are you sure you want to remove the file?')) {
|
||||
|
||||
|
||||
@@ -591,7 +671,7 @@ async function handle_hosted_files_uploaded(hosted_file_id_li: string[], hosted_
|
||||
<button
|
||||
type="button"
|
||||
class="novi_btn btn btn-sm variant-soft-secondary float-right"
|
||||
on:click={() => {
|
||||
onclick={() => {
|
||||
$idaa_loc.archives.show__admin_options = !$idaa_loc.archives.show__admin_options;
|
||||
}}
|
||||
>
|
||||
@@ -744,7 +824,7 @@ async function handle_hosted_files_uploaded(hosted_file_id_li: string[], hosted_
|
||||
{#if $idaa_slct.archive_content_id && !$idaa_slct.archive_content_obj?.hosted_file_id}
|
||||
<button
|
||||
type="button"
|
||||
on:click={() => {
|
||||
onclick={() => {
|
||||
if (!confirm('Are you sure you want to delete this archive content?')) {return false;}
|
||||
|
||||
prom_api__archive_content_obj = archives_func.delete_ae_obj_id__archive_content({
|
||||
|
||||
Reference in New Issue
Block a user