Working on posts with linked content (hosted files).
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import type { key_val } from '$lib/ae_stores';
|
||||
import { api } from '$lib/api';
|
||||
|
||||
import { db_posts } from "$lib/db_posts";
|
||||
import { db_posts } from "$lib/ae_posts/db_posts";
|
||||
|
||||
import { load_ae_obj_li__post_comment } from "$lib/ae_posts/ae_posts__post_comment";
|
||||
|
||||
@@ -652,18 +652,22 @@ export function db_save_ae_obj_li__post(
|
||||
topic: obj.topic,
|
||||
topic_name: obj.topic_name,
|
||||
|
||||
title: obj.title,
|
||||
name: obj.title,
|
||||
title: obj.title, // Switching to name instead of title
|
||||
// summary: obj.summary,
|
||||
content: obj.content,
|
||||
|
||||
anonymous: obj.anonymous,
|
||||
full_name: obj.full_name,
|
||||
email: obj.email,
|
||||
notify: obj.notify,
|
||||
|
||||
enable_comments: obj.enable_comments,
|
||||
|
||||
archive: obj.archive,
|
||||
archive_on: obj.archive_on,
|
||||
|
||||
linked_li_json: obj.linked_li_json,
|
||||
cfg_json: obj.cfg_json,
|
||||
|
||||
enable: obj.enable,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { key_val } from '$lib/ae_stores';
|
||||
import { api } from '$lib/api';
|
||||
|
||||
import { db_posts } from "$lib/db_posts";
|
||||
import { db_posts } from "$lib/ae_posts/db_posts";
|
||||
|
||||
let ae_promises: key_val = {};
|
||||
|
||||
@@ -328,15 +328,17 @@ export function db_save_ae_obj_li__post_comment(
|
||||
|
||||
external_person_id: obj.external_person_id,
|
||||
|
||||
// name: obj.name,
|
||||
name: obj.name,
|
||||
title: obj.title, // Switching to name instead of title
|
||||
// summary: obj.summary,
|
||||
title: obj.title,
|
||||
content: obj.content,
|
||||
|
||||
anonymous: obj.anonymous,
|
||||
full_name: obj.full_name,
|
||||
email: obj.email,
|
||||
notify: obj.notify,
|
||||
|
||||
linked_li_json: obj.linked_li_json,
|
||||
cfg_json: obj.cfg_json,
|
||||
|
||||
enable: obj.enable,
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import Dexie, { type Table } from 'dexie';
|
||||
|
||||
import type { key_val } from './ae_stores';
|
||||
import type { key_val } from '../ae_stores';
|
||||
|
||||
// li = list
|
||||
// kv = key value list
|
||||
|
||||
// Updated 2024-09-25
|
||||
// Updated 2024-11-13
|
||||
export interface Post {
|
||||
id: string;
|
||||
// id_random: string;
|
||||
@@ -23,20 +23,22 @@ export interface Post {
|
||||
topic?: string; // or topic_name?
|
||||
topic_name?: string;
|
||||
|
||||
// name: null|string;
|
||||
// summary?: null|string;
|
||||
name: null|string;
|
||||
title: null|string;
|
||||
// summary?: null|string;
|
||||
content?: null|string;
|
||||
|
||||
anonymous?: null|boolean;
|
||||
full_name?: null|string;
|
||||
email?: null|string;
|
||||
notify?: null|boolean;
|
||||
|
||||
enable_comments?: null|boolean;
|
||||
|
||||
archive?: null|boolean;
|
||||
archive_on?: Date;
|
||||
|
||||
linked_li_json?: null|string;
|
||||
cfg_json?: null|key_val;
|
||||
|
||||
enable: null|boolean;
|
||||
@@ -52,7 +54,8 @@ export interface Post {
|
||||
post_comment_count?: number;
|
||||
}
|
||||
|
||||
// Updated 2024-09-25
|
||||
|
||||
// Updated 2024-11-13
|
||||
export interface Post_Comment {
|
||||
id: string;
|
||||
// id_random: string;
|
||||
@@ -64,15 +67,17 @@ export interface Post_Comment {
|
||||
|
||||
external_person_id?: null|string; // For IDAA this is the Novi UUID
|
||||
|
||||
// name: null|string;
|
||||
// summary?: null|string;
|
||||
name: null|string;
|
||||
title: null|string;
|
||||
// summary?: null|string;
|
||||
content?: null|string;
|
||||
|
||||
anonymous?: null|boolean;
|
||||
full_name?: null|string;
|
||||
email?: null|string;
|
||||
notify?: null|boolean;
|
||||
|
||||
linked_li_json?: null|string;
|
||||
cfg_json?: null|key_val;
|
||||
|
||||
enable: null|boolean;
|
||||
@@ -77,6 +77,8 @@ export interface Archive_Content {
|
||||
content_html?: null|string;
|
||||
content_json?: null|string;
|
||||
|
||||
// linked_li_json?: null|string; // For future use? linked content list instead of one content item
|
||||
|
||||
url?: null|string;
|
||||
url_text?: null|string;
|
||||
|
||||
|
||||
@@ -409,7 +409,7 @@ async function handle_hosted_files_uploaded(hosted_file_id_li: string[], hosted_
|
||||
<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>
|
||||
Media: audio (mp3, m4a) and video (mp4, mkv)<br>
|
||||
Supplemental files: Word Doc, Excel, txt, etc
|
||||
</span>
|
||||
</span>
|
||||
|
||||
@@ -31,6 +31,7 @@ let ae_promises: key_val = {};
|
||||
{#if idaa_archive_content_obj.group && idaa_archive_content_obj.group != $lq__archive_content_obj_li[index - 1]?.group}
|
||||
<div class="ae_row archive_content__group flex flex-row items-center justify-center">
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-md variant-glass-secondary hover:variant-filled-secondary transition w-96"
|
||||
on:click={() => {
|
||||
if ($idaa_loc.archives.show_list__archive_content_li_group == idaa_archive_content_obj.group) {
|
||||
@@ -83,6 +84,7 @@ let ae_promises: key_val = {};
|
||||
|
||||
<div class="ae_options flex flex-row flex-wrap gap-2 items-center justify-center">
|
||||
<button
|
||||
type="button"
|
||||
disabled={!$ae_loc.trusted_access}
|
||||
on:click={() => {
|
||||
$idaa_slct.archive_content_id = idaa_archive_content_obj?.archive_content_id;
|
||||
@@ -108,6 +110,7 @@ let ae_promises: key_val = {};
|
||||
|
||||
{#if $ae_loc.authenticated_access && idaa_archive_content_obj?.hosted_file_id}
|
||||
<button
|
||||
type="button"
|
||||
disabled={!$ae_loc.trusted_access}
|
||||
on:click={() => {
|
||||
ae_promises[idaa_archive_content_obj.hosted_file_id] = api.download_hosted_file({
|
||||
@@ -158,6 +161,7 @@ let ae_promises: key_val = {};
|
||||
|
||||
{#if $ae_loc.trusted_access && $ae_loc.edit_mode}
|
||||
<button
|
||||
type="button"
|
||||
disabled={!$ae_loc.trusted_access}
|
||||
on:click={() => {
|
||||
$idaa_slct.archive_content_id = idaa_archive_content_obj.archive_content_id;
|
||||
|
||||
@@ -13,7 +13,7 @@ import { ae_util } from '$lib/ae_utils/ae_utils';
|
||||
|
||||
import { liveQuery } from "dexie";
|
||||
import { core_func } from '$lib/ae_core/ae_core_functions';
|
||||
import { db_posts } from "$lib/db_posts";
|
||||
import { db_posts } from "$lib/ae_posts/db_posts";
|
||||
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, idaa_trigger } from '$lib/ae_idaa_stores';
|
||||
import { posts_func } from '$lib/ae_posts/ae_posts_functions';
|
||||
|
||||
@@ -11,10 +11,13 @@ import { ae_snip, ae_loc, ae_sess, ae_api, ae_trig, slct, slct_trigger } from '$
|
||||
import { idaa_loc, idaa_sess, idaa_slct } from '$lib/ae_idaa_stores';
|
||||
import { posts_func } from '$lib/ae_posts/ae_posts_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__post_obj: any;
|
||||
|
||||
let prom_api__post_obj_v2: any;
|
||||
let ae_promises: key_val = {};
|
||||
let prom_api__post_obj: any;
|
||||
let prom_api__post_obj__hosted_file: any;
|
||||
|
||||
let disable_submit_btn = false;
|
||||
|
||||
@@ -96,7 +99,7 @@ async function handle_submit_form(event: any) {
|
||||
console.log(post_do);
|
||||
|
||||
if (!$idaa_slct.post_id) {
|
||||
prom_api__post_obj_v2 = posts_func.create_ae_obj__post({
|
||||
prom_api__post_obj = posts_func.create_ae_obj__post({
|
||||
api_cfg: $ae_api,
|
||||
account_id: $ae_loc.account_id,
|
||||
data_kv: post_do,
|
||||
@@ -122,9 +125,9 @@ async function handle_submit_form(event: any) {
|
||||
$idaa_sess.bb.show__inline_edit__post_obj = false;
|
||||
});
|
||||
|
||||
return prom_api__post_obj_v2;
|
||||
return prom_api__post_obj;
|
||||
} else {
|
||||
prom_api__post_obj_v2 = posts_func.update_ae_obj__post({
|
||||
prom_api__post_obj = posts_func.update_ae_obj__post({
|
||||
api_cfg: $ae_api,
|
||||
post_id: $idaa_slct.post_id,
|
||||
data_kv: post_do,
|
||||
@@ -150,7 +153,7 @@ async function handle_submit_form(event: any) {
|
||||
$idaa_sess.bb.show__inline_edit__post_obj = false;
|
||||
});
|
||||
|
||||
return prom_api__post_obj_v2;
|
||||
return prom_api__post_obj;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,6 +166,39 @@ async function handle_delete_post_obj({post_id, method}: key_val) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
$: if ($idaa_slct.post_obj.upload_complete && $idaa_slct.post_obj.hosted_file_id_li?.length && $idaa_slct.post_obj.hosted_file_obj_li?.length) {
|
||||
handle_hosted_files_uploaded($idaa_slct.post_obj.hosted_file_id_li, $idaa_slct.post_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 post_obj with the new file (for now just the first one).
|
||||
prom_api__post_obj = posts_func.update_ae_obj__post({
|
||||
api_cfg: $ae_api,
|
||||
post_id: $idaa_slct.post_id,
|
||||
data_kv: {
|
||||
linked_li_json: JSON.stringify(hosted_file_obj_li),
|
||||
// hosted_file_id_random: hosted_file_obj_li[0].hosted_file_id_random,
|
||||
// filename: hosted_file_obj_li[0].filename,
|
||||
// file_extension: hosted_file_obj_li[0].extension,
|
||||
},
|
||||
log_lvl: log_lvl
|
||||
})
|
||||
.then(function (post_obj_update_result) {
|
||||
$idaa_slct.post_obj = $lq__post_obj;
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.log('Something went wrong.');
|
||||
console.log(error);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
@@ -174,10 +210,10 @@ async function handle_delete_post_obj({post_id, method}: key_val) {
|
||||
|
||||
<form on:submit|preventDefault={handle_submit_form} class="space-y-1">
|
||||
|
||||
{#await prom_api__post_obj_v2}
|
||||
{#await prom_api__post_obj}
|
||||
<div class="awaiting alert_msg_pulse" out:fade={{ duration: 2000 }}>Saving...</div>
|
||||
{:then}
|
||||
{#if prom_api__post_obj_v2}
|
||||
{#if prom_api__post_obj}
|
||||
<!-- <div class="awaiting" out:fade={{ duration: 2000 }}>Finished saving</div> -->
|
||||
{:else}
|
||||
<!-- <div class="awaiting" out:fade={{ duration: 2000 }}>Nothing here yet</div> -->
|
||||
@@ -219,6 +255,88 @@ async function handle_delete_post_obj({post_id, method}: key_val) {
|
||||
|
||||
</label>
|
||||
|
||||
{#if !$idaa_slct.post_obj.linked_li_json && $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="post"
|
||||
link_to_id={$idaa_slct.post_obj.post_id}
|
||||
bind:hosted_file_id_li={$idaa_slct.post_obj.hosted_file_id_li}
|
||||
bind:hosted_file_obj_li={$idaa_slct.post_obj.hosted_file_obj_li}
|
||||
bind:upload_complete={$idaa_slct.post_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 post files</strong>
|
||||
</div>
|
||||
<span class="text-sm text-gray-600 dark:text-gray-400 italic">
|
||||
<strong>Aether hosted files only</strong><br>
|
||||
Recommended: documents (PDF), audio (mp3, m4a), and video (mp4, mkv)<br>
|
||||
</span>
|
||||
</span>
|
||||
</Comp_hosted_files_upload>
|
||||
{/if}
|
||||
|
||||
{#if $idaa_slct.post_obj.linked_li_json && $idaa_slct.post_obj.linked_li_json.length}
|
||||
<div class="ae_section flex flex-row flex-wrap gap-1 items-center justify-center">
|
||||
<span class="fas fa-paperclip"></span>
|
||||
<span class="text-sm text-gray-600 dark:text-gray-400 italic">Linked files:</span>
|
||||
{#each $idaa_slct.post_obj.linked_li_json as linked_obj, index}
|
||||
<!-- <a
|
||||
href={linked_obj.url}
|
||||
target="_blank"
|
||||
class="badge badge-info variant-filled-info"
|
||||
>
|
||||
<span class="fas fa-paperclip m-1"></span>
|
||||
{linked_obj.filename}
|
||||
({linked_obj.hosted_file_id_random})
|
||||
</a> -->
|
||||
|
||||
{#if $ae_loc.authenticated_access && linked_obj?.hosted_file_id_random}
|
||||
<button
|
||||
type="button"
|
||||
disabled={!$ae_loc.trusted_access}
|
||||
on:click={() => {
|
||||
ae_promises[linked_obj.hosted_file_id_random] = api.download_hosted_file({
|
||||
api_cfg: $ae_api,
|
||||
hosted_file_id: linked_obj.hosted_file_id_random,
|
||||
return_file: true,
|
||||
filename: linked_obj.filename,
|
||||
auto_download: true,
|
||||
log_lvl: 0
|
||||
});
|
||||
|
||||
// window.postMessage({ type: 'download_event_file', hosted_file_id: linked_obj.hosted_file_id_random, filename: linked_obj.filename, auto_download: true }, '*');
|
||||
}}
|
||||
class="btn btn-sm lg:btn-md variant-soft-primary hover:variant-filled-primary min-w-48"
|
||||
title={`Download this file:\n${linked_obj.filename}\n[API] SHA256: ${linked_obj?.hash_sha256.slice(0, 10)}... Hosted ID: ${linked_obj.hosted_file_id_random} Archive Content ID: ${linked_obj.archive_content_id}`}
|
||||
>
|
||||
{#await ae_promises[linked_obj.hosted_file_id_random]}
|
||||
<span class="fas fa-spinner fa-spin mx-1"></span>
|
||||
<span class="">
|
||||
Downloading
|
||||
{#if $ae_sess.api_download_kv[linked_obj.hosted_file_id_random]}
|
||||
{$ae_sess.api_download_kv[linked_obj.hosted_file_id_random].percent_completed}%
|
||||
{/if}
|
||||
:
|
||||
</span>
|
||||
{:then}
|
||||
<span class="fas fa-{ae_util.file_extension_icon(linked_obj?.extension)}"></span>
|
||||
{/await}
|
||||
|
||||
<span class="grow">
|
||||
{ae_util.shorten_filename({filename: linked_obj?.filename, max_length: 30})}
|
||||
</span>
|
||||
</button>
|
||||
{/if}
|
||||
|
||||
|
||||
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<div>
|
||||
<label class="">
|
||||
BB post topic:
|
||||
@@ -477,7 +595,7 @@ async function handle_delete_post_obj({post_id, method}: key_val) {
|
||||
disabled={(disable_submit_btn)}
|
||||
class="ae_btn btn_primary btn btn-primary variant-ghost-primary hover:variant-filled-primary transition"
|
||||
>
|
||||
{#await prom_api__post_obj_v2}
|
||||
{#await prom_api__post_obj}
|
||||
<span class="fas fa-spinner fa-spin m-1"></span> Saving
|
||||
{:then}
|
||||
<span class="fas fa-save m-1"></span> Save
|
||||
@@ -493,7 +611,7 @@ async function handle_delete_post_obj({post_id, method}: key_val) {
|
||||
}}
|
||||
class="ae_btn btn_primary btn btn-primary variant-ghost-primary hover:variant-filled-primary transition"
|
||||
>
|
||||
{#await prom_api__post_obj_v2}
|
||||
{#await prom_api__post_obj}
|
||||
<span class="fas fa-spinner fa-spin m-1"></span> Saving
|
||||
{:then}
|
||||
<span class="fas fa-plus m-1"></span> Save New Event
|
||||
|
||||
@@ -3,7 +3,9 @@ import { onDestroy } from 'svelte';
|
||||
import { browser } from '$app/environment';
|
||||
|
||||
// *** Import Aether core variables and functions
|
||||
import type { key_val } from '$lib/ae_stores';
|
||||
import { ae_util } from '$lib/ae_utils/ae_utils';
|
||||
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, idaa_trigger } from '$lib/ae_idaa_stores';
|
||||
|
||||
@@ -14,6 +16,7 @@ export let lq__post_obj: any;
|
||||
export let lq__post_comment_obj_li: any;
|
||||
export let lq__post_comment_obj: any;
|
||||
|
||||
let ae_promises: key_val = {};
|
||||
|
||||
if ($idaa_slct.post_id) {
|
||||
console.log(`Post ID selected: ${$idaa_slct.post_id}`);
|
||||
@@ -106,6 +109,66 @@ onDestroy(() => {
|
||||
|
||||
<div class="post__content">
|
||||
<pre class="post__content p-2 bg-white shadow-md rounded-lg text-wrap text-sm font-normal whitespace-pre-wrap">{@html $idaa_slct.post_obj.content}</pre>
|
||||
|
||||
{#if $idaa_slct.post_obj.linked_li_json && $idaa_slct.post_obj.linked_li_json.length}
|
||||
<div class="ae_section flex flex-row flex-wrap gap-1 items-center justify-center">
|
||||
<span class="fas fa-paperclip"></span>
|
||||
<span class="text-sm text-gray-600 dark:text-gray-400 italic">Linked files:</span>
|
||||
{#each $idaa_slct.post_obj.linked_li_json as linked_obj, index}
|
||||
<!-- <a
|
||||
href={linked_obj.url}
|
||||
target="_blank"
|
||||
class="badge badge-info variant-filled-info"
|
||||
>
|
||||
<span class="fas fa-paperclip m-1"></span>
|
||||
{linked_obj.filename}
|
||||
({linked_obj.hosted_file_id_random})
|
||||
</a> -->
|
||||
|
||||
{#if $ae_loc.authenticated_access && linked_obj?.hosted_file_id_random}
|
||||
<button
|
||||
type="button"
|
||||
disabled={!$ae_loc.trusted_access}
|
||||
on:click={() => {
|
||||
ae_promises[linked_obj.hosted_file_id_random] = api.download_hosted_file({
|
||||
api_cfg: $ae_api,
|
||||
hosted_file_id: linked_obj.hosted_file_id_random,
|
||||
return_file: true,
|
||||
filename: linked_obj.filename,
|
||||
auto_download: true,
|
||||
log_lvl: 0
|
||||
});
|
||||
|
||||
// window.postMessage({ type: 'download_event_file', hosted_file_id: linked_obj.hosted_file_id_random, filename: linked_obj.filename, auto_download: true }, '*');
|
||||
}}
|
||||
class="btn btn-sm lg:btn-md variant-soft-primary hover:variant-filled-primary min-w-48"
|
||||
title={`Download this file:\n${linked_obj.filename}\n[API] SHA256: ${linked_obj?.hash_sha256.slice(0, 10)}... Hosted ID: ${linked_obj.hosted_file_id_random} Archive Content ID: ${linked_obj.archive_content_id}`}
|
||||
>
|
||||
{#await ae_promises[linked_obj.hosted_file_id_random]}
|
||||
<span class="fas fa-spinner fa-spin mx-1"></span>
|
||||
<span class="">
|
||||
Downloading
|
||||
{#if $ae_sess.api_download_kv[linked_obj.hosted_file_id_random]}
|
||||
{$ae_sess.api_download_kv[linked_obj.hosted_file_id_random].percent_completed}%
|
||||
{/if}
|
||||
:
|
||||
</span>
|
||||
{:then}
|
||||
<span class="fas fa-{ae_util.file_extension_icon(linked_obj?.extension)}"></span>
|
||||
{/await}
|
||||
|
||||
<span class="grow">
|
||||
{ae_util.shorten_filename({filename: linked_obj?.filename, max_length: 30})}
|
||||
</span>
|
||||
</button>
|
||||
{/if}
|
||||
|
||||
|
||||
|
||||
{/each}
|
||||
</div>
|
||||
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<section class="ae_section ae_meta post__meta text-sm text-gray-500 mt-4 flex flex-row gap-2 items-center justify-between">
|
||||
|
||||
Reference in New Issue
Block a user