Now with upload and download percent! Also better editing for session POC.
This commit is contained in:
@@ -355,33 +355,35 @@ async function handle_update_ae_obj_id_crud(
|
||||
|
||||
async function handle_download_export__obj_type(
|
||||
{
|
||||
api_cfg,
|
||||
get_obj_type, // The type of object to return: event_badge, event_presenter, sponsorship, etc.
|
||||
for_obj_type, // Usually for an account, event, event_exhibit, or sponsorship_cfg
|
||||
for_obj_id, // The ID of the object
|
||||
file_type='CSV', // 'CSV' or 'Excel'
|
||||
return_file=true,
|
||||
filename='no_filename.csv',
|
||||
auto_download=false,
|
||||
limit=5000,
|
||||
params={}, // key value object is expected
|
||||
log_lvl=0
|
||||
api_cfg,
|
||||
get_obj_type, // The type of object to return: event_badge, event_presenter, sponsorship, etc.
|
||||
for_obj_type, // Usually for an account, event, event_exhibit, or sponsorship_cfg
|
||||
for_obj_id, // The ID of the object
|
||||
file_type='CSV', // 'CSV' or 'Excel'
|
||||
return_file=true,
|
||||
filename='no_filename.csv',
|
||||
auto_download=false,
|
||||
limit=5000,
|
||||
params={}, // key value object is expected
|
||||
log_lvl=0
|
||||
} : {
|
||||
api_cfg: any,
|
||||
get_obj_type: string,
|
||||
for_obj_type: string,
|
||||
for_obj_id: string,
|
||||
file_type?: string,
|
||||
return_file?: boolean,
|
||||
filename?: string,
|
||||
auto_download?: boolean,
|
||||
limit?: number,
|
||||
params?: key_val,
|
||||
log_lvl?: number
|
||||
api_cfg: any,
|
||||
get_obj_type: string,
|
||||
for_obj_type: string,
|
||||
for_obj_id: string,
|
||||
file_type?: string,
|
||||
return_file?: boolean,
|
||||
filename?: string,
|
||||
auto_download?: boolean,
|
||||
limit?: number,
|
||||
params?: key_val,
|
||||
log_lvl?: number
|
||||
}
|
||||
) {
|
||||
console.log('*** ae_core_functions.js: handle_download_export__obj_type() ***');
|
||||
|
||||
let task_id = for_obj_id;
|
||||
|
||||
const endpoint = `/v2/crud/${get_obj_type}/list`;
|
||||
params['for_obj_type'] = for_obj_type;
|
||||
params['for_obj_id'] = for_obj_id;
|
||||
@@ -402,7 +404,16 @@ async function handle_download_export__obj_type(
|
||||
params['limit'] = limit;
|
||||
}
|
||||
|
||||
ae_promises.download__sponsorship_export_file = await api.get_object({api_cfg: api_cfg, endpoint: endpoint, params: params, return_blob: return_file, filename: clean_filename, auto_download: auto_download, log_lvl: log_lvl});
|
||||
ae_promises.download__sponsorship_export_file = await api.get_object({
|
||||
api_cfg: api_cfg,
|
||||
endpoint: endpoint,
|
||||
params: params,
|
||||
return_blob: return_file,
|
||||
filename: clean_filename,
|
||||
auto_download: auto_download,
|
||||
task_id: task_id,
|
||||
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;
|
||||
|
||||
@@ -198,7 +198,10 @@ export let ae_app_session_data_struct: key_val = {
|
||||
},
|
||||
|
||||
'download': {},
|
||||
'download_li': {},
|
||||
// For API download and upload progress status per file.
|
||||
'api_download_kv': {},
|
||||
// Example: {example_file_id: {status: 'downloading', endpoint: '/event/file/abc123/download', filename: 'example_file_name.ext', size_total: 0, size_loaded: 0, percent_completed: 0}}
|
||||
'api_upload_kv': {}, // {example_temp_id: {status: 'uploading', endpoint: '/event/file/abc123/upload', filename: 'example_file_name.ext', size_total: 0, size_loaded: 0, percent_completed: 0}}
|
||||
};
|
||||
// console.log(`AE Stores - App Session Storage Data:`, ae_app_session_data_struct);
|
||||
export let ae_sess = writable(ae_app_session_data_struct);
|
||||
|
||||
@@ -841,13 +841,24 @@ export let download_hosted_file = async function download_hosted_file({
|
||||
}) {
|
||||
console.log('*** stores_hosted_api.js: download_hosted_file() ***');
|
||||
|
||||
let task_id = hosted_file_id;
|
||||
|
||||
const endpoint = `/hosted_file/${hosted_file_id}/download`;
|
||||
if (filename) {
|
||||
params['filename'] = filename;
|
||||
}
|
||||
params['return_file'] = true;
|
||||
|
||||
let hosted_file_download_get_promise = await api.get_object({api_cfg: api_cfg, endpoint: endpoint, params: params, return_blob: true, filename: filename, auto_download: auto_download, log_lvl: log_lvl});
|
||||
let hosted_file_download_get_promise = await api.get_object({
|
||||
api_cfg: api_cfg,
|
||||
endpoint: endpoint,
|
||||
params: params,
|
||||
return_blob: true,
|
||||
filename: filename,
|
||||
auto_download: auto_download,
|
||||
task_id: task_id,
|
||||
log_lvl: log_lvl
|
||||
});
|
||||
// console.log(hosted_file_download_get_promise);
|
||||
return hosted_file_download_get_promise;
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ export let get_object = async function get_object(
|
||||
timeout?: number,
|
||||
return_meta?: boolean,
|
||||
return_blob?: boolean,
|
||||
filename?: string,
|
||||
filename?: null|string,
|
||||
auto_download?: boolean,
|
||||
as_list?: boolean,
|
||||
task_id?: string,
|
||||
@@ -119,9 +119,27 @@ export let get_object = async function get_object(
|
||||
let percent_completed = Math.round(
|
||||
(progressEvent.loaded * 100) / progressEvent.total
|
||||
);
|
||||
// console.log('GET Data Timestamp:', progressEvent.timeStamp, 'Total:', progressEvent.total, 'Loaded:', progressEvent.loaded, 'Percent Completed', percent_completed);
|
||||
console.log('GET Data Progress:', progressEvent.progress, 'Total:', progressEvent.total, 'Loaded:', progressEvent.loaded, 'Percent Completed', percent_completed);
|
||||
|
||||
temp_get_object_percent_completed = percent_completed;
|
||||
|
||||
// WARNING: This needs to be tied to an object type and ID. This is a temporary solution.
|
||||
try {
|
||||
window.postMessage({
|
||||
type: 'api_download_data',
|
||||
status: 'downloading',
|
||||
task_id: task_id,
|
||||
endpoint: endpoint,
|
||||
filename: filename,
|
||||
size_total: progressEvent.total,
|
||||
size_loaded: progressEvent.loaded,
|
||||
percent_completed: percent_completed,
|
||||
},
|
||||
'*'
|
||||
);
|
||||
} catch (error) {
|
||||
console.log('Error posting message to window:', error);
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
@@ -132,6 +150,25 @@ export let get_object = async function get_object(
|
||||
if (log_lvl > 1) {
|
||||
console.log('GET Response:', response);
|
||||
}
|
||||
|
||||
// Post file download message
|
||||
try {
|
||||
window.postMessage({
|
||||
type: 'api_download_data',
|
||||
status: 'complete',
|
||||
task_id: task_id,
|
||||
endpoint: endpoint,
|
||||
filename: filename,
|
||||
size_total: 0,
|
||||
size_loaded: 0,
|
||||
percent_completed: 100,
|
||||
},
|
||||
'*'
|
||||
);
|
||||
} catch (error) {
|
||||
console.log('Error posting message to window:', error);
|
||||
}
|
||||
|
||||
if (!Array.isArray(response.data['data']) && as_list) {
|
||||
if (log_lvl) {
|
||||
console.log('Data result is a dictionary/object, not an array/list. Forcing return as an array/list');
|
||||
@@ -252,11 +289,13 @@ export let get_object = async function get_object(
|
||||
try {
|
||||
window.postMessage({
|
||||
type: 'api_download_blob',
|
||||
status: 'downloading',
|
||||
task_id: task_id,
|
||||
endpoint: endpoint,
|
||||
filename: filename,
|
||||
size_total: progressEvent.total,
|
||||
size_loaded: progressEvent.loaded,
|
||||
percent_completed: percent_completed
|
||||
percent_completed: percent_completed,
|
||||
},
|
||||
'*'
|
||||
);
|
||||
@@ -287,7 +326,14 @@ export let get_object = async function get_object(
|
||||
// WARNING: This needs to be tied to an object type and ID. This is a temporary solution.
|
||||
try {
|
||||
window.postMessage({
|
||||
type: 'api_download_blob', endpoint: endpoint, filename: filename, size_total: 0, size_loaded: 0, percent_completed: 100
|
||||
type: 'api_download_blob',
|
||||
status: 'complete',
|
||||
task_id: task_id,
|
||||
endpoint: endpoint,
|
||||
filename: filename,
|
||||
size_total: 0,
|
||||
size_loaded: 0,
|
||||
percent_completed: 100,
|
||||
},
|
||||
'*'
|
||||
);
|
||||
|
||||
@@ -87,6 +87,8 @@ export let post_object = async function post_object(
|
||||
try {
|
||||
window.postMessage({
|
||||
type: 'api_post_json_form',
|
||||
status: 'uploading',
|
||||
task_id: task_id,
|
||||
endpoint: endpoint,
|
||||
size_total: progressEvent.total,
|
||||
size_loaded: progressEvent.loaded,
|
||||
@@ -104,6 +106,24 @@ export let post_object = async function post_object(
|
||||
)
|
||||
.then(function (response) {
|
||||
console.log('POST Response Data:', response.data);
|
||||
try {
|
||||
window.postMessage({
|
||||
type: 'api_post_json_form',
|
||||
status: 'complete',
|
||||
task_id: task_id,
|
||||
endpoint: endpoint,
|
||||
size_total: 0,
|
||||
size_loaded: 0,
|
||||
percent_completed: 100,
|
||||
progress: 100,
|
||||
rate: 0,
|
||||
},
|
||||
'*'
|
||||
);
|
||||
} catch (error) {
|
||||
console.log('Error posting message to window:', error);
|
||||
}
|
||||
|
||||
if (response.data['data'].result === null) {
|
||||
// This should mean that the request was successful, but a result of None/null was returned from Aether API.
|
||||
// console.log('Returning null after POST');
|
||||
|
||||
Reference in New Issue
Block a user