Merge pull request #54 from Kitzanos/master-sync-02-07-2025

Master sync 02 07 2025
This commit is contained in:
Vitalii Kiiko
2025-07-02 12:18:18 +02:00
committed by GitHub
9 changed files with 94 additions and 51 deletions

View File

@@ -45,10 +45,11 @@ const AllBandiPreInstructorTableAsync = () => {
} }
}); });
const statuses = ['DRAFT', 'PUBLISH', 'EXPIRED']; const statuses = ['DRAFT', 'PUBLISH', 'EXPIRED'];
const initialFetchStatuses = ['PUBLISH', 'EXPIRED'];
const role = storeGet('getRole') const role = storeGet('getRole')
const getPaginationQuery = useCallback(() => getQueryParamsForPaginatedEndpoint(lazyState, statuses, 'id'), [lazyState]); const getPaginationQuery = useCallback(() => getQueryParamsForPaginatedEndpoint(lazyState, initialFetchStatuses, 'id'), [lazyState]);
const onPage = (event) => { const onPage = (event) => {
setLazyState(event); setLazyState(event);
@@ -174,7 +175,7 @@ const AllBandiPreInstructorTableAsync = () => {
const paginationQuery = getPaginationQuery(); const paginationQuery = getPaginationQuery();
BandoService.getBandiPaginated(paginationQuery, getCallback, errGetCallbacks); BandoService.getBandiPaginated(paginationQuery, getCallback, errGetCallbacks);
}, [lazyState]); }, [lazyState, getPaginationQuery]);
return ( return (
<div className="appPageSection__table"> <div className="appPageSection__table">

View File

@@ -574,12 +574,17 @@ const BandoApplication = () => {
const formula = head(o.settings.filter(o => o.name === 'formula')); const formula = head(o.settings.filter(o => o.name === 'formula'));
if (formula && !isEmpty(formula.value)) { if (formula && !isEmpty(formula.value)) {
context = getTokens(formula.value) try {
.filter(v => !['false', 'null', 'true'].includes(v)) context = getTokens(formula.value)
.reduce((acc, cur) => { .filter(v => !['false', 'null', 'true'].includes(v))
acc[cur] = isNil(context[cur]) ? 0 : parseCommaDecimal(context[cur]); .reduce((acc, cur) => {
return acc; acc[cur] = isNil(context[cur]) ? 0 : parseCommaDecimal(context[cur]);
}, context); return acc;
}, context);
} catch {
console.error('Error in formula', formula)
context = {}
}
const mathFormula = renderWithDataVars(formula.value, context); const mathFormula = renderWithDataVars(formula.value, context);
try { try {

View File

@@ -288,12 +288,17 @@ const BandoApplicationPreview = () => {
const formula = head(o.settings.filter(o => o.name === 'formula')); const formula = head(o.settings.filter(o => o.name === 'formula'));
if (formula && !isEmpty(formula.value)) { if (formula && !isEmpty(formula.value)) {
context = getTokens(formula.value) try {
.filter(v => !['false', 'null', 'true'].includes(v)) context = getTokens(formula.value)
.reduce((acc, cur) => { .filter(v => !['false', 'null', 'true'].includes(v))
acc[cur] = isNil(context[cur]) ? 0 : parseCommaDecimal(context[cur]); .reduce((acc, cur) => {
return acc; acc[cur] = isNil(context[cur]) ? 0 : parseCommaDecimal(context[cur]);
}, context); return acc;
}, context);
} catch {
console.error('Error in formula', formula)
context = {}
}
const mathFormula = renderWithDataVars(formula.value, context); const mathFormula = renderWithDataVars(formula.value, context);
try { try {
updatedFormValues[o.id] = evaluate(mathFormula); updatedFormValues[o.id] = evaluate(mathFormula);

View File

@@ -22,6 +22,7 @@ import ElementSettingTableColumnsForCsv from '../ElementSettingTableColumnsForCs
import { mimeTypes } from '../../../../../../configData'; import { mimeTypes } from '../../../../../../configData';
import ElementSettingReportHeader from '../ElementSettingReportHeader'; import ElementSettingReportHeader from '../ElementSettingReportHeader';
import ElementSettingReportEnable from '../ElementSettingReportEnable'; import ElementSettingReportEnable from '../ElementSettingReportEnable';
import getTokens from '../../../../../../helpers/getTokens';
const ElementSetting = ({ setting, changeFn, updateDataFn, bandoStatus }) => { const ElementSetting = ({ setting, changeFn, updateDataFn, bandoStatus }) => {
@@ -72,6 +73,15 @@ const ElementSetting = ({ setting, changeFn, updateDataFn, bandoStatus }) => {
const header = renderHeader(); const header = renderHeader();
const invalidFormula = (value) => {
try {
const context = getTokens(value)
return false;
} catch {
return __('Potrebbe essere un errore nella formula!')
}
}
const getProperField = (setting) => { const getProperField = (setting) => {
if (setting.name === 'options') { if (setting.name === 'options') {
return <ElementSettingRepeater return <ElementSettingRepeater
@@ -145,6 +155,14 @@ const ElementSetting = ({ setting, changeFn, updateDataFn, bandoStatus }) => {
name={setting.name} name={setting.name}
bandoStatus={bandoStatus} bandoStatus={bandoStatus}
setDataFn={updateDataFn}/> setDataFn={updateDataFn}/>
} else if (setting.name === 'formula') {
const isInvalid = invalidFormula(setting.value);
return <>
<InputText id={setting.name} aria-describedby={`${setting.name}-help`}
value={setting.value}
onChange={(e) => changeFn(e.target.value, setting.name)}/>
<p style={{margiTop: 0, fontSize: '14px', color: '#df3636'}}>{isInvalid}</p>
</>
} else { } else {
return <InputText id={setting.name} aria-describedby={`${setting.name}-help`} return <InputText id={setting.name} aria-describedby={`${setting.name}-help`}
value={setting.value} value={setting.value}

View File

@@ -103,12 +103,17 @@ const BandoFormsPreview = () => {
const formula = head(o.settings.filter(o => o.name === 'formula')); const formula = head(o.settings.filter(o => o.name === 'formula'));
if (formula && !isEmpty(formula.value)) { if (formula && !isEmpty(formula.value)) {
context = getTokens(formula.value) try {
.filter(v => !['false', 'null', 'true'].includes(v)) context = getTokens(formula.value)
.reduce((acc, cur) => { .filter(v => !['false', 'null', 'true'].includes(v))
acc[cur] = isNil(context[cur]) ? 0 : parseCommaDecimal(context[cur]); .reduce((acc, cur) => {
return acc; acc[cur] = isNil(context[cur]) ? 0 : parseCommaDecimal(context[cur]);
}, context); return acc;
}, context);
} catch {
console.error('Error in formula', formula)
context = {}
}
const mathFormula = renderWithDataVars(formula.value, context); const mathFormula = renderWithDataVars(formula.value, context);
try { try {
updatedFormValues[o.id] = evaluate(mathFormula); updatedFormValues[o.id] = evaluate(mathFormula);

View File

@@ -40,10 +40,10 @@ const LatestBandiTableAsync = () => {
name: { value: null, matchMode: 'contains' }, name: { value: null, matchMode: 'contains' },
startDate: { value: null, matchMode: 'dateIs' }, startDate: { value: null, matchMode: 'dateIs' },
endDate: { value: null, matchMode: 'dateIs' }, endDate: { value: null, matchMode: 'dateIs' },
status: { value: null, matchMode: 'equals' } status: { value: 'PUBLISH', matchMode: 'equals' }
} }
}); });
const statuses = ['PUBLISH', 'EXPIRED']; const statuses = ['PUBLISH'];
const getPaginationQuery = useCallback(() => getQueryParamsForPaginatedEndpoint(lazyState, statuses, 'id'), [lazyState]); const getPaginationQuery = useCallback(() => getQueryParamsForPaginatedEndpoint(lazyState, statuses, 'id'), [lazyState]);
@@ -197,7 +197,7 @@ const LatestBandiTableAsync = () => {
const paginationQuery = getPaginationQuery(); const paginationQuery = getPaginationQuery();
BandoService.getBandiPaginated(paginationQuery, getCallback, errGetCallbacks); BandoService.getBandiPaginated(paginationQuery, getCallback, errGetCallbacks);
}, [lazyState]); }, [lazyState, getPaginationQuery]);
return ( return (
<div className="appPageSection__table"> <div className="appPageSection__table">

View File

@@ -39,10 +39,10 @@ const LatestBandiTableInstructorManagerAsync = () => {
name: { value: null, matchMode: 'contains' }, name: { value: null, matchMode: 'contains' },
startDate: { value: null, matchMode: 'dateIs' }, startDate: { value: null, matchMode: 'dateIs' },
endDate: { value: null, matchMode: 'dateIs' }, endDate: { value: null, matchMode: 'dateIs' },
status: { value: null, matchMode: 'equals' } status: { value: 'PUBLISH', matchMode: 'equals' }
} }
}); });
const statuses = ['PUBLISH', 'EXPIRED']; const statuses = ['PUBLISH'];
const getPaginationQuery = useCallback(() => getQueryParamsForPaginatedEndpoint(lazyState, statuses, 'id'), [lazyState]); const getPaginationQuery = useCallback(() => getQueryParamsForPaginatedEndpoint(lazyState, statuses, 'id'), [lazyState]);
@@ -128,23 +128,23 @@ const LatestBandiTableInstructorManagerAsync = () => {
return <div className="appPageSection__tableActions"> return <div className="appPageSection__tableActions">
<Button type="button" <Button type="button"
size="small" size="small"
icon="pi pi-receipt" severity="info"
icon="pi pi-download"
iconPos="right" iconPos="right"
label={__('CSV', 'gepafin')} label={__('Scarica graduatoria', 'gepafin')}
onClick={() => exportToCSV(rowData.id)}/> onClick={() => handleDownloadRanking(rowData.id)}
/>
</div> </div>
} }
const exportToCSV = (applicationId) => { const handleDownloadRanking = (callId) => {
setLocalAsyncRequest(true); setLocalAsyncRequest(true);
ApplicationService.downloadCsvReport( ApplicationService.downloadRanking(callId,
applicationId, (resp) => downloadSuccessCallback(resp, callId),
(resp) => getCsvReportback(resp, applicationId), downloadErrorCallback)
errCsvReportCallback
)
} }
const getCsvReportback = (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');
@@ -156,7 +156,7 @@ const LatestBandiTableInstructorManagerAsync = () => {
setLocalAsyncRequest(false); setLocalAsyncRequest(false);
} }
const errCsvReportCallback = (resp) => { const downloadErrorCallback = (resp) => {
set404FromErrorResponse(resp); set404FromErrorResponse(resp);
setLocalAsyncRequest(false); setLocalAsyncRequest(false);
} }
@@ -172,7 +172,7 @@ const LatestBandiTableInstructorManagerAsync = () => {
name: { value: null, matchMode: 'contains' }, name: { value: null, matchMode: 'contains' },
startDate: { value: null, matchMode: 'dateIs' }, startDate: { value: null, matchMode: 'dateIs' },
endDate: { value: null, matchMode: 'dateIs' }, endDate: { value: null, matchMode: 'dateIs' },
status: { value: null, matchMode: 'equals' } status: { value: 'PUBLISH', matchMode: 'equals' }
} }
}); });
}; };
@@ -192,7 +192,7 @@ const LatestBandiTableInstructorManagerAsync = () => {
const paginationQuery = getPaginationQuery(); const paginationQuery = getPaginationQuery();
BandoService.getBandiPaginated(paginationQuery, getCallback, errGetCallbacks); BandoService.getBandiPaginated(paginationQuery, getCallback, errGetCallbacks);
}, [lazyState]); }, [lazyState, getPaginationQuery]);
return ( return (
<div className="appPageSection__table"> <div className="appPageSection__table">

View File

@@ -940,13 +940,17 @@ const DomandaEditInstructorManager = () => {
const formula = head(o.settings.filter(o => o.name === 'formula')); const formula = head(o.settings.filter(o => o.name === 'formula'));
if (formula && !isEmpty(formula.value)) { if (formula && !isEmpty(formula.value)) {
context = getTokens(formula.value) try {
.filter(v => !['false', 'null', 'true'].includes(v)) context = getTokens(formula.value)
.reduce((acc, cur) => { .filter(v => !['false', 'null', 'true'].includes(v))
acc[cur] = isNil(context[cur]) ? 0 : parseCommaDecimal(context[cur]); .reduce((acc, cur) => {
return acc; acc[cur] = isNil(context[cur]) ? 0 : parseCommaDecimal(context[cur]);
}, context); return acc;
}, context);
} catch {
console.error('Error in formula', formula)
context = {}
}
const mathFormula = renderWithDataVars(formula.value, context); const mathFormula = renderWithDataVars(formula.value, context);
try { try {
updatedFormValues[o.id] = evaluate(mathFormula); updatedFormValues[o.id] = evaluate(mathFormula);

View File

@@ -940,12 +940,17 @@ const DomandaEditPreInstructor = () => {
const formula = head(o.settings.filter(o => o.name === 'formula')); const formula = head(o.settings.filter(o => o.name === 'formula'));
if (formula && !isEmpty(formula.value)) { if (formula && !isEmpty(formula.value)) {
context = getTokens(formula.value) try {
.filter(v => !['false', 'null', 'true'].includes(v)) context = getTokens(formula.value)
.reduce((acc, cur) => { .filter(v => !['false', 'null', 'true'].includes(v))
acc[cur] = isNil(context[cur]) ? 0 : parseCommaDecimal(context[cur]); .reduce((acc, cur) => {
return acc; acc[cur] = isNil(context[cur]) ? 0 : parseCommaDecimal(context[cur]);
}, context); return acc;
}, context);
} catch {
console.error('Error in formula', formula)
context = {}
}
const mathFormula = renderWithDataVars(formula.value, context); const mathFormula = renderWithDataVars(formula.value, context);
try { try {