Now with a new recent files report.

This commit is contained in:
Scott Idem
2024-07-12 16:20:23 -04:00
parent 47c742d004
commit 997f470ebe
8 changed files with 522 additions and 23 deletions

View File

@@ -269,6 +269,129 @@ export async function handle_update_ae_obj__event_file(
}
// Updated 2024-07-12
export async function handle_search__event_file(
{
api_cfg,
event_id,
created_on = null,
fulltext_search_qry_str,
ft_file_search_qry_str,
like_search_qry_str = null,
like_presentation_search_qry_str = null,
like_file_search_qry_str = null,
params = {},
try_cache = true,
log_lvl = 0
}: {
api_cfg: any,
event_id: any,
created_on?: null|string,
fulltext_search_qry_str?: null|string,
ft_file_search_qry_str?: null|string,
like_search_qry_str?: null|string,
like_presentation_search_qry_str?: null|string,
like_file_search_qry_str?: null|string,
params?: any,
try_cache?: boolean,
log_lvl?: number
}
) {
console.log(`*** handle_search__event_file() *** event_id=${event_id}`);
let enabled: string = (params.qry__enabled ?? 'enabled'); // all, disabled, enabled
let hidden: string = (params.qry__hidden ?? 'not_hidden'); // all, hidden, not_hidden
let limit: number = (params.qry__limit ?? 25); // 99
let offset: number = (params.qry__offset ?? 0); // 0
let params_json: key_val = {};
// if (!fulltext_search_qry_str && !like_search_qry_str) {
// console.log('No search string provided!!!');
// return false; // Returning false instead of [] because no search was performed.
// }
if (fulltext_search_qry_str || ft_file_search_qry_str) {
params_json['ft_qry'] = {};
if (fulltext_search_qry_str && fulltext_search_qry_str.length > 2) {
params_json['ft_qry']['default_qry_str'] = fulltext_search_qry_str;
}
if (ft_file_search_qry_str && ft_file_search_qry_str.length > 2) {
params_json['ft_qry']['event_file_li_qry_str'] = ft_file_search_qry_str;
}
}
// Use the AND (AND LIKE) query
// if (like_search_qry_str || like_file_search_qry_str) {
// params_json['and_like'] = {};
// if (like_search_qry_str && like_search_qry_str.length > 2) {
// params_json['and_like']['default_qry_str'] = like_search_qry_str;
// }
// if (like_file_search_qry_str && like_file_search_qry_str.length > 2) {
// params_json['and_like']['event_file_li_qry_str'] = like_file_search_qry_str;
// }
// }
// Use the AND (OR LIKE) query
// if (like_search_qry_str || like_presentation_search_qry_str || like_file_search_qry_str) {
// params_json['or_like'] = {};
// if (like_search_qry_str && like_search_qry_str.length > 2) {
// params_json['or_like']['default_qry_str'] = like_search_qry_str;
// }
// if (like_presentation_search_qry_str && like_presentation_search_qry_str.length > 2) {
// params_json['or_like']['event_presentation_li_qry_str'] = like_presentation_search_qry_str;
// }
// if (like_file_search_qry_str && like_file_search_qry_str.length > 2) {
// params_json['or_like']['event_file_li_qry_str'] = like_file_search_qry_str;
// }
// }
// params_json['and_qry'] = {};
// if (created_on) {
// params_json['and_qry']['created_on'] = created_on;
// }
let order_by_li = {'priority': 'DESC', 'sort': 'DESC', 'filename': 'ASC', 'extension': 'ASC', 'hosted_file_size': 'ASC', 'updated_on': 'DESC', 'created_on': 'DESC'};
ae_promises.load__event_file_obj_li = await api.get_ae_obj_li_for_obj_id_crud({
api_cfg: api_cfg,
obj_type: 'event_file',
for_obj_type: 'event',
for_obj_id: event_id,
use_alt_table: true, // NOTE: We want to use the alt table for file searching?
use_alt_base: false,
enabled: enabled,
hidden: hidden,
order_by_li: order_by_li,
limit: limit,
offset: offset,
params_json: params_json,
params: params,
log_lvl: log_lvl
})
.then(function (event_file_obj_li_get_result) {
if (event_file_obj_li_get_result) {
handle_db_save_ae_obj_li__event_file({obj_type: 'event_file', obj_li: event_file_obj_li_get_result});
return event_file_obj_li_get_result;
} else {
return [];
}
})
.catch(function (error) {
console.log('No results returned or failed.', error);
})
.finally(function () {
});
if (log_lvl) {
console.log('ae_promises.load__event_file_obj_li:', ae_promises.load__event_file_obj_li);
}
return ae_promises.load__event_file_obj_li;
}
// This function will loop through the event_file_obj_li and save each one to the DB.
export function handle_db_save_ae_obj_li__event_file(
{
@@ -329,6 +452,19 @@ export function handle_db_save_ae_obj_li__event_file(
hosted_file_content_type: obj.hosted_file_content_type,
file_size: obj.file_size,
hosted_file_size: obj.hosted_file_size,
event_location_code: obj.event_location_code,
event_location_name: obj.event_location_name,
event_session_code: obj.event_session_code,
event_session_name: obj.event_session_name,
event_session_start_datetime: obj.event_session_start_datetime,
event_presentation_code: obj.event_presentation_code,
event_presentation_name: obj.event_presentation_name,
event_presentation_start_datetime: obj.event_presentation_start_datetime,
event_presenter_given_name: obj.event_presenter_given_name,
event_presenter_family_name: obj.event_presenter_family_name,
event_presenter_full_name: obj.event_presenter_full_name,
event_presenter_email: obj.event_presenter_email,
});
// console.log(`Put obj with ID: ${obj.event_file_id_random} or ${id_random}`);
} catch (error) {

View File

@@ -12,6 +12,7 @@ import {
handle_delete_ae_obj_id__event_file,
create_event_file_obj_from_hosted_file_async,
handle_update_ae_obj__event_file,
handle_search__event_file,
handle_db_save_ae_obj_li__event_file,
} from "$lib/ae_events__event_file";
@@ -74,6 +75,7 @@ let export_obj = {
handle_load_ae_obj_li__event_file: handle_load_ae_obj_li__event_file,
handle_delete_ae_obj_id__event_file: handle_delete_ae_obj_id__event_file,
handle_update_ae_obj__event_file: handle_update_ae_obj__event_file,
handle_search__event_file: handle_search__event_file,
handle_load_ae_obj_id__event_location: handle_load_ae_obj_id__event_location,
handle_load_ae_obj_li__event_location: handle_load_ae_obj_li__event_location,

View File

@@ -281,6 +281,9 @@ let events_session_data_struct: key_val = {
show_content__agree_text: false,
show_content__presenter_start: false,
show_report__presenters_agree: false,
show_report__recent_files: false,
new_upload_list: null,
files_uploading_count: null,
},
@@ -334,6 +337,8 @@ let events_slct_obj_template: key_val = {
'file_obj': {},
'file_obj_li': [],
'event_file_obj_li': [],
'location_id': null,
'location_obj': {},
'location_obj_li': [],

View File

@@ -238,6 +238,19 @@ export interface File {
hosted_file_content_type: string;
file_size: number; // In bytes
hosted_file_size?: number; // In bytes
event_location_code?: null|string;
event_location_name?: null|string;
event_session_code?: null|string;
event_session_name?: string;
event_session_start_datetime?: null|Date;
event_presentation_code?: null|string;
event_presentation_name?: string;
event_presentation_start_datetime?: null|Date;
event_presenter_given_name?: null|string;
event_presenter_family_name?: null|string;
event_presenter_full_name?: null|string;
event_presenter_email?: null|string;
}

View File

@@ -36,7 +36,7 @@ export let show_convert_btn: null|boolean = null;
// }
let ae_placeholder_li: key_val = {};
let ae_promises: key_val = {}; // Promise<any>;
let ae_promises: key_val = {};
let ae_tmp: key_val = {};
ae_tmp.show__file_li = true;
let ae_triggers: key_val = {};

View File

@@ -0,0 +1,209 @@
<script lang="ts">
// Imports
import type { key_val } from '$lib/ae_stores';
import { ae_util } from '$lib/ae_utils';
import { api } from '$lib/api';
import { liveQuery } from "dexie";
import { db_events } from "$lib/db_events";
import { ae_snip, ae_loc, ae_sess, ae_api, ae_trig, slct, slct_trigger } from '$lib/ae_stores';
// import { events_loc, events_sess, events_slct, events_trigger, events_trig_kv } from '$lib/ae_events_stores';
// import { events_func } from '$lib/ae_events_functions';
// Exports
export let container_class_li: string|Array<string> = [];
export let event_file_id_random_li: Array<string> = [''];
export let allow_basic: boolean = false;
export let allow_moderator: boolean = false;
export let show_location_fields: boolean = false;
export let show_presentation_fields: boolean = false;
export let show_presenter_fields: boolean = false;
export let show_session_fields: boolean = false;
export let display_mode: string = 'default'; // 'default', 'compact', 'minimal', 'launcher'
// Variables
let ae_promises: key_val = {};
// Functions and Logic
// let lq__event_file_obj = liveQuery(
// () => db_events.files.get($events_slct.event_file_id)
// );
let lq_kv__event_file_obj_li = liveQuery(
() => db_events.files
.bulkGet(event_file_id_random_li)
);
</script>
<section class="ae_comp event_file_obj_tbl container {container_class_li}">
{#if event_file_id_random_li && $lq_kv__event_file_obj_li && $lq_kv__event_file_obj_li?.length > 0 && $lq_kv__event_file_obj_li?.length == event_file_id_random_li?.length}
<div class="overflow-scroll">
<table
class="table-auto w-full table-striped table-hover"
>
<thead>
<tr>
<th class="px-4 py-2">
Filename
({$lq_kv__event_file_obj_li?.length}x)
</th>
<th class="px-4 py-2">Size</th>
{#if show_location_fields}
<th class="px-4 py-2">Location</th>
{/if}
{#if show_session_fields}
<th class="px-4 py-2">
Session
</th>
<th class="px-4 py-2">Start datetime</th>
{/if}
{#if show_presentation_fields}
<th class="px-4 py-2">Presentation</th>
<th class="px-4 py-2">Presentation time</th>
{/if}
<th class="px-4 py-2">Name</th>
<!-- <th class="px-4 py-2">Email</th> -->
<!-- <th class="px-4 py-2">Agree</th> -->
</tr>
</thead>
<tbody>
{#each $lq_kv__event_file_obj_li as event_file_obj}
<tr
class:dim={event_file_obj?.hide}>
<td class="px-4 py-2">
<button
disabled={!allow_basic && !allow_moderator && !$ae_loc.trusted_access}
on:click={() => {
// ae_promises[event_file_obj.event_file_id_random]
ae_promises[event_file_obj?.event_file_id_random] = api.download_hosted_file({
api_cfg: $ae_api,
hosted_file_id: event_file_obj?.hosted_file_id_random,
return_file: true,
filename: event_file_obj?.filename,
auto_download: true,
log_lvl: 0
});
// window.postMessage({ type: 'download_event_file', event_file_id: event_file_obj?.event_file_id_random, filename: event_file_obj?.filename, auto_download: true }, '*');
}}
class="btn btn-sm lg:btn-md variant-soft-primary hover:variant-filled-primary min-w-72 lg:min-w-96"
title={`Download this file: ${event_file_obj?.filename} [API] -- SHA256 hash: ${event_file_obj?.hash_sha256.slice(0, 10)}...`}
>
{#await ae_promises[event_file_obj?.event_file_id_random]}
<span class="fas fa-spinner fa-spin mx-1"></span>
<span class="">
Downloading
{#if $ae_sess.api_download_kv[event_file_obj?.hosted_file_id_random]}
{$ae_sess.api_download_kv[event_file_obj?.hosted_file_id_random].percent_completed}%
{/if}
:
</span>
{:then}
<!-- <span class="fas fa-download mx-1"></span> -->
<span class="fas fa-{ae_util.file_extension_icon(event_file_obj?.extension)}"></span>
<!-- <span class="text-sm">
Download:
</span> -->
{/await}
<span class="grow">
{ae_util.shorten_filename({filename: event_file_obj?.filename, max_length: 30})}
</span>
<span
class="badge variant-glass-success hover:variant-filled-success text-sm"
class:hidden={!event_file_obj?.file_purpose}
>
{event_file_obj?.file_purpose}
</span>
</button>
<!-- {event_file_obj?.filename} -->
</td>
<td class="px-4 py-2">{ae_util.format_bytes(event_file_obj?.file_size)}</td>
{#if show_location_fields}
<td class="px-4 py-2">
{#if event_file_obj?.event_location_id_random}
<!-- <span class="fas fa-map-marker-alt"></span> -->
{event_file_obj?.event_location_name}
{:else}
{@html ae_snip.html__not_set}
{/if}
</td>
{/if}
{#if show_session_fields}
<td class="px-4 py-2">
<span class="fas fa-chalkboard-teacher"></span>
<a
href="/events_pres_mgmt/session/{event_file_obj?.event_session_id_random}"
class="text-blue-500 underline hover:text-blue-800"
>
{event_file_obj?.event_session_name}
</a>
</td>
<td class="px-4 py-2">{ae_util.iso_datetime_formatter(event_file_obj?.event_session_start_datetime, 'datetime_us_no_seconds')}</td>
{/if}
{#if show_presentation_fields}
<td class="px-4 py-2">
{#if event_file_obj?.event_presentation_id_random}
{event_file_obj?.event_presentation_name}
{:else}
{@html ae_snip.html__not_set}
{/if}
</td>
<td class="px-4 py-2">
{#if event_file_obj?.event_presentation_id_random}
{ae_util.iso_datetime_formatter(event_file_obj?.event_presentation_start_datetime, 'time_us_short')}
{:else}
{@html ae_snip.html__not_set}
{/if}
</td>
{/if}
<td class="px-4 py-2">
{#if event_file_obj?.event_presenter_id_random}
<span class="fas fa-user"></span>
<a
href="/events_pres_mgmt/file/{event_file_obj?.event_file_id_random}"
class="text-blue-500 underline hover:text-blue-800"
>
{event_file_obj?.event_presenter_full_name}
</a>
{:else}
<!-- <span class="text-gray-500">--</span> -->
{@html ae_snip.html__not_set}
{/if}
</td>
<!-- <td class="px-4 py-2">
<span class="fas fa-envelope"></span>
<a
href="mailto:{event_file_obj?.email}"
class="text-blue-500 underline hover:text-blue-800"
>
{event_file_obj?.email}
</a>
</td> -->
<!-- <td class="px-4 py-2">{event_file_obj?.agree ? 'Yes' : 'No'}</td> -->
</tr>
{/each}
</tbody>
</table>
</div>
{/if}
</section>
<style>
.dim {
opacity: 0.5;
color: #999;
}
</style>

View File

@@ -44,12 +44,15 @@ let lq_kv__event_presenter_obj_li = liveQuery(
<thead>
<tr>
{#if show_session_fields}
<th class="px-4 py-2">Session</th>
<th class="px-4 py-2">
Session
({$lq_kv__event_presenter_obj_li?.length}x)
</th>
<th class="px-4 py-2">Start datetime</th>
{/if}
{#if show_presentation_fields}
<th class="px-4 py-2">Presentation</th>
<th class="px-4 py-2">Start time</th>
<th class="px-4 py-2">Presentation time</th>
{/if}
<th class="px-4 py-2">Name</th>
<th class="px-4 py-2">Email</th>
@@ -75,7 +78,7 @@ let lq_kv__event_presenter_obj_li = liveQuery(
{/if}
{#if show_presentation_fields}
<td class="px-4 py-2">{event_presenter_obj?.event_presentation_name}</td>
<td class="px-4 py-2">{ae_util.iso_datetime_formatter(event_presenter_obj?.event_presentation_start_time, 'time_us_short')}</td>
<td class="px-4 py-2">{ae_util.iso_datetime_formatter(event_presenter_obj?.event_presentation_start_datetime, 'time_us_short')}</td>
{/if}
<td class="px-4 py-2">
<span class="fas fa-user"></span>

View File

@@ -9,6 +9,7 @@ import type { key_val } from '$lib/ae_stores';
import { ae_util } from '$lib/ae_utils';
// import Element_ae_crud from '$lib/element_ae_crud.svelte';
import Element_data_store from '$lib/element_data_store.svelte';
import Comp_event_file_obj_tbl from '../../../ae_comp__event_file_obj_tbl.svelte';
// import Comp_event_presenter_obj_li from '../../../ae_comp__event_presenter_obj_li.svelte';
import Comp_event_presenter_obj_tbl from '../../../ae_comp__event_presenter_obj_tbl.svelte';
@@ -33,9 +34,10 @@ let lq__event_obj = liveQuery(
() => db_events.events.get($events_slct.event_id)
);
let event_file_id_random_li: string[] = []; // ['NPKOzGFKZZU'];
let event_session_id_random_li: string[] = ['VSBH-19-41-50'];
let event_presentation_id_random_li: string[] = ['VSBH-19-41-50'];
let event_presenter_id_random_li: string[] = ['I245hLQ4aek'];
let event_presenter_id_random_li: string[] = [];// ['I245hLQ4aek'];
let load_obj_li_results: Promise<any>|key_val;
let search_submit_results: Promise<any>|key_val;
@@ -54,6 +56,96 @@ onMount(() => {
});
async function handle_search__event_file(
{
api_cfg,
event_id,
created_on = null,
ft_search_str = '',
lk_search_str = '',
params = {
'qry__enabled': 'enabled',
'qry__hidden': 'not_hidden',
'qry__limit': 35,},
try_cache=false,
log_lvl=1,
}: {
api_cfg: any,
event_id: string,
created_on?: null|string,
ft_search_str?: string,
lk_search_str?: string,
params?: key_val,
try_cache?: boolean,
log_lvl?: number,
}
) {
console.log('handle_search__event_file()');
$events_sess.pres_mgmt.status_qry__search = 'loading';
search_submit_results = events_func.handle_search__event_file({
api_cfg: $ae_api,
event_id: $events_slct.event_id,
created_on: created_on,
fulltext_search_qry_str: ft_search_str,
like_search_qry_str: lk_search_str,
// external_event_id: $events_loc.pres_mgmt.default__external_registration_id,
params: params,
try_cache: try_cache,
log_lvl: 0,
})
.then(function (search_results) {
// Processing the results from the search.
$events_sess.pres_mgmt.status_qry__search = 'processing';
$events_slct.event_file_obj_li = search_results;
console.log(search_results);
// $events_sess.pres_mgmt.status_qry__search = 'done';
})
.finally(() => {
if (log_lvl) {
console.log('TEST SEARCH - Search done. Pulling out the event_file_id_randoms.');
}
// console.log(`TEST search: ${$lq_kv__event_file_obj_li}`);
event_file_id_random_li = [];
// We need to loop through the array of objects and get the event_file_id_random from each object a new list of event_file_id_randoms. Then we can use this list to get the full objects from the database.
let tmp_li = []; // This is to prevent the array from constantly updating and triggering the liveQuery.
for (let i = 0; i < $events_slct.event_file_obj_li.length; i++) {
tmp_li.push($events_slct.event_file_obj_li[i].event_file_id_random);
}
event_file_id_random_li = tmp_li;
// event_file_id_random_li = $events_slct.event_file_obj_li.map(file_obj => file_obj.event_file_id_random);
// Finally done with the search.
$events_sess.pres_mgmt.status_qry__search = 'done';
if (log_lvl > 1) {
console.log(`TEST SEARCH - event_file_id_random_li:`, event_file_id_random_li);
// console.log(`TEST SEARCH - search live query: ${$lq_kv__event_file_obj_li}`);
}
});
}
// handle_search__event_file({
// api_cfg: $ae_api,
// event_id: $events_slct.event_id,
// created_on: null,
// ft_search_str: '',
// lk_search_str: '',
// params: {
// 'qry__enabled': 'enabled',
// 'qry__hidden': 'not_hidden',
// 'qry__limit': 35,},
// try_cache: false,
// log_lvl: 2,
// });
async function handle_search__event_presenter(
{
@@ -138,19 +230,19 @@ async function handle_search__event_presenter(
}
handle_search__event_presenter({
api_cfg: $ae_api,
event_id: $events_slct.event_id,
agree: true,
ft_search_str: '',
lk_search_str: '',
params: {
'qry__enabled': 'enabled',
'qry__hidden': 'not_hidden',
'qry__limit': 35,},
try_cache: false,
log_lvl: 0,
});
// handle_search__event_presenter({
// api_cfg: $ae_api,
// event_id: $events_slct.event_id,
// agree: true,
// ft_search_str: '',
// lk_search_str: '',
// params: {
// 'qry__enabled': 'enabled',
// 'qry__hidden': 'not_hidden',
// 'qry__limit': 35,},
// try_cache: false,
// log_lvl: 0,
// });
</script>
@@ -253,7 +345,21 @@ handle_search__event_presenter({
type="button"
disabled={!$ae_loc.trusted_access}
on:click={() => {
$events_loc.pres_mgmt.show_report__presenters_agree = !$events_loc.pres_mgmt.show_report__presenters_agree;
handle_search__event_presenter({
api_cfg: $ae_api,
event_id: $events_slct.event_id,
agree: true,
ft_search_str: '',
lk_search_str: '',
params: {
'qry__enabled': 'enabled',
'qry__hidden': 'not_hidden',
'qry__limit': 35,},
try_cache: false,
log_lvl: 1,
});
$events_sess.pres_mgmt.show_report__presenters_agree = !$events_sess.pres_mgmt.show_report__presenters_agree;
$events_sess.pres_mgmt.show_report__recent_files = false;
}}
class="btn btn-sm variant-ghost-success hover:variant-filled-success transition-all mx-1"
title="Show presenters who have agreed to present."
@@ -269,7 +375,21 @@ handle_search__event_presenter({
type="button"
disabled={!$ae_loc.administrator_access}
on:click={() => {
$events_loc.pres_mgmt.show_report__recent_files = !$events_loc.pres_mgmt.show_report__recent_files;
handle_search__event_file({
api_cfg: $ae_api,
event_id: $events_slct.event_id,
created_on: null,
ft_search_str: '',
lk_search_str: '',
params: {
'qry__enabled': 'enabled',
'qry__hidden': 'not_hidden',
'qry__limit': 35,},
try_cache: false,
log_lvl: 1,
});
$events_sess.pres_mgmt.show_report__presenters_agree = false;
$events_sess.pres_mgmt.show_report__recent_files = !$events_sess.pres_mgmt.show_report__recent_files;
}}
class="btn btn-sm variant-ghost-success hover:variant-filled-success transition-all mx-1"
title="NOT READY YET: Show recent file uploads."
@@ -302,17 +422,28 @@ handle_search__event_presenter({
{/await} -->
<!-- Show presenters for this presentation -->
{#if $events_loc.pres_mgmt.show_report__presenters_agree && event_presenter_id_random_li?.length > 0}
{#if $events_sess.pres_mgmt.show_report__presenters_agree && event_presenter_id_random_li?.length > 0}
<!-- <div class="overflow-x-auto"> -->
<div class="">
<Comp_event_presenter_obj_tbl
event_presenter_id_random_li={event_presenter_id_random_li}
show_session_fields={true}
bind:event_presenter_id_random_li={event_presenter_id_random_li}
show_presentation_fields={true}
show_session_fields={true}
>
</Comp_event_presenter_obj_tbl>
</div>
{/if}
{#if $events_sess.pres_mgmt.show_report__recent_files && event_file_id_random_li?.length > 0}
<Comp_event_file_obj_tbl
bind:event_file_id_random_li={event_file_id_random_li}
show_location_fields={true}
show_presenter_fields={true}
show_presentation_fields={true}
show_session_fields={true}
>
</Comp_event_file_obj_tbl>
{/if}
<!-- {#if $events_slct.event_presenter_obj_li?.length == event_presenter_id_random_li?.length}