Skip to content

Commit

Permalink
merge 'active' and 'inactive' into year filter
Browse files Browse the repository at this point in the history
  • Loading branch information
c2d13p committed Jul 23, 2024
1 parent 86e06cb commit 90ccacd
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 163 deletions.
119 changes: 58 additions & 61 deletions src/models/Grant.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,70 +34,67 @@ export default class Grant extends Model {
}

function GrantsFilters({ filter }) {
const setFilterFields = filter.setFilter
const [year, setYear] = useState(0)
const [status, setStatus] = useState('all')
const currentYear = new Date().getFullYear()
const startYear = 2007
const years = Array.from({ length: currentYear - startYear + 1 }, (_, i) => currentYear - i)

const setFilterFields = filter.setFilter;
const [selectedOption, setSelectedOption] = useState('all');
const currentYear = new Date().getFullYear();
const startYear = 2007;
const years = Array.from({ length: currentYear - startYear + 1 }, (_, i) => currentYear - i);

const options = [
{ value: 'all', label: 'Tutti' },
{ value: 'active', label: 'Attivi' },
{ value: 'inactive', label: 'Non attivi' },
...years.map(year => ({ value: year.toString(), label: year.toString() })),
];

return (
<>
<select
className="mx-1 form-control"
style={{ width: '10%' }}
placeholder='Seleziona anno'
value={year || ""}
onChange={evt => {
const year = parseInt(evt.target.value);
setYear(year);
if (year) {
setFilterFields(prev => ({
...prev,
<select
className="mx-1 form-control"
style={{ width: '10%' }}
value={selectedOption}
onChange={evt => {
const value = evt.target.value;
setSelectedOption(value);

if (value === 'all') {
setFilterFields(prev => {
const { startDate__lt_or_null, endDate__gte_or_null, endDate__lt, ...rest } = prev;
return rest;
});
} else if (value === 'active') {
setFilterFields(prev => {
const { startDate__lt_or_null, endDate__gte_or_null, endDate__lt, ...rest } = prev;
return {
...rest,
endDate__gte_or_null: 'today',
};
});
} else if (value === 'inactive') {
setFilterFields(prev => {
const { startDate__lt_or_null, endDate__gte_or_null, endDate__lt, ...rest } = prev;
return {
...rest,
endDate__lt: 'today',
};
});
} else {
const year = parseInt(value);
setFilterFields(prev => {
const { startDate__lt_or_null, endDate__gte_or_null, endDate__lt, ...rest } = prev;
return {
...rest,
startDate__lt_or_null: `${year + 1}-01-01`,
endDate__gte_or_null: `${year}-01-01`,
}));
} else {
setFilterFields(prev => {
const { startDate__lt_or_null, endDate__gte_or_null, ...rest } = prev;
return rest;
});
}
}}
>
<option value="">Tutti gli anni</option>
{years.map(y => <option key={y} value={y}>{y}</option>)}
</select>
<select
className="mx-1 form-control"
style={{ width: '10%' }}
value={status}
onChange={evt => {
const status = evt.target.value;
setStatus(status);
setFilterFields(prev => {
const { endDate__gte_or_null, endDate__lt, ...rest } = prev;

if (status === 'active') {
return {
...rest,
endDate__gte_or_null: 'today',
};
} else if (status === 'inactive') {
return {
...rest,
endDate__lt: 'today',
};
} else {
return rest;
}
};
});
}}
>
<option value="all">Tutti</option>
<option value="active">Attivi</option>
<option value="inactive">Non attivi</option>
</select>
</>
}
}}
>
{options.map(option => (
<option key={option.value} value={option.value}>
{option.label}
</option>
))}
</select>
);
}
119 changes: 58 additions & 61 deletions src/models/Group.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,70 +29,67 @@ export default class Group extends Model {
}

function GroupsFilters({ filter }) {
const setFilterFields = filter.setFilter
const [year, setYear] = useState(0)
const [status, setStatus] = useState('all')
const currentYear = new Date().getFullYear()
const startYear = 2007
const years = Array.from({ length: currentYear - startYear + 1 }, (_, i) => currentYear - i)

const setFilterFields = filter.setFilter;
const [selectedOption, setSelectedOption] = useState('all');
const currentYear = new Date().getFullYear();
const startYear = 2018;
const years = Array.from({ length: currentYear - startYear + 1 }, (_, i) => currentYear - i);

const options = [
{ value: 'all', label: 'Tutti' },
{ value: 'active', label: 'Attivi' },
{ value: 'inactive', label: 'Non attivi' },
...years.map(year => ({ value: year.toString(), label: year.toString() })),
];

return (
<>
<select
className="mx-1 form-control"
style={{ width: '10%' }}
placeholder='Seleziona anno'
value={year || ""}
onChange={evt => {
const year = parseInt(evt.target.value);
setYear(year);
if (year) {
setFilterFields(prev => ({
...prev,
<select
className="mx-1 form-control"
style={{ width: '10%' }}
value={selectedOption}
onChange={evt => {
const value = evt.target.value;
setSelectedOption(value);

if (value === 'all') {
setFilterFields(prev => {
const { startDate__lt_or_null, endDate__gte_or_null, endDate__lt, ...rest } = prev;
return rest;
});
} else if (value === 'active') {
setFilterFields(prev => {
const { startDate__lt_or_null, endDate__gte_or_null, endDate__lt, ...rest } = prev;
return {
...rest,
endDate__gte_or_null: 'today',
};
});
} else if (value === 'inactive') {
setFilterFields(prev => {
const { startDate__lt_or_null, endDate__gte_or_null, endDate__lt, ...rest } = prev;
return {
...rest,
endDate__lt: 'today',
};
});
} else {
const year = parseInt(value);
setFilterFields(prev => {
const { startDate__lt_or_null, endDate__gte_or_null, endDate__lt, ...rest } = prev;
return {
...rest,
startDate__lt_or_null: `${year + 1}-01-01`,
endDate__gte_or_null: `${year}-01-01`,
}));
} else {
setFilterFields(prev => {
const { startDate__lt_or_null, endDate__gte_or_null, ...rest } = prev;
return rest;
});
}
}}
>
<option value="">Tutti gli anni</option>
{years.map(y => <option key={y} value={y}>{y}</option>)}
</select>
<select
className="mx-1 form-control"
style={{ width: '10%' }}
value={status}
onChange={evt => {
const status = evt.target.value;
setStatus(status);
setFilterFields(prev => {
const { endDate__gte_or_null, endDate__lt, ...rest } = prev;

if (status === 'active') {
return {
...rest,
endDate__gte_or_null: 'today',
};
} else if (status === 'inactive') {
return {
...rest,
endDate__lt: 'today',
};
} else {
return rest;
}
};
});
}}
>
<option value="all">Tutti</option>
<option value="active">Attivi</option>
<option value="inactive">Non attivi</option>
</select>
</>
}
}}
>
{options.map(option => (
<option key={option.value} value={option.value}>
{option.label}
</option>
))}
</select>
);
}
79 changes: 39 additions & 40 deletions src/models/Staff.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,70 +33,69 @@ export default class Staff extends Model {

function StaffsFilters({ filter }) {
const setFilterFields = filter.setFilter
const [year, setYear] = useState(0)
const [status, setStatus] = useState('all')
const [selectedOption, setSelectedOption] = useState('all');
const [qualification, setQualification] = useState('')
const currentYear = new Date().getFullYear()
const startYear = 2007
const startYear = 2011
const years = Array.from({ length: currentYear - startYear + 1 }, (_, i) => currentYear - i)
const qualificationOptions = ['PO', 'PA', 'RTDb', 'RTDa', 'RIC', 'Assegnista', 'Dottorando', 'PTA', 'Professore Emerito', 'Collaboratore', 'Docente Esterno', 'Dottorando Esterno', 'Personale in quiescenza', 'ex Docente']

const options = [
{ value: 'all', label: 'Tutti' },
{ value: 'active', label: 'Attivi' },
{ value: 'inactive', label: 'Non attivi' },
...years.map(year => ({ value: year.toString(), label: year.toString() })),
];

return (
<>
<select
className="mx-1 form-control"
style={{ width: '10%' }}
placeholder='Seleziona anno'
value={year || ""}
value={selectedOption}
onChange={evt => {
const year = parseInt(evt.target.value);
setYear(year);
if (year) {
setFilterFields(prev => ({
...prev,
startDate__lt_or_null: `${year + 1}-01-01`,
endDate__gte_or_null: `${year}-01-01`,
}));
} else {
const value = evt.target.value;
setSelectedOption(value);

if (value === 'all') {
setFilterFields(prev => {
const { startDate__lt_or_null, endDate__gte_or_null, ...rest } = prev;
const { startDate__lt_or_null, endDate__gte_or_null, endDate__lt, ...rest } = prev;
return rest;
});
}
}}
>
<option value="">Tutti gli anni</option>
{years.map(y => <option key={y} value={y}>{y}</option>)}
</select>
<select
className="mx-1 form-control"
style={{ width: '10%' }}
value={status}
onChange={evt => {
const status = evt.target.value;
setStatus(status);
setFilterFields(prev => {
const { endDate__gte_or_null, endDate__lt, ...rest } = prev;

if (status === 'active') {
} else if (value === 'active') {
setFilterFields(prev => {
const { startDate__lt_or_null, endDate__gte_or_null, endDate__lt, ...rest } = prev;
return {
...rest,
endDate__gte_or_null: 'today',
};
} else if (status === 'inactive') {
});
} else if (value === 'inactive') {
setFilterFields(prev => {
const { startDate__lt_or_null, endDate__gte_or_null, endDate__lt, ...rest } = prev;
return {
...rest,
endDate__lt: 'today',
};
} else {
return rest;
}
});
});
} else {
const year = parseInt(value);
setFilterFields(prev => {
const { startDate__lt_or_null, endDate__gte_or_null, endDate__lt, ...rest } = prev;
return {
...rest,
startDate__lt_or_null: `${year + 1}-01-01`,
endDate__gte_or_null: `${year}-01-01`,
};
});
}
}}
>
<option value="all">Tutti</option>
<option value="active">Attivi</option>
<option value="inactive">Non attivi</option>
{options.map(option => (
<option key={option.value} value={option.value}>
{option.label}
</option>
))}
</select>
<select
className="mx-1 form-control"
Expand Down
2 changes: 1 addition & 1 deletion src/models/Visit.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function VisitsFilters({filter}) {
const setFilterFields = filter.setFilter
const [year, setYear] = useState(0)
const currentYear = new Date().getFullYear()
const startYear = 2013
const startYear = 2021
const years = Array.from({ length: currentYear - startYear + 1 }, (_, i) => currentYear - i)

return <>
Expand Down

0 comments on commit 90ccacd

Please sign in to comment.