codis quasi del tot bé. Cal repassar les dates condicionals d'inici i fi
This commit is contained in:
parent
b61adc4f91
commit
6b3944277d
@ -10,20 +10,12 @@ import { Roles } from 'meteor/roles';
|
|||||||
// import { useUserId } from 'meteor/react-meteor-accounts';
|
// import { useUserId } from 'meteor/react-meteor-accounts';
|
||||||
import Select from 'react-select';
|
import Select from 'react-select';
|
||||||
|
|
||||||
// import CreatableSelect from 'react-select/creatable';
|
|
||||||
// import AsyncCreatableSelect from 'react-select/async-creatable';
|
|
||||||
// import { BarraNav } from "./BarraNav/BarraNav";
|
|
||||||
|
|
||||||
// import InfiniteCalendar from 'react-infinite-calendar';
|
|
||||||
// import 'react-infinite-calendar/styles.css';
|
|
||||||
|
|
||||||
function generaCodi() {
|
function generaCodi() {
|
||||||
return Random.id().slice(0, 5).toUpperCase();
|
return Random.id().slice(0, 5).toUpperCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
export const Codis = () => {
|
export const Codis = () => {
|
||||||
|
|
||||||
// const [permes, setPermes] = useState(false);
|
|
||||||
const [esEditor, setEsEditor] = useState(false);
|
const [esEditor, setEsEditor] = useState(false);
|
||||||
const userId = Meteor.userId();
|
const userId = Meteor.userId();
|
||||||
|
|
||||||
@ -36,10 +28,6 @@ export const Codis = () => {
|
|||||||
})();
|
})();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
// console.log("isAdmin: ", isAdmin) ;
|
|
||||||
|
|
||||||
// const [ambitSeleccionat, setAmbitSeleccionat] = useState(null);
|
|
||||||
|
|
||||||
const [confecCodObj, setConfecCodObj] = useState({
|
const [confecCodObj, setConfecCodObj] = useState({
|
||||||
codi: generaCodi(),
|
codi: generaCodi(),
|
||||||
ambit: null,
|
ambit: null,
|
||||||
@ -50,9 +38,6 @@ export const Codis = () => {
|
|||||||
condFi: null
|
condFi: null
|
||||||
});
|
});
|
||||||
|
|
||||||
// useSubscribe('necessitats');
|
|
||||||
// const necessitats = useTracker("necessitats", () => NecessitatsCollection.find().fetchAsync());
|
|
||||||
|
|
||||||
useSubscribe('codis');
|
useSubscribe('codis');
|
||||||
const codis = useTracker("codis", () => CodisCollection.find().fetchAsync());
|
const codis = useTracker("codis", () => CodisCollection.find().fetchAsync());
|
||||||
|
|
||||||
@ -60,29 +45,10 @@ export const Codis = () => {
|
|||||||
const pobles = useTracker("pobles", () => PoblesCollection.find().fetchAsync());
|
const pobles = useTracker("pobles", () => PoblesCollection.find().fetchAsync());
|
||||||
const ambits = pobles?.map(p => p?.ambitAssociat);
|
const ambits = pobles?.map(p => p?.ambitAssociat);
|
||||||
|
|
||||||
// console.log("ambits: ", ambits);
|
|
||||||
|
|
||||||
// useSubscribe('tipus');
|
|
||||||
// const ambits = useTracker("ambits", () => Collection.find().fetchAsync());
|
|
||||||
|
|
||||||
// console.log("tipus: ", tipus);
|
|
||||||
// console.log("necessitats: ", necessitats);
|
|
||||||
|
|
||||||
// console.log("tipusSeleccionat: ", tipusSeleccionat);
|
|
||||||
|
|
||||||
|
|
||||||
// const filterAmbit = (inputValue) => {
|
|
||||||
// return ambits.filter((i) =>
|
|
||||||
// i.toLowerCase().includes(inputValue.toLowerCase())
|
|
||||||
// );
|
|
||||||
// };
|
|
||||||
// const [ambitGeneral, setAmbitGeneral] = useState(ambitSeleccionat === "GENERAL");
|
|
||||||
const codiDoc = useTracker("valsFormDoc", () => CodisCollection.findOneAsync(codiSeleccionat?._id));
|
const codiDoc = useTracker("valsFormDoc", () => CodisCollection.findOneAsync(codiSeleccionat?._id));
|
||||||
|
|
||||||
// let selRolVal = codiDoc?.rol || "usuari";
|
|
||||||
|
|
||||||
const SelectorDeRol = () => {
|
const SelectorDeRol = () => {
|
||||||
// const [docRol, setDocRol] = useState(codiDoc?.rol)
|
|
||||||
|
|
||||||
return <>
|
return <>
|
||||||
<label htmlFor="selRol">Rol: </label>
|
<label htmlFor="selRol">Rol: </label>
|
||||||
@ -90,7 +56,7 @@ export const Codis = () => {
|
|||||||
required
|
required
|
||||||
key={Math.random()}
|
key={Math.random()}
|
||||||
name="selRol"
|
name="selRol"
|
||||||
// filterOption={(opts) => necessitats.find(nec => nec.tipus === tipusSeleccionat._id)}
|
|
||||||
defaultValue={
|
defaultValue={
|
||||||
codiSeleccionat
|
codiSeleccionat
|
||||||
? {
|
? {
|
||||||
@ -99,26 +65,19 @@ export const Codis = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
: confecCodObj?.rol || null
|
: confecCodObj?.rol || null
|
||||||
// ? {
|
|
||||||
// label: confecCodObj.rol,
|
|
||||||
// value: confecCodObj.rol
|
|
||||||
// }
|
|
||||||
|
|
||||||
// : null
|
|
||||||
// docRol && {label: docRol, value: docRol}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onChange={v => {
|
onChange={v => {
|
||||||
console.log("v: ", v);
|
// console.log("v: ", v);
|
||||||
|
|
||||||
console.log("cCO abans: ", confecCodObj);
|
// console.log("cCO abans: ", confecCodObj);
|
||||||
// setDocRol(v);
|
|
||||||
setConfecCodObj({
|
setConfecCodObj({
|
||||||
...confecCodObj,
|
...confecCodObj,
|
||||||
rol: v
|
rol: v
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log("cCO despres: ", confecCodObj);
|
// console.log("cCO despres: ", confecCodObj);
|
||||||
}}
|
}}
|
||||||
|
|
||||||
options={
|
options={
|
||||||
@ -162,8 +121,8 @@ export const Codis = () => {
|
|||||||
|
|
||||||
const codSelAbsActChecked = codiDoc ? {checked: codiDoc.absActiu} : {defaultChecked: confecCodObj.absActiu};
|
const codSelAbsActChecked = codiDoc ? {checked: codiDoc.absActiu} : {defaultChecked: confecCodObj.absActiu};
|
||||||
|
|
||||||
console.log("cS: ", codiSeleccionat);
|
// console.log("cS: ", codiSeleccionat);
|
||||||
console.log("cCO: ", confecCodObj);
|
// console.log("cCO: ", confecCodObj);
|
||||||
|
|
||||||
return <div style={{
|
return <div style={{
|
||||||
display: `inline-block`,
|
display: `inline-block`,
|
||||||
@ -174,17 +133,8 @@ export const Codis = () => {
|
|||||||
outline: `${codiSeleccionat?._id ? '5px solid black' : 'none'}`
|
outline: `${codiSeleccionat?._id ? '5px solid black' : 'none'}`
|
||||||
}}>
|
}}>
|
||||||
|
|
||||||
{/* {ambitSeleccionat && <h1>{ambitSeleccionat?.value}</h1>} */}
|
|
||||||
<h1>Codis</h1>
|
<h1>Codis</h1>
|
||||||
|
|
||||||
{/* <button
|
|
||||||
onClick={ev => {
|
|
||||||
ev.preventDefault();
|
|
||||||
ev.stopPropagation();
|
|
||||||
|
|
||||||
setCodiGenerat(generaCodi());
|
|
||||||
}}
|
|
||||||
>Genera el codi</button> */}
|
|
||||||
|
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
@ -208,7 +158,6 @@ export const Codis = () => {
|
|||||||
|
|
||||||
<form
|
<form
|
||||||
action={d => {
|
action={d => {
|
||||||
// if (d.get('selTipus'))
|
|
||||||
try {
|
try {
|
||||||
Meteor.callAsync('editaOAfigCodi', {
|
Meteor.callAsync('editaOAfigCodi', {
|
||||||
...codiGenerat || [],
|
...codiGenerat || [],
|
||||||
@ -216,7 +165,6 @@ export const Codis = () => {
|
|||||||
ambit: d.get('selAmbit') || "",
|
ambit: d.get('selAmbit') || "",
|
||||||
rol: d.get('selRol'),
|
rol: d.get('selRol'),
|
||||||
|
|
||||||
// act_abs: d.get('activAbs'),
|
|
||||||
absCond,
|
absCond,
|
||||||
absActiu: d.get('absActiu'),
|
absActiu: d.get('absActiu'),
|
||||||
condIni: d.get('condIni'),
|
condIni: d.get('condIni'),
|
||||||
@ -235,17 +183,11 @@ export const Codis = () => {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<label htmlFor="selAmbit">Àmbit: </label>
|
<label htmlFor="selAmbit">Àmbit: </label>
|
||||||
{/* Si
|
|
||||||
l'usuari és ADMINISTRADOR o té permisos de responsabilitat, podrà crear nous Tipus al CREAR o a l'EDITAR
|
|
||||||
si no
|
|
||||||
tansols podrà assignar a un tipus predefinit o al de ALTRES
|
|
||||||
*/}
|
|
||||||
|
|
||||||
<Select
|
<Select
|
||||||
required
|
required
|
||||||
name="selAmbit"
|
name="selAmbit"
|
||||||
// formatCreateLabel={(inputValue) => "Crear nou tipus..."}
|
|
||||||
// filterOption={filterAmbit}
|
|
||||||
defaultValue={codiDoc && {
|
defaultValue={codiDoc && {
|
||||||
label: codiDoc?.ambit,
|
label: codiDoc?.ambit,
|
||||||
value: codiDoc?.ambit
|
value: codiDoc?.ambit
|
||||||
@ -264,12 +206,8 @@ export const Codis = () => {
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
// onCreateOption={(inputValue) => Meteor.callAsync('afigT', {titol: inputValue})}
|
|
||||||
isSearchable
|
isSearchable
|
||||||
// loadOptions={tipus.map((v,i) => ({value: v, label: v.titol}))}
|
|
||||||
onChange={amb => {
|
onChange={amb => {
|
||||||
// setAmbitSeleccionat(amb);
|
|
||||||
// console.log("amb: ", amb);
|
|
||||||
|
|
||||||
setConfecCodObj({
|
setConfecCodObj({
|
||||||
...confecCodObj,
|
...confecCodObj,
|
||||||
@ -278,19 +216,11 @@ export const Codis = () => {
|
|||||||
|
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{/* <select name="selTipus">
|
|
||||||
<option value="moble">Moble</option>
|
|
||||||
<option value="maquinari">Maquinari</option>
|
|
||||||
<option value="menjar">Menjar i beguda</option>
|
|
||||||
<option value="infantil">Infantils</option>
|
|
||||||
<option value="higiene">Higiene</option>
|
|
||||||
</select> */}
|
|
||||||
|
|
||||||
<br />
|
<br />
|
||||||
|
|
||||||
<SelectorDeRol />
|
<SelectorDeRol />
|
||||||
{/* {... {ambitSeleccionat, selRolVal}} /> */}
|
|
||||||
|
|
||||||
<br /><br />
|
<br /><br />
|
||||||
|
|
||||||
@ -304,52 +234,82 @@ export const Codis = () => {
|
|||||||
backgroundColor: `lightslategray`
|
backgroundColor: `lightslategray`
|
||||||
}}>
|
}}>
|
||||||
{/* <p>TEMPS REAL:</p> */}
|
{/* <p>TEMPS REAL:</p> */}
|
||||||
<input
|
<label htmlFor="inActAbs">
|
||||||
type="radio"
|
<input
|
||||||
name='absCond'
|
type="radio"
|
||||||
value="abs"
|
name='absCond'
|
||||||
// defaultChecked={codiDoc?.act_abs === "on"}
|
value="abs"
|
||||||
// checked={absCond === 'abs'}
|
id="inActAbs"
|
||||||
// onChange={(ev) => setAbsCond('abs')}
|
|
||||||
|
|
||||||
checked={codiSeleccionat && codiSeleccionat.absCond === 'abs' || confecCodObj?.absCond === 'abs'}
|
checked={
|
||||||
onChange={(ev) => setConfecCodObj({
|
codiSeleccionat
|
||||||
...confecCodObj,
|
&&
|
||||||
absCond: 'abs'
|
codiSeleccionat.absCond === 'abs'
|
||||||
})}
|
|
||||||
/>
|
||
|
||||||
<label
|
|
||||||
htmlFor="absCond"
|
confecCodObj?.absCond === 'abs'
|
||||||
|
&&
|
||||||
onClick={() => setConfecCodObj({
|
!codiSeleccionat
|
||||||
...confecCodObj,
|
}
|
||||||
absCond: 'abs'
|
|
||||||
})}>Activació absoluta</label>
|
onChange={(ev) => {
|
||||||
|
if (codiSeleccionat) {
|
||||||
|
Meteor.callAsync('modActivacioAbsolutaCodi', codiSeleccionat);
|
||||||
|
setCodiSeleccionat({
|
||||||
|
...codiSeleccionat,
|
||||||
|
absCond: 'abs'
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
setConfecCodObj({
|
||||||
|
...confecCodObj,
|
||||||
|
absCond: 'abs'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<span>Activació absoluta</span>
|
||||||
|
</label>
|
||||||
|
|
||||||
<br />
|
<br />
|
||||||
|
|
||||||
{/* L'activació condicionada desactivada fa que no siguen 'required' les dates d'inici i final */}
|
<label htmlFor="inActCond">
|
||||||
|
<input
|
||||||
|
type="radio"
|
||||||
|
name='absCond'
|
||||||
|
value="cond"
|
||||||
|
id="inActCond"
|
||||||
|
|
||||||
|
checked={
|
||||||
|
codiSeleccionat
|
||||||
|
&&
|
||||||
|
codiSeleccionat.absCond === 'cond'
|
||||||
|
|
||||||
|
||
|
||||||
|
|
||||||
|
confecCodObj?.absCond === 'cond'
|
||||||
|
&&
|
||||||
|
!codiSeleccionat
|
||||||
|
}
|
||||||
|
|
||||||
<input
|
onChange={(ev) => {
|
||||||
type="radio"
|
if (codiSeleccionat) {
|
||||||
name='absCond'
|
Meteor.callAsync('modActivacioAbsolutaCodi', codiSeleccionat);
|
||||||
value="cond"
|
setCodiSeleccionat({
|
||||||
|
...codiSeleccionat,
|
||||||
// checked={absCond === 'cond'}
|
absCond: 'cond'
|
||||||
// onChange={(ev) => setAbsCond('cond')}
|
});
|
||||||
checked={codiSeleccionat && codiSeleccionat.absCond === 'cond' || confecCodObj?.absCond === 'cond'}
|
} else {
|
||||||
onChange={(ev) => setConfecCodObj({
|
setConfecCodObj({
|
||||||
...confecCodObj,
|
...confecCodObj,
|
||||||
absCond: 'cond'
|
absCond: 'cond'
|
||||||
})}
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/>
|
}}
|
||||||
<label htmlFor="absCond" onClick={
|
/>
|
||||||
() => setConfecCodObj({
|
<span>Activació condicionada</span>
|
||||||
...confecCodObj,
|
</label>
|
||||||
absCond: 'cond'
|
|
||||||
})
|
|
||||||
}>Activació condicionada</label>
|
|
||||||
|
|
||||||
<br />
|
<br />
|
||||||
<br />
|
<br />
|
||||||
@ -370,6 +330,8 @@ export const Codis = () => {
|
|||||||
confecCodObj?.absCond === 'abs'
|
confecCodObj?.absCond === 'abs'
|
||||||
)
|
)
|
||||||
&&
|
&&
|
||||||
|
codiSeleccionat?.absCond !== 'cond'
|
||||||
|
&&
|
||||||
|
|
||||||
<>
|
<>
|
||||||
<label htmlFor="act_status">Actiu</label>
|
<label htmlFor="act_status">Actiu</label>
|
||||||
@ -382,8 +344,6 @@ export const Codis = () => {
|
|||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
|
|
||||||
// console.log("ev: ", ev);
|
|
||||||
|
|
||||||
if (codiSeleccionat) {
|
if (codiSeleccionat) {
|
||||||
Meteor.callAsync('modActivacioAbsolutaCodi', codiSeleccionat);
|
Meteor.callAsync('modActivacioAbsolutaCodi', codiSeleccionat);
|
||||||
setCodiSeleccionat({
|
setCodiSeleccionat({
|
||||||
@ -400,18 +360,20 @@ export const Codis = () => {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
// codiDoc &&
|
|
||||||
// Meteor.callAsync('modActivacioAbsolutaCodi', codiDoc);
|
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
codiSeleccionat
|
(codiSeleccionat
|
||||||
&&
|
&&
|
||||||
codiSeleccionat.absCond === 'cond'
|
codiSeleccionat.absCond === 'cond'
|
||||||
|
|
||||||
||
|
||
|
||||||
|
|
||||||
confecCodObj?.absCond === 'cond'
|
confecCodObj?.absCond === 'cond'
|
||||||
|
)
|
||||||
&&
|
&&
|
||||||
|
codiSeleccionat?.absCond !== 'abs'
|
||||||
|
&&
|
||||||
|
|
||||||
<>
|
<>
|
||||||
<p
|
<p
|
||||||
style={{
|
style={{
|
||||||
@ -425,7 +387,7 @@ export const Codis = () => {
|
|||||||
name="condIni"
|
name="condIni"
|
||||||
onChange={v => {
|
onChange={v => {
|
||||||
|
|
||||||
console.log("dataIni: ", v.currentTarget.value);
|
// console.log("dataIni: ", v.currentTarget.value);
|
||||||
setConfecCodObj({
|
setConfecCodObj({
|
||||||
...confecCodObj,
|
...confecCodObj,
|
||||||
condIni: v.currentTarget.value
|
condIni: v.currentTarget.value
|
||||||
@ -440,7 +402,7 @@ export const Codis = () => {
|
|||||||
type="date"
|
type="date"
|
||||||
name="condFi"
|
name="condFi"
|
||||||
onChange={v => {
|
onChange={v => {
|
||||||
console.log("dataFi: ", v.currentTarget.value);
|
// console.log("dataFi: ", v.currentTarget.value);
|
||||||
setConfecCodObj({
|
setConfecCodObj({
|
||||||
...confecCodObj,
|
...confecCodObj,
|
||||||
condFi: v.currentTarget.value
|
condFi: v.currentTarget.value
|
||||||
@ -453,26 +415,9 @@ export const Codis = () => {
|
|||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* <select name="s.
|
|
||||||
elPoble">
|
|
||||||
{
|
|
||||||
pobles.map((v,i) => <option key={`optPob${i}`}>{v.nomPoble}</option>)
|
|
||||||
}
|
|
||||||
</select> */}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<input type='submit' value="Donar d'alta el codi" />
|
<input type='submit' value="Donar d'alta el codi" />
|
||||||
|
|
||||||
{/* {ambitSeleccionat && esEditor && <button onClick={ev => {
|
|
||||||
ev.preventDefault();
|
|
||||||
if (confirm(`Vas a eliminar el poble "${pobleSeleccionat.nomPoble}". És una operació irreversible. Procedir?`)) {
|
|
||||||
Meteor.callAsync('eliminaPoble', pobleSeleccionat._id).catch(err => console.error(err));
|
|
||||||
setNecessitatSeleccionada(null);
|
|
||||||
}
|
|
||||||
}}>Elimina</button>} */}
|
|
||||||
</form>
|
</form>
|
||||||
</div>;
|
</div>;
|
||||||
};
|
};
|
||||||
@ -482,24 +427,12 @@ export const Codis = () => {
|
|||||||
lastWeek = new Date(today.getFullYear(), today.getMonth(), today.getDate() - 7)
|
lastWeek = new Date(today.getFullYear(), today.getMonth(), today.getDate() - 7)
|
||||||
;
|
;
|
||||||
|
|
||||||
// console.log("codis: ", codis);
|
|
||||||
|
|
||||||
|
|
||||||
return <Suspense fallback={<>Carregant...</>} >
|
return <Suspense fallback={<>Carregant...</>} >
|
||||||
|
|
||||||
<QuadreInfo_Codis />
|
<QuadreInfo_Codis />
|
||||||
|
|
||||||
<br /><br />
|
<br /><br />
|
||||||
|
|
||||||
{/* <AsyncCreatableSelect
|
|
||||||
cacheOptions
|
|
||||||
defaultOptions={tipus.map((v,i) => ({value: v, label: v.titol})) }
|
|
||||||
loadOptions={tipus.map((v,i) => ({value: v, label: v.titol}))}
|
|
||||||
/> */}
|
|
||||||
|
|
||||||
{/* <SelectSearch options={options} value="sv" name="language" placeholder="Choose your language" /> */}
|
|
||||||
|
|
||||||
|
|
||||||
<ul style={{
|
<ul style={{
|
||||||
display: `flex`,
|
display: `flex`,
|
||||||
flexWrap: `wrap`,
|
flexWrap: `wrap`,
|
||||||
@ -508,8 +441,7 @@ export const Codis = () => {
|
|||||||
alignContent: `space-around`
|
alignContent: `space-around`
|
||||||
}}>{
|
}}>{
|
||||||
codis
|
codis
|
||||||
// .reverse()
|
|
||||||
// .sort((a,b) => a?.codi?.editedAt < b?.codi?.editedAt)
|
|
||||||
.map(cod => <li
|
.map(cod => <li
|
||||||
key={cod._id}
|
key={cod._id}
|
||||||
style={{
|
style={{
|
||||||
@ -526,7 +458,6 @@ export const Codis = () => {
|
|||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
|
|
||||||
// console.log("codSel: ", codiSeleccionat);
|
|
||||||
setCodiSeleccionat(codiSeleccionat?._id === cod._id ? null : cod);
|
setCodiSeleccionat(codiSeleccionat?._id === cod._id ? null : cod);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
@ -550,16 +481,9 @@ export const Codis = () => {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
{cod.codi}
|
{cod.codi}
|
||||||
{/* {esEditor && <button onClick={() => {setAmbitSeleccionat({value: cod, label: cod})}}>Edita</button>} */}
|
|
||||||
</li>)
|
</li>)
|
||||||
}</ul>
|
}</ul>
|
||||||
|
|
||||||
{/* <InfiniteCalendar
|
|
||||||
width={400}
|
|
||||||
height={600}
|
|
||||||
selected={today}
|
|
||||||
disabledDays={[0,6]}
|
|
||||||
minDate={lastWeek}
|
|
||||||
/> */}
|
|
||||||
</Suspense>;
|
</Suspense>;
|
||||||
};
|
};
|
||||||
Loading…
Reference in New Issue
Block a user