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