From b61adc4f91271c58bae074f50eb43effa6b851b4 Mon Sep 17 00:00:00 2001 From: Pasq G Date: Tue, 28 Jan 2025 17:07:45 +0100 Subject: [PATCH] Codis quasi operatius --- PROBLEMES.MD | 1 + imports/ui/Codis.jsx | 275 +++++++++++++++++++++++++++++++++++-------- server/main.js | 2 +- 3 files changed, 226 insertions(+), 52 deletions(-) create mode 100644 PROBLEMES.MD diff --git a/PROBLEMES.MD b/PROBLEMES.MD new file mode 100644 index 0000000..0049480 --- /dev/null +++ b/PROBLEMES.MD @@ -0,0 +1 @@ + - Al crear codis encara se poden crear (i posteriorment assignarien) codis amb Àmbits i Rols incoherents. diff --git a/imports/ui/Codis.jsx b/imports/ui/Codis.jsx index 86775f7..1478c25 100644 --- a/imports/ui/Codis.jsx +++ b/imports/ui/Codis.jsx @@ -1,4 +1,4 @@ -import React, { Suspense, useEffect, useState, useRef, lazy } from 'react'; +import React, { Suspense, useEffect, useState } from 'react'; import { Meteor } from 'meteor/meteor'; import { Random } from 'meteor/random'; import { NecessitatsCollection } from '/imports/api/necessitats.js'; @@ -10,15 +10,15 @@ import { Roles } from 'meteor/roles'; // import { useUserId } from 'meteor/react-meteor-accounts'; import Select from 'react-select'; -import CreatableSelect from 'react-select/creatable'; +// 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() {0 - return Random.id().slice(0, 5); +function generaCodi() { + return Random.id().slice(0, 5).toUpperCase(); } export const Codis = () => { @@ -38,10 +38,20 @@ export const Codis = () => { // console.log("isAdmin: ", isAdmin) ; - const [ambitSeleccionat, setAmbitSeleccionat] = useState(null); + // const [ambitSeleccionat, setAmbitSeleccionat] = useState(null); - useSubscribe('necessitats'); - const necessitats = useTracker("necessitats", () => NecessitatsCollection.find().fetchAsync()); + const [confecCodObj, setConfecCodObj] = useState({ + codi: generaCodi(), + ambit: null, + rol: null, + absCond: "abs", + absActiu: false, + condIni: null, + condFi: null + }); + + // useSubscribe('necessitats'); + // const necessitats = useTracker("necessitats", () => NecessitatsCollection.find().fetchAsync()); useSubscribe('codis'); const codis = useTracker("codis", () => CodisCollection.find().fetchAsync()); @@ -67,9 +77,12 @@ export const Codis = () => { // ); // }; // const [ambitGeneral, setAmbitGeneral] = useState(ambitSeleccionat === "GENERAL"); - const codiDoc = useTracker("codiDoc", () => CodisCollection.findOneAsync(codiSeleccionat?._id)); + const codiDoc = useTracker("valsFormDoc", () => CodisCollection.findOneAsync(codiSeleccionat?._id)); + + // let selRolVal = codiDoc?.rol || "usuari"; const SelectorDeRol = () => { + // const [docRol, setDocRol] = useState(codiDoc?.rol) return <> @@ -78,9 +91,38 @@ export const Codis = () => { key={Math.random()} name="selRol" // filterOption={(opts) => necessitats.find(nec => nec.tipus === tipusSeleccionat._id)} + defaultValue={ + codiSeleccionat + ? { + label: codiSeleccionat?.rol, + value: codiSeleccionat?.rol + } + + : confecCodObj?.rol || null + // ? { + // label: confecCodObj.rol, + // value: confecCodObj.rol + // } + + // : null + // docRol && {label: docRol, value: docRol} + } + + onChange={v => { + console.log("v: ", v); + + console.log("cCO abans: ", confecCodObj); + // setDocRol(v); + setConfecCodObj({ + ...confecCodObj, + rol: v + }); + + console.log("cCO despres: ", confecCodObj); + }} options={ - (ambitSeleccionat?.value === "GENERAL") + (confecCodObj?.ambit?.value === "GENERAL") ? [ { value: "admin", @@ -114,9 +156,14 @@ export const Codis = () => { const QuadreInfo_Codis = () => { const [actCond, setActCond] = useState(true); - const [codiGenerat, setCodiGenerat] = useState(generaCodi()?.toUpperCase()); + const [codiGenerat, setCodiGenerat] = useState(generaCodi()); - + const [absCond, setAbsCond] = useState('cond'); + + const codSelAbsActChecked = codiDoc ? {checked: codiDoc.absActiu} : {defaultChecked: confecCodObj.absActiu}; + + console.log("cS: ", codiSeleccionat); + console.log("cCO: ", confecCodObj); return
{ outline: `${codiSeleccionat?._id ? '5px solid black' : 'none'}` }}> - {ambitSeleccionat &&

{ambitSeleccionat?.value}

} + {/* {ambitSeleccionat &&

{ambitSeleccionat?.value}

} */}

Codis

{/*

Tria el rol que adquirirà qui utilitze el codi anterior una vegada activat

-
{ // if (d.get('selTipus')) @@ -169,10 +215,15 @@ export const Codis = () => { codi: codiGenerat, ambit: d.get('selAmbit') || "", rol: d.get('selRol'), - act_abs: d.get('activ_abs'), - act_cond: d.get('activ_cond'), - periode_validesa_ini: d.get('periode_validesa_ini'), - periode_validesa_fi: d.get('periode_validesa_fi') + + // act_abs: d.get('activAbs'), + absCond, + absActiu: d.get('absActiu'), + condIni: d.get('condIni'), + condFi: d.get('condFi') + + + }) .then(() => setAmbitSeleccionat(null)) .catch(err => console.error(err)) @@ -195,7 +246,10 @@ export const Codis = () => { name="selAmbit" // formatCreateLabel={(inputValue) => "Crear nou tipus..."} // filterOption={filterAmbit} - defaultValue={ambitSeleccionat} + defaultValue={codiDoc && { + label: codiDoc?.ambit, + value: codiDoc?.ambit + } || confecCodObj.ambit} options={ [... ambits @@ -214,8 +268,13 @@ export const Codis = () => { isSearchable // loadOptions={tipus.map((v,i) => ({value: v, label: v.titol}))} onChange={amb => { - setAmbitSeleccionat(amb); - console.log("amb: ", amb); + // setAmbitSeleccionat(amb); + // console.log("amb: ", amb); + + setConfecCodObj({ + ...confecCodObj, + ambit: amb + }); }} /> @@ -230,11 +289,12 @@ export const Codis = () => {
- + + {/* {... {ambitSeleccionat, selRolVal}} /> */}

- +

Periode de validesa:

{ padding: `.6rem`, backgroundColor: `lightslategray` }}> -

TEMPS REAL:

- + {/*

TEMPS REAL:

*/} { - ev.preventDefault(); - ev.stopPropagation(); + type="radio" + name='absCond' + value="abs" + // defaultChecked={codiDoc?.act_abs === "on"} + // checked={absCond === 'abs'} + // onChange={(ev) => setAbsCond('abs')} - Meteor.callAsync('modActivacioAbsolutaCodi', codiDoc); - }} - + checked={codiSeleccionat && codiSeleccionat.absCond === 'abs' || confecCodObj?.absCond === 'abs'} + onChange={(ev) => setConfecCodObj({ + ...confecCodObj, + absCond: 'abs' + })} /> +
{/* L'activació condicionada desactivada fa que no siguen 'required' les dates d'inici i final */} - - setActCond(!actCond)} - /> -

ATENCIÓ al format! (mm/dd/aaaa)

+ setAbsCond('cond')} + checked={codiSeleccionat && codiSeleccionat.absCond === 'cond' || confecCodObj?.absCond === 'cond'} + onChange={(ev) => setConfecCodObj({ + ...confecCodObj, + absCond: 'cond' + })} + + /> + - Des de:
- Fins a:
+ +
+ { + (codiSeleccionat + && + codiSeleccionat?.absCond === 'abs' + + || + + confecCodObj?.absCond === 'abs' + ) + && + + <> + + { + ev.preventDefault(); + ev.stopPropagation(); + + // console.log("ev: ", ev); + + if (codiSeleccionat) { + Meteor.callAsync('modActivacioAbsolutaCodi', codiSeleccionat); + setCodiSeleccionat({ + ...codiSeleccionat, + absActiu: !codiSeleccionat.absActiu + }); + } + + setConfecCodObj({ + ...confecCodObj, + absActiu: !confecCodObj.absActiu + }); + + }} + /> + + // codiDoc && + // Meteor.callAsync('modActivacioAbsolutaCodi', codiDoc); + } + { + codiSeleccionat + && + codiSeleccionat.absCond === 'cond' + + || + + confecCodObj?.absCond === 'cond' + && + <> +

ATENCIÓ al format! (mm/dd/aaaa)

+ + Des de: { + + console.log("dataIni: ", v.currentTarget.value); + setConfecCodObj({ + ...confecCodObj, + condIni: v.currentTarget.value + }) + }} + defaultValue={confecCodObj.condIni} + /> +
+ Fins a: { + console.log("dataFi: ", v.currentTarget.value); + setConfecCodObj({ + ...confecCodObj, + condFi: v.currentTarget.value + }) + }} + defaultValue={confecCodObj.condFi} + /> +
+ + } +
{/*