Avanços amb els formularis
This commit is contained in:
parent
f621a29953
commit
e129eb4107
@ -59,11 +59,20 @@ export const Necessitats = () => {
|
|||||||
action={d => {
|
action={d => {
|
||||||
if (d.get('selTipus'))
|
if (d.get('selTipus'))
|
||||||
try {
|
try {
|
||||||
|
const tipusSeleccionat = tipus.find(t => t._id === d.get('selTipus')) || "";
|
||||||
|
const pobleSeleccionat = pobles.find(p => p._id === d.get('selPoble')) || "";
|
||||||
Meteor.callAsync('afigNecessitat', {
|
Meteor.callAsync('afigNecessitat', {
|
||||||
...necessitatSeleccionada || [],
|
...necessitatSeleccionada || [],
|
||||||
titol: d.get('titol'),
|
titol: d.get('taTitol'),
|
||||||
tipus: d.get('selTipus') || "",
|
tipus: tipusSeleccionat,
|
||||||
poble: d.get('selPoble')
|
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))
|
.then(() => setNecessitatSeleccionada(null))
|
||||||
.catch(err => console.error(err))
|
.catch(err => console.error(err))
|
||||||
@ -76,7 +85,7 @@ export const Necessitats = () => {
|
|||||||
>
|
>
|
||||||
|
|
||||||
<label htmlFor="taTitol">Títol</label> <br />
|
<label htmlFor="taTitol">Títol</label> <br />
|
||||||
<textarea name='taTitol' placeholder='Títol de la necessitat...'></textarea>
|
<textarea name='taTitol' placeholder='Títol de la necessitat...' defaultValue={ necessitatSeleccionada ? necessitatSeleccionada.titol : ""} ></textarea>
|
||||||
|
|
||||||
<br /><br />
|
<br /><br />
|
||||||
|
|
||||||
@ -91,6 +100,7 @@ export const Necessitats = () => {
|
|||||||
formatCreateLabel={(inputValue) => "Crear nou tipus..."}
|
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()) }
|
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})}
|
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}))}
|
// loadOptions={tipus.map((v,i) => ({value: v, label: v.titol}))}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
@ -106,7 +116,9 @@ export const Necessitats = () => {
|
|||||||
|
|
||||||
<label htmlFor="poble">Poble</label>
|
<label htmlFor="poble">Poble</label>
|
||||||
|
|
||||||
<CreatableSelect name="selPoble" options={pobles.map((v,i) => ({value: v._id, label: v.nomPoble})) } />
|
<CreatableSelect name="selPoble" options={pobles.map((v,i) => ({value: v._id, label: v.nomPoble})) }
|
||||||
|
defaultValue={ necessitatSeleccionada ? { value: necessitatSeleccionada.poble._id, label: necessitatSeleccionada.poble.nomPoble} : ""}
|
||||||
|
/>
|
||||||
{/* <select name="selPoble">
|
{/* <select name="selPoble">
|
||||||
{
|
{
|
||||||
pobles.map((v,i) => <option key={`optPob${i}`}>{v.nomPoble}</option>)
|
pobles.map((v,i) => <option key={`optPob${i}`}>{v.nomPoble}</option>)
|
||||||
@ -116,7 +128,9 @@ export const Necessitats = () => {
|
|||||||
<br />
|
<br />
|
||||||
|
|
||||||
<label htmlFor="taDescripcio">Descripció: </label> <br />
|
<label htmlFor="taDescripcio">Descripció: </label> <br />
|
||||||
<textarea name="taDescripcio" id="taDescripcio" placeholder='Observacions i detalls particulars...'></textarea> <br />
|
<textarea name="taDescripcio" id="taDescripcio" placeholder='Observacions i detalls particulars...'
|
||||||
|
defaultValue={ necessitatSeleccionada ? necessitatSeleccionada?.descrip : ""}
|
||||||
|
></textarea> <br />
|
||||||
|
|
||||||
<br />
|
<br />
|
||||||
|
|
||||||
@ -125,10 +139,18 @@ export const Necessitats = () => {
|
|||||||
border: `1px solid #6666`
|
border: `1px solid #6666`
|
||||||
}}>
|
}}>
|
||||||
<legend>Contacte</legend>
|
<legend>Contacte</legend>
|
||||||
<input required type="text" name="inContacte" id="inContacte" placeholder='Nom' /> <br />
|
<input required type="text" name="inContacte" id="inContacte" placeholder='Nom'
|
||||||
<input required type="text" name="inTelefon" id="inTelefon" placeholder='Telèfon' /> <br />
|
defaultValue={ necessitatSeleccionada ? necessitatSeleccionada.contacte?.nom : ""}
|
||||||
<input required type="text" name="inEMail" id="inEMail" placeholder='Correu electrònic' /> <br />
|
/> <br />
|
||||||
<input type="text" name="inAdreça" id="inAdreça" placeholder='Adreça' /> <br />
|
<input required type="text" name="inTelefon" id="inTelefon" placeholder='Telèfon'
|
||||||
|
defaultValue={ necessitatSeleccionada ? necessitatSeleccionada.contacte?.tel : ""}
|
||||||
|
/> <br />
|
||||||
|
<input required type="text" name="inEMail" id="inEMail" placeholder='Correu electrònic'
|
||||||
|
defaultValue={ necessitatSeleccionada ? necessitatSeleccionada.contacte?.email : ""}
|
||||||
|
/> <br />
|
||||||
|
<input type="text" name="inAdreça" id="inAdreça" placeholder='Adreça'
|
||||||
|
defaultValue={ necessitatSeleccionada ? necessitatSeleccionada.contacte?.adr : ""}
|
||||||
|
/> <br />
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
<br />
|
<br />
|
||||||
@ -173,7 +195,7 @@ export const Necessitats = () => {
|
|||||||
backgroundColor: `${'lightgreen' || 'lightcoral'}`
|
backgroundColor: `${'lightgreen' || 'lightcoral'}`
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{nec.titol}{esEditor && <button onClick={() => {setNecessitatSeleccionada(nec)}}>Edita</button>}</li>)
|
{nec.titol} {esEditor && <button onClick={() => {setNecessitatSeleccionada(nec)}}>Edita</button>}</li>)
|
||||||
}</ul>
|
}</ul>
|
||||||
</Suspense>;
|
</Suspense>;
|
||||||
};
|
};
|
||||||
@ -18,6 +18,7 @@ export const Poble = () => {
|
|||||||
// const [pobleSeleccionat, setPobleSeleccionat] = useState(null);
|
// const [pobleSeleccionat, setPobleSeleccionat] = useState(null);
|
||||||
// const [creantPoble, setCreantPoble] = useState(false);
|
// const [creantPoble, setCreantPoble] = useState(false);
|
||||||
useSubscribe('pobles');
|
useSubscribe('pobles');
|
||||||
|
useSubscribe('usuaris');
|
||||||
// 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}}]);
|
||||||
|
|
||||||
@ -111,6 +112,60 @@ export const Poble = () => {
|
|||||||
|
|
||||||
<h1>{pob?.nomPoble}</h1>
|
<h1>{pob?.nomPoble}</h1>
|
||||||
|
|
||||||
|
<h2>Monitores:</h2>
|
||||||
|
<ul>
|
||||||
|
{
|
||||||
|
(async () => {
|
||||||
|
const monitors = await Roles.getUsersInRoleAsync("monitor_de_poble", pob?.ambitAssociat);
|
||||||
|
console.log("monitors: ", monitors);
|
||||||
|
return monitors?.map( (u) => <li style={{
|
||||||
|
display: `block`,
|
||||||
|
border: `1px solid #6666`,
|
||||||
|
borderRadius: `.4em`,
|
||||||
|
padding: `4px`,
|
||||||
|
listStyle: `none`,
|
||||||
|
backgroundColor: `${'lightcoral'}`
|
||||||
|
}}>{u.username}</li> );
|
||||||
|
})()
|
||||||
|
}
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<h2>Encarregades de tasques:</h2>
|
||||||
|
<ul>
|
||||||
|
{
|
||||||
|
(async () => {
|
||||||
|
const encarregats = await Roles.getUsersInRoleAsync("encarregat_de_tasques", pob?.ambitAssociat);
|
||||||
|
console.log("encarregats: ", encarregats);
|
||||||
|
return encarregats?.map( (u) => <li style={{
|
||||||
|
display: `block`,
|
||||||
|
border: `1px solid #6666`,
|
||||||
|
borderRadius: `.4em`,
|
||||||
|
padding: `4px`,
|
||||||
|
listStyle: `none`,
|
||||||
|
backgroundColor: `${'orange'}`
|
||||||
|
}}>{u.username}</li> );
|
||||||
|
})()
|
||||||
|
}
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<h2>Voluntàries de poble:</h2>
|
||||||
|
<ul>
|
||||||
|
{
|
||||||
|
(async () => {
|
||||||
|
const voluntaris = await Roles.getUsersInRoleAsync("voluntari_de_poble", pob?.ambitAssociat);
|
||||||
|
console.log("voluntaris: ", voluntaris);
|
||||||
|
return voluntaris?.map( (u) => <li style={{
|
||||||
|
display: `block`,
|
||||||
|
border: `1px solid #6666`,
|
||||||
|
borderRadius: `.4em`,
|
||||||
|
padding: `4px`,
|
||||||
|
listStyle: `none`,
|
||||||
|
backgroundColor: `${'lightgreen'}`
|
||||||
|
}}>{u.username}</li> );
|
||||||
|
})()
|
||||||
|
}
|
||||||
|
</ul>
|
||||||
|
|
||||||
{/* { esEditor && (pobleSeleccionat || creantPoble) && <QuadreInfo_Poble /> }
|
{/* { esEditor && (pobleSeleccionat || creantPoble) && <QuadreInfo_Poble /> }
|
||||||
|
|
||||||
<ul style={{
|
<ul style={{
|
||||||
|
|||||||
@ -125,7 +125,14 @@ export const Pobles = () => {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Link to={`/poble/${pob.ambitAssociat}`}>
|
<Link to={`/poble/${pob.ambitAssociat}`}>
|
||||||
{pob.nomPoble}{esEditor && <button onClick={() => {setPobleSeleccionat(pob)}}>Edita</button>}
|
{pob.nomPoble}{esEditor && <button
|
||||||
|
onClick={(ev) => {
|
||||||
|
ev.preventDefault();
|
||||||
|
ev.stopPropagation();
|
||||||
|
|
||||||
|
setPobleSeleccionat(pob);
|
||||||
|
}
|
||||||
|
}>Edita</button>}
|
||||||
</Link>
|
</Link>
|
||||||
</li>)
|
</li>)
|
||||||
|
|
||||||
|
|||||||
@ -194,13 +194,20 @@ Meteor.startup(async () => {
|
|||||||
|
|
||||||
Meteor.publish('usuaris', async function (uid) {
|
Meteor.publish('usuaris', async function (uid) {
|
||||||
|
|
||||||
const esAdmin = await Roles.userIsInRoleAsync(Meteor.userId(), "admin");
|
const esAdmin = await Roles.userIsInRoleAsync(this.userId, "admin", null);
|
||||||
const userRoles = await Roles.getRolesForUserAsync(Meteor.userId());
|
const userRoles = await Roles.getRolesForUserAsync(this.userId);
|
||||||
|
|
||||||
console.log("userRoles: ", userRoles);
|
console.log("userRoles: ", userRoles);
|
||||||
if (uid) {
|
console.log("esAdmin: ", esAdmin);
|
||||||
return Meteor.users.find({_id: uid},{fields: {username: 1, avatarId: 1, avatarLink: 1}});
|
|
||||||
|
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}});
|
return Meteor.users.find({},{fields: {username: 1, avatarId: 1, avatarLink: 1}});
|
||||||
});
|
});
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -222,7 +229,7 @@ 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(Meteor.userId(), "admin")) {
|
if (await Roles.userIsInRoleAsync(this.userId, "admin")) {
|
||||||
return Meteor.roleAssignment.find();
|
return Meteor.roleAssignment.find();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user