From 060bd28bf83d0a933280e2bd467158c22b53d30c Mon Sep 17 00:00:00 2001 From: Mariela Date: Mon, 1 Aug 2022 02:05:02 -0600 Subject: [PATCH 01/14] agregar primeras funciones en el frontend --- .../src/components/AdministradoresSistema.js | 81 ++++++++++++++++++- 1 file changed, 79 insertions(+), 2 deletions(-) diff --git a/web-ui/web-react/src/components/AdministradoresSistema.js b/web-ui/web-react/src/components/AdministradoresSistema.js index 5d007e38..a1b78350 100644 --- a/web-ui/web-react/src/components/AdministradoresSistema.js +++ b/web-ui/web-react/src/components/AdministradoresSistema.js @@ -27,6 +27,10 @@ const AdministradoresSistema = () => { const toast = useRef(null); const dt = useRef(null); + const [changeStatusAdminSystemDialog, setChangeStatusAdminSystemDialog] = useState(false); + const [changeStatusAdminsSystemDialog, setChangeStatusAdminsSystemDialog] = + useState(false); + let emptySysAdmin = { _id: null, dni: '', @@ -111,6 +115,14 @@ const AdministradoresSistema = () => { setDeleteAdminsSystemDialog(false); }; + const confirmChangeStatusAdminSystem = (sysAdmin) => { + setSysAdmin(sysAdmin); + setDeleteAdminSystemDialog(true); + }; + + const hideChangeStatusAdminSystemDialog = () => { + setChangeStatusAdminSystemDialog(false); + }; const deleteSysAdmin = () => { fetch('http://localhost:4000/user/deleteAdminSystem/' + sysadmin._id, { @@ -127,8 +139,9 @@ const AdministradoresSistema = () => { }) .then(function (response) { let _sysadmin = administrators.filter( - (val) => val._id !== sysadmin._id, + (val) => (val._id !== sysadmin._id || val.status != -1), ); + setAdministrators(_sysadmin); setDeleteAdminSystemDialog(false); setSysAdmin(emptySysAdmin); @@ -152,7 +165,7 @@ const AdministradoresSistema = () => { const deleteSelectedAdminsSystem = () => { let _administrators = administrators.filter( - (val) => !selectedAdministrators.includes(val), + (val) => (!selectedAdministrators.includes(val) || val.status != -1), ); selectedAdministrators.map((item) => { fetch('http://localhost:4000/user/deleteAdminSystem/' + item._id, { @@ -163,6 +176,7 @@ const AdministradoresSistema = () => { }, }); }); + setAdministrators(_administrators); setDeleteAdminsSystemDialog(false); setSelectedAdministrators(null); @@ -174,9 +188,55 @@ const AdministradoresSistema = () => { }); }; + const changeStatusAdminSystm = () => { + fetch('http://localhost:4000/user/statusAdminSystem/' + sysadmin._id, { + cache: 'no-cache', + method: 'POST', + 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) { + let _sysadmin = administrators.filter( + (val) => (val._id !== sysadmin._id || val.status != -1), + ); + + setAdministrators(_sysadmin); + setDeleteAdminSystemDialog(false); + setSysAdmin(emptySysAdmin); + toast.current.show({ + severity: 'success', + summary: 'Éxito', + detail: 'Administrador del Sistema Eliminado', + life: 3000, + }); + }) + .catch((err) => { + console.log('Ocurrió un error con el fetch', err); + toast.current.show({ + severity: 'danger', + summary: 'Error', + detail: 'Administrador del Sistema no se pudo Eliminar', + life: 3000, + }); + }); + }; + + + const actionsAdmin = (rowData) => { 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 03/14] 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' }} > + + Date: Tue, 2 Aug 2022 21:48:10 -0600 Subject: [PATCH 04/14] remove console.log --- web-ui/web-react/src/components/ComunidadViviendas.js | 1 - 1 file changed, 1 deletion(-) diff --git a/web-ui/web-react/src/components/ComunidadViviendas.js b/web-ui/web-react/src/components/ComunidadViviendas.js index c9076d26..e220c777 100644 --- a/web-ui/web-react/src/components/ComunidadViviendas.js +++ b/web-ui/web-react/src/components/ComunidadViviendas.js @@ -353,7 +353,6 @@ const Communities = () => { id: community._id, status: community.status, }; - console.log(data); fetch('http://localhost:4000/community/changeStatus', { cache: 'no-cache', method: 'POST', From e2f0b401c554c4fd12191e165d7bf824082a8c5f Mon Sep 17 00:00:00 2001 From: Mariela Date: Tue, 2 Aug 2022 21:50:01 -0600 Subject: [PATCH 05/14] agregar funciones en servicio de usuarios --- servicio-usuarios/src/users/users.controller.ts | 9 +++++++-- servicio-usuarios/src/users/users.service.ts | 5 +++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/servicio-usuarios/src/users/users.controller.ts b/servicio-usuarios/src/users/users.controller.ts index bd875b12..a32d265d 100644 --- a/servicio-usuarios/src/users/users.controller.ts +++ b/servicio-usuarios/src/users/users.controller.ts @@ -6,7 +6,7 @@ import { MongoExceptionFilter } from 'src/MongoExceptionFilter'; @Controller() export class UsersController { - constructor(private readonly userService: UsersService) {} + constructor(private readonly userService: UsersService) { } @MessagePattern({ cmd: 'createUser' }) create(@Payload() user: UserDocument) { @@ -117,6 +117,11 @@ export class UsersController { return this.userService.deleteAdminSystem(user['id']); } - + @MessagePattern({ cmd: 'changeStatus' }) + changeStatus(@Payload() body: string) { + let pid = body['id']; + let pstatus = body['status']; + return this.userService.changeStatus(pid, pstatus); + } } diff --git a/servicio-usuarios/src/users/users.service.ts b/servicio-usuarios/src/users/users.service.ts index 268ab49a..2015ef45 100644 --- a/servicio-usuarios/src/users/users.service.ts +++ b/servicio-usuarios/src/users/users.service.ts @@ -223,5 +223,10 @@ export class UsersService { return num_house; } + async changeStatus(id: string, status: string) { + return this.userModel.findOneAndUpdate({ _id: id }, {status: status}, { + new: true, + }); + } } From 89469a687c13673540ff6520491d79389cae2b04 Mon Sep 17 00:00:00 2001 From: Mariela Date: Tue, 2 Aug 2022 21:52:30 -0600 Subject: [PATCH 06/14] agregar y actualizar funciones en api-gateway --- api-gateway/src/app.controller.ts | 12 +++++-- api-gateway/src/app.service.ts | 52 ++++++++++++++++++------------- 2 files changed, 40 insertions(+), 24 deletions(-) diff --git a/api-gateway/src/app.controller.ts b/api-gateway/src/app.controller.ts index 3884c89a..5d2b9f92 100644 --- a/api-gateway/src/app.controller.ts +++ b/api-gateway/src/app.controller.ts @@ -128,6 +128,14 @@ export class AppController { return this.appService.deleteAdminSystem(id); } + @Post('user/changeStatus') + changeStatusUser( + @Body('id') pId: string, + @Body('status') pStatus: string, + ) { + return this.appService.changeStatusUser(pId, pStatus); + } + // #==== API Communities @Post('community/createCommunity') createCommunity( @@ -174,11 +182,11 @@ export class AppController { return this.appService.findCommunityAdmin(community_id); } @Post('community/changeStatus') - changeStatus( + changeStatusCommunity( @Body('id') pId: string, @Body('status') pStatus: string, ) { - return this.appService.changeStatus(pId, pStatus); + return this.appService.changeStatusCommunity(pId, pStatus); } // #==== API Common Areas @Post('commonArea/createCommonArea') diff --git a/api-gateway/src/app.service.ts b/api-gateway/src/app.service.ts index 52c79492..d4a5c20b 100644 --- a/api-gateway/src/app.service.ts +++ b/api-gateway/src/app.service.ts @@ -18,7 +18,7 @@ export class AppService { @Inject('SERVICIO_REPORTES') private readonly clientReportApp: ClientProxy, @Inject('SERVICIO_NOTIFICACIONES') private readonly clientNotificationtApp: ClientProxy, - ) {} + ) { } // ====================== USERS =============================== @@ -79,7 +79,7 @@ export class AppService { .pipe(map((message: string) => ({ message }))); } - + createAdminCommunity(dni: string, name: string, last_name: string, email: string, phone: number , user_type: string, status: string, date_entry: Date, community_id: string) { const pattern = { cmd: 'createAdminCommunity' }; @@ -128,7 +128,7 @@ export class AppService { map((message: string) => ({ message })), ); } - + //GET parameter from API findUser(paramUserDNI: string) { @@ -179,17 +179,10 @@ export class AppService { .send(pattern, payload) .pipe(map((message: string) => ({ message }))); } - changeStatus(pId: string, pStatus: string) { - const pattern = { cmd: 'changeStatus' }; - const payload = { id: pId, status: pStatus }; - return this.clientCommunityApp - .send(pattern, payload) - .pipe(map((message: string) => ({ message }))); - } - //GET parameter from API - findUserById(id: string) { + //GET parameter from API + findUserById(id: string) { const pattern = { cmd: 'findById' }; const payload = { id: id }; return this.clientUserApp @@ -197,8 +190,23 @@ export class AppService { .pipe(map((message: string) => ({ message }))); } + changeStatusUser(pId: string, pStatus: string) { + const pattern = { cmd: 'changeStatus' }; + const payload = { id: pId, status: pStatus }; + return this.clientUserApp + .send(pattern, payload) + .pipe(map((message: string) => ({ message }))); + } + // ====================== COMMUNITIES =============================== + changeStatusCommunity(pId: string, pStatus: string) { + const pattern = { cmd: 'changeStatus' }; + const payload = { id: pId, status: pStatus }; + return this.clientCommunityApp + .send(pattern, payload) + .pipe(map((message: string) => ({ message }))); + } //POST parameter from API createCommunity(name: string, province: string, canton: string, district: string @@ -285,8 +293,8 @@ export class AppService { } - //GET parameter from API - findByCommunity(paramCommunityId: string) { + //GET parameter from API + findByCommunity(paramCommunityId: string) { const pattern = { cmd: 'findByCommunity' }; const payload = { community_id: paramCommunityId }; return this.clientCommonAreaApp @@ -295,14 +303,14 @@ export class AppService { } - //DELETE parameter from API - deleteCommonArea(paramCommonAreaId: string) { - const pattern = { cmd: 'removeCommonArea' }; - const payload = { id: paramCommonAreaId }; - return this.clientCommonAreaApp - .send(pattern, payload) - .pipe(map((message: string) => ({ message }))); - } + //DELETE parameter from API + deleteCommonArea(paramCommonAreaId: string) { + const pattern = { cmd: 'removeCommonArea' }; + const payload = { id: paramCommonAreaId }; + return this.clientCommonAreaApp + .send(pattern, payload) + .pipe(map((message: string) => ({ message }))); + } // ====================== GUESTS =============================== From 2424d78bf6c6184a59271d6a7fc6177ae5c2ec65 Mon Sep 17 00:00:00 2001 From: Mariela Date: Tue, 2 Aug 2022 22:09:24 -0600 Subject: [PATCH 07/14] finalizar funcionalidad cambiar de estado --- .../src/components/AdministradoresSistema.js | 147 +++++++++++------- .../src/components/ComunidadViviendas.js | 2 - 2 files changed, 95 insertions(+), 54 deletions(-) diff --git a/web-ui/web-react/src/components/AdministradoresSistema.js b/web-ui/web-react/src/components/AdministradoresSistema.js index b2eca848..c2761b49 100644 --- a/web-ui/web-react/src/components/AdministradoresSistema.js +++ b/web-ui/web-react/src/components/AdministradoresSistema.js @@ -11,7 +11,7 @@ import { faUserAlt } from '@fortawesome/free-solid-svg-icons'; import { faPhoneAlt } from '@fortawesome/free-solid-svg-icons'; import { faAt } from '@fortawesome/free-solid-svg-icons'; import { faIdCardAlt } from '@fortawesome/free-solid-svg-icons'; -import { faEllipsis } from '@fortawesome/free-solid-svg-icons'; +import { faCircleQuestion } from '@fortawesome/free-solid-svg-icons'; const AdministradoresSistema = () => { const [administrators, setAdministrators] = useState([]); @@ -98,6 +98,51 @@ const AdministradoresSistema = () => { ); } + const cambiarStatusUser = () => { + if (sysadmin.status == '1') { + sysadmin.status = '0'; + sysadmin.status_text = 'Inactivo'; + + } else if (sysadmin.status == '0') { + sysadmin.status = '1'; + sysadmin.status_text = 'Activo'; + } + var data = { + id: sysadmin._id, + status: sysadmin.status, + }; + fetch('http://localhost:4000/user/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) { + setChangeStatusAdminSystemDialog(false); + toast.current.show({ + severity: 'success', + summary: 'Éxito', + detail: 'Administrador del Sistema Actualizado', + life: 3000, + }); + } + ) + .catch( + err => console.log('Ocurrió un error con el fetch', err) + ); + } + const confirmDeleteAdminSystem = (sysAdmin) => { setSysAdmin(sysAdmin); setDeleteAdminSystemDialog(true); @@ -115,13 +160,13 @@ const AdministradoresSistema = () => { setDeleteAdminsSystemDialog(false); }; - const confirmChangeStatusAdminSystem = (sysAdmin) => { - setSysAdmin(sysAdmin); - setDeleteAdminSystemDialog(true); + const hideChangeStatusAdminDialog = () => { + setChangeStatusAdminSystemDialog(false); }; - const hideChangeStatusAdminSystemDialog = () => { - setChangeStatusAdminSystemDialog(false); + const confirmChangeStatusAdminSystem = (sysAdmin) => { + setSysAdmin(sysAdmin); + setChangeStatusAdminSystemDialog(true); }; const deleteSysAdmin = () => { @@ -165,7 +210,7 @@ const AdministradoresSistema = () => { const deleteSelectedAdminsSystem = () => { let _administrators = administrators.filter( - (val) => (!selectedAdministrators.includes(val) || val.status != -1), + (val) => (!selectedAdministrators.includes(val)), ); selectedAdministrators.map((item) => { fetch('http://localhost:4000/user/deleteAdminSystem/' + item._id, { @@ -176,7 +221,9 @@ const AdministradoresSistema = () => { }, }); }); - + _administrators = _administrators.filter( + (val) => val.status != -1, + ) setAdministrators(_administrators); setDeleteAdminsSystemDialog(false); setSelectedAdministrators(null); @@ -188,53 +235,21 @@ const AdministradoresSistema = () => { }); }; - const changeStatusAdminSystm = () => { - fetch('http://localhost:4000/user/statusAdminSystem/' + sysadmin._id, { - cache: 'no-cache', - method: 'POST', - 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) { - let _sysadmin = administrators.filter( - (val) => (val._id !== sysadmin._id || val.status != -1), - ); - - setAdministrators(_sysadmin); - setDeleteAdminSystemDialog(false); - setSysAdmin(emptySysAdmin); - toast.current.show({ - severity: 'success', - summary: 'Éxito', - detail: 'Administrador del Sistema Eliminado', - life: 3000, - }); - }) - .catch((err) => { - console.log('Ocurrió un error con el fetch', err); - toast.current.show({ - severity: 'danger', - summary: 'Error', - detail: 'Administrador del Sistema no se pudo Eliminar', - life: 3000, - }); - }); - }; - - + const actionsAdmin = (rowData) => { + let icono = ''; + if (rowData.status == '0') { + icono = "pi pi-eye"; + } else if (rowData.status == '1') { + icono = "pi pi-eye-slash"; + } + return (
+ +
+ + {sysadmin && ( + + ¿Estás seguro que desea cambiar estado a {sysadmin.name}? + + )} +
+
diff --git a/web-ui/web-react/src/components/ComunidadViviendas.js b/web-ui/web-react/src/components/ComunidadViviendas.js index e220c777..5b607e5e 100644 --- a/web-ui/web-react/src/components/ComunidadViviendas.js +++ b/web-ui/web-react/src/components/ComunidadViviendas.js @@ -12,9 +12,7 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faHome, faUserAlt } from '@fortawesome/free-solid-svg-icons'; 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'; import { faCircleQuestion } from '@fortawesome/free-solid-svg-icons'; const Communities = () => { From e0fe79a1e50d40c0512ca3a120d75ceca3f0e7ba Mon Sep 17 00:00:00 2001 From: Mariela Date: Tue, 2 Aug 2022 22:22:45 -0600 Subject: [PATCH 08/14] agregar columna de estado en la lista --- .../src/components/AdministradoresSistema.js | 52 +++++++++++++++---- .../src/components/ComunidadViviendas.js | 28 +++++----- 2 files changed, 57 insertions(+), 23 deletions(-) diff --git a/web-ui/web-react/src/components/AdministradoresSistema.js b/web-ui/web-react/src/components/AdministradoresSistema.js index c2761b49..40529fc6 100644 --- a/web-ui/web-react/src/components/AdministradoresSistema.js +++ b/web-ui/web-react/src/components/AdministradoresSistema.js @@ -41,14 +41,24 @@ const AdministradoresSistema = () => { password: '', user_type: '1', status: '1', + status_text: '', }; async function fetchP() { let nombres = await fetch(urlFetch, { method: 'GET' }); let adminRes = await nombres.json(); + let data = await adminRes.message.filter( + (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'; + } + }) setAdministrators(adminRes.message); - console.log(administrators); } useEffect(() => { fetchP(); @@ -67,7 +77,6 @@ const AdministradoresSistema = () => { status: "1" }; setSysAdmin(data) - // console.log(data); fetch('http://localhost:4000/user/createAdminSystem/', { cache: 'no-cache', @@ -186,7 +195,7 @@ const AdministradoresSistema = () => { let _sysadmin = administrators.filter( (val) => (val._id !== sysadmin._id || val.status != -1), ); - + setAdministrators(_sysadmin); setDeleteAdminSystemDialog(false); setSysAdmin(emptySysAdmin); @@ -235,27 +244,33 @@ const AdministradoresSistema = () => { }); }; - + const actionsAdmin = (rowData) => { - let icono = ''; + let icono = ''; + let text = ''; if (rowData.status == '0') { icono = "pi pi-eye"; + text = "Activar Administrador" } else if (rowData.status == '1') { icono = "pi pi-eye-slash"; + text = "Inactivar Administrador" + } return (
-
); @@ -413,6 +428,18 @@ const AdministradoresSistema = () => { ) + const statusBodyTemplate = (rowData) => { + return ( + <> + + {rowData.status_text} + + + ); + }; + return (
@@ -502,8 +529,15 @@ const AdministradoresSistema = () => { }} > + + diff --git a/web-ui/web-react/src/components/ComunidadViviendas.js b/web-ui/web-react/src/components/ComunidadViviendas.js index 5b607e5e..61c86b41 100644 --- a/web-ui/web-react/src/components/ComunidadViviendas.js +++ b/web-ui/web-react/src/components/ComunidadViviendas.js @@ -696,15 +696,15 @@ const Communities = () => { const statusBodyTemplate = (rowData) => { return ( - <> - - {rowData.status_text} - - + <> + + {rowData.status_text} + + ); -}; + }; const tenantsBodyTemplate = (rowData) => { let tenants = rowData.tenants; @@ -790,12 +790,12 @@ const Communities = () => { header={headerAdministrator} style={{ flexGrow: 1, flexBasis: '180px' }} > - + Date: Tue, 2 Aug 2022 22:38:54 -0600 Subject: [PATCH 09/14] agregar filtros para comunidades eliminadas --- web-ui/web-react/src/components/Inquilinos.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/web-ui/web-react/src/components/Inquilinos.js b/web-ui/web-react/src/components/Inquilinos.js index 78fa76df..879c2cba 100644 --- a/web-ui/web-react/src/components/Inquilinos.js +++ b/web-ui/web-react/src/components/Inquilinos.js @@ -34,7 +34,8 @@ const Inquilinos = () => { number_house: 'Sin número de vivienda', user_type: '4', date_entry: new Date(), - status: '1' + status: '1', + status_text: '', }; const [tenants, setTenants] = useState([]); @@ -50,6 +51,7 @@ const Inquilinos = () => { const dt = useRef(null); const [cookies, setCookie] = useCookies(); + const [changeStatusTenantDialog, setChangeStatusTenantDialog] = useState(false); async function tenantsList() { @@ -72,7 +74,9 @@ const Inquilinos = () => { let response = await fetch('http://localhost:4000/community/allCommunities', { method: 'GET' }); let resList = await response.json(); let list = await resList.message; - + list = await list.filter( + (val) => val.status != -1, + ) setCommunitiesList(await list); } From 8428463a9ed2875636a357f70f0f815ed7edd342 Mon Sep 17 00:00:00 2001 From: Mariela Date: Tue, 2 Aug 2022 22:46:15 -0600 Subject: [PATCH 10/14] Funcionalidad cambiar estado de inquilino --- web-ui/web-react/src/components/Inquilinos.js | 127 +++++++++++++++++- 1 file changed, 122 insertions(+), 5 deletions(-) diff --git a/web-ui/web-react/src/components/Inquilinos.js b/web-ui/web-react/src/components/Inquilinos.js index 879c2cba..f693cb8d 100644 --- a/web-ui/web-react/src/components/Inquilinos.js +++ b/web-ui/web-react/src/components/Inquilinos.js @@ -59,9 +59,18 @@ const Inquilinos = () => { .then((response) => response.json()) .then(data => data.message) .then(data => { - + data = data.filter( + (val) => val.status != -1, + ) data.map((item) => { - if(item.number_house ==""){ + if (item.status == '1') { + item.status_text = 'Activo'; + } else if (item.status == '0') { + item.status_text = 'Inactivo'; + } + + + if (item.number_house == "") { item.number_house = "Sin vivienda asignada"; } }) @@ -193,6 +202,50 @@ const Inquilinos = () => { }); }; + const cambiarStatusUser = () => { + if (tenant.status == '1') { + tenant.status = '0'; + tenant.status_text = 'Inactivo'; + + } else if (tenant.status == '0') { + tenant.status = '1'; + tenant.status_text = 'Activo'; + } + var data = { + id: tenant._id, + status: tenant.status, + }; + fetch('http://localhost:4000/user/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) { + setChangeStatusTenantDialog(false); + toast.current.show({ + severity: 'success', + summary: 'Éxito', + detail: 'Inquilino Actualizado', + life: 3000, + }); + } + ) + .catch( + err => console.log('Ocurrió un error con el fetch', err) + ); + } const hideDeleteTenantDialog = () => { setDeleteTenantDialog(false); @@ -211,11 +264,37 @@ const Inquilinos = () => { setDeleteTenantsDialog(true); }; + const hideChangeStatusTenantDialog = () => { + setChangeStatusTenantDialog(false); + }; + + const confirmChangeStatusTenant = (tenant) => { + setTenant(tenant); + setChangeStatusTenantDialog(true); + }; const actionsTenant = (rowData) => { + let icono = ''; + let text = ''; + if (rowData.status == '0') { + icono = "pi pi-eye"; + text = "Activar Inquilino" + } else if (rowData.status == '1') { + icono = "pi pi-eye-slash"; + text = "Inactivar Inquilino" + + } return (
-
); } @@ -262,6 +341,24 @@ const Inquilinos = () => { ); + + const changeStatusTenantDialogFooter = ( + <> +
); @@ -397,6 +398,26 @@ const Inquilinos = () => { ) + const headerStatus = ( + <> +

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

+ + ) + + const statusBodyTemplate = (rowData) => { + return ( + <> + + {rowData.status_text} + + + ); + }; return (
@@ -418,7 +439,14 @@ const Inquilinos = () => { - + + +
From 52fea9937e9003dda3a91061399219b9b5323e58 Mon Sep 17 00:00:00 2001 From: Mariela Date: Tue, 2 Aug 2022 23:19:00 -0600 Subject: [PATCH 12/14] funcionalidad desactivar-activar guarda de seguridad --- .../src/components/AdministradoresSistema.js | 2 +- .../src/components/GuardasSeguridad.js | 180 +++++++++++++++--- 2 files changed, 157 insertions(+), 25 deletions(-) diff --git a/web-ui/web-react/src/components/AdministradoresSistema.js b/web-ui/web-react/src/components/AdministradoresSistema.js index 933d0381..3a2b8a97 100644 --- a/web-ui/web-react/src/components/AdministradoresSistema.js +++ b/web-ui/web-react/src/components/AdministradoresSistema.js @@ -58,7 +58,7 @@ const AdministradoresSistema = () => { item.status_text = 'Inactivo'; } }) - setAdministrators(adminRes.message); + setAdministrators(await data); } useEffect(() => { fetchP(); diff --git a/web-ui/web-react/src/components/GuardasSeguridad.js b/web-ui/web-react/src/components/GuardasSeguridad.js index a092910f..79bb2763 100644 --- a/web-ui/web-react/src/components/GuardasSeguridad.js +++ b/web-ui/web-react/src/components/GuardasSeguridad.js @@ -11,7 +11,8 @@ import { faUserAlt } from '@fortawesome/free-solid-svg-icons'; import { faPhoneAlt } from '@fortawesome/free-solid-svg-icons'; import { faAt } from '@fortawesome/free-solid-svg-icons'; import { faIdCardAlt } from '@fortawesome/free-solid-svg-icons'; -import { faEllipsis } from '@fortawesome/free-solid-svg-icons'; +import { faCircleQuestion } from '@fortawesome/free-solid-svg-icons'; +import { useCookies } from "react-cookie"; const GuardasSeguridad = () => { const [listaGuardas, setListaGuardas] = useState([]); @@ -23,6 +24,10 @@ const GuardasSeguridad = () => { const [deleteGuardasDialog, setDeleteGuardasDialog] = useState(false); const toast = useRef(null); const dt = useRef(null); + + const [cookies, setCookie] = useCookies(); + const [changeStatusGuardDialog, setChangeStatusGuardDialog] = useState(false); + let emptyGuarda = { _id: null, dni: '', @@ -32,7 +37,8 @@ const GuardasSeguridad = () => { phone: '', password: '', user_type: '1', - status: '' + status: '', + status_text: '', }; @@ -40,7 +46,17 @@ const GuardasSeguridad = () => { async function listaGuardasF() { let nombres = await fetch(urlFetch, { method: 'GET' }); let listaGuardasRes = await nombres.json(); - setListaGuardas(listaGuardasRes.message); + let data = await listaGuardasRes.message.filter( + (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'; + } + }) + setListaGuardas(await data); } useEffect(() => { listaGuardasF(); @@ -56,7 +72,7 @@ const GuardasSeguridad = () => { password: document.getElementById('correo_electronico').value, user_type: "4", //4 es guarda status: "1", - community_id: "62be68215692582bbfd77134" + community_id: cookies.community_id }; var data2 = { dni: "11979037", @@ -66,7 +82,7 @@ const GuardasSeguridad = () => { phone: 84664515, password: "1203", user_type: "2", - status: "4", + status: "1", community_id: "62be68215692582bbfd77134" } console.log('ssss'); @@ -74,7 +90,7 @@ const GuardasSeguridad = () => { cache: 'no-cache', method: 'POST', mode: 'cors', - body: JSON.stringify(data2), + body: JSON.stringify(data), headers: { 'Content-Type': 'application/json' } @@ -89,7 +105,6 @@ const GuardasSeguridad = () => { ) .then( function (response) { - console.log('fff'); listaGuardasF(); } ) @@ -98,22 +113,51 @@ const GuardasSeguridad = () => { ); } - const hideDeleteGuardaDialog = () => { - setDeleteGuardaDialog(false); + const cambiarStatusUser = () => { + if (guarda.status == '1') { + guarda.status = '0'; + guarda.status_text = 'Inactivo'; + + } else if (guarda.status == '0') { + guarda.status = '1'; + guarda.status_text = 'Activo'; + } + var data = { + id: guarda._id, + status: guarda.status, + }; + fetch('http://localhost:4000/user/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) { + setChangeStatusGuardDialog(false); + toast.current.show({ + severity: 'success', + summary: 'Éxito', + detail: 'Guarda de Seguridad Actualizado', + life: 3000, + }); + } + ) + .catch( + err => console.log('Ocurrió un error con el fetch', err) + ); } - const hideDeleteGuardasDialog = () => { - setDeleteGuardasDialog(false); - } - - const confirmDeleteGuarda = (guarda) => { - setGuarda(guarda); - setDeleteGuardaDialog(true); - } - - const confirmDeleteSelected = () => { - setDeleteGuardasDialog(true); - } const deleteGuarda = () => { @@ -166,10 +210,55 @@ const GuardasSeguridad = () => { toast.current.show({ severity: 'success', summary: 'Éxito', detail: 'Administradores del Sistema Eliminados', life: 3000 }); } + const hideDeleteGuardaDialog = () => { + setDeleteGuardaDialog(false); + } + + const hideDeleteGuardasDialog = () => { + setDeleteGuardasDialog(false); + } + + const confirmDeleteGuarda = (guarda) => { + setGuarda(guarda); + setDeleteGuardaDialog(true); + } + + const confirmDeleteSelected = () => { + setDeleteGuardasDialog(true); + } + + const hideChangeStatusGuardDialog = () => { + setChangeStatusGuardDialog(false); + }; + + const confirmChangeStatusGuard = (guard) => { + setGuarda(guard); + setChangeStatusGuardDialog(true); + }; + + const actionsAdmin = (rowData) => { + let icono = ''; + let text = ''; + if (rowData.status == '0') { + icono = "pi pi-eye"; + text = "Activar Guarda de Seguridad" + } else if (rowData.status == '1') { + icono = "pi pi-eye-slash"; + text = "Inactivar Guarda de Seguridad" + + } return (
-
); } @@ -178,7 +267,11 @@ const GuardasSeguridad = () => { return (
-
) @@ -187,7 +280,9 @@ const GuardasSeguridad = () => { const rightToolbarTemplate = () => { return ( -
+ +
+ + {guarda && ( + + ¿Estás seguro que desea cambiar estado a {guarda.name}? + + )} +
+
From 3294422e6a7bc2c17b11ff41d90b4e62af563ce0 Mon Sep 17 00:00:00 2001 From: Mariela Date: Tue, 2 Aug 2022 23:22:51 -0600 Subject: [PATCH 13/14] arreglar textos y estilos --- web-ui/web-react/src/components/GuardasSeguridad.js | 12 ++++++------ web-ui/web-react/src/components/Inquilinos.js | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/web-ui/web-react/src/components/GuardasSeguridad.js b/web-ui/web-react/src/components/GuardasSeguridad.js index 79bb2763..77cbc676 100644 --- a/web-ui/web-react/src/components/GuardasSeguridad.js +++ b/web-ui/web-react/src/components/GuardasSeguridad.js @@ -257,7 +257,7 @@ const GuardasSeguridad = () => { title={`${text}`} />
); @@ -300,14 +300,14 @@ const GuardasSeguridad = () => { const deleteAdminSystemDialogFooter = ( <>
- +
- +
diff --git a/web-ui/web-react/src/components/GuardasSeguridad.js b/web-ui/web-react/src/components/GuardasSeguridad.js index 77cbc676..d09b09fc 100644 --- a/web-ui/web-react/src/components/GuardasSeguridad.js +++ b/web-ui/web-react/src/components/GuardasSeguridad.js @@ -373,6 +373,26 @@ const GuardasSeguridad = () => { ) + const headerStatus = ( + <> +

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

+ + ) + + const statusBodyTemplate = (rowData) => { + return ( + <> + + {rowData.status_text} + + + ); + }; return (
@@ -393,6 +413,13 @@ const GuardasSeguridad = () => { + + @@ -438,12 +465,12 @@ const GuardasSeguridad = () => {
- +
- +
@@ -451,7 +478,7 @@ const GuardasSeguridad = () => {
- +
diff --git a/web-ui/web-react/src/components/Inquilinos.js b/web-ui/web-react/src/components/Inquilinos.js index 8f461bb5..26971e1f 100644 --- a/web-ui/web-react/src/components/Inquilinos.js +++ b/web-ui/web-react/src/components/Inquilinos.js @@ -491,7 +491,7 @@ const Inquilinos = () => {
- +