Compare commits
4 Commits
69ef122f9c
...
2530991ba0
| Author | SHA1 | Date | |
|---|---|---|---|
| 2530991ba0 | |||
| c82cd4f545 | |||
| 4ce2ee304d | |||
| 11928b58aa |
@ -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
|
||||
|
||||
@ -1 +1 @@
|
||||
METEOR@3.1
|
||||
METEOR@3.1.1
|
||||
|
||||
@ -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
|
||||
|
||||
3
imports/api/codis.js
Normal file
3
imports/api/codis.js
Normal file
@ -0,0 +1,3 @@
|
||||
import { Mongo } from 'meteor/mongo';
|
||||
|
||||
export const CodisCollection = new Mongo.Collection('codis');
|
||||
@ -1,7 +1,9 @@
|
||||
import React, { Suspense, useEffect, useState, useRef, lazy } from 'react';
|
||||
import { Meteor } from 'meteor/meteor';;
|
||||
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';
|
||||
@ -12,6 +14,12 @@ 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() {
|
||||
return Random.id().slice(0, 5);
|
||||
}
|
||||
|
||||
export const Codis = () => {
|
||||
|
||||
@ -33,6 +41,9 @@ export const Codis = () => {
|
||||
useSubscribe('necessitats');
|
||||
const necessitats = useTracker("necessitats", () => NecessitatsCollection.find().fetchAsync());
|
||||
|
||||
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);
|
||||
@ -60,6 +71,7 @@ export const Codis = () => {
|
||||
return <>
|
||||
<label htmlFor="selRol">Rol: </label>
|
||||
<Select
|
||||
required
|
||||
key={Math.random()}
|
||||
name="selRol"
|
||||
// filterOption={(opts) => necessitats.find(nec => nec.tipus === tipusSeleccionat._id)}
|
||||
@ -97,6 +109,10 @@ export const Codis = () => {
|
||||
}
|
||||
|
||||
const QuadreInfo_Codis = () => {
|
||||
|
||||
const [actCond, setActCond] = useState(true);
|
||||
const [codiGenerat, setCodiGenerat] = useState(generaCodi()?.toUpperCase());
|
||||
|
||||
|
||||
return <div style={{
|
||||
display: `inline-block`,
|
||||
@ -109,17 +125,49 @@ export const Codis = () => {
|
||||
{ambitSeleccionat && <h1>{ambitSeleccionat?.value}</h1>}
|
||||
<h1>Codis</h1>
|
||||
|
||||
<p>Tria el rol que adquirirà qui utilitze el codi.</p>
|
||||
{/* <button
|
||||
onClick={ev => {
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
|
||||
setCodiGenerat(generaCodi());
|
||||
}}
|
||||
>Genera el codi</button> */}
|
||||
|
||||
<div
|
||||
style={{
|
||||
fontWeight: `bolder`,
|
||||
textAlign: `center`,
|
||||
transform: `scale(2)`
|
||||
}}
|
||||
>
|
||||
<span
|
||||
style={{
|
||||
backgroundColor: `white`,
|
||||
border: `3px solid black`,
|
||||
padding: `0 .2em`,
|
||||
margin: `1rem auto`,
|
||||
}}
|
||||
>{codiGenerat}</span>
|
||||
</div>
|
||||
<br />
|
||||
|
||||
<p>Tria el rol que adquirirà qui utilitze el codi anterior una vegada activat</p>
|
||||
|
||||
|
||||
<form
|
||||
action={d => {
|
||||
// if (d.get('selTipus'))
|
||||
try {
|
||||
Meteor.callAsync('editaOAfigNecessitat', {
|
||||
...tipusSeleccionat || [],
|
||||
titol: d.get('titol'),
|
||||
tipus: d.get('selTipus') || "",
|
||||
poble: d.get('selPoble')
|
||||
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))
|
||||
@ -138,6 +186,7 @@ export const Codis = () => {
|
||||
*/}
|
||||
|
||||
<Select
|
||||
required
|
||||
name="selAmbit"
|
||||
// formatCreateLabel={(inputValue) => "Crear nou tipus..."}
|
||||
// filterOption={filterAmbit}
|
||||
@ -178,37 +227,75 @@ export const Codis = () => {
|
||||
|
||||
<SelectorDeRol {... {ambitSeleccionat}} />
|
||||
|
||||
<br />
|
||||
|
||||
<label htmlFor="actiu">Actiu? </label>
|
||||
<input type="checkbox" name='actiu' />
|
||||
|
||||
<br /><br />
|
||||
|
||||
<label htmlFor="periode_validesa">Periode de validesa: </label>
|
||||
<input type="date" name="periode_validesa" />
|
||||
|
||||
<div style={{
|
||||
border: `1px solid #cccc`,
|
||||
borderRadius: `.4em`,
|
||||
margin: `1rem`,
|
||||
padding: `.6rem`,
|
||||
backgroundColor: `lightslategray`
|
||||
}}>
|
||||
<p>TEMPS REAL:</p>
|
||||
<label htmlFor="activ_abs"
|
||||
style={{
|
||||
color: `red`
|
||||
}}
|
||||
>Activació absoluta: </label>
|
||||
<input type="checkbox" name='activ_abs' />
|
||||
|
||||
<br />
|
||||
|
||||
{/* L'activació condicionada desactivada fa que no siguen 'required' les dates d'inici i final */}
|
||||
|
||||
<label htmlFor="activa_cond">Activació condicionada: </label>
|
||||
<input type="checkbox" name='activ_cond' checked={actCond}
|
||||
onChange={(ev) => setActCond(!actCond)}
|
||||
/>
|
||||
<p
|
||||
style={{
|
||||
color: `red`
|
||||
}}
|
||||
>ATENCIÓ al format! <b>(mm/dd/aaaa)</b></p>
|
||||
|
||||
Des de: <input required={actCond} type="date" name="periode_validesa_ini" />
|
||||
<br />
|
||||
Fins a: <input required={actCond} type="date" name="periode_validesa_fi" />
|
||||
<br />
|
||||
</div>
|
||||
|
||||
{/* <select name="selPoble">
|
||||
{/* <select name="s.
|
||||
elPoble">
|
||||
{
|
||||
pobles.map((v,i) => <option key={`optPob${i}`}>{v.nomPoble}</option>)
|
||||
}
|
||||
</select> */}
|
||||
|
||||
<br />
|
||||
|
||||
<input type='submit' value="Enviar" />
|
||||
|
||||
{ambitSeleccionat && esEditor && <button onClick={ev => {
|
||||
|
||||
|
||||
<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>}
|
||||
}}>Elimina</button>} */}
|
||||
</form>
|
||||
</div>;
|
||||
};
|
||||
|
||||
const
|
||||
today = new Date(),
|
||||
lastWeek = new Date(today.getFullYear(), today.getMonth(), today.getDate() - 7)
|
||||
;
|
||||
|
||||
console.log("codis: ", codis);
|
||||
|
||||
|
||||
return <Suspense fallback={<>Carregant...</>} >
|
||||
|
||||
@ -232,10 +319,11 @@ export const Codis = () => {
|
||||
rowGap: `.3em`,
|
||||
alignContent: `space-around`
|
||||
}}>{
|
||||
ambits
|
||||
.sort((a,b) => a.toLowerCase() > b.toLowerCase())
|
||||
.map(amb => <li
|
||||
key={amb}
|
||||
codis
|
||||
// .reverse()
|
||||
// .sort((a,b) => a?.codi?.editedAt < b?.codi?.editedAt)
|
||||
.map(cod => <li
|
||||
key={cod._id}
|
||||
style={{
|
||||
display: `block`,
|
||||
border: `1px solid #6666`,
|
||||
@ -245,8 +333,17 @@ export const Codis = () => {
|
||||
backgroundColor: `${'lightgreen' || 'lightcoral'}`
|
||||
}}
|
||||
>
|
||||
{amb}{esEditor && <button onClick={() => {setAmbitSeleccionat({value: amb, label: amb})}}>Edita</button>}
|
||||
{cod.codi}
|
||||
{/* {esEditor && <button onClick={() => {setAmbitSeleccionat({value: cod, label: cod})}}>Edita</button>} */}
|
||||
</li>)
|
||||
}</ul>
|
||||
|
||||
{/* <InfiniteCalendar
|
||||
width={400}
|
||||
height={600}
|
||||
selected={today}
|
||||
disabledDays={[0,6]}
|
||||
minDate={lastWeek}
|
||||
/> */}
|
||||
</Suspense>;
|
||||
};
|
||||
@ -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>
|
||||
// );
|
||||
// };
|
||||
|
||||
3991
package-lock.json
generated
Normal file
3991
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -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",
|
||||
|
||||
@ -6,6 +6,7 @@ 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';
|
||||
|
||||
async function insertPoble({ nomPoble, cp, comarca }) {
|
||||
await PoblesCollection.insertAsync({ nomPoble, cp, comarca, createdAt: new Date() });
|
||||
@ -201,6 +202,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 +401,31 @@ 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);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
});
|
||||
Loading…
Reference in New Issue
Block a user