From e129eb41075a42f89ee29cdf70ff1590be2ddb54 Mon Sep 17 00:00:00 2001 From: Pasq G Date: Wed, 25 Dec 2024 15:24:14 +0100 Subject: [PATCH] =?UTF-8?q?Avan=C3=A7os=20amb=20els=20formularis?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- imports/ui/Necessitats.jsx | 44 +++++++++++++++++++------- imports/ui/Poble.jsx | 63 +++++++++++++++++++++++++++++++++++--- imports/ui/Pobles.jsx | 9 +++++- server/main.js | 17 +++++++--- 4 files changed, 112 insertions(+), 21 deletions(-) diff --git a/imports/ui/Necessitats.jsx b/imports/ui/Necessitats.jsx index ad5b45f..deae70f 100644 --- a/imports/ui/Necessitats.jsx +++ b/imports/ui/Necessitats.jsx @@ -59,11 +59,20 @@ export const Necessitats = () => { action={d => { if (d.get('selTipus')) try { + const tipusSeleccionat = tipus.find(t => t._id === d.get('selTipus')) || ""; + const pobleSeleccionat = pobles.find(p => p._id === d.get('selPoble')) || ""; Meteor.callAsync('afigNecessitat', { ...necessitatSeleccionada || [], - titol: d.get('titol'), - tipus: d.get('selTipus') || "", - poble: d.get('selPoble') + titol: d.get('taTitol'), + tipus: tipusSeleccionat, + poble: pobleSeleccionat, + descrip: d.get('taDescripcio'), + contacte: { + nom: d.get('inContacte'), + tel: d.get('inTelefon'), + email: d.get('inEMail'), + adr: d.get('inAdreça') + } }) .then(() => setNecessitatSeleccionada(null)) .catch(err => console.error(err)) @@ -76,7 +85,7 @@ export const Necessitats = () => { >
- +

@@ -91,6 +100,7 @@ export const Necessitats = () => { formatCreateLabel={(inputValue) => "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})} + defaultValue={ necessitatSeleccionada ? { value: necessitatSeleccionada.tipus._id, label: necessitatSeleccionada.tipus.titol} : ""} // loadOptions={tipus.map((v,i) => ({value: v, label: v.titol}))} /> @@ -106,7 +116,9 @@ export const Necessitats = () => { - ({value: v._id, label: v.nomPoble})) } /> + ({value: v._id, label: v.nomPoble})) } + defaultValue={ necessitatSeleccionada ? { value: necessitatSeleccionada.poble._id, label: necessitatSeleccionada.poble.nomPoble} : ""} + /> {/*
+

@@ -125,10 +139,18 @@ export const Necessitats = () => { border: `1px solid #6666` }}> Contacte -
-
-
-
+
+
+
+

@@ -173,7 +195,7 @@ export const Necessitats = () => { backgroundColor: `${'lightgreen' || 'lightcoral'}` }} > - {nec.titol}{esEditor && }) + {nec.titol} {esEditor && }) } ; }; \ No newline at end of file diff --git a/imports/ui/Poble.jsx b/imports/ui/Poble.jsx index 57ff162..4877e68 100644 --- a/imports/ui/Poble.jsx +++ b/imports/ui/Poble.jsx @@ -18,6 +18,7 @@ export const Poble = () => { // const [pobleSeleccionat, setPobleSeleccionat] = useState(null); // const [creantPoble, setCreantPoble] = useState(false); useSubscribe('pobles'); + useSubscribe('usuaris'); // const pobles = useTracker("pobles", () => PoblesCollection.find().fetchAsync()); const pobles = useFind(PoblesCollection, [{}, {sort: {nomPoble: 1}}]); @@ -77,10 +78,10 @@ export const Poble = () => { // }} // > // - // refInAmbitAssignat.current.value = ev.target.value.replace(/ +/g, '-').toLowerCase()} // />
//
@@ -111,6 +112,60 @@ export const Poble = () => {

{pob?.nomPoble}

+

Monitores:

+
    + { + (async () => { + const monitors = await Roles.getUsersInRoleAsync("monitor_de_poble", pob?.ambitAssociat); + console.log("monitors: ", monitors); + return monitors?.map( (u) =>
  • {u.username}
  • ); + })() + } +
+ +

Encarregades de tasques:

+
    + { + (async () => { + const encarregats = await Roles.getUsersInRoleAsync("encarregat_de_tasques", pob?.ambitAssociat); + console.log("encarregats: ", encarregats); + return encarregats?.map( (u) =>
  • {u.username}
  • ); + })() + } +
+ +

Voluntàries de poble:

+
    + { + (async () => { + const voluntaris = await Roles.getUsersInRoleAsync("voluntari_de_poble", pob?.ambitAssociat); + console.log("voluntaris: ", voluntaris); + return voluntaris?.map( (u) =>
  • {u.username}
  • ); + })() + } +
+ {/* { esEditor && (pobleSeleccionat || creantPoble) && }
    { }} > - {pob.nomPoble}{esEditor && } + {pob.nomPoble}{esEditor && } ) diff --git a/server/main.js b/server/main.js index c154f0f..e522993 100644 --- a/server/main.js +++ b/server/main.js @@ -194,13 +194,20 @@ Meteor.startup(async () => { Meteor.publish('usuaris', async function (uid) { - const esAdmin = await Roles.userIsInRoleAsync(Meteor.userId(), "admin"); - const userRoles = await Roles.getRolesForUserAsync(Meteor.userId()); + const esAdmin = await Roles.userIsInRoleAsync(this.userId, "admin", null); + const userRoles = await Roles.getRolesForUserAsync(this.userId); console.log("userRoles: ", userRoles); - if (uid) { - return Meteor.users.find({_id: uid},{fields: {username: 1, avatarId: 1, avatarLink: 1}}); + console.log("esAdmin: ", esAdmin); + + if (esAdmin) { + return Meteor.users.find({}); } + + if (uid) { + return Meteor.users.find({_id: uid}, {fields: {username: 1, avatarId: 1, avatarLink: 1}}); + } + return Meteor.users.find({},{fields: {username: 1, avatarId: 1, avatarLink: 1}}); }); //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -222,7 +229,7 @@ Meteor.startup(async () => { // Publish user's own roles Meteor.publish(null, async function () { - if (await Roles.userIsInRoleAsync(Meteor.userId(), "admin")) { + if (await Roles.userIsInRoleAsync(this.userId, "admin")) { return Meteor.roleAssignment.find(); }