Compare commits

...

23 Commits
rrv7 ... main

Author SHA1 Message Date
1cefb0b28e pre files 2025-02-07 17:52:39 +01:00
b25dfe10aa Codis en alpha 2025-02-03 20:03:20 +01:00
6b3944277d codis quasi del tot bé. Cal repassar les dates condicionals d'inici i fi 2025-01-30 00:31:43 +01:00
b61adc4f91 Codis quasi operatius 2025-01-28 17:07:45 +01:00
6fd0e86205 Comença a funcionar el panell del codi seleccionat amb canvis en temps real sobre la bd 2025-01-24 03:13:35 +01:00
2cefdc58aa Ja se creen usuaris amb Codis. També funciona l'act_abs 2025-01-23 03:06:24 +01:00
a7b3ba7cb5 Encara no acaba de crear amb codi 2025-01-22 23:59:04 +01:00
2530991ba0 Generem i afegim codis 2025-01-22 03:07:57 +01:00
c82cd4f545 Generem i afegim codis 2025-01-22 03:07:27 +01:00
4ce2ee304d post audit fix 2025-01-19 16:45:37 +01:00
11928b58aa 311 ok 2025-01-19 16:42:55 +01:00
69ef122f9c WIP push 2025-01-10 10:44:13 +01:00
52c381b592 pre codis 2025-01-09 18:27:36 +01:00
f8072fd2d7 Versió async de 'ambits' en assignació de rols 2025-01-08 03:39:28 +01:00
f3b9214019 Eliminat package-lock.json 2025-01-08 03:18:48 +01:00
7c21d374ba Després d'un clot 2025-01-08 03:12:15 +01:00
8c67900952 Assignació de rol admin 2025-01-08 03:05:30 +01:00
6efa6956d7 Resolt problema amb versió síncrona 2025-01-08 01:32:40 +01:00
182c1025ac Unmessing. Abans de provar les solucions de kapa ai 2025-01-08 00:55:39 +01:00
945cfa46e3 codis_1 2025-01-07 21:58:03 +01:00
d6e1329d79 codis_0 2025-01-07 12:08:38 +01:00
1ca37ff79b Abans del RRv7 2024-12-15 16:13:37 +01:00
2b1dd38b95 Abans d'actualitzar a Router v7 2024-12-15 15:29:55 +01:00
17 changed files with 1491 additions and 112 deletions

View File

@ -6,7 +6,7 @@
meteor-base@1.5.2 # Packages every Meteor app needs to have
mobile-experience@1.1.2 # Packages for a great mobile UX
mongo@2.0.3 # The database Meteor supports right now
mongo@2.1.0 # The database Meteor supports right now
reactive-var@1.0.13 # Reactive variable for tracker
standard-minifier-css@1.9.3 # CSS minifier run for production mode
@ -19,6 +19,6 @@ hot-module-replacement@0.5.4 # Update client in development without reloading t
static-html@1.4.0 # Define static page content in .html files
react-meteor-data # React higher-order component for reactively tracking Meteor data
roles@1.0.0
roles@1.0.1
accounts-password@3.0.3
react-meteor-accounts

View File

@ -1 +1 @@
METEOR@3.1
METEOR@3.1.1

View File

@ -1,8 +1,8 @@
accounts-base@3.0.3
accounts-base@3.0.4
accounts-password@3.0.3
allow-deny@2.0.0
allow-deny@2.1.0
autoupdate@2.0.0
babel-compiler@7.11.2
babel-compiler@7.11.3
babel-runtime@1.5.2
base64@1.0.13
binary-heap@1.0.12
@ -12,10 +12,10 @@ callback-hook@1.6.0
check@1.4.4
core-runtime@1.0.0
ddp@1.4.2
ddp-client@3.0.3
ddp-client@3.1.0
ddp-common@1.4.4
ddp-rate-limiter@1.2.2
ddp-server@3.0.3
ddp-server@3.1.0
diff-sequence@1.1.3
dynamic-import@0.7.4
ecmascript@0.16.10
@ -35,7 +35,7 @@ inter-process-messaging@0.1.2
launch-screen@2.0.1
localstorage@1.2.1
logging@1.3.5
meteor@2.0.2
meteor@2.1.0
meteor-base@1.5.2
minifier-css@2.0.0
minifier-js@3.0.1
@ -46,11 +46,11 @@ modern-browsers@0.1.11
modules@0.20.3
modules-runtime@0.13.2
modules-runtime-hot@0.14.3
mongo@2.0.3
mongo@2.1.0
mongo-decimal@0.2.0
mongo-dev-server@1.1.1
mongo-id@1.0.9
npm-mongo@6.10.0
npm-mongo@6.10.2
ordered-dict@1.2.0
promise@1.0.0
random@1.2.2
@ -61,11 +61,11 @@ react-meteor-data@3.0.3
reactive-var@1.0.13
reload@1.3.2
retry@1.1.1
roles@1.0.0
roles@1.0.1
routepolicy@1.1.2
sha@1.0.10
shell-server@0.6.1
socket-stream-client@0.5.3
socket-stream-client@0.6.0
standard-minifier-css@1.9.3
standard-minifier-js@3.0.0
static-html@1.4.0
@ -75,4 +75,3 @@ typescript@5.6.3
url@1.3.5
webapp@2.0.4
webapp-hashing@1.1.2
zodern:types@1.0.13

1
PROBLEMES.MD Normal file
View File

@ -0,0 +1 @@
- Al crear codis encara se poden crear (i posteriorment assignarien) codis amb Àmbits i Rols incoherents.

3
imports/api/codis.js Normal file
View File

@ -0,0 +1,3 @@
import { Mongo } from 'meteor/mongo';
export const CodisCollection = new Mongo.Collection('codis');

View File

@ -12,6 +12,7 @@ import { BarraNav } from './BarraNav/BarraNav';
import { UserStat } from './BarraNav/UserStat';
import { Usuaris } from './Usuaris';
import { Codis } from './Codis';
const Loguejat = lazy(async () => await import('/imports/ui/Loguejat.jsx'));
@ -54,6 +55,7 @@ export const App = () => {
<Route path="necessitats" element={ <Necessitats /> } />
<Route path="tipus" element={ <Tipus /> } />
<Route path="login" element={ <Login /> } />
{esAdministrador && <Route path="codis" element={ <Codis /> } />}
</Routes>
</BrowserRouter>
};

View File

@ -19,6 +19,10 @@ const SeccióUsuaris = lazy(async () => {
const module = await import('/imports/ui/BarraNav/PanellSeccions/PanellSeccions.jsx');
return ({ default: module.SeccióUsuaris });
});
const SeccióCodis = lazy(async () => {
const module = await import('/imports/ui/BarraNav/PanellSeccions/PanellSeccions.jsx');
return ({ default: module.SeccióCodis });
});
const BarraNav = ({esAdministrador, setEsAdministrador}) => {
const userId = Meteor.userId();
@ -38,6 +42,7 @@ const BarraNav = ({esAdministrador, setEsAdministrador}) => {
<SeccióPobles />
<SeccióNecessitats />
<SeccióTipus />
{ esAdministrador && <SeccióCodis />}
</PanellSeccions>;
};

View File

@ -34,15 +34,21 @@ export const SeccióUsuaris = () => <BotóSecció
linkto="usuaris"
/>;
export const SeccióCodis = () => <BotóSecció
titol="Codis"
linkto="codis"
/>;
export const PanellSeccions = ({children}) => {
return <><div style={{
display: `flex`,
border: `1px solid #cccc`,
padding: `.5rem`,
borderRadius: `.5rem`,
backgroundColor: `lightslategray`
backgroundColor: `lightslategray`,
flexWrap: `wrap`,
justifyContent: `space-around`
}}>{children}</div>
<br />
</>;
};

View File

@ -1,5 +1,5 @@
import { Meteor } from 'meteor/meteor';
import React, {useState, useEffect, Suspense} from 'react';
import React, {useState, useRef, useEffect, Suspense} from 'react';
import { useTracker, useFind } from 'meteor/react-meteor-data/suspense';
// import { FilesCol } from '/imports/api/files.js';
@ -10,6 +10,7 @@ import { Roles } from 'meteor/roles';
// import { groupBy } from 'lodash';
//import Radium from 'radium';
import { useLongTap } from '../hooks';
const IndicadorMissatges = ({notif}) => {
@ -27,9 +28,89 @@ const IndicadorMissatges = ({notif}) => {
</span>;
};
const UserStat = ({esAdministrador, setEsAdministrador}) => {
const useLongPress = (mostraMenu, setMostraMenu) => {
const [isPressed, setIsPressed] = useState(false);
const [startTime, setStartTime] = useState(0);
const [hasLongPressed, setHasLongPressed] = useState(false);
const targetRef = useRef(null);
const onPointerDown = (e) => {
if (!isPressed) {
setIsPressed(true);
setStartTime(Date.now());
}
};
const onPointerUp = () => {
if (isPressed) {
setIsPressed(false);
// Clear any pending timeout
clearTimeout(timeoutId?.current);
}
};
const onPointerMove = () => {
if (!isPressed) return;
// Check pointer position changes and update state if needed
// You can implement your own logic here to detect movement
};
useEffect(() => {
let timeoutId = undefined;
if (isPressed) {
timeoutId = setTimeout(() => {
const duration = Date.now() - startTime;
if (duration >= 500 && isPressed) {
setHasLongPressed(true);
setMostraMenu(true);
}
}, 500);
}
return () => clearTimeout(timeoutId);
}, [isPressed]);
useEffect(() => {
const handleDocumentClick = (e) => {
if (targetRef.current && !targetRef.current.contains(e.target)) {
setHasLongPressed(false);
setIsPressed(false);
setMostraMenu(false);
}
};
document.addEventListener('click', handleDocumentClick);
document.addEventListener('touchstart', handleDocumentClick);
document.addEventListener('pointerdown', handleDocumentClick);
return () => {
document.removeEventListener('click', handleDocumentClick);
document.removeEventListener('touchstart', handleDocumentClick);
document.removeEventListener('pointerdown', handleDocumentClick);
};
}, [targetRef]);
return {
hasLongPressed,
setHasLongPressed,
onPointerDown,
onPointerUp,
onPointerMove,
targetRef
};
};
const UserStat = ({esAdministrador, setEsAdministrador}) => {
// const [esAdministrador, setEsAdministrador] = useState(false);
const [mostraMenu, setMostraMenu] = useState(false);
const { hasLongPressed, setHasLongPressed, onPointerDown, onPointerUp, onPointerMove, targetRef } = useLongPress(mostraMenu, setMostraMenu);
const u = useTracker("user", async () => await Meteor.userAsync());
const userId = Meteor.userId();
@ -58,13 +139,19 @@ const UserStat = ({esAdministrador, setEsAdministrador}) => {
// const uname = useTracker(() => Meteor.user({ fields: { 'username': 1 } })?.username );
const [mostraMenu, setMostraMenu] = useState(false);
//const avatarLink = u.avatarLink;
// alert("avLnk: ", u.profile.avatarLink);
// if (hasLongPressed) {
// setMostraMenu(true);
// }
return <Suspense fallback="Carregant...">
<div
style={{
// color: `lightblue`,
@ -80,22 +167,36 @@ const UserStat = ({esAdministrador, setEsAdministrador}) => {
fontWeight: `bold`,
display: `inline-block`
}}
onMouseEnter={ev => {
setMostraMenu(true);
}}
// onMouseEnter={ev => {
// setMostraMenu(true);
// }}
onPointerDown={onPointerDown}
onPointerUp={onPointerUp}
onPointerMove={onPointerMove}
ref={targetRef}
// title="Logout"
// // title="Logout"
onClick={ev => {
ev.stopPropagation();
ev.preventDefault();
// onClick={ev => {
// ev.stopPropagation();
// ev.preventDefault();
// console.log("u: ", u);
// // console.log("u: ", u);
navigate(`/${u.username}`);
// navigate(`/${u.username}`);
}}
// }}
// onPointerCancel={onPointerCancel}
// onPointerOut={onPointerOut}
>
{/* <span onClick={() => setHasLongPressed(!hasLongPressed)}>
{hasLongPressed ? 'Yes!' : 'No'}
</span> */}
{ (u && esAdministrador) && <div style={{
color: `red`,
fontSize: `xx-small`,

547
imports/ui/Codis.jsx Normal file
View File

@ -0,0 +1,547 @@
import React, { Suspense, useEffect, useState } from 'react';
import { Meteor } from 'meteor/meteor';
import { Random } from 'meteor/random';
import { NecessitatsCollection } from '/imports/api/necessitats.js';
import { PoblesCollection } from '../api/pobles';
import { CodisCollection } from '../api/codis';
// import { TipusCollection } from '../api/tipus';
import { useSubscribe, useTracker, useFind } from 'meteor/react-meteor-data/suspense';
import { Roles } from 'meteor/roles';
// import { useNavigate } from 'react-router-dom';
// import { useUserId } from 'meteor/react-meteor-accounts';
import Select from 'react-select';
function generaCodi() {
return Random.id().slice(0, 5).toUpperCase();
}
export const Codis = () => {
const [esEditor, setEsEditor] = useState(false);
const userId = Meteor.userId();
const [codiSeleccionat, setCodiSeleccionat] = useState(null);
useEffect(() => {
(async () => {
const comprovaAdmin = await Roles.userIsInRoleAsync(userId, ["admin"]);
setEsEditor(comprovaAdmin);
})();
}, []);
const [confecCodObj, setConfecCodObj] = useState({
codi: generaCodi(),
ambit: null,
rol: null,
absCond: "abs",
absActiu: false,
condIni: null,
condFi: null
});
useSubscribe('codis');
const codis = useTracker("codis", () => CodisCollection.find().fetchAsync());
useSubscribe('pobles');
const pobles = useTracker("pobles", () => PoblesCollection.find().fetchAsync());
const ambits = pobles?.map(p => p?.ambitAssociat);
const codiDoc = useTracker("valsFormDoc", () => CodisCollection.findOneAsync(codiSeleccionat?._id));
const SelectorDeRol = () => {
return <>
<label htmlFor="selRol">Rol: </label>
<Select
required
key={Math.random()}
name="selRol"
defaultValue={
codiSeleccionat
? {
label: codiSeleccionat?.rol,
value: codiSeleccionat?.rol
}
: confecCodObj?.rol || null
}
onChange={v => {
// console.log("v: ", v);
// console.log("cCO abans: ", confecCodObj);
setConfecCodObj({
...confecCodObj,
rol: v
});
// console.log("cCO despres: ", confecCodObj);
}}
options={
(confecCodObj?.ambit?.value === "GENERAL")
? [
{
value: "admin",
label: "administrador"
},
{
value: "usuari",
label: "usuari"
}
]
: [
{
value: "monitor_de_poble",
label: "monitor_de_poble"
},
{
value: "encarregat_de_tasques",
label: "encarregat_de_tasques"
},
{
value: "voluntari_de_poble",
label: "voluntari_de_poble"
}
]
}
/>
</>;
}
function handleToggleAbsActiu(ev) {
ev.preventDefault();
ev.stopPropagation();
if (codiSeleccionat) {
Meteor.callAsync('modCodiDocToggleAbsActiu', codiSeleccionat);
setCodiSeleccionat({
...codiSeleccionat,
absActiu: !codiSeleccionat.absActiu
});
} else {
setConfecCodObj({
...confecCodObj,
absActiu: !confecCodObj.absActiu
});
}
}
function handleSetCondIni(v) {
console.log("h")
Meteor.callAsync('modCodiDocSetCondIni', {
...codiSeleccionat,
condIni: v.currentTarget.value
});
if (codiSeleccionat) {
setCodiSeleccionat({
...codiSeleccionat,
condIni: v.currentTarget.value
});
} else {
setConfecCodObj({
...confecCodObj,
condIni: v.currentTarget.value
});
}
}
function handleSetCondFi(v) {
Meteor.callAsync('modCodiDocSetCondFi', {
...codiSeleccionat,
condFi: v.currentTarget.value
});
if (codiSeleccionat) {
setCodiSeleccionat({
...codiSeleccionat,
condFi: v.currentTarget.value
});
} else {
setConfecCodObj({
...confecCodObj,
condFi: v.currentTarget.value
});
}
}
const QuadreInfo_Codis = () => {
// const navigate = useNavigate();
const [actCond, setActCond] = useState(true);
// 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 <div style={{
display: `inline-block`,
border: `1px solid #6666`,
padding: `.5rem`,
borderRadius: `.3em`,
backgroundColor: `lightcyan`,
outline: `${codiSeleccionat?._id ? '5px solid black' : 'none'}`
}}>
<h1>Codis</h1>
<div
style={{
fontWeight: `bolder`,
textAlign: `center`,
transform: `scale(2)`
}}
>
<span
style={{
backgroundColor: `white`,
border: `3px solid black`,
padding: `0 .2em`,
margin: `1rem auto`,
}}
>{codiSeleccionat ? codiSeleccionat?.codi : confecCodObj.codi}</span>
</div>
<br />
<p>Tria el rol que adquirirà qui utilitze el codi anterior una vegada activat</p>
<form
action={d => {
try {
Meteor.callAsync('editaOAfigCodi', {
...confecCodObj || [],
codi: confecCodObj.codi,
ambit: d.get('selAmbit') || "",
rol: d.get('selRol'),
absCond: d.get('absCond'),
absActiu: d.get('absActiu'),
condIni: d.get('condIni'),
condFi: d.get('condFi')
})
.then(() => setConfecCodObj({
codi: generaCodi(),
ambit: null,
rol: null,
absCond: "abs",
absActiu: false,
condIni: null,
condFi: null
}))
.catch(err => console.error(err))
;
} catch (err) {
alert(err);
console.error(err);
}
}}
>
<label htmlFor="selAmbit">Àmbit: </label>
<Select
required
name="selAmbit"
defaultValue={codiDoc && {
label: codiDoc?.ambit,
value: codiDoc?.ambit
} || confecCodObj.ambit}
options={
[...
ambits
.map((v,i) => ({
value: v,
label: v
}))
.sort((a,b) => a.label.toLowerCase() > b.label.toLowerCase()),
{
value: "GENERAL",
label: "GENERAL"
}
]
}
isSearchable
onChange={amb => {
setConfecCodObj({
...confecCodObj,
ambit: amb
});
}}
/>
<br />
<SelectorDeRol />
<br /><br />
<p>Periode de validesa: </p>
<div style={{
border: `1px solid #cccc`,
borderRadius: `.4em`,
margin: `1rem`,
padding: `.6rem`,
backgroundColor: `lightslategray`
}}>
{/* <p>TEMPS REAL:</p> */}
<label htmlFor="inActAbs">
<input
type="radio"
name='absCond'
value="abs"
id="inActAbs"
checked={
codiSeleccionat
&&
codiSeleccionat.absCond === 'abs'
||
confecCodObj?.absCond === 'abs'
&&
!codiSeleccionat
}
onChange={(ev) => {
if (codiSeleccionat) {
Meteor.callAsync('modActivacioAbsCond', codiSeleccionat, 'abs');
setCodiSeleccionat({
...codiSeleccionat,
absCond: 'abs'
});
} else {
setConfecCodObj({
...confecCodObj,
absCond: 'abs'
})
}
}}
/>
<span>Activació absoluta</span>
</label>
<br />
<label htmlFor="inActCond">
<input
type="radio"
name='absCond'
value="cond"
id="inActCond"
checked={
codiSeleccionat
&&
codiSeleccionat.absCond === 'cond'
||
confecCodObj?.absCond === 'cond'
&&
!codiSeleccionat
}
onChange={(ev) => {
// console.log("ev: ", ev);
if (codiSeleccionat) {
Meteor.callAsync('modActivacioAbsCond', codiSeleccionat, 'cond');
setCodiSeleccionat({
...codiSeleccionat,
absCond: 'cond'
});
} else {
setConfecCodObj({
...confecCodObj,
absCond: 'cond'
})
}
}}
/>
<span>Activació condicionada</span>
</label>
<br />
<br />
<div style={{
border: `1px solid #6666`,
padding: `0 1rem`,
borderRadius: `.5em`,
backgroundColor: `#fff2`
}}>
{
(codiSeleccionat
&&
codiSeleccionat?.absCond === 'abs'
||
confecCodObj?.absCond === 'abs'
)
&&
codiSeleccionat?.absCond !== 'cond'
&&
<>
<label htmlFor="act_status">Actiu</label>
<input
type="checkbox"
name="absActiu"
id="absActiu"
{...codSelAbsActChecked}
onChange={ev => {
handleToggleAbsActiu(ev);
}}
/>
</>
}
{
(codiSeleccionat
&&
codiSeleccionat.absCond === 'cond'
||
confecCodObj?.absCond === 'cond'
)
&&
codiSeleccionat?.absCond !== 'abs'
&&
<>
<p
style={{
color: `red`
}}
>ATENCIÓ al format! <b>(mm/dd/aaaa)</b></p>
Des de: <input
required={confecCodObj.actCond === 'cond'}
type="date"
name="condIni"
onChange={v => {
// // console.log("dataIni: ", v.currentTarget.value);
// setConfecCodObj({
// ...confecCodObj,
// condIni: v.currentTarget.value
// })
handleSetCondIni(v);
}}
defaultValue={codiSeleccionat?.condIni || confecCodObj.condIni}
/>
<br />
Fins a: <input
required={confecCodObj.actCond === 'cond'}
type="date"
name="condFi"
onChange={v => {
// console.log("dataFi: ", v.currentTarget.value);
// setConfecCodObj({
// ...confecCodObj,
// condFi: v.currentTarget.value
// })
handleSetCondFi(v);
}}
defaultValue={codiSeleccionat?.condFi || confecCodObj.condFi}
/>
<br />
</>
}
</div>
</div>
{!codiSeleccionat && <input type='submit' value="Donar d'alta el codi" />}
</form>
</div>;
};
const
today = new Date(),
lastWeek = new Date(today.getFullYear(), today.getMonth(), today.getDate() - 7)
;
return <Suspense fallback={<>Carregant...</>} >
<QuadreInfo_Codis />
<br /><br />
<ul style={{
display: `flex`,
flexWrap: `wrap`,
justifyContent: `space-evenly`,
rowGap: `.3em`,
alignContent: `space-around`
}}>{
codis
.map(cod => <li
key={cod._id}
style={{
display: `block`,
border: `1px solid #6666`,
borderRadius: `.4em`,
padding: `4px`,
listStyle: `none`,
backgroundColor: `${'lightgreen' || 'lightcoral'}`,
position: `relative`,
outline: `${codiSeleccionat?._id === cod._id ? '3px solid black' : 'none'}`
}}
onClick={ev => {
ev.preventDefault();
ev.stopPropagation();
setCodiSeleccionat(codiSeleccionat?._id === cod._id ? null : cod);
}}
>
<span
style={{
width: `5px`,
border: `1px solid #fffa`,
position: `absolute`,
borderRadius: `50%`,
height: `5px`,
right: `2px`,
top: `2px`,
boxShadow: `0 0 14px 5px ${cod.absActiu ? "lime" : "red"}`,
backgroundColor: `${cod.absActiu ? "lime" : "red"}`
}}
onClick={ev => {
handleToggleAbsActiu(ev);
}}
/>
<div>{cod.codi}</div>
<div>{}</div>
</li>)
}</ul>
</Suspense>;
};

View File

@ -1,23 +1,23 @@
import React from 'react';
import { useFind, useSubscribe } from 'meteor/react-meteor-data';
import { LinksCollection } from '../api/links';
// import React from 'react';
// import { useFind, useSubscribe } from 'meteor/react-meteor-data';
// import { LinksCollection } from '../api/links';
export const Info = () => {
const isLoading = useSubscribe('links');
const links = useFind(() => LinksCollection.find());
// export const Info = () => {
// const isLoading = useSubscribe('links');
// const links = useFind(() => LinksCollection.find());
if(isLoading()) {
return <div>Loading...</div>;
}
// if(isLoading()) {
// return <div>Loading...</div>;
// }
return (
<div>
<h2>Learn Meteor!</h2>
<ul>{links.map(
link => <li key={link._id}>
<a href={link.url} target="_blank">{link.title}</a>
</li>
)}</ul>
</div>
);
};
// return (
// <div>
// <h2>Learn Meteor!</h2>
// <ul>{links.map(
// link => <li key={link._id}>
// <a href={link.url} target="_blank">{link.title}</a>
// </li>
// )}</ul>
// </div>
// );
// };

View File

@ -53,7 +53,16 @@ export const Login = () => {
};
if (isLogin) {
return <form onSubmit={handleLogin}>
return <form
onSubmit={handleLogin}
style={{
border: `2px solid #cccc`,
padding: `.8rem`,
borderRadius: `.5em`,
display: `inline-block`,
backgroundColor: `#eeed`
}}
>
<label htmlFor="email">Correu electrònic o nom d'usuari: </label>
<input id="email" type="email" required />
<br />
@ -66,24 +75,128 @@ export const Login = () => {
}
return (
<form onSubmit={handleRegistration}>
<form
action={async d => {
// let userId, codi;
try {
const username = d.get('username');
const email = d.get('email');
const tel = d.get('tel');
const password = d.get('password');
const password2 = d.get('password2');
const codi = d.get('codi');
if (password !== password2) {
console.error("Passwords do not match!");
return null;
}
console.log("username: ", username);
console.log("email: ", email);
console.log("tel: ", tel);
console.log("password: ", password);
console.log("password2: ", password2);
console.log("codi: ", codi);
const uObj = {
username,
email,
tel,
password,
password2
};
Meteor.callAsync('creaUsuariAmbCodi', uObj, codi);
// userId = await Accounts.createUser({
// username,
// email,
// password
// });
// userId && await Roles.addUsersToRolesAsync(userId, [ROLS_GLOBALS.USUARI]);
// console.log("userId deL NOU USUARI: ", userId);
} catch (err) {
alert(err);
console.error(err);
}
// try {
// userId && await Meteor.callAsync('usaCodiAmbUsuari', userId, codi);
// navigate('/');
// } catch (err2) {
// alert(err2);
// console.error(err2);
// }
// Meteor.callAsync('editaOAfigCodi', {
// ...codiGenerat || [],
// 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')
// })
// .then(() => setAmbitSeleccionat(null))
// .catch(err => console.error(err))
// ;
}}
style={{
border: `2px solid #cccc`,
padding: `.8rem`,
borderRadius: `.5em`,
display: `inline-block`,
backgroundColor: `#eeed`
}}
>
Avatar: <img
style={{
width: `3em`,
height: `3em`,
borderRadius: `50%`,
overflow: `hidden`,
verticalAlign: `middle`,
margin: `.3em`,
border: `solid 4px whitesmoke`
}}
// src={u?.profile?.avatarLink}
onClick={ev => {
}}
/>
<br />
<label htmlFor="username">Nom d'usuari: </label>
<input id="username" type="text" required />
<input id="username" name="username" type="text" required />
<br />
<label htmlFor="email">Correu electrònic: </label>
<input id="email" type="email" required />
<input id="email" name="email" type="email" required />
<br />
<label htmlFor="password">Contrasenya: </label>
<input id="password" type="password" required />
<input id="password" name="password" type="password" required />
<br />
<label htmlFor="password2">Repeteix la contrasenya: </label>
<input id="password2" type="password" required />
<input id="password2" name="password2" type="password" required />
<br />
<label htmlFor="tel">Telèfon: </label>
<input id="tel" type="tel" required />
<input id="tel" name="tel" type="tel" required />
<br />
<label htmlFor="codi">Codi d'entrada (opcional): </label>
<input id="codi" type="text" />
<input id="codi" name="codi" type="text" style={{textAlign: `center`, fontWeight: `bolder`, fontSize: `1.1rem`}} onChange={ev => ev.target.value = (ev.currentTarget.value.length <= 5 && ev.currentTarget.value.toUpperCase()) || ev.currentTarget.value.slice(0, 5) } />
<br />
<button type="submit">Registrar</button>
<button onClick={() => setIsLogin( true )}>Torna per accedir</button>

View File

@ -36,7 +36,7 @@ import { useNavigate, Link } from 'react-router-dom';
// </span>;
// };
const U = ({u, esAdministrador}) => {
const U = ({u, esAdministrador, setUsrSeleccionat}) => {
const [adm, setAdm] = useState(false);
const [mon, setMon] = useState(false);
@ -99,6 +99,7 @@ const U = ({u, esAdministrador}) => {
return <Suspense fallback="Carregant...">
<div
key={`u_${u._id}`}
style={{
// color: `lightblue`,
@ -190,9 +191,10 @@ const U = ({u, esAdministrador}) => {
ev.preventDefault();
ev.stopPropagation();
alert("Click en missatges");
// alert("Click en missatges");
}}
>
{<button onClick={() => {setUsrSeleccionat(u)}}>Edita</button>}
{/* <IndicadorMissatges notif={false} /> */}
</span>
</div>
@ -210,7 +212,7 @@ const U = ({u, esAdministrador}) => {
// zIndex: `200`
// }}
// // onMouseLeave={ev => {
// // setMostraMenu(false);
// // setMostraMenu(false);p
// // }}
// >
// {/* <Link to="/c/config"> */}
@ -245,6 +247,201 @@ const U = ({u, esAdministrador}) => {
};
const AssignadorDeRols = ({pobles, esEditor, rols, usrSeleccionat, ambitsUSel}) => {
const [creantRol, setCreantRol] = useState(false);
const [ambitGeneral, setAmbitGeneral] = useState(false);
// const [ambitsUSel, setAmbitsUSel] = useState([]);
// let ambitsUSel;
// let ambitsUSel = [];
// useEffect(() => {
// (async () => {
// const ambits = await Roles.getScopesForUserAsync(usrSeleccionat?._id);
// // console.log("ambitsUSel: ", ambitsUSel);
// // ambitsUSel = ambits;
// // setAmbitsUSel(ambits);
// ambitsUSel = ambits;
// // console.log("ambitsUSel: ", ambitsUSel);
// })();
// }, []);
return <div
style={{
display: `block`,
border: `1px solid #6666`,
padding: `.5rem`,
borderRadius: `.3em`,
margin: `1em`,
backgroundColor: `#fffa`
}}
>
<h3>Rols</h3>
<h4>Àmbits</h4>
<h5>General:</h5>
<ul>{
rols?.map(uRol => <li
key={`rol_${uRol}`}
style={{
display: `block`,
border: `1px solid #6666`,
borderRadius: `.4em`,
padding: `4px`,
listStyle: `none`,
backgroundColor: `${'orange'}`,
textAlign: `center`
}}
>
{uRol}
{esEditor && <button onClick={ev => {
ev.preventDefault();
ev.stopPropagation();
confirm(`Vas a retirar el Rol ${uRol} a l'usuari ${usrSeleccionat.username}. Procedir?`) && Meteor.callAsync('retiraRols', uRol, usrSeleccionat._id)
}}>&times;</button>}
</li>)
}</ul>
{/* <ul> */}
{
ambitsUSel.map(async aus => {
console.log("usrSeleccionat: ", usrSeleccionat);
console.log("ambitsUSel: ", ambitsUSel);
const uRol = await Roles.getRolesForUserAsync(usrSeleccionat._id, {scope: aus, onlyScoped: true});
return <>
<h5>{aus}:</h5>
{
<span style={{
display: `block`,
border: `1px solid #6666`,
borderRadius: `.4em`,
padding: `4px`,
listStyle: `none`,
backgroundColor: `${'orange'}`,
textAlign: `center`
}}>{uRol}
{esEditor && <button onClick={ev => {
ev.preventDefault();
ev.stopPropagation();
confirm(`Vas a retirar el Rol ${uRol} a l'usuari ${usrSeleccionat.username}. Procedir?`) && Meteor.callAsync('retiraRols', uRol, usrSeleccionat._id, aus)
}}>&times;</button>}
</span>
} <br />
</>;
})
}
{/* </ul> */}
{esEditor && creantRol && <div style={{
display: `block`,
border: `1px solid #6666`,
padding: `.5rem`,
borderRadius: `.3em`,
margin: `1em`,
backgroundColor: `#fffa`
}}>
<form action={d => {
if (ambitGeneral) {
Meteor.callAsync('assignaRol', usrSeleccionat._id, d.get('selRol'));
} else {
Meteor.callAsync('assignaRol', usrSeleccionat._id, d.get('selRol'), d.get('selAmbit'));
}
}}>
Àmbit: <select name="selAmbit" id="selAmbit"
onChange={ev => setAmbitGeneral(ev.target.value === "GENERAL")}
>
{
pobles.sort((a,b) => a.ambitAssociat > b.ambitAssociat).map((pob,i) => <option key={`optAmb_${i}`} value={pob.ambitAssociat}>{pob.ambitAssociat}</option>)
}
<option value={"GENERAL"}>General</option>
</select> <br />
Rol: <select name="selRol" id="selRol">
{
ambitGeneral
? <option value={"admin"}>Administrador general</option>
: <>
<option value="monitor_de_poble">Monitor de poble</option>
<option value="encarregat_de_tasques">Encarregat de tasques</option>
<option value="voluntari_de_poble">Voluntairi de poble</option>
</>
}
</select> <br /> <br />
<input type="submit" value="Estableix nou rol" />
</form>
</div>}
{esEditor && usrSeleccionat && <button
onClick={ev => {
ev.preventDefault();
ev.stopPropagation();
return false;
}}
onPointerUp={ev => {
ev.preventDefault();
ev.stopPropagation();
setCreantRol(!creantRol);
return false;
}}
>+</button>}
</div>;
};
const QuadreInfo_Usuari = ({usrSeleccionat, esEditor, pobles, rols, ambitsUSel}) => {
return <div style={{
display: `inline-block`,
border: `1px solid #6666`,
padding: `.5rem`,
borderRadius: `.3em`,
backgroundColor: `lightcyan`
}}>
{usrSeleccionat && <h2>{usrSeleccionat._id}</h2>}
<form
action={d => {
try {
Meteor.callAsync('editaOAfigPoble',
{
...usrSeleccionat || [],
nomPoble: d.get('nomPoble'),
cp: d.get('cp') || "",
comarca: d.get('comarca') || "",
}).then(() => setUsrSeleccionat(null))
.catch(err => console.error(err));
} catch (err) {
alert(err);
console.error(err);
}
}}
>
<label htmlFor="inUsername">Nom d'usuari: </label><input name="inUsername" type="text" defaultValue={ usrSeleccionat ? usrSeleccionat.username : ""}/><br />
<label htmlFor="inTel">Telèfon: </label><input name="inTel" type="tel" /><br />
<label htmlFor="inEmail">Correu Electrònic: </label><input name="inEmail" type="email" /><br />
<input type='submit' value="Actualitzar la Població" />
<button onClick={ev => {
ev.preventDefault();
if (confirm(`Vas a eliminar el poble "${usrSeleccionat.nomPoble}". És una operació irreversible. Procedir?`)) {
Meteor.callAsync('eliminaPoble', usrSeleccionat._id).catch(err => console.error(err));
setUsrSeleccionat(null);
}
}}>Elimina</button>
</form>
{ esEditor && <Suspense>
<AssignadorDeRols {... {esEditor, usrSeleccionat, rols, pobles, ambitsUSel}} />
</Suspense>
}
</div>;
};
export const Usuaris = () => {
const [usrSeleccionat, setUsrSeleccionat] = useState(null);
@ -260,14 +457,31 @@ export const Usuaris = () => {
});
// console.log("isAdmin: ", isAdmin) ;
console.log("usuaris: ", usuaris);
// const [ambitsUSel, setAmbitsUSel] = useState([]);
// (async () => {
useEffect(() => {
(async () => {
const comprovaAdmin = await Roles.userIsInRoleAsync(userId, ["admin"]);
setEsEditor(comprovaAdmin);
})();
}, []);
// let ambitsUSel = [];
useEffect(() => {
(async () => {
const comprovaAdmin = await Roles.userIsInRoleAsync(userId, ["admin"]);
setEsEditor(comprovaAdmin);
// console.log("ambitsUSel: ", ambitsUSel);
})();
}, []);
const ambitsUSel = useTracker("ambits", async () => {
return await Roles.getScopesForUserAsync(usrSeleccionat?._id);
});
// setAmbitsUSel(ambits);
const rols = useTracker("rols", async () => {
return await Roles.getRolesForUserAsync(usrSeleccionat?._id);
});
// })();
// const [monitors, setMonitors] = useState(false);
@ -307,54 +521,12 @@ export const Usuaris = () => {
// })();
const QuadreInfo_Usuari = () => {
return <div style={{
display: `inline-block`,
border: `1px solid #6666`,
padding: `.5rem`,
borderRadius: `.3em`,
backgroundColor: `lightcyan`
}}>
{usrSeleccionat && <h2>{usrSeleccionat._id}</h2>}
<form
action={d => {
try {
Meteor.callAsync('editaOAfigPoble',
{
...usrSeleccionat || [],
nomPoble: d.get('nomPoble'),
cp: d.get('cp') || "",
comarca: d.get('comarca') || "",
}).then(() => setUsrSeleccionat(null))
.catch(err => console.error(err));
} catch (err) {
alert(err);
console.error(err);
}
}}
>
<label htmlFor="inUsername">Nom d'usuari: </label><input name="inUsername" type="text" defaultValue={ usrSeleccionat ? usrSeleccionat.username : ""}/><br />
<label htmlFor="inTel">Telèfon: </label><input name="inTel" type="tel" /><br />
<label htmlFor="inEmail">Correu Electrònic: </label><input name="inEmail" type="email" /><br />
<input type='submit' value="Actualitzar la Població" />
<button onClick={ev => {
ev.preventDefault();
if (confirm(`Vas a eliminar el poble "${usrSeleccionat.nomPoble}". És una operació irreversible. Procedir?`)) {
Meteor.callAsync('eliminaPoble', usrSeleccionat._id).catch(err => console.error(err));
setUsrSeleccionat(null);
}
}}>Elimina</button>
</form>
</div>;
};
return <Suspense fallback={<>Carregant...</>} >
<h1>Usuaris</h1>
{ esEditor && <QuadreInfo_Usuari /> }
{ esEditor && <QuadreInfo_Usuari {... {usrSeleccionat, esEditor, pobles, rols, ambitsUSel}} /> }
<ul style={{
display: `flex`,
@ -378,7 +550,7 @@ export const Usuaris = () => {
}}
>
{/* {usr.username}{esEditor && <button onClick={() => {setUsrSeleccionat(usr)}}>Edita</button>} */}
<U u={usr} esAdministrador={usr._id === Meteor.userId() && esEditor} />
<U u={usr} esAdministrador={usr._id === Meteor.userId() && esEditor} setUsrSeleccionat={setUsrSeleccionat} />
</li>)
}</ul>
</Suspense>;

46
imports/ui/hooks.jsx Normal file
View File

@ -0,0 +1,46 @@
import { useState, useEffect } from 'react';
const useLongTap = (onLongTap, duration = 500) => {
const [isPressing, setIsPressing] = useState(false);
const [startTime, setStartTime] = useState(null);
useEffect(() => {
if (isPressing && startTime) {
const elapsedTime = performance.now() - startTime;
if (elapsedTime >= duration) {
onLongTap();
setIsPressing(false);
setStartTime(null);
}
}
}, [isPressing, startTime, onLongTap, duration]);
const handlePointerDown = (event) => {
setIsPressing(true);
setStartTime(performance.now());
};
const handlePointerUp = () => {
setIsPressing(false);
setStartTime(null);
};
const handlePointerCancel = () => {
setIsPressing(false);
setStartTime(null);
};
const handlePointerOut = () => {
setIsPressing(false);
setStartTime(null);
};
return {
onPointerDown: handlePointerDown,
onPointerUp: handlePointerUp,
onPointerCancel: handlePointerCancel,
onPointerOut: handlePointerOut,
};
};
export { useLongTap };

196
package-lock.json generated
View File

@ -10,6 +10,7 @@
"meteor-node-stubs": "^1.2.5",
"react": "19",
"react-dom": "19",
"react-infinite-calendar": "^1.2.2",
"react-router": "^7.0.2",
"react-router-dom": "^6.28.0",
"react-select": "^5.8.3",
@ -977,6 +978,22 @@
"@babel/types": "^7.19.0"
}
},
"node_modules/babel-runtime": {
"version": "6.26.0",
"resolved": "https://registry.npmjs.org/babel-runtime/-/babel-runtime-6.26.0.tgz",
"integrity": "sha512-ITKNuq2wKlW1fJg9sSW52eepoYgZBggvOAHC0u/CYu/qxQ9EVzThCgR69BnSXLHjy2f7SY5zaQ4yt7H9ZVxY2g==",
"license": "MIT",
"dependencies": {
"core-js": "^2.4.0",
"regenerator-runtime": "^0.11.0"
}
},
"node_modules/babel-runtime/node_modules/regenerator-runtime": {
"version": "0.11.1",
"resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.11.1.tgz",
"integrity": "sha512-MguG95oij0fC3QV3URf4V2SDYGJhJnJGqvIIgdECeODCT98wSWDAJ94SSuVpYQUoTcGUIL6L4yNB7j1DFFHSBg==",
"license": "MIT"
},
"node_modules/balanced-match": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
@ -1069,6 +1086,13 @@
],
"license": "CC-BY-4.0"
},
"node_modules/chain-function": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/chain-function/-/chain-function-1.0.1.tgz",
"integrity": "sha512-SxltgMwL9uCko5/ZCLiyG2B7R9fY4pDZUw7hJ4MhirdjBLosoDqkWABi3XMucddHdLiFJMb7PD2MZifZriuMTg==",
"license": "MIT",
"peer": true
},
"node_modules/chalk": {
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz",
@ -1087,6 +1111,12 @@
"url": "https://github.com/chalk/chalk?sponsor=1"
}
},
"node_modules/classnames": {
"version": "2.5.1",
"resolved": "https://registry.npmjs.org/classnames/-/classnames-2.5.1.tgz",
"integrity": "sha512-saHYOzhIQs6wy2sVxTM6bUDsQO4F50V9RQ22qBpEdCW+I+/Wmke2HOl6lS6dTpdxVhb88/I6+Hs+438c3lfUow==",
"license": "MIT"
},
"node_modules/color-convert": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
@ -1132,6 +1162,14 @@
"node": ">=18"
}
},
"node_modules/core-js": {
"version": "2.6.12",
"resolved": "https://registry.npmjs.org/core-js/-/core-js-2.6.12.tgz",
"integrity": "sha512-Kb2wC0fvsWfQrgk8HU5lW6U/Lcs8+9aaYcy4ZFc6DDlo4nZ7n70dEgE5rtR0oG6ufKDUnrwfWL1mXR5ljDatrQ==",
"deprecated": "core-js@<3.23.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Some versions have web compatibility issues. Please, upgrade your dependencies to the actual version of core-js.",
"hasInstallScript": true,
"license": "MIT"
},
"node_modules/cosmiconfig": {
"version": "7.1.0",
"resolved": "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-7.1.0.tgz",
@ -1838,6 +1876,12 @@
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/lodash": {
"version": "4.17.21",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==",
"license": "MIT"
},
"node_modules/lodash.merge": {
"version": "4.6.2",
"resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz",
@ -3057,6 +3101,27 @@
"node": "*"
}
},
"node_modules/moment": {
"version": "2.30.1",
"resolved": "https://registry.npmjs.org/moment/-/moment-2.30.1.tgz",
"integrity": "sha512-uEmtNhbDOrWPFS+hdjFCBfy9f2YoyzRpwcl+DqpC6taX21FzsTLQVbMV/W7PzNSX6x/bhC1zA3c2UQ5NzH6how==",
"license": "MIT",
"engines": {
"node": "*"
}
},
"node_modules/moment-range": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/moment-range/-/moment-range-2.2.0.tgz",
"integrity": "sha512-nh2IRdxV+wxiQunifqFVNTSzqNej8HMB/rA8Jxb0CAuhftpjJcRnxrbb30iEs2TLMbcjmXCie4Tsx1JnUomH+g==",
"license": "Public Domain",
"engines": {
"node": "*"
},
"peerDependencies": {
"moment": ">= 1"
}
},
"node_modules/ms": {
"version": "2.1.3",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
@ -3307,6 +3372,84 @@
"node": ">=0.10.0"
}
},
"node_modules/react-addons-css-transition-group": {
"version": "15.6.2",
"resolved": "https://registry.npmjs.org/react-addons-css-transition-group/-/react-addons-css-transition-group-15.6.2.tgz",
"integrity": "sha512-M5AJydHOUGq+YujoQLL8f9mQ0QLqxjqHUpWyvUmWVCYi93iGz53HwNBwzHbr0u21KABoPzyLYZZgMk974uPovw==",
"license": "MIT",
"peer": true,
"dependencies": {
"react-transition-group": "^1.2.0"
},
"peerDependencies": {
"react": "^15.4.2"
}
},
"node_modules/react-addons-css-transition-group/node_modules/dom-helpers": {
"version": "3.4.0",
"resolved": "https://registry.npmjs.org/dom-helpers/-/dom-helpers-3.4.0.tgz",
"integrity": "sha512-LnuPJ+dwqKDIyotW1VzmOZ5TONUN7CwkCR5hrgawTUbkBGYdeoNLZo6nNfGkCrjtE1nXXaj7iMMpDa8/d9WoIA==",
"license": "MIT",
"peer": true,
"dependencies": {
"@babel/runtime": "^7.1.2"
}
},
"node_modules/react-addons-css-transition-group/node_modules/react-dom": {
"version": "16.14.0",
"resolved": "https://registry.npmjs.org/react-dom/-/react-dom-16.14.0.tgz",
"integrity": "sha512-1gCeQXDLoIqMgqD3IO2Ah9bnf0w9kzhwN5q4FGnHZ67hBm9yePzB5JJAIQCc8x3pFnNlwFq4RidZggNAAkzWWw==",
"license": "MIT",
"peer": true,
"dependencies": {
"loose-envify": "^1.1.0",
"object-assign": "^4.1.1",
"prop-types": "^15.6.2",
"scheduler": "^0.19.1"
},
"peerDependencies": {
"react": "^16.14.0"
}
},
"node_modules/react-addons-css-transition-group/node_modules/react-transition-group": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/react-transition-group/-/react-transition-group-1.2.1.tgz",
"integrity": "sha512-CWaL3laCmgAFdxdKbhhps+c0HRGF4c+hdM4H23+FI1QBNUyx/AMeIJGWorehPNSaKnQNOAxL7PQmqMu78CDj3Q==",
"license": "BSD-3-Clause",
"peer": true,
"dependencies": {
"chain-function": "^1.0.0",
"dom-helpers": "^3.2.0",
"loose-envify": "^1.3.1",
"prop-types": "^15.5.6",
"warning": "^3.0.0"
},
"peerDependencies": {
"react": "^15.0.0 || ^16.0.0",
"react-dom": "^15.0.0 || ^16.0.0"
}
},
"node_modules/react-addons-css-transition-group/node_modules/scheduler": {
"version": "0.19.1",
"resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.19.1.tgz",
"integrity": "sha512-n/zwRWRYSUj0/3g/otKDRPMh6qv2SYMWNq85IEa8iZyAv8od9zDYpGSnpBEjNgcMNq6Scbu5KfIPxNF72R/2EA==",
"license": "MIT",
"peer": true,
"dependencies": {
"loose-envify": "^1.1.0",
"object-assign": "^4.1.1"
}
},
"node_modules/react-addons-shallow-compare": {
"version": "15.6.3",
"resolved": "https://registry.npmjs.org/react-addons-shallow-compare/-/react-addons-shallow-compare-15.6.3.tgz",
"integrity": "sha512-EDJbgKTtGRLhr3wiGDXK/+AEJ59yqGS+tKE6mue0aNXT6ZMR7VJbbzIiT6akotmHg1BLj46ElJSb+NBMp80XBg==",
"license": "MIT",
"peer": true,
"dependencies": {
"object-assign": "^4.1.0"
}
},
"node_modules/react-dom": {
"version": "19.0.0",
"resolved": "https://registry.npmjs.org/react-dom/-/react-dom-19.0.0.tgz",
@ -3319,6 +3462,49 @@
"react": "^19.0.0"
}
},
"node_modules/react-infinite-calendar": {
"version": "1.2.2",
"resolved": "https://registry.npmjs.org/react-infinite-calendar/-/react-infinite-calendar-1.2.2.tgz",
"integrity": "sha512-q4brkGDmrCVDsjV0glalu8dSGvU9/DGjg4NzYao0GKNmF1LbtbNTjArCiY8rIMRbJJOrXQzWi9LlON1qauBhFw==",
"license": "MIT",
"dependencies": {
"classnames": "^2.1.2",
"dom-helpers": "^2.4.0",
"lodash": "^4.12.0",
"moment": "^2.13.0",
"moment-range": "^2.2.0",
"react-virtualized": "^8.0.7"
},
"peerDependencies": {
"react": "^0.14.0 || ^15.0.0",
"react-addons-css-transition-group": "^0.14.0 || ^15.0.0",
"react-addons-shallow-compare": "^0.14.0 || ^15.0.0",
"react-dom": "^0.14.0 || ^15.0.0"
}
},
"node_modules/react-infinite-calendar/node_modules/dom-helpers": {
"version": "2.4.0",
"resolved": "https://registry.npmjs.org/dom-helpers/-/dom-helpers-2.4.0.tgz",
"integrity": "sha512-urx8RB5tJo+FTdG0ZGPryUD25wUtK/QXRYg7+GaSgfNZNWOAcGZm0puzrKThZINKQJAVAlVijrAKoKd5jnl4FQ==",
"license": "MIT"
},
"node_modules/react-infinite-calendar/node_modules/react-virtualized": {
"version": "8.11.4",
"resolved": "https://registry.npmjs.org/react-virtualized/-/react-virtualized-8.11.4.tgz",
"integrity": "sha512-xSxTTeMzsl2X6VH+wzTp5MBs5VEnb14/OaljCs646mj+SMkDXmVL9RCneu6mq6zeAapoHYFGV2/aXh9pQ0/Dwg==",
"license": "MIT",
"dependencies": {
"babel-runtime": "^6.11.6",
"classnames": "^2.2.3",
"dom-helpers": "^2.4.0 || ^3.0.0",
"loose-envify": "^1.3.0"
},
"peerDependencies": {
"react": "^0.14.0 || ^15.0.0",
"react-addons-shallow-compare": "^0.14.0 || ^15.0.0",
"react-dom": "^0.14.0 || ^15.0.0"
}
},
"node_modules/react-is": {
"version": "16.13.1",
"resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz",
@ -3710,6 +3896,16 @@
"punycode": "^2.1.0"
}
},
"node_modules/warning": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/warning/-/warning-3.0.0.tgz",
"integrity": "sha512-jMBt6pUrKn5I+OGgtQ4YZLdhIeJmObddh6CsibPxyQ5yPZm1XExSyzC1LCNX7BzhxWgiHmizBWJTHJIjMjTQYQ==",
"license": "BSD-3-Clause",
"peer": true,
"dependencies": {
"loose-envify": "^1.0.0"
}
},
"node_modules/which": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz",

View File

@ -12,6 +12,7 @@
"meteor-node-stubs": "^1.2.5",
"react": "19",
"react-dom": "19",
"react-infinite-calendar": "^1.2.2",
"react-router": "^7.0.2",
"react-router-dom": "^6.28.0",
"react-select": "^5.8.3",

View File

@ -6,6 +6,8 @@ import { Roles } from 'meteor/roles';
import { ROLS_GLOBALS, ROLS_DE_POBLE } from '../imports/roles';
import { NecessitatsCollection } from '../imports/api/necessitats';
import { TipusCollection } from '../imports/api/tipus';
import { CodisCollection } from '../imports/api/codis';
// import { Codis } from '../imports/ui/Codis';
async function insertPoble({ nomPoble, cp, comarca }) {
await PoblesCollection.insertAsync({ nomPoble, cp, comarca, createdAt: new Date() });
@ -201,6 +203,27 @@ Meteor.startup(async () => {
return TipusCollection.find();
});
Meteor.publish('codis', async function (uid) {
const esAdmin = await Roles.userIsInRoleAsync(this.userId, "admin", null);
const userRoles = await Roles.getRolesForUserAsync(this.userId);
// console.log("userRoles: ", userRoles);
// console.log("esAdmin: ", esAdmin);
if (esAdmin) {
return CodisCollection.find({});
}
return false;
// 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}});
});
Meteor.publish('usuaris', async function (uid) {
const esAdmin = await Roles.userIsInRoleAsync(this.userId, "admin", null);
@ -379,6 +402,170 @@ Meteor.methods({
console.error(e);
}
},
'editaOAfigCodi': async function (codiObj) {
const esAdmin = await Roles.userIsInRoleAsync(Meteor.userId(), "admin");
try {
console.log(`CREACIÓ DE CODI sol·licitada per a "${codiObj.codi}". Comprovant si ${Meteor.userId()} és Admin: `, esAdmin);
if (esAdmin && codiObj.codi) {
return await CodisCollection.upsertAsync(
{
_id: codiObj._id
}, {
$set: {
...codiObj,
usuari: Meteor.userId(),
editedAt: new Date()
}
}
);
} else {
throw new Error("El valor del codi no és vàlid");
}
} catch (e) {
console.error(e);
}
},
'creaUsuariAmbCodi': async function (uObj, codi) {
const codiObj = await CodisCollection.findOneAsync({codi});
const userId = await Accounts.createUserAsync(uObj);
const ara = new Date();
let dataIni, dataFi;
console.log("codiObj.periode_validesa_ini: ", await codiObj.periode_validesa_ini);
if (codiObj.act_cond === "on") {
dataIni = new Date(await codiObj.periode_validesa_ini);
dataFi = new Date(await codiObj.periode_validesa_fi);
}
// const dataIni = codiObj.act_cond === "on" ? new Date(codiObj.periode_validesa_ini) : null;
// const dataFi = codiObj.act_cond === "on" ? new Date(codiObj.periode_validesa_fi) : null;
console.log("codiObj: ", codiObj);
console.log("ara: ", ara);
console.log("dataIni: ", dataIni);
console.log("dataFi: ", dataFi);
console.log(`codiObj.act_cond === "on"`, codiObj.act_cond === "on");
try {
console.log(`APLICANT CODI "${codi}" sobre "${userId}".`); // Comprovant si ${Meteor.userId()} és Admin: `, esAdmin);
if ((codiObj.act_cond==="on" && (ara >= dataIni && ara <= dataFi)) || codiObj.act_abs) {
Roles.addUsersToRolesAsync(userId, codiObj.rol, codiObj.ambit);
}
} catch (e) {
console.error(e);
}
},
'usaCodiAmbUsuari': async function (userId, codi) {
// const esAdmin = await Roles.userIsInRoleAsync(Meteor.userId(), "admin");
const codiObj = await CodisCollection.find({codi}).fetchAsync();
const ara = new Date();
let dataIni, dataFi;
if (codiObj.act_cond === "on") {
dataIni = new Date(codiObj.periode_validesa_ini);
dataFi = new Date(codiObj.periode_validesa_fi);
}
console.log("codiObj: ", codiObj);
try {
console.log(`APLICANT CODI "${codi}" sobre "${userId}".`); // Comprovant si ${Meteor.userId()} és Admin: `, esAdmin);
if ((codiObj.act_cond==="on" && (ara >= dataIni || ara <= dataFi)) || codiObj.act_abs) {
Roles.addUsersToRolesAsync(userId, codiObj.rol, codiObj.ambit);
}
// if (esAdmin && codiObj.codi) {
// return await CodisCollection.upsertAsync(
// {
// _id: codiObj._id
// }, {
// $set: {
// ...codiObj,
// usuari: Meteor.userId(),
// editedAt: new Date()
// }
// }
// );
// } else {
// throw new Error("El valor del codi no és vàlid");
// }
} catch (e) {
console.error(e);
}
},
'modCodiDocToggleAbsActiu': async function (cod) {
console.log("modCodiDocToggleAbsActiu: ", cod);
return await CodisCollection.updateAsync(
{ _id: cod._id },
{ $set: {
...cod,
absActiu: !cod.absActiu
}}
);
},
'modActivacioAbsCond': async function (cod, absCond) {
console.log("modActivacioAbsCond: ", cod, absCond);
return await CodisCollection.updateAsync(
{ _id: cod._id },
{ $set: {
...cod,
absCond
}}
);
},
'modCodiDocSetCondIni': async function (cod) {
console.log("modCodiDocSetCondIni: ", cod);
return await CodisCollection.updateAsync(
{ _id: cod._id },
{ $set: {
...cod,
condIni: cod.condIni
}}
);
},
'modCodiDocSetCondFi': async function (cod) {
console.log("modCodiDocSetCondFi: ", cod);
return await CodisCollection.updateAsync(
{ _id: cod._id },
{ $set: {
...cod,
condFi: cod.condFi
}}
);
},
});
});