- re enabled CSV export for super user;

This commit is contained in:
Vitalii Kiiko
2025-07-03 08:44:38 +02:00
parent 194ab25c7e
commit 70cb4c99e6
4 changed files with 84 additions and 17 deletions

View File

@@ -94,30 +94,65 @@ const AllBandiTableAsync = () => {
<Button severity="info" label={__('Mostra', 'gepafin')} icon="pi pi-eye" size="small" iconPos="right"/> <Button severity="info" label={__('Mostra', 'gepafin')} icon="pi pi-eye" size="small" iconPos="right"/>
</Link> </Link>
{['PUBLISH', 'EXPIRED'].includes(rowData.status) {['PUBLISH', 'EXPIRED'].includes(rowData.status)
? <Button type="button" ? <>
size="small" <Button type="button"
severity='info' size="small"
icon="pi pi-download" severity="info"
iconPos="right" icon="pi pi-download"
label={__('Scarica graduatoria', 'gepafin')} iconPos="right"
onClick={() => handleDownloadRanking(rowData.id)} label={__('Scarica graduatoria', 'gepafin')}
/> : null} onClick={() => handleDownloadRanking(rowData.id)}
/>
<Button type="button"
size="small"
icon="pi pi-receipt"
iconPos="right"
label={__('CSV', 'gepafin')}
onClick={() => exportToCSV(rowData.id)}/>
</>
: null}
</div> </div>
} }
const exportToCSV = (applicationId) => {
setLocalAsyncRequest(true);
ApplicationService.downloadCsvReport(
applicationId,
(resp) => getCsvReportback(resp, applicationId),
errCsvReportCallback
)
}
const getCsvReportback = (resp, applicationId) => {
const file = new Blob([resp], { type: 'text/csv' });
const url = window.URL.createObjectURL(file);
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', `call-${applicationId}-applications-report.csv`);
document.body.appendChild(link);
link.click();
link.remove();
setLocalAsyncRequest(false);
}
const errCsvReportCallback = (resp) => {
set404FromErrorResponse(resp);
setLocalAsyncRequest(false);
}
const handleDownloadRanking = (callId) => { const handleDownloadRanking = (callId) => {
setLocalAsyncRequest(true); setLocalAsyncRequest(true);
ApplicationService.downloadRanking(callId, ApplicationService.downloadRanking(callId,
(resp) => downloadSuccessCallback(resp, callId), (resp) => downloadSuccessCallback(resp, callId),
downloadErrorCallback) downloadErrorCallback)
} }
const downloadSuccessCallback = (resp, applicationId) => { const downloadSuccessCallback = (resp, applicationId) => {
const file = new Blob([resp], { type: 'text/csv' }); const file = new Blob([resp], { type: 'text/csv' });
const url = window.URL.createObjectURL(file); const url = window.URL.createObjectURL(file);
const link = document.createElement('a'); const link = document.createElement('a');
link.href = url; link.href = url;
link.setAttribute('download', `call-${applicationId}-applications-report.csv`); link.setAttribute('download', `call-${applicationId}-graduatoria.csv`);
document.body.appendChild(link); document.body.appendChild(link);
link.click(); link.click();
link.remove(); link.remove();

View File

@@ -75,7 +75,7 @@ const ElementSetting = ({ setting, changeFn, updateDataFn, bandoStatus }) => {
const invalidFormula = (value) => { const invalidFormula = (value) => {
try { try {
const context = getTokens(value) getTokens(value)
return false; return false;
} catch { } catch {
return __('Potrebbe essere un errore nella formula!') return __('Potrebbe essere un errore nella formula!')

View File

@@ -100,9 +100,41 @@ const LatestBandiTableAsync = () => {
iconPos="right" iconPos="right"
label={__('Scarica graduatoria', 'gepafin')} label={__('Scarica graduatoria', 'gepafin')}
onClick={() => handleDownloadRanking(rowData.id)}/> onClick={() => handleDownloadRanking(rowData.id)}/>
<Button type="button"
size="small"
icon="pi pi-receipt"
iconPos="right"
label={__('CSV', 'gepafin')}
onClick={() => exportToCSV(rowData.id)}/>
</div> </div>
} }
const exportToCSV = (applicationId) => {
setLocalAsyncRequest(true);
ApplicationService.downloadCsvReport(
applicationId,
(resp) => getCsvReportback(resp, applicationId),
errCsvReportCallback
)
}
const getCsvReportback = (resp, applicationId) => {
const file = new Blob([resp], { type: 'text/csv' });
const url = window.URL.createObjectURL(file);
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', `call-${applicationId}-applications-report.csv`);
document.body.appendChild(link);
link.click();
link.remove();
setLocalAsyncRequest(false);
}
const errCsvReportCallback = (resp) => {
set404FromErrorResponse(resp);
setLocalAsyncRequest(false);
}
const handleDownloadRanking = (callId) => { const handleDownloadRanking = (callId) => {
setLocalAsyncRequest(true); setLocalAsyncRequest(true);
ApplicationService.downloadRanking(callId, ApplicationService.downloadRanking(callId,
@@ -115,7 +147,7 @@ const LatestBandiTableAsync = () => {
const url = window.URL.createObjectURL(file); const url = window.URL.createObjectURL(file);
const link = document.createElement('a'); const link = document.createElement('a');
link.href = url; link.href = url;
link.setAttribute('download', `call-${applicationId}-applications-report.csv`); link.setAttribute('download', `call-${applicationId}-graduatoria.csv`);
document.body.appendChild(link); document.body.appendChild(link);
link.click(); link.click();
link.remove(); link.remove();

View File

@@ -149,7 +149,7 @@ const LatestBandiTableInstructorManagerAsync = () => {
const url = window.URL.createObjectURL(file); const url = window.URL.createObjectURL(file);
const link = document.createElement('a'); const link = document.createElement('a');
link.href = url; link.href = url;
link.setAttribute('download', `call-${applicationId}-applications-report.csv`); link.setAttribute('download', `call-${applicationId}-graduatoria.csv`);
document.body.appendChild(link); document.body.appendChild(link);
link.click(); link.click();
link.remove(); link.remove();