- added btn 'csv report';
This commit is contained in:
@@ -6,6 +6,7 @@ import translationStrings from '../../../../translationStringsForComponents';
|
|||||||
|
|
||||||
// api
|
// api
|
||||||
import BandoService from '../../../../service/bando-service';
|
import BandoService from '../../../../service/bando-service';
|
||||||
|
import ApplicationService from '../../../../service/application-service';
|
||||||
|
|
||||||
// tools
|
// tools
|
||||||
import getTimeParsedFromString from '../../../../helpers/getTimeParsedFromString';
|
import getTimeParsedFromString from '../../../../helpers/getTimeParsedFromString';
|
||||||
@@ -14,6 +15,7 @@ import getFormattedDateString from '../../../../helpers/getFormattedDateString';
|
|||||||
import getBandoLabel from '../../../../helpers/getBandoLabel';
|
import getBandoLabel from '../../../../helpers/getBandoLabel';
|
||||||
import getBandoSeverity from '../../../../helpers/getBandoSeverity';
|
import getBandoSeverity from '../../../../helpers/getBandoSeverity';
|
||||||
import getQueryParamsForPaginatedEndpoint from '../../../../helpers/getQueryParamsForPaginatedEndpoint';
|
import getQueryParamsForPaginatedEndpoint from '../../../../helpers/getQueryParamsForPaginatedEndpoint';
|
||||||
|
import set404FromErrorResponse from '../../../../helpers/set404FromErrorResponse';
|
||||||
|
|
||||||
// components
|
// components
|
||||||
import { DataTable } from 'primereact/datatable';
|
import { DataTable } from 'primereact/datatable';
|
||||||
@@ -41,7 +43,7 @@ const AllBandiTableAsync = () => {
|
|||||||
status: { value: null, matchMode: 'equals' }
|
status: { value: null, matchMode: 'equals' }
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const statuses = ['DRAFT','PUBLISH','EXPIRED'];
|
const statuses = ['DRAFT', 'PUBLISH', 'EXPIRED'];
|
||||||
|
|
||||||
const getPaginationQuery = useCallback(() => getQueryParamsForPaginatedEndpoint(lazyState, statuses, 'id'), [lazyState]);
|
const getPaginationQuery = useCallback(() => getQueryParamsForPaginatedEndpoint(lazyState, statuses, 'id'), [lazyState]);
|
||||||
|
|
||||||
@@ -63,7 +65,8 @@ const AllBandiTableAsync = () => {
|
|||||||
|
|
||||||
const getCallback = (resp) => {
|
const getCallback = (resp) => {
|
||||||
if (resp.status === 'SUCCESS') {
|
if (resp.status === 'SUCCESS') {
|
||||||
const { body, totalRecords,
|
const {
|
||||||
|
body, totalRecords,
|
||||||
//currentPage, totalPages, pageSize
|
//currentPage, totalPages, pageSize
|
||||||
} = resp.data;
|
} = resp.data;
|
||||||
setTotalRecordsNum(totalRecords);
|
setTotalRecordsNum(totalRecords);
|
||||||
@@ -86,9 +89,44 @@ const AllBandiTableAsync = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const actionsBodyTemplate = (rowData) => {
|
const actionsBodyTemplate = (rowData) => {
|
||||||
return <Link to={`/bandi/${rowData.id}`}>
|
return <div className="appPageSection__tableActions">
|
||||||
<Button severity="info" label={__('Mostra', 'gepafin')} icon="pi pi-eye" size="small" iconPos="right" />
|
<Link to={`/bandi/${rowData.id}`}>
|
||||||
</Link>
|
<Button severity="info" label={__('Mostra', 'gepafin')} icon="pi pi-eye" size="small" iconPos="right"/>
|
||||||
|
</Link>
|
||||||
|
{['PUBLISH', 'EXPIRED'].includes(rowData.status)
|
||||||
|
? <Button type="button"
|
||||||
|
size="small"
|
||||||
|
icon="pi pi-receipt"
|
||||||
|
iconPos="right"
|
||||||
|
label={__('CSV', 'gepafin')}
|
||||||
|
onClick={() => exportToCSV(rowData.id)}/> : null}
|
||||||
|
</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 statusBodyTemplate = (rowData) => {
|
const statusBodyTemplate = (rowData) => {
|
||||||
@@ -111,7 +149,8 @@ const AllBandiTableAsync = () => {
|
|||||||
}
|
}
|
||||||
setLazyState({ ...lazyState, filters, first: 0 });
|
setLazyState({ ...lazyState, filters, first: 0 });
|
||||||
}}
|
}}
|
||||||
itemTemplate={statusItemTemplate} placeholder={translationStrings.selectOneLabel} className="p-column-filter"/>;
|
itemTemplate={statusItemTemplate} placeholder={translationStrings.selectOneLabel}
|
||||||
|
className="p-column-filter"/>;
|
||||||
};
|
};
|
||||||
|
|
||||||
const dateFilterTemplate = (options) => {
|
const dateFilterTemplate = (options) => {
|
||||||
@@ -126,7 +165,7 @@ const AllBandiTableAsync = () => {
|
|||||||
|
|
||||||
const dateEndBodyTemplate = (rowData) => {
|
const dateEndBodyTemplate = (rowData) => {
|
||||||
const endTimeObg = getTimeParsedFromString(rowData.endTime);
|
const endTimeObg = getTimeParsedFromString(rowData.endTime);
|
||||||
return getFormattedDateString(rowData.endDate) + ' ' + getTimeFromISOstring(endTimeObg);
|
return getFormattedDateString(rowData.endDate) + ' ' + getTimeFromISOstring(endTimeObg);
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -169,7 +208,7 @@ const AllBandiTableAsync = () => {
|
|||||||
filterMatchModeOptions={translationStrings.statusFilterOptions}
|
filterMatchModeOptions={translationStrings.statusFilterOptions}
|
||||||
header={__('Stato', 'gepafin')}
|
header={__('Stato', 'gepafin')}
|
||||||
style={{ minWidth: '7rem' }}
|
style={{ minWidth: '7rem' }}
|
||||||
body={statusBodyTemplate} />
|
body={statusBodyTemplate}/>
|
||||||
<Column header={__('Azioni', 'gepafin')}
|
<Column header={__('Azioni', 'gepafin')}
|
||||||
body={actionsBodyTemplate}/>
|
body={actionsBodyTemplate}/>
|
||||||
</DataTable>
|
</DataTable>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import React, { useCallback, useEffect, useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import { __ } from '@wordpress/i18n';
|
import { __ } from '@wordpress/i18n';
|
||||||
import { head, is, isEmpty, isNil, uniq } from 'ramda';
|
import { head, is, isEmpty, isNil, uniq } from 'ramda';
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import { Accordion, AccordionTab } from 'primereact/accordion';
|
|||||||
// tools
|
// tools
|
||||||
import uniqid from '../../../../../../helpers/uniqid';
|
import uniqid from '../../../../../../helpers/uniqid';
|
||||||
import removeKey from '../../../../../../helpers/removeKey';
|
import removeKey from '../../../../../../helpers/removeKey';
|
||||||
import { klona } from 'klona';
|
|
||||||
|
|
||||||
const ElementSettingTableColumns = ({
|
const ElementSettingTableColumns = ({
|
||||||
value,
|
value,
|
||||||
|
|||||||
@@ -25,11 +25,11 @@ const ElementSettingTableColumnsForCsv = ({ name, setDataFn }) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const setChecked = (value, index) => {
|
const setChecked = (value, index) => {
|
||||||
let name = '';
|
//let name = '';
|
||||||
const newData = stateFieldData.map((o, i) => {
|
const newData = stateFieldData.map((o, i) => {
|
||||||
if (i === index) {
|
if (i === index) {
|
||||||
o.enableCsv = value;
|
o.enableCsv = value;
|
||||||
name = o.name;
|
//name = o.name;
|
||||||
}
|
}
|
||||||
return o;
|
return o;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import translationStrings from '../../../../translationStringsForComponents';
|
|||||||
|
|
||||||
// api
|
// api
|
||||||
import BandoService from '../../../../service/bando-service';
|
import BandoService from '../../../../service/bando-service';
|
||||||
|
import ApplicationService from '../../../../service/application-service';
|
||||||
|
|
||||||
// tools
|
// tools
|
||||||
import getTimeParsedFromString from '../../../../helpers/getTimeParsedFromString';
|
import getTimeParsedFromString from '../../../../helpers/getTimeParsedFromString';
|
||||||
@@ -14,6 +15,7 @@ import getFormattedDateString from '../../../../helpers/getFormattedDateString';
|
|||||||
import getBandoLabel from '../../../../helpers/getBandoLabel';
|
import getBandoLabel from '../../../../helpers/getBandoLabel';
|
||||||
import getBandoSeverity from '../../../../helpers/getBandoSeverity';
|
import getBandoSeverity from '../../../../helpers/getBandoSeverity';
|
||||||
import getQueryParamsForPaginatedEndpoint from '../../../../helpers/getQueryParamsForPaginatedEndpoint';
|
import getQueryParamsForPaginatedEndpoint from '../../../../helpers/getQueryParamsForPaginatedEndpoint';
|
||||||
|
import set404FromErrorResponse from '../../../../helpers/set404FromErrorResponse';
|
||||||
|
|
||||||
// components
|
// components
|
||||||
import { DataTable } from 'primereact/datatable';
|
import { DataTable } from 'primereact/datatable';
|
||||||
@@ -41,7 +43,7 @@ const LatestBandiTableAsync = () => {
|
|||||||
status: { value: null, matchMode: 'equals' }
|
status: { value: null, matchMode: 'equals' }
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const statuses = ['PUBLISH'];
|
const statuses = ['PUBLISH', 'EXPIRED'];
|
||||||
|
|
||||||
const getPaginationQuery = useCallback(() => getQueryParamsForPaginatedEndpoint(lazyState, statuses, 'id'), [lazyState]);
|
const getPaginationQuery = useCallback(() => getQueryParamsForPaginatedEndpoint(lazyState, statuses, 'id'), [lazyState]);
|
||||||
|
|
||||||
@@ -86,9 +88,44 @@ const LatestBandiTableAsync = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const actionsBodyTemplate = (rowData) => {
|
const actionsBodyTemplate = (rowData) => {
|
||||||
return <Link to={`/bandi/${rowData.id}`}>
|
return <div className="appPageSection__tableActions">
|
||||||
<Button severity="info" label={__('Modifica', 'gepafin')} icon="pi pi-pencil" size="small" iconPos="right" />
|
<Link to={`/bandi/${rowData.id}`}>
|
||||||
</Link>
|
<Button severity="info" label={__('Modifica', 'gepafin')} icon="pi pi-pencil" size="small"
|
||||||
|
iconPos="right"/>
|
||||||
|
</Link>
|
||||||
|
<Button type="button"
|
||||||
|
size="small"
|
||||||
|
icon="pi pi-receipt"
|
||||||
|
iconPos="right"
|
||||||
|
label={__('CSV', 'gepafin')}
|
||||||
|
onClick={() => exportToCSV(rowData.id)}/>
|
||||||
|
</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 statusBodyTemplate = (rowData) => {
|
const statusBodyTemplate = (rowData) => {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import translationStrings from '../../../../translationStringsForComponents';
|
|||||||
|
|
||||||
// api
|
// api
|
||||||
import BandoService from '../../../../service/bando-service';
|
import BandoService from '../../../../service/bando-service';
|
||||||
|
import ApplicationService from '../../../../service/application-service';
|
||||||
|
|
||||||
// tools
|
// tools
|
||||||
import getTimeParsedFromString from '../../../../helpers/getTimeParsedFromString';
|
import getTimeParsedFromString from '../../../../helpers/getTimeParsedFromString';
|
||||||
@@ -13,6 +14,7 @@ import getFormattedDateString from '../../../../helpers/getFormattedDateString';
|
|||||||
import getBandoLabel from '../../../../helpers/getBandoLabel';
|
import getBandoLabel from '../../../../helpers/getBandoLabel';
|
||||||
import getBandoSeverity from '../../../../helpers/getBandoSeverity';
|
import getBandoSeverity from '../../../../helpers/getBandoSeverity';
|
||||||
import getQueryParamsForPaginatedEndpoint from '../../../../helpers/getQueryParamsForPaginatedEndpoint';
|
import getQueryParamsForPaginatedEndpoint from '../../../../helpers/getQueryParamsForPaginatedEndpoint';
|
||||||
|
import set404FromErrorResponse from '../../../../helpers/set404FromErrorResponse';
|
||||||
|
|
||||||
// components
|
// components
|
||||||
import { DataTable } from 'primereact/datatable';
|
import { DataTable } from 'primereact/datatable';
|
||||||
@@ -21,6 +23,7 @@ import ProperBandoLabel from '../../../../components/ProperBandoLabel';
|
|||||||
import { Dropdown } from 'primereact/dropdown';
|
import { Dropdown } from 'primereact/dropdown';
|
||||||
import { Tag } from 'primereact/tag';
|
import { Tag } from 'primereact/tag';
|
||||||
import { Calendar } from 'primereact/calendar';
|
import { Calendar } from 'primereact/calendar';
|
||||||
|
import { Button } from 'primereact/button';
|
||||||
|
|
||||||
const LatestBandiTableInstructorManagerAsync = () => {
|
const LatestBandiTableInstructorManagerAsync = () => {
|
||||||
const [localAsyncRequest, setLocalAsyncRequest] = useState(false);
|
const [localAsyncRequest, setLocalAsyncRequest] = useState(false);
|
||||||
@@ -39,7 +42,7 @@ const LatestBandiTableInstructorManagerAsync = () => {
|
|||||||
status: { value: null, matchMode: 'equals' }
|
status: { value: null, matchMode: 'equals' }
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const statuses = ['PUBLISH'];
|
const statuses = ['PUBLISH', 'EXPIRED'];
|
||||||
|
|
||||||
const getPaginationQuery = useCallback(() => getQueryParamsForPaginatedEndpoint(lazyState, statuses, 'id'), [lazyState]);
|
const getPaginationQuery = useCallback(() => getQueryParamsForPaginatedEndpoint(lazyState, statuses, 'id'), [lazyState]);
|
||||||
|
|
||||||
@@ -121,6 +124,43 @@ const LatestBandiTableInstructorManagerAsync = () => {
|
|||||||
return getFormattedDateString(rowData.endDate) + ' ' + getTimeFromISOstring(endTimeObg);
|
return getFormattedDateString(rowData.endDate) + ' ' + getTimeFromISOstring(endTimeObg);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const actionsBodyTemplate = (rowData) => {
|
||||||
|
return <div className="appPageSection__tableActions">
|
||||||
|
<Button type="button"
|
||||||
|
size="small"
|
||||||
|
icon="pi pi-receipt"
|
||||||
|
iconPos="right"
|
||||||
|
label={__('CSV', 'gepafin')}
|
||||||
|
onClick={() => exportToCSV(rowData.id)}/>
|
||||||
|
</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);
|
||||||
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setLocalAsyncRequest(true);
|
setLocalAsyncRequest(true);
|
||||||
const paginationQuery = getPaginationQuery();
|
const paginationQuery = getPaginationQuery();
|
||||||
@@ -162,6 +202,8 @@ const LatestBandiTableInstructorManagerAsync = () => {
|
|||||||
header={__('Stato', 'gepafin')}
|
header={__('Stato', 'gepafin')}
|
||||||
style={{ minWidth: '7rem' }}
|
style={{ minWidth: '7rem' }}
|
||||||
body={statusBodyTemplate} />
|
body={statusBodyTemplate} />
|
||||||
|
<Column header={__('Azioni', 'gepafin')}
|
||||||
|
body={actionsBodyTemplate}/>
|
||||||
</DataTable>
|
</DataTable>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -59,4 +59,8 @@ export default class ApplicationService {
|
|||||||
static downloadCompleteZip = (id, callback, errCallback, queryParams) => {
|
static downloadCompleteZip = (id, callback, errCallback, queryParams) => {
|
||||||
NetworkService.getBlob(`${API_BASE_URL}/application/${id}/documents/zip`, callback, errCallback, queryParams);
|
NetworkService.getBlob(`${API_BASE_URL}/application/${id}/documents/zip`, callback, errCallback, queryParams);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static downloadCsvReport = (id, callback, errCallback, queryParams) => {
|
||||||
|
NetworkService.getBlob(`${API_BASE_URL}/application/call/${id}/csv`, callback, errCallback, queryParams);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user