From 060bd28bf83d0a933280e2bd467158c22b53d30c Mon Sep 17 00:00:00 2001 From: Mariela Date: Mon, 1 Aug 2022 02:05:02 -0600 Subject: [PATCH 1/6] 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 (
+
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 6/6] 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' }} > - +