Abans de gitea

This commit is contained in:
Pasq G 2024-12-27 18:22:06 +01:00
parent 9a64c013ea
commit c566cad6e7
3 changed files with 167 additions and 107 deletions

View File

@ -7,6 +7,7 @@ import { Roles } from 'meteor/roles';
// import { useUserId } from 'meteor/react-meteor-accounts'; // import { useUserId } from 'meteor/react-meteor-accounts';
import { BarraNav } from "./BarraNav/BarraNav"; import { BarraNav } from "./BarraNav/BarraNav";
import { useParams } from "react-router-dom"; import { useParams } from "react-router-dom";
import { NecessitatsCollection } from '../api/necessitats';
@ -19,8 +20,11 @@ export const Poble = () => {
// const [creantPoble, setCreantPoble] = useState(false); // const [creantPoble, setCreantPoble] = useState(false);
useSubscribe('pobles'); useSubscribe('pobles');
useSubscribe('usuaris'); useSubscribe('usuaris');
useSubscribe('necessitats', ambitPoble);
// const pobles = useTracker("pobles", () => PoblesCollection.find().fetchAsync()); // const pobles = useTracker("pobles", () => PoblesCollection.find().fetchAsync());
const pobles = useFind(PoblesCollection, [{}, {sort: {nomPoble: 1}}]); const pobles = useFind(PoblesCollection, [{}, {sort: {nomPoble: 1}}]);
const necessitats = useFind(NecessitatsCollection, [{}, {sort: {titol: 1}}]);
const [esEditor, setEsEditor] = useState(false); const [esEditor, setEsEditor] = useState(false);
const userId = Meteor.userId(); const userId = Meteor.userId();
@ -166,6 +170,31 @@ export const Poble = () => {
} }
</ul> </ul>
<h2>Necessitats:</h2>
<ul style={{
display: `flex`,
flexWrap: `wrap`,
justifyContent: `space-evenly`,
rowGap: `.3em`,
alignContent: `space-around`
}}>{
necessitats
.sort((a,b) => a.titol?.toLowerCase() > b.titol?.toLowerCase())
.map(nec => <li
key={`nec_${nec._id}`}
style={{
display: `block`,
border: `1px solid #6666`,
borderRadius: `.4em`,
padding: `4px`,
listStyle: `none`,
backgroundColor: `${'lightgreen' || 'lightcoral'}`
}}
>
{nec.titol} {esEditor && <button onClick={() => {setNecessitatSeleccionada(nec)}}>Edita</button>}</li>)
}</ul>
{/* { esEditor && (pobleSeleccionat || creantPoble) && <QuadreInfo_Poble /> } {/* { esEditor && (pobleSeleccionat || creantPoble) && <QuadreInfo_Poble /> }
<ul style={{ <ul style={{

View File

@ -7,6 +7,7 @@ import { Roles } from 'meteor/roles';
// import { useUserId } from 'meteor/react-meteor-accounts'; // import { useUserId } from 'meteor/react-meteor-accounts';
import { BarraNav } from "./BarraNav/BarraNav"; import { BarraNav } from "./BarraNav/BarraNav";
import { Link } from 'react-router-dom'; import { Link } from 'react-router-dom';
import { NecessitatsCollection } from '../api/necessitats';
@ -33,6 +34,116 @@ export const Pobles = () => {
}, []); }, []);
// })(); // })();
const BotoPobleAmbIndicadors = ({pob}) => {
useSubscribe('necessitats', pob.ambitAssociat);
const necessitats = useFind(NecessitatsCollection, [{"poble.ambitAssociat": pob.ambitAssociat}]);
const [monitors, setMonitors] = useState(false);
useEffect(() => {
(async () => {
const mon = await Roles.getUsersInRoleAsync('monitor_de_poble', pob.ambitAssociat);
setMonitors(mon.map(m => m).length);
})();
}, [pob]);
// console.log("mon: ", monitors);
return <li
key={`pob_${pob._id}`}
style={{
display: `block`,
border: `1px solid #6666`,
borderRadius: `.4em`,
padding: `4px`,
listStyle: `none`,
backgroundColor: `${'lightgreen' || 'lightcoral'}`,
position: 'relative',
margin: '.2em'
}}
>
{// Indicadors de Responsables
<div style={{
position: `absolute`,
// display: `inline-block`,
display: `flex`,
justifyContent: `space-around`,
left: `0`,
top: `-.8em`,
width: `100%`,
fontSize: `60%`,
textAlign: `center`,
pointerEvents: `none`
}}>
{
monitors
? <span style={{
border: `1px solid #6666`,
borderRadius: `50%`,
minWidth: `1rem`,
backgroundColor: `#ff0a`
}}>{monitors}</span>
: false
}
<span style={{
border: `1px solid #6666`,
borderRadius: `50%`,
minWidth: `1rem`,
backgroundColor: `#fffa`
}}>2</span>
<span style={{
border: `1px solid #6666`,
borderRadius: `50%`,
minWidth: `1rem`,
backgroundColor: `#fffa`
}}>3</span>
</div>
}
{// Indicadors de Necessitats
<div style={{
position: `absolute`,
// display: `inline-block`,
display: `flex`,
// justifyContent: `space-around`,
left: `-1.5em`,
// top: `-.8em`,
width: `100%`,
fontSize: `60%`,
textAlign: `center`,
// lineHeight: `100%`
top: `.8em`,
pointerEvents: `none`
}}>
{
necessitats.length
?
<span style={{
border: `1px solid #6666`,
borderRadius: `50%`,
minWidth: `1rem`,
backgroundColor: `#f006`
}}>{necessitats.length }</span>
: false
}
</div>
}
{// Botó de creació de nou poble
<Link to={`/poble/${pob.ambitAssociat}`}>
{pob.nomPoble} {esEditor && <button
onClick={(ev) => {
ev.preventDefault();
ev.stopPropagation();
setPobleSeleccionat(pob);
}
}>Edita</button>}
</Link>
}
</li>;
}
const QuadreInfo_Poble = () => { const QuadreInfo_Poble = () => {
@ -68,10 +179,10 @@ export const Pobles = () => {
}} }}
> >
<label htmlFor="nomPoble">Població: </label> <label htmlFor="nomPoble">Població: </label>
<input <input
name="nomPoble" name="nomPoble"
type="text" type="text"
defaultValue={ pobleSeleccionat ? pobleSeleccionat.nomPoble : ""} defaultValue={ pobleSeleccionat ? pobleSeleccionat.nomPoble : ""}
onChange={ev => refInAmbitAssignat.current.value = ev.target.value.replace(/ +/g, '-').toLowerCase()} onChange={ev => refInAmbitAssignat.current.value = ev.target.value.replace(/ +/g, '-').toLowerCase()}
/><br /> /><br />
<label htmlFor="comarca">Comarca: </label><input name="comarca" type="text" /><br /> <label htmlFor="comarca">Comarca: </label><input name="comarca" type="text" /><br />
@ -97,6 +208,10 @@ export const Pobles = () => {
</form> </form>
</div>; </div>;
}; };
// const Indicador = ({valor, ambit, }) => {
// };
return <Suspense fallback={<>Carregant...</>} > return <Suspense fallback={<>Carregant...</>} >
@ -113,102 +228,9 @@ export const Pobles = () => {
}}>{ }}>{
pobles pobles
.sort((a,b) => a.nomPoble?.toLowerCase() > b.nomPoble?.toLowerCase()) .sort((a,b) => a.nomPoble?.toLowerCase() > b.nomPoble?.toLowerCase())
.map(pob => .map(pob => {
<li return <BotoPobleAmbIndicadors pob={pob} />
key={`pob_${pob._id}`} })
style={{
display: `block`,
border: `1px solid #6666`,
borderRadius: `.4em`,
padding: `4px`,
listStyle: `none`,
backgroundColor: `${'lightgreen' || 'lightcoral'}`,
position: 'relative',
margin: '.2em'
}}
>
{
<div style={{
position: `absolute`,
// display: `inline-block`,
display: `flex`,
justifyContent: `space-around`,
left: `0`,
top: `-.8em`,
width: `100%`,
fontSize: `60%`,
textAlign: `center`,
pointerEvents: `none`
}}>
<span style={{
border: `1px solid #6666`,
borderRadius: `50%`,
minWidth: `1rem`,
backgroundColor: `#fffa`
}}>1</span>
<span style={{
border: `1px solid #6666`,
borderRadius: `50%`,
minWidth: `1rem`,
backgroundColor: `#fffa`
}}>2</span>
<span style={{
border: `1px solid #6666`,
borderRadius: `50%`,
minWidth: `1rem`,
backgroundColor: `#fffa`
}}>3</span>
</div>
}
{
<div style={{
position: `absolute`,
// display: `inline-block`,
display: `flex`,
// justifyContent: `space-around`,
left: `-1.5em`,
// top: `-.8em`,
width: `100%`,
fontSize: `60%`,
textAlign: `center`,
// lineHeight: `100%`
top: `.8em`,
pointerEvents: `none`
}}>
<span style={{
border: `1px solid #6666`,
borderRadius: `50%`,
minWidth: `1rem`,
backgroundColor: `#fffa`
}}>0</span>
{/* <span style={{
border: `1px solid #6666`,
borderRadius: `50%`,
minWidth: `1rem`,
backgroundColor: `#fffa`
}}>2</span>
<span style={{
border: `1px solid #6666`,
borderRadius: `50%`,
minWidth: `1rem`,
backgroundColor: `#fffa`
}}>3</span> */}
</div>
}
<Link to={`/poble/${pob.ambitAssociat}`}>
{pob.nomPoble} {esEditor && <button
onClick={(ev) => {
ev.preventDefault();
ev.stopPropagation();
setPobleSeleccionat(pob);
}
}>Edita</button>}
</Link>
</li>
)
}</ul> }</ul>
{esEditor && <button {esEditor && <button

View File

@ -184,7 +184,16 @@ Meteor.startup(async () => {
return PoblesCollection.find(); return PoblesCollection.find();
}); });
Meteor.publish("necessitats", function () { Meteor.publish("necessitats", function (ambits) {
if (Array.isArray(ambits)) {
return;
}
if (ambits) {
return NecessitatsCollection.find({"poble.ambitAssociat": ambits});
}
return NecessitatsCollection.find(); return NecessitatsCollection.find();
}); });
@ -229,14 +238,14 @@ Meteor.startup(async () => {
// Publish user's own roles // Publish user's own roles
Meteor.publish(null, async function () { Meteor.publish(null, async function () {
if (await Roles.userIsInRoleAsync(this.userId, "admin")) { // if (await Roles.userIsInRoleAsync(this.userId, "admin")) {
return Meteor.roleAssignment.find(); return Meteor.roleAssignment.find();
} // }
if (this.userId) { // if (this.userId) {
return Meteor.roleAssignment.find({ "user._id": this.userId }); // return Meteor.roleAssignment.find({ "user._id": this.userId });
} // }
this.ready(); // this.ready();
}); });
// Publish roles for specific scope // Publish roles for specific scope