From 6d8fcd264ee18b207eb802e19183b693f3709dbc Mon Sep 17 00:00:00 2001 From: Mariela Date: Tue, 2 Aug 2022 21:00:38 -0600 Subject: [PATCH 1/2] fixes functions de cambiar estado MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Se deja una sola función y un solo botón para cambiar el estado... también se realizar un filtro para que no se muestren las comunidades marcadas como eliminadas --- .../src/components/ComunidadViviendas.js | 154 ++++++------------ 1 file changed, 52 insertions(+), 102 deletions(-) diff --git a/web-ui/web-react/src/components/ComunidadViviendas.js b/web-ui/web-react/src/components/ComunidadViviendas.js index bb4e549d..9183a223 100644 --- a/web-ui/web-react/src/components/ComunidadViviendas.js +++ b/web-ui/web-react/src/components/ComunidadViviendas.js @@ -14,6 +14,7 @@ import { faMapLocationDot } from '@fortawesome/free-solid-svg-icons'; import { faPhoneAlt } from '@fortawesome/free-solid-svg-icons'; import { faEllipsis } from '@fortawesome/free-solid-svg-icons'; import { faHashtag } from '@fortawesome/free-solid-svg-icons'; +import { icon } from '@fortawesome/fontawesome-svg-core'; const Communities = () => { let emptyCommunity = { @@ -161,7 +162,11 @@ const Communities = () => { let pList = await getProvinces(); let cList = await getCantons(); let dList = await getDistricts(); - await resJson.message.map((item) => { + let data = await resJson.message.filter( + (val) => val.status != -1, + ) + await data.map((item) => { + item.province = pList.find((p) => p.code === item.province).name; item.canton = cList.find((p) => p.code === item.canton).name; item.district = dList.find((p) => p.code === item.district).name; @@ -169,7 +174,7 @@ const Communities = () => { item.name_admin = 'Sin Administrador'; } }); - setCommunitiesList(await resJson.message); + setCommunitiesList(await data); } useEffect(() => { @@ -181,6 +186,9 @@ const Communities = () => { .then((response) => response.json()) .then(data => data.message) .then(data => { + data = data.filter( + (val) => val.status != -1, + ) setTenants(data) }); } @@ -265,7 +273,7 @@ const Communities = () => { if (tenant_id == '') { name = 'Sin inquilino'; } else { - let tenant = tenants.find(t => t._id == tenant_id ) + let tenant = tenants.find(t => t._id == tenant_id) name = tenant['name'] + ' ' + tenant['last_name']; } console.log(name); @@ -323,14 +331,19 @@ const Communities = () => { setCommunity(community); setEditCommunityDialog(true); }; + //desactivar o activar una comunidad - const cambiarDesactivarEstadoCommunity = () => { + const cambiarEstadoCommunity = () => { + if (community.status == '1') { + community.status = '0'; + } else if (community.status == '0') { + community.status = '1'; + } var data = { id: community._id, - status: "0", + status: community.status, }; console.log(data); - fetch('http://localhost:4000/community/changeStatus', { cache: 'no-cache', method: 'POST', @@ -362,44 +375,6 @@ const Communities = () => { err => console.log('Ocurrió un error con el fetch', err) ); } - //desactivar o activar una comunidad - const cambiarActivarEstadoCommunity = () => { - var data = { - id: community._id, - status: "1", - }; - console.log(data); - fetch('http://localhost:4000/community/changeStatus', { - cache: 'no-cache', - method: 'POST', - body: JSON.stringify(data), - headers: { - 'Content-Type': 'application/json' - } - }) - .then( - function (response) { - if (response.status != 201) - console.log('Ocurrió un error con el servicio: ' + response.status); - else - return response.json(); - } - ) - .then( - function (response) { - setEditCommunityDialog(false); - toast.current.show({ - severity: 'success', - summary: 'Éxito', - detail: 'Comunidad de Viviendas Actualizada', - life: 3000, - }); - } - ) - .catch( - err => console.log('Ocurrió un error con el fetch', err) - ); - } const deleteCommunity = () => { @@ -435,8 +410,11 @@ const Communities = () => { } ); */ - let _community = communitiesList.filter((val) => val._id !== community._id); - setCommunitiesList(_community); + let _communities = communitiesList.filter((val) => val._id !== community._id); + _communities = _communities.filter( + (val) => val.status != -1, + ) + setCommunitiesList(_communities); setDeleteCommunityDialog(false); setCommunity(emptyCommunity); toast.current.show({ @@ -460,6 +438,9 @@ const Communities = () => { } }) })*/ + _communities = _communities.filter( + (val) => val.status != -1, + ) setCommunitiesList(_communities); setDeleteCommunitiesDialog(false); setSelectedCommunities(null); @@ -472,23 +453,26 @@ const Communities = () => { }; const actionsCommunity = (rowData) => { + + let icono = ''; + if (rowData.status == '0') { + icono = "pi pi-eye"; + } else if (rowData.status == '1') { + icono = "pi pi-eye-slash"; + } + return (
-
+ -
- - {community && ( - - ¿Estás seguro que desea cambiar estado a {community.name}? - - )} -
-
-
From 45b459742c3e682837315c9ce27640d94652983c Mon Sep 17 00:00:00 2001 From: Mariela Date: Tue, 2 Aug 2022 21:45:57 -0600 Subject: [PATCH 2/2] agregar columna de estado --- .../src/communities/communities.controller.ts | 2 - .../src/components/ComunidadViviendas.js | 44 +++++++++++++++++-- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/servicio-comunidad-viviendas/src/communities/communities.controller.ts b/servicio-comunidad-viviendas/src/communities/communities.controller.ts index b9f75310..83335420 100644 --- a/servicio-comunidad-viviendas/src/communities/communities.controller.ts +++ b/servicio-comunidad-viviendas/src/communities/communities.controller.ts @@ -51,8 +51,6 @@ export class CommunitiesController { changeStatus(@Payload() body: string) { let pid = body['id']; let pstatus = body['status']; - console.log(pid); - console.log(pstatus); return this.communitiesService.changeStatus(pid,pstatus); } } diff --git a/web-ui/web-react/src/components/ComunidadViviendas.js b/web-ui/web-react/src/components/ComunidadViviendas.js index 9183a223..c9076d26 100644 --- a/web-ui/web-react/src/components/ComunidadViviendas.js +++ b/web-ui/web-react/src/components/ComunidadViviendas.js @@ -15,6 +15,7 @@ import { faPhoneAlt } from '@fortawesome/free-solid-svg-icons'; import { faEllipsis } from '@fortawesome/free-solid-svg-icons'; import { faHashtag } from '@fortawesome/free-solid-svg-icons'; import { icon } from '@fortawesome/fontawesome-svg-core'; +import { faCircleQuestion } from '@fortawesome/free-solid-svg-icons'; const Communities = () => { let emptyCommunity = { @@ -26,6 +27,7 @@ const Communities = () => { phone: '', num_houses: 0, status: '1', + status_text: '', date_entry: new Date(), houses: [], }; @@ -166,7 +168,13 @@ const Communities = () => { (val) => val.status != -1, ) await data.map((item) => { - + if (item.status == '1') { + item.status_text = 'Activo'; + } else if (item.status == '0') { + item.status_text = 'Inactivo'; + } else { + item.status_text = 'Eliminado'; + } item.province = pList.find((p) => p.code === item.province).name; item.canton = cList.find((p) => p.code === item.canton).name; item.district = dList.find((p) => p.code === item.district).name; @@ -276,7 +284,6 @@ const Communities = () => { let tenant = tenants.find(t => t._id == tenant_id) name = tenant['name'] + ' ' + tenant['last_name']; } - console.log(name); return name; } @@ -336,8 +343,11 @@ const Communities = () => { const cambiarEstadoCommunity = () => { if (community.status == '1') { community.status = '0'; + community.status_text = 'Inactivo'; + } else if (community.status == '0') { community.status = '1'; + community.status_text = 'Activo'; } var data = { id: community._id, @@ -413,7 +423,7 @@ const Communities = () => { let _communities = communitiesList.filter((val) => val._id !== community._id); _communities = _communities.filter( (val) => val.status != -1, - ) + ) setCommunitiesList(_communities); setDeleteCommunityDialog(false); setCommunity(emptyCommunity); @@ -666,6 +676,15 @@ const Communities = () => { ); + const headerStatus = ( + <> +

{' '} + {' '} + Estado +

+ + ) + //ver perfil comunidad const headerTenant = ( <> @@ -678,11 +697,21 @@ const Communities = () => { ); + const statusBodyTemplate = (rowData) => { + return ( + <> + + {rowData.status_text} + + + ); +}; const tenantsBodyTemplate = (rowData) => { let tenants = rowData.tenants; let name = findNameTenant(tenants.tenant_id); - console.log(name); return ( <> {name} @@ -764,6 +793,13 @@ const Communities = () => { header={headerAdministrator} style={{ flexGrow: 1, flexBasis: '180px' }} > + +