Adding back in the sponsorship export stuff I was working on... Annoyed.

This commit is contained in:
Scott Idem
2024-04-23 15:53:43 -04:00
parent a87b4d53a0
commit 38e73cb40c
4 changed files with 74 additions and 22 deletions

View File

@@ -66,8 +66,47 @@ async function handle_load_ae_obj_id__sponsorship_cfg(
}
async function handle_download_export__sponsorship(
{
api_cfg,
account_id,
file_type='CSV', // 'CSV' or 'Excel'
return_file=true,
filename='no_filename.csv',
auto_download=false,
params={}, // key value object is expected
log_lvl=0
} : {
api_cfg: any,
account_id: string,
file_type?: string,
return_file?: boolean,
filename?: string,
auto_download?: boolean,
params?: key_val,
log_lvl?: number
}
) {
console.log('*** stores_event_api.js: get_sponsorship_export() ***');
const endpoint = `/v2/crud/sponsorship/list`;
params['for_obj_type'] = 'account';
params['for_obj_id'] = account_id;
if (file_type == 'CSV' || file_type == 'Excel') {
params['file_type'] = file_type;
}
params['return_file'] = true;
ae_promises.download__sponsorship_export_file = await api.get_object({api_cfg: api_cfg, endpoint: endpoint, params: params, return_blob: return_file, filename: filename, auto_download: auto_download, log_lvl: log_lvl});
console.log('ae_promises.download__sponsorship_export_file:', ae_promises.download__sponsorship_export_file);
return ae_promises.download__sponsorship_export_file;
}
let export_obj = {
handle_load_ae_obj_id__sponsorship_cfg: handle_load_ae_obj_id__sponsorship_cfg,
handle_download_export__sponsorship: handle_download_export__sponsorship,
};
export let spons_func = export_obj;

View File

@@ -45,6 +45,8 @@ export let ae_app_local_data_struct: key_val = {
'debug': false, // A simple flag to know if we should show debug information.
'account_id': ae_account_id, // OSIT Demo _XY7DXtc9MY
'account_code': 'not_set',
'account_name': 'Account Name Not Set',
'site_domain': null, // https://example.com, https://dev.example.com, etc.
'site_cfg_json': {
slct__event_id: null,

View File

@@ -147,6 +147,9 @@ export async function load({ fetch, params, parent, route, url }) { // params, r
ae_api_init['headers']['x-no-account-id'] = null;
ae_loc_init['account_id'] = site_domain_results.account_id_random;
ae_loc_init['account_code'] = site_domain_results.account_code; // Useful for export file naming
ae_loc_init['account_name'] = site_domain_results.account_name; // Generally useful for display
ae_loc_init['site_id'] = site_domain_results.site_id_random;
ae_loc_init['site_domain_id'] = site_domain_results.site_domain_id_random;
ae_loc_init['site_enable'] = site_domain_results.enable;

View File

@@ -21,11 +21,13 @@ import { api } from '$lib/api';
import { ae_loc, ae_sess, ae_api, slct, slct_trigger } from '$lib/ae_stores';
import { ae_util } from '$lib/ae_utils';
import type { key_val } from '$lib/ae_stores';
import { spons_func } from '$lib/ae_sponsorships_functions';
import Edit_modal_sponsorship_obj from './10_edit_modal__sponsorship_obj.svelte';
import List_sponsorship_obj from './10_list__sponsorship_obj.svelte';
import View_modal_sponsorship_obj from './10_view_modal__sponsorship_obj.svelte';
let ae_promises: key_val = {};
// Editing
const modalComponentEditSponsorshipObj: ModalComponent = { ref: Edit_modal_sponsorship_obj, props: {container_class_li: 'w-full p-4 space-y-4 card ae_modal_scrollfix'} };
@@ -392,32 +394,38 @@ async function handle_load_ae_obj_id__sponsorship({sponsorship_id, try_cache=fal
Start Sponsor Submission Form
</button>
<!-- <button
{#if $ae_loc.trusted_access}
<button
type="button"
on:click={() => {
console.log('Open drawer');
drawerStore.open(drawer_settings_x);
}}
>
Open Drawer X
</button> -->
if (!confirm('Download exported data Excel file?')) {
return false;
}
ae_promises.download__sponsorships_export = spons_func.handle_download_export__sponsorship({
api_cfg: $ae_api,
account_id: $slct.account_id,
file_type: 'Excel',
return_file: true,
filename: `lead_retrieval_export_${$ae_loc.account_code.replaceAll(' ', '_')}.xlsx`,
auto_download: true,
log_lvl: 2
});
<!-- <button
on:click={() => {
console.log('Open drawer');
drawerStore.open(drawer_settings_y);
}}
class="btn btn-sm variant-ghost-primary w-48 mb-1 export_data_btn"
title={`Download sponsorship data for ${$ae_loc.account_name}`}
>
Open Drawer Y
</button> -->
<!-- <button
on:click={() => {
console.log('Open drawer');
drawerStore.open(drawer_settings_edit);
}}
>
Open Drawer Edit
</button> -->
{#await ae_promises.download__sponsorship_export}
<span class="fas fa-spinner fa-spin"></span>
<!-- <span class="loading-text">
Downloading...
</span> -->
{:then}
<!-- Done? -->
{/await}
<span class="fas fa-download mx-1"></span> Export Data
</button>
{/if}
</section>
<section class="sponsorships_list ae_h_scrollfix">