provincias, cantones, distritos dinámicos

This commit is contained in:
Mariela 2022-07-21 00:15:43 -06:00
parent 31ef827baf
commit e88408eb77
5 changed files with 3040 additions and 14 deletions

View File

@ -27,24 +27,20 @@ export class CommunitiesService {
.find()
.setOptions({ sanitizeFilter: true })
.exec()
.then( async community => {
if(community){
.then(async community => {
if (community) {
await Promise.all(community.map(async c => {
//buscar al usuario con el id de la comunidad anexado
let admin = await this.findCommunityAdmin(c["_id"], "2")
if(admin){
if (admin) {
c["id_admin"] = admin["_id"]
c["name_admin"] = admin["name"]
}
return c
}))
console.log(community)
}
return community;
return community;
})
//buscar al usuario con el id de la comunidad anexado
}
findOne(id: string): Promise<Community> {

View File

@ -0,0 +1,489 @@
[
{
"name": "San José",
"code": "101",
"parentCode": "1",
"isoParent": "SJ"
},
{
"name": "Escazú",
"code": "102",
"parentCode": "1",
"isoParent": "SJ"
},
{
"name": "Desamparados",
"code": "103",
"parentCode": "1",
"isoParent": "SJ"
},
{
"name": "Puriscal",
"code": "104",
"parentCode": "1",
"isoParent": "SJ"
},
{
"name": "Tarrazú",
"code": "105",
"parentCode": "1",
"isoParent": "SJ"
},
{
"name": "Aserrí­",
"code": "106",
"parentCode": "1",
"isoParent": "SJ"
},
{
"name": "Mora",
"code": "107",
"parentCode": "1",
"isoParent": "SJ"
},
{
"name": "Goicoechea",
"code": "108",
"parentCode": "1",
"isoParent": "SJ"
},
{
"name": "Santa Ana",
"code": "109",
"parentCode": "1",
"isoParent": "SJ"
},
{
"name": "Alajuelita",
"code": "110",
"parentCode": "1",
"isoParent": "SJ"
},
{
"name": "Vasquez de Coronado",
"code": "111",
"parentCode": "1",
"isoParent": "SJ"
},
{
"name": "Acosta",
"code": "112",
"parentCode": "1",
"isoParent": "SJ"
},
{
"name": "Tibás",
"code": "113",
"parentCode": "1",
"isoParent": "SJ"
},
{
"name": "Moravia",
"code": "114",
"parentCode": "1",
"isoParent": "SJ"
},
{
"name": "Montes de Oca",
"code": "115",
"parentCode": "1",
"isoParent": "SJ"
},
{
"name": "Turrubares",
"code": "116",
"parentCode": "1",
"isoParent": "SJ"
},
{
"name": "Dota",
"code": "117",
"parentCode": "1",
"isoParent": "SJ"
},
{
"name": "Curridabat",
"code": "118",
"parentCode": "1",
"isoParent": "SJ"
},
{
"name": "Pérez Zeledón",
"code": "119",
"parentCode": "1",
"isoParent": "SJ"
},
{
"name": "León Cortés",
"code": "120",
"parentCode": "1",
"isoParent": "SJ"
},
{
"name": "Alajuela",
"code": "201",
"parentCode": "2",
"isoParent": "ALAJ"
},
{
"name": "San Ramón",
"code": "202",
"parentCode": "2",
"isoParent": "ALAJ"
},
{
"name": "Grecia",
"code": "203",
"parentCode": "2",
"isoParent": "ALAJ"
},
{
"name": "San Mateo",
"code": "204",
"parentCode": "2",
"isoParent": "ALAJ"
},
{
"name": "Atenas",
"code": "205",
"parentCode": "2",
"isoParent": "ALAJ"
},
{
"name": "Naranjo",
"code": "206",
"parentCode": "2",
"isoParent": "ALAJ"
},
{
"name": "Palmares",
"code": "207",
"parentCode": "2",
"isoParent": "ALAJ"
},
{
"name": "Poás",
"code": "208",
"parentCode": "2",
"isoParent": "ALAJ"
},
{
"name": "Orotina",
"code": "209",
"parentCode": "2",
"isoParent": "ALAJ"
},
{
"name": "San Carlos",
"code": "210",
"parentCode": "2",
"isoParent": "ALAJ"
},
{
"name": "Alfaro Ruiz",
"code": "211",
"parentCode": "2",
"isoParent": "ALAJ"
},
{
"name": "Valverde Vega",
"code": "212",
"parentCode": "2",
"isoParent": "ALAJ"
},
{
"name": "Upala",
"code": "213",
"parentCode": "2",
"isoParent": "ALAJ"
},
{
"name": "Los Chiles",
"code": "214",
"parentCode": "2",
"isoParent": "ALAJ"
},
{
"name": "Guatuso",
"code": "215",
"parentCode": "2",
"isoParent": "ALAJ"
},
{
"name": "Cartago",
"code": "301",
"parentCode": "3",
"isoParent": "CAR"
},
{
"name": "Paraí­so",
"code": "302",
"parentCode": "3",
"isoParent": "CAR"
},
{
"name": "La Unión",
"code": "303",
"parentCode": "3",
"isoParent": "CAR"
},
{
"name": "Jiménez",
"code": "304",
"parentCode": "3",
"isoParent": "CAR"
},
{
"name": "Turrialba",
"code": "305",
"parentCode": "3",
"isoParent": "CAR"
},
{
"name": "Alvarado",
"code": "306",
"parentCode": "3",
"isoParent": "CAR"
},
{
"name": "Oreamuno",
"code": "307",
"parentCode": "3",
"isoParent": "CAR"
},
{
"name": "El Guarco",
"code": "308",
"parentCode": "3",
"isoParent": "CAR"
},
{
"name": "Heredia",
"code": "401",
"parentCode": "4",
"isoParent": "HER"
},
{
"name": "Barva",
"code": "402",
"parentCode": "4",
"isoParent": "HER"
},
{
"name": "Santo Domingo",
"code": "403",
"parentCode": "4",
"isoParent": "HER"
},
{
"name": "Santa Bárbara",
"code": "404",
"parentCode": "4",
"isoParent": "HER"
},
{
"name": "San Rafael",
"code": "405",
"parentCode": "4",
"isoParent": "HER"
},
{
"name": "San Isidro",
"code": "406",
"parentCode": "4",
"isoParent": "HER"
},
{
"name": "Belén",
"code": "407",
"parentCode": "4",
"isoParent": "HER"
},
{
"name": "Flores",
"code": "408",
"parentCode": "4",
"isoParent": "HER"
},
{
"name": "San Pablo",
"code": "409",
"parentCode": "4",
"isoParent": "HER"
},
{
"name": "Sarapiquí­ ",
"code": "410",
"parentCode": "4",
"isoParent": "HER"
},
{
"name": "Liberia",
"code": "501",
"parentCode": "5",
"isoParent": "GUANA"
},
{
"name": "Nicoya",
"code": "502",
"parentCode": "5",
"isoParent": "GUANA"
},
{
"name": "Santa Cruz",
"code": "503",
"parentCode": "5",
"isoParent": "GUANA"
},
{
"name": "Bagaces",
"code": "504",
"parentCode": "5",
"isoParent": "GUANA"
},
{
"name": "Carrillo",
"code": "505",
"parentCode": "5",
"isoParent": "GUANA"
},
{
"name": "Cañas",
"code": "506",
"parentCode": "5",
"isoParent": "GUANA"
},
{
"name": "Abangares",
"code": "507",
"parentCode": "5",
"isoParent": "GUANA"
},
{
"name": "Tilarán",
"code": "508",
"parentCode": "5",
"isoParent": "GUANA"
},
{
"name": "Nandayure",
"code": "509",
"parentCode": "5",
"isoParent": "GUANA"
},
{
"name": "La Cruz",
"code": "510",
"parentCode": "5",
"isoParent": "GUANA"
},
{
"name": "Hojancha",
"code": "511",
"parentCode": "5",
"isoParent": "GUANA"
},
{
"name": "Puntarenas",
"code": "601",
"parentCode": "6",
"isoParent": "PUNT"
},
{
"name": "Esparza",
"code": "602",
"parentCode": "6",
"isoParent": "PUNT"
},
{
"name": "Buenos Aires",
"code": "603",
"parentCode": "6",
"isoParent": "PUNT"
},
{
"name": "Montes de Oro",
"code": "604",
"parentCode": "6",
"isoParent": "PUNT"
},
{
"name": "Osa",
"code": "605",
"parentCode": "6",
"isoParent": "PUNT"
},
{
"name": "Aguirre",
"code": "606",
"parentCode": "6",
"isoParent": "PUNT"
},
{
"name": "Golfito",
"code": "607",
"parentCode": "6",
"isoParent": "PUNT"
},
{
"name": "Coto Brus",
"code": "608",
"parentCode": "6",
"isoParent": "PUNT"
},
{
"name": "Parrita",
"code": "609",
"parentCode": "6",
"isoParent": "PUNT"
},
{
"name": "Corredores",
"code": "610",
"parentCode": "6",
"isoParent": "PUNT"
},
{
"name": "Garabito",
"code": "611",
"parentCode": "6",
"isoParent": "PUNT"
},
{
"name": "Limón",
"code": "701",
"parentCode": "7",
"isoParent": "LIM"
},
{
"name": "Pococí­",
"code": "702",
"parentCode": "7",
"isoParent": "LIM"
},
{
"name": "Siquirres ",
"code": "703",
"parentCode": "7",
"isoParent": "LIM"
},
{
"name": "Talamanca",
"code": "704",
"parentCode": "7",
"isoParent": "LIM"
},
{
"name": "Matina",
"code": "705",
"parentCode": "7",
"isoParent": "LIM"
},
{
"name": "Guácimo",
"code": "706",
"parentCode": "7",
"isoParent": "LIM"
}
]

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,30 @@
[
{
"name":"San José",
"code":"1"
},
{
"name":"Alajuela",
"code":"2"
},
{
"name":"Cartago",
"code":"3"
},
{
"name":"Heredia",
"code":"4"
},
{
"name":"Guanacaste",
"code":"5"
},
{
"name":"Puntarenas",
"code":"6"
},
{
"name":"Limón",
"code":"7"
}
]

View File

@ -3,11 +3,37 @@ import { InputText } from 'primereact/inputtext';
import { Button } from 'primereact/button';
import { DataTable } from 'primereact/datatable';
import { Column } from 'primereact/column';
import { Dropdown } from 'primereact/dropdown';
import { LocationService } from '../service/LocationService';
const Communities = () => {
const [communitiesList, setCommunitiesList] = useState([]);
const [housesList, setHousesList] = useState([]);
const [provincesList, setProvincesList] = useState([]);
const [provinciaId, setProvinciaId] = useState();
const [cantonsList, setCantonsList] = useState([]);
const [cantonId, setCantonId] = useState(null);
const [districtsList, setDistrictsList] = useState([]);
const [districtId, setDistrictId] = useState(null);
const p = provincesList.map((item) => ({
label: item.name,
value: item.code
}))
const c = cantonsList.map((item) => ({
label: item.name,
value: item.code,
parent: item.parentCode
}))
const d = districtsList.map((item) => ({
label: item.name,
value: item.code,
parent: item.parentCode
}))
async function getCommunites() {
@ -15,18 +41,69 @@ const Communities = () => {
let list = await response.json();
setCommunitiesList(list.message);
}
useEffect(() => {
getCommunites();
}, [])
useEffect(() => {
getProvinces();
}, [])
useEffect(() => {
getCantons();
}, [provinciaId])
useEffect(() => {
getDistricts();
}, [cantonId])
async function getProvinces() {
const response = await fetch('assets/demo/data/provincias.json', { method: 'GET' });
const getP = await response.json();
setProvincesList(await getP)
}
const handleProvinces = (event) => {
const getprovinciaId = event.target.value;
setProvinciaId(getprovinciaId);
}
async function getCantons() {
const response = await fetch('assets/demo/data/cantones.json', { method: 'GET' });
const resJson = await response.json();
const cantones = await resJson.filter(function (i, n) {
return i.parentCode === provinciaId;
});
setCantonsList(await cantones);
}
const handleCanton = (event) => {
const getCantonId = event.target.value;
setCantonId(getCantonId);
}
async function getDistricts() {
const response = await fetch('assets/demo/data/distritos.json', { method: 'GET' });
const resJson = await response.json();
const distrits = await resJson.filter(function (i, n) {
return i.parentCode === cantonId;
});
setDistrictsList(await distrits);
}
return (
<div className="grid">
<div className="col-12">
<div className="card">
<h5>Comunidades de Viviendas</h5>
<DataTable value={communitiesList} scrollable scrollHeight="400px" scrollDirection="both" className="mt-3">
<DataTable value={communitiesList} scrollable scrollHeight="400px" scrollDirection="both" className="mt-3">
<Column field="name" header="Nombre" style={{ flexGrow: 1, flexBasis: '160px' }}></Column>
<Column field="province" header="Provincia" style={{ flexGrow: 1, flexBasis: '160px' }}></Column>
<Column field="canton" header="Cantón" style={{ flexGrow: 1, flexBasis: '160px' }}></Column>
@ -38,10 +115,92 @@ const Communities = () => {
</DataTable>
</div>
</div>
</div>
<div className="col-12">
<div className="card">
<h5>Registro de comunidad de viviendas</h5>
<div className="p-fluid formgrid grid">
<div className="field col-12 md:col-6">
<label htmlFor="name">Nombre</label>
<div className="p-0 col-12 md:col-12">
<div className="p-inputgroup">
<span className="p-inputgroup-addon p-button p-khaki-dropdown">
<i className="pi pi-home"></i>
</span>
<InputText id="name" type="text" />
</div>
</div>
</div>
<div className="field col-12 md:col-6">
<label htmlFor="districts">Provincia</label>
<div className="p-0 col-12 md:col-12">
<div className="p-inputgroup">
<span className="p-inputgroup-addon p-button p-khaki-dropdown">
<i className="pi pi-map-marker"></i>
</span>
<Dropdown placeholder="--Seleccione Provincia--" value={provinciaId} options={p} onChange={handleProvinces} />
</div>
</div>
</div>
<div className="field col-12 md:col-6">
<label htmlFor="cantons">Cantón</label>
<div className="p-0 col-12 md:col-12">
<div className="p-inputgroup">
<span className="p-inputgroup-addon p-button p-khaki-dropdown">
<i className="pi pi-map-marker"></i>
</span>
<Dropdown placeholder="--Seleccione Cantón--" value={cantonId} options={c} onChange={handleCanton} />
</div>
</div>
</div>
<div className="field col-12 md:col-6">
<label htmlFor="districts">Distrito</label>
<div className="p-0 col-12 md:col-12">
<div className="p-inputgroup">
<span className="p-inputgroup-addon p-button p-khaki-dropdown">
<i className="pi pi-map-marker"></i>
</span>
<Dropdown placeholder="--Seleccione Distrito--" value={districtId} options={d} />
</div>
</div>
)
</div>
<div className="field col-12 md:col-6">
<label htmlFor="telefono">Teléfono</label>
<div className="p-0 col-12 md:col-12">
<div className="p-inputgroup">
<span className="p-inputgroup-addon p-button p-khaki-dropdown">
<i className="pi pi-phone"></i>
</span>
<InputText id="telefono" type="text" rows="4" />
</div>
</div>
</div>
<div className="field col-12 md:col-6">
<label htmlFor="numHouse">Numero de Viviendas</label>
<div className="p-0 col-12 md:col-12">
<div className="p-inputgroup">
<span className="p-inputgroup-addon p-button p-khaki-dropdown">
<i className="pi pi-hashtag"></i>
</span>
<InputText id="num" type="number" rows="4" />
</div>
</div>
</div>
<div className="col-12 md:col-12 py-2">
<Button label="Registrar" icon="pi pi-check"></Button>
</div>
</div>
</div>
</div>
</div >
)
}
export default React.memo(Communities);