From 04d436a10ffd633f71e25727dfc47fe638cb53d4 Mon Sep 17 00:00:00 2001 From: Pasq G Date: Wed, 4 Dec 2024 13:10:40 +0100 Subject: [PATCH] =?UTF-8?q?Avan=C3=A7ant=20amb=20els=20formularis?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- imports/ui/App.jsx | 2 + imports/ui/Loguejat.jsx | 6 ++ imports/ui/Necessitats.jsx | 89 ++++++++++++-------- imports/ui/Pobles.jsx | 30 +++++-- imports/ui/Tipus.jsx | 168 +++++++++++++++++++++++++++++++++++++ 5 files changed, 254 insertions(+), 41 deletions(-) create mode 100644 imports/ui/Tipus.jsx diff --git a/imports/ui/App.jsx b/imports/ui/App.jsx index e6435d8..d1d8e40 100644 --- a/imports/ui/App.jsx +++ b/imports/ui/App.jsx @@ -6,6 +6,7 @@ import { useSubscribe, useTracker, useFind } from 'meteor/react-meteor-data/susp import { Pobles } from './Pobles'; import { Necessitats } from './Necessitats'; +import { Tipus } from './Tipus'; const Loguejat = lazy(async () => await import('/imports/ui/Loguejat.jsx')); @@ -20,6 +21,7 @@ export const App = () => { Carregant...}>{user ? : } } /> } /> } /> + } /> } /> diff --git a/imports/ui/Loguejat.jsx b/imports/ui/Loguejat.jsx index 0a302b6..71de603 100644 --- a/imports/ui/Loguejat.jsx +++ b/imports/ui/Loguejat.jsx @@ -28,6 +28,11 @@ const SeccióNecessitats = () => ; +const SeccióTipus = () => ; + const PanellSeccions = ({children}) => { return
{ + diff --git a/imports/ui/Necessitats.jsx b/imports/ui/Necessitats.jsx index 0edb994..2159cee 100644 --- a/imports/ui/Necessitats.jsx +++ b/imports/ui/Necessitats.jsx @@ -41,13 +41,6 @@ export const Necessitats = () => { const tipus = useTracker("tipus", () => TipusCollection.find().fetchAsync()); - const filterColors = (inputValue) => { - return colourOptions.filter((i) => - i.label.toLowerCase().includes(inputValue.toLowerCase()) - ); - }; - - const QuadreInfo_Necessitats = () => { return
{ action={d => { if (d.get('selTipus')) try { - Meteor.callAsync('editaOAfigNecessitat', { + Meteor.callAsync('afigNecessitat', { ...necessitatSeleccionada || [], titol: d.get('titol'), tipus: d.get('selTipus') || "", @@ -82,15 +75,22 @@ export const Necessitats = () => { } }} > - - {/* Si + +
+ + +

+ + + {/* 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 */} - ({value: v, label: v.titol})) } + "Crear nou tipus..."} + defaultOptions={tipus.map((v,i) => ({value: v._id, label: v.titol})).sort((a,b) => a.label.toLowerCase() > b.label.toLowerCase()) } onCreateOption={(inputValue) => Meteor.callAsync('afigTipus', {titol: inputValue})} // loadOptions={tipus.map((v,i) => ({value: v, label: v.titol}))} /> @@ -105,14 +105,9 @@ export const Necessitats = () => {
- - + -

- - - - ({value: v, label: v.nomPoble})) } /> + ({value: v._id, label: v.nomPoble})) } /> {/* */}
- + +
+
+ +
+ +
+ Contacte +
+
+
+
+
+ +
+ {necessitatSeleccionada && esEditor && }) - } */} + .sort((a,b) => a.titol?.toLowerCase() > b.titol?.toLowerCase()) + .map(nec =>
  • + {nec.titol}{esEditor && }
  • ) + } ; }; \ No newline at end of file diff --git a/imports/ui/Pobles.jsx b/imports/ui/Pobles.jsx index a2e39dd..18169f7 100644 --- a/imports/ui/Pobles.jsx +++ b/imports/ui/Pobles.jsx @@ -44,7 +44,7 @@ export const Pobles = () => { {pobleSeleccionat &&

    {pobleSeleccionat._id}

    }

    Pobles

    -
    { try { Meteor.callAsync('editaOAfigPoble', @@ -68,23 +68,39 @@ export const Pobles = () => {
    ; }; return Carregant...} > - { esEditor && } -
      { +
        { pobles .sort((a,b) => a.nomPoble?.toLowerCase() > b.nomPoble?.toLowerCase()) - .map(pob =>
      • {pob.nomPoble}{esEditor && }
      • ) + .map(pob =>
      • + {pob.nomPoble}{esEditor && }
      • ) }
      ; }; \ No newline at end of file diff --git a/imports/ui/Tipus.jsx b/imports/ui/Tipus.jsx new file mode 100644 index 0000000..78066ae --- /dev/null +++ b/imports/ui/Tipus.jsx @@ -0,0 +1,168 @@ +import React, { Suspense, useEffect, useState, useRef, lazy } from 'react'; +import { Meteor } from 'meteor/meteor';; +import { NecessitatsCollection } from '/imports/api/necessitats.js'; +import { PoblesCollection } from '../api/pobles'; +import { TipusCollection } from '../api/tipus'; +import { useSubscribe, useTracker, useFind } from 'meteor/react-meteor-data/suspense'; +import { Roles } from 'meteor/roles'; +// import { useUserId } from 'meteor/react-meteor-accounts'; +import Select from 'react-select'; + +import CreatableSelect from 'react-select/creatable'; +import AsyncCreatableSelect from 'react-select/async-creatable'; + + + + +export const Tipus = () => { + + // const [permes, setPermes] = useState(false); + const [esEditor, setEsEditor] = useState(false); + const userId = Meteor.userId(); + + useEffect(() => { + (async () => { + const comprovaAdmin = await Roles.userIsInRoleAsync(userId, ["admin"]); + setEsEditor(comprovaAdmin); + })(); + }, []); + + // console.log("isAdmin: ", isAdmin) ; + + const [tipusSeleccionat, setNecessitatSeleccionat] = useState(null); + + useSubscribe('necessitats'); + const necessitats = useTracker("necessitats", () => NecessitatsCollection.find().fetchAsync()); + + useSubscribe('pobles'); + const pobles = useTracker("pobles", () => PoblesCollection.find().fetchAsync()); + + useSubscribe('tipus'); + const tipus = useTracker("tipus", () => TipusCollection.find().fetchAsync()); + + console.log("tipus: ", tipus); + console.log("necessitats: ", necessitats); + + console.log("tipusSeleccionat: ", tipusSeleccionat); + + const QuadreInfo_Tipus = () => { + + return
      + { esEditor &&
      ADMINISTRADOR
      } + {tipusSeleccionat &&

      {tipusSeleccionat._id}

      } +

      Tipus

      + + + +
      { + if (d.get('selTipus')) + try { + Meteor.callAsync('editaOAfigNecessitat', { + ...tipusSeleccionat || [], + titol: d.get('titol'), + tipus: d.get('selTipus') || "", + poble: d.get('selPoble') + }) + .then(() => setTipusSeleccionat(null)) + .catch(err => console.error(err)) + ; + } catch (err) { + alert(err); + console.error(err); + } + }} + > + + {/* 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 + */} + "Crear nou tipus..."} + defaultOptions={tipus.map((v,i) => ({value: v._id, label: v.titol})).sort((a,b) => a.label.toLowerCase() > b.label.toLowerCase()) } + onCreateOption={(inputValue) => Meteor.callAsync('afigTipus', {titol: inputValue})} + // loadOptions={tipus.map((v,i) => ({value: v, label: v.titol}))} + /> + + {/* */} + +
      + + + + +

      + + + + ({value: v._id, label: v.nomPoble})) } /> + {/* */} + +
      + + + + {tipusSeleccionat && esEditor && } + +
      ; + }; + + + return Carregant...} > + + + +

      + + {/* ({value: v, label: v.titol})) } + loadOptions={tipus.map((v,i) => ({value: v, label: v.titol}))} + /> */} + + {/* */} + + + {/*
        { + tipus + .sort((a,b) => a.nomPoble?.toLowerCase() > b.nomPoble?.toLowerCase()) + .map(pob =>
      • {pob.nomPoble}{esEditor && }
      • ) + }
      */} +
      ; +}; \ No newline at end of file