diff --git a/api-gateway/src/app.controller.ts b/api-gateway/src/app.controller.ts index 20a6ee27..ff53abf1 100644 --- a/api-gateway/src/app.controller.ts +++ b/api-gateway/src/app.controller.ts @@ -191,6 +191,11 @@ export class AppController { return this.appService.findCommonArea(paramCommonAreaId); } + @Get('commonArea/findByCommunity/:community_id') + findByCommunity(@Param('community_id') paramCommunityId: string) { + return this.appService.findByCommunity(paramCommunityId); + } + // #==== API GUEST //#API userService - create user @Post('guest/createGuest') diff --git a/api-gateway/src/app.service.ts b/api-gateway/src/app.service.ts index 4b71002b..426764c0 100644 --- a/api-gateway/src/app.service.ts +++ b/api-gateway/src/app.service.ts @@ -248,6 +248,16 @@ export class AppService { .pipe(map((message: string) => ({ message }))); } + + //GET parameter from API + findByCommunity(paramCommunityId: string) { + const pattern = { cmd: 'findByCommunity' }; + const payload = { community_id: paramCommunityId }; + return this.clientCommonAreaApp + .send(pattern, payload) + .pipe(map((message: string) => ({ message }))); + } + // ====================== GUESTS =============================== //POST parameter from API diff --git a/servicio-areas-comunes/src/common_areas/common_areas.controller.ts b/servicio-areas-comunes/src/common_areas/common_areas.controller.ts index 3fa8e1c6..08d2866a 100644 --- a/servicio-areas-comunes/src/common_areas/common_areas.controller.ts +++ b/servicio-areas-comunes/src/common_areas/common_areas.controller.ts @@ -33,4 +33,10 @@ export class CommonAreasController { let _id = id['_id']; return this.commonAreasService.remove(_id); } + + @MessagePattern({ cmd: 'findByCommunity' }) + findByCommunity(@Payload() id: string) { + let _community_id = id['community_id']; + return this.commonAreasService.findByCommunity(_community_id); + } } diff --git a/servicio-areas-comunes/src/common_areas/common_areas.service.ts b/servicio-areas-comunes/src/common_areas/common_areas.service.ts index 325a9821..142b527a 100644 --- a/servicio-areas-comunes/src/common_areas/common_areas.service.ts +++ b/servicio-areas-comunes/src/common_areas/common_areas.service.ts @@ -36,4 +36,9 @@ export class CommonAreasService { new: true, }); } + + async findByCommunity(community_id: string): Promise { + return this.commonAreaModel.find({ community_id: community_id }).exec(); + } + } diff --git a/web-ui/web-react/package-lock.json b/web-ui/web-react/package-lock.json index 5ddda7d4..e9ff9cd3 100644 --- a/web-ui/web-react/package-lock.json +++ b/web-ui/web-react/package-lock.json @@ -27,6 +27,7 @@ "prismjs": "1.9.0", "react": "^17.0.1", "react-app-polyfill": "^1.0.6", + "react-cookie": "^4.1.1", "react-dom": "^17.0.1", "react-router-dom": "^5.2.0", "react-scripts": "3.4.1", @@ -2475,6 +2476,11 @@ "@babel/types": "^7.3.0" } }, + "node_modules/@types/cookie": { + "version": "0.3.3", + "resolved": "https://registry.npmjs.org/@types/cookie/-/cookie-0.3.3.tgz", + "integrity": "sha512-LKVP3cgXBT9RYj+t+9FDKwS5tdI+rPBXaNSkma7hvqy35lc7mAokC2zsqWJH0LaqIt3B962nuYI77hsJoT1gow==" + }, "node_modules/@types/eslint-visitor-keys": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/@types/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz", @@ -2489,6 +2495,15 @@ "@types/node": "*" } }, + "node_modules/@types/hoist-non-react-statics": { + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/@types/hoist-non-react-statics/-/hoist-non-react-statics-3.3.1.tgz", + "integrity": "sha512-iMIqiko6ooLrTh1joXodJK5X9xeEALT1kM5G3ZLhD3hszxBdIEd5C75U834D9mLcINgD4OyZf5uQXjkuYydWvA==", + "dependencies": { + "@types/react": "*", + "hoist-non-react-statics": "^3.3.0" + } + }, "node_modules/@types/istanbul-lib-coverage": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.4.tgz", @@ -2531,11 +2546,31 @@ "resolved": "https://registry.npmjs.org/@types/parse-json/-/parse-json-4.0.0.tgz", "integrity": "sha512-//oorEZjL6sbPcKUaCdIGlIUeH26mgzimjBB77G6XRgnDl/L5wOnpyBGRe/Mmf5CVW3PwEBE1NjiMZ/ssFh4wA==" }, + "node_modules/@types/prop-types": { + "version": "15.7.5", + "resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.5.tgz", + "integrity": "sha512-JCB8C6SnDoQf0cNycqd/35A7MjcnK+ZTqE7judS6o7utxUCg6imJg3QK2qzHKszlTjcj2cn+NwMB2i96ubpj7w==" + }, "node_modules/@types/q": { "version": "1.5.5", "resolved": "https://registry.npmjs.org/@types/q/-/q-1.5.5.tgz", "integrity": "sha512-L28j2FcJfSZOnL1WBjDYp2vUHCeIFlyYI/53EwD/rKUBQ7MtUUfbQWiyKJGpcnv4/WgrhWsFKrcPstcAt/J0tQ==" }, + "node_modules/@types/react": { + "version": "18.0.15", + "resolved": "https://registry.npmjs.org/@types/react/-/react-18.0.15.tgz", + "integrity": "sha512-iz3BtLuIYH1uWdsv6wXYdhozhqj20oD4/Hk2DNXIn1kFsmp9x8d9QB6FnPhfkbhd2PgEONt9Q1x/ebkwjfFLow==", + "dependencies": { + "@types/prop-types": "*", + "@types/scheduler": "*", + "csstype": "^3.0.2" + } + }, + "node_modules/@types/scheduler": { + "version": "0.16.2", + "resolved": "https://registry.npmjs.org/@types/scheduler/-/scheduler-0.16.2.tgz", + "integrity": "sha512-hppQEBDmlwhFAXKJX2KnWLYu5yMfi91yazPb2l+lbJiwW+wdo1gNeRA+3RgNSO39WYX2euey41KEwnqesU2Jew==" + }, "node_modules/@types/stack-utils": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/@types/stack-utils/-/stack-utils-1.0.1.tgz", @@ -13402,6 +13437,19 @@ "node": ">=6" } }, + "node_modules/react-cookie": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/react-cookie/-/react-cookie-4.1.1.tgz", + "integrity": "sha512-ffn7Y7G4bXiFbnE+dKhHhbP+b8I34mH9jqnm8Llhj89zF4nPxPutxHT1suUqMeCEhLDBI7InYwf1tpaSoK5w8A==", + "dependencies": { + "@types/hoist-non-react-statics": "^3.0.1", + "hoist-non-react-statics": "^3.0.0", + "universal-cookie": "^4.0.0" + }, + "peerDependencies": { + "react": ">= 16.3.0" + } + }, "node_modules/react-dev-utils": { "version": "10.2.1", "resolved": "https://registry.npmjs.org/react-dev-utils/-/react-dev-utils-10.2.1.tgz", @@ -16599,6 +16647,23 @@ "imurmurhash": "^0.1.4" } }, + "node_modules/universal-cookie": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/universal-cookie/-/universal-cookie-4.0.4.tgz", + "integrity": "sha512-lbRVHoOMtItjWbM7TwDLdl8wug7izB0tq3/YVKhT/ahB4VDvWMyvnADfnJI8y6fSvsjh51Ix7lTGC6Tn4rMPhw==", + "dependencies": { + "@types/cookie": "^0.3.3", + "cookie": "^0.4.0" + } + }, + "node_modules/universal-cookie/node_modules/cookie": { + "version": "0.4.2", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.2.tgz", + "integrity": "sha512-aSWTXFzaKWkvHO1Ny/s+ePFpvKsPnjc551iI41v3ny/ow6tBG5Vd+FuqGNhh1LxOmVzOlGUriIlOaokOvhaStA==", + "engines": { + "node": ">= 0.6" + } + }, "node_modules/universalify": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz", @@ -19769,6 +19834,11 @@ "@babel/types": "^7.3.0" } }, + "@types/cookie": { + "version": "0.3.3", + "resolved": "https://registry.npmjs.org/@types/cookie/-/cookie-0.3.3.tgz", + "integrity": "sha512-LKVP3cgXBT9RYj+t+9FDKwS5tdI+rPBXaNSkma7hvqy35lc7mAokC2zsqWJH0LaqIt3B962nuYI77hsJoT1gow==" + }, "@types/eslint-visitor-keys": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/@types/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz", @@ -19783,6 +19853,15 @@ "@types/node": "*" } }, + "@types/hoist-non-react-statics": { + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/@types/hoist-non-react-statics/-/hoist-non-react-statics-3.3.1.tgz", + "integrity": "sha512-iMIqiko6ooLrTh1joXodJK5X9xeEALT1kM5G3ZLhD3hszxBdIEd5C75U834D9mLcINgD4OyZf5uQXjkuYydWvA==", + "requires": { + "@types/react": "*", + "hoist-non-react-statics": "^3.3.0" + } + }, "@types/istanbul-lib-coverage": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.4.tgz", @@ -19825,11 +19904,31 @@ "resolved": "https://registry.npmjs.org/@types/parse-json/-/parse-json-4.0.0.tgz", "integrity": "sha512-//oorEZjL6sbPcKUaCdIGlIUeH26mgzimjBB77G6XRgnDl/L5wOnpyBGRe/Mmf5CVW3PwEBE1NjiMZ/ssFh4wA==" }, + "@types/prop-types": { + "version": "15.7.5", + "resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.5.tgz", + "integrity": "sha512-JCB8C6SnDoQf0cNycqd/35A7MjcnK+ZTqE7judS6o7utxUCg6imJg3QK2qzHKszlTjcj2cn+NwMB2i96ubpj7w==" + }, "@types/q": { "version": "1.5.5", "resolved": "https://registry.npmjs.org/@types/q/-/q-1.5.5.tgz", "integrity": "sha512-L28j2FcJfSZOnL1WBjDYp2vUHCeIFlyYI/53EwD/rKUBQ7MtUUfbQWiyKJGpcnv4/WgrhWsFKrcPstcAt/J0tQ==" }, + "@types/react": { + "version": "18.0.15", + "resolved": "https://registry.npmjs.org/@types/react/-/react-18.0.15.tgz", + "integrity": "sha512-iz3BtLuIYH1uWdsv6wXYdhozhqj20oD4/Hk2DNXIn1kFsmp9x8d9QB6FnPhfkbhd2PgEONt9Q1x/ebkwjfFLow==", + "requires": { + "@types/prop-types": "*", + "@types/scheduler": "*", + "csstype": "^3.0.2" + } + }, + "@types/scheduler": { + "version": "0.16.2", + "resolved": "https://registry.npmjs.org/@types/scheduler/-/scheduler-0.16.2.tgz", + "integrity": "sha512-hppQEBDmlwhFAXKJX2KnWLYu5yMfi91yazPb2l+lbJiwW+wdo1gNeRA+3RgNSO39WYX2euey41KEwnqesU2Jew==" + }, "@types/stack-utils": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/@types/stack-utils/-/stack-utils-1.0.1.tgz", @@ -28396,6 +28495,16 @@ "whatwg-fetch": "^3.0.0" } }, + "react-cookie": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/react-cookie/-/react-cookie-4.1.1.tgz", + "integrity": "sha512-ffn7Y7G4bXiFbnE+dKhHhbP+b8I34mH9jqnm8Llhj89zF4nPxPutxHT1suUqMeCEhLDBI7InYwf1tpaSoK5w8A==", + "requires": { + "@types/hoist-non-react-statics": "^3.0.1", + "hoist-non-react-statics": "^3.0.0", + "universal-cookie": "^4.0.0" + } + }, "react-dev-utils": { "version": "10.2.1", "resolved": "https://registry.npmjs.org/react-dev-utils/-/react-dev-utils-10.2.1.tgz", @@ -30926,6 +31035,22 @@ "imurmurhash": "^0.1.4" } }, + "universal-cookie": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/universal-cookie/-/universal-cookie-4.0.4.tgz", + "integrity": "sha512-lbRVHoOMtItjWbM7TwDLdl8wug7izB0tq3/YVKhT/ahB4VDvWMyvnADfnJI8y6fSvsjh51Ix7lTGC6Tn4rMPhw==", + "requires": { + "@types/cookie": "^0.3.3", + "cookie": "^0.4.0" + }, + "dependencies": { + "cookie": { + "version": "0.4.2", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.2.tgz", + "integrity": "sha512-aSWTXFzaKWkvHO1Ny/s+ePFpvKsPnjc551iI41v3ny/ow6tBG5Vd+FuqGNhh1LxOmVzOlGUriIlOaokOvhaStA==" + } + } + }, "universalify": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz", diff --git a/web-ui/web-react/package.json b/web-ui/web-react/package.json index 876ccccc..12dd1f1d 100644 --- a/web-ui/web-react/package.json +++ b/web-ui/web-react/package.json @@ -27,6 +27,7 @@ "prismjs": "1.9.0", "react": "^17.0.1", "react-app-polyfill": "^1.0.6", + "react-cookie": "^4.1.1", "react-dom": "^17.0.1", "react-router-dom": "^5.2.0", "react-scripts": "3.4.1", diff --git a/web-ui/web-react/public/assets/themes/khaki/theme.css b/web-ui/web-react/public/assets/themes/khaki/theme.css index 08d350a6..5aa7ff7b 100644 --- a/web-ui/web-react/public/assets/themes/khaki/theme.css +++ b/web-ui/web-react/public/assets/themes/khaki/theme.css @@ -89,8 +89,8 @@ } .p-icon-input-khaki { - border-top-right-radius: 0!important; - border-bottom-right-radius: 0!important; + border-top-right-radius: 0 !important; + border-bottom-right-radius: 0 !important; border-color: #C08135; } @@ -7117,4 +7117,34 @@ .p-button.p-button-danger:enabled:focus { box-shadow: 0 0 0 2px #ffffff, 0 0 0 4px #f7a2a2, 0 1px 2px 0 black; +} + + +.status { + border-radius: var(--border-radius); + padding: 0.25em 0.5rem; + text-transform: uppercase; + font-weight: 700; + font-size: 12px; + letter-spacing: 0.3px; +} + +.status.status-1 { + background: #c8e6c9!important; + color: #256029!important; +} + +.status.status-0 { + background: #ffcdd2; + color: #c63737; +} + +.status.status-2 { + background: #feedaf; + color: #8a5340; +} + +.status.status--1 { + background: #565656; + color: #f7f9f7; } \ No newline at end of file diff --git a/web-ui/web-react/src/App.js b/web-ui/web-react/src/App.js index 1fef97b4..a70c89ec 100644 --- a/web-ui/web-react/src/App.js +++ b/web-ui/web-react/src/App.js @@ -51,6 +51,7 @@ import './assets/layout/layout.scss'; import './App.scss'; import LogIn from './components/LogIn'; import { PrimeIcons } from 'primereact/api'; +import AreasComunes from './components/AreasComunes'; const App = () => { const [layoutMode, setLayoutMode] = useState('static'); @@ -187,7 +188,16 @@ const App = () => { icon: PrimeIcons.BUILDING, to: '/comunidadesViviendas', }, - { label: 'Inquilinos', icon: PrimeIcons.USER, to: '/inquilinos' }, + { + label: 'Inquilinos', + icon: PrimeIcons.USER, + to: '/inquilinos' + }, + { + label: 'Áreas Comunes de Comunidad', + icon: PrimeIcons.BUILDING, + to: '/areasComunes', + }, { label: 'Log in', icon: 'pi pi-fw pi-id-card', to: '/logIn' }, ], }, @@ -411,6 +421,7 @@ const App = () => { + diff --git a/web-ui/web-react/src/components/AreasComunes.js b/web-ui/web-react/src/components/AreasComunes.js new file mode 100644 index 00000000..7eefc66c --- /dev/null +++ b/web-ui/web-react/src/components/AreasComunes.js @@ -0,0 +1,307 @@ +import React, { useEffect, useState, useRef } from 'react'; +import { InputText } from 'primereact/inputtext'; +import { Button } from 'primereact/button'; +import { Dropdown } from 'primereact/dropdown'; +import { DataTable } from 'primereact/datatable'; +import { Column } from 'primereact/column'; +import { Toast } from 'primereact/toast'; +import { Dialog } from 'primereact/dialog'; +import { Toolbar } from 'primereact/toolbar'; +import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; +import { faHome, 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 { faHomeAlt } from '@fortawesome/free-solid-svg-icons'; +import classNames from 'classnames'; +import { useCookies } from "react-cookie"; + + +const AreasComunes = () => { + + let emptyCommonArea = { + _id: null, + dni: '', + name: '', + hourMin: '', + hourMax: '', + community_id: '', + bookable: '1', + bookable_text: '', + }; + + const [commonAreaList, setCommonAreaList] = useState([]); + const [commonArea, setCommonArea] = useState(emptyCommonArea); + const [selectedCommonAreas, setSelectedCommonAreas] = useState(null); + const [globalFilter, setGlobalFilter] = useState(null); + const [deleteCommonAreaDialog, setDeleteCommonAreaDialog] = useState(false); + const [deleteCommonAreasDialog, setDeleteCommonAreasDialog] = useState(false); + const [submitted, setSubmitted] = useState(false); + const toast = useRef(null); + const dt = useRef(null); + + const [cookies, setCookie] = useCookies(); + + async function getCommonAreas() { + await fetch(`http://localhost:4000/commonArea/findByCommunity/${cookies.community_id}`, { method: 'GET' }) + .then((response) => response.json()) + .then(data => data.message) + .then(data => { + if(data) { + data.map(item => { + if(item.bookable == '1') { + item.bookable_text = 'Disponible'; + } else{ + item.bookable_text = 'Cerrado'; + } + }) + } + setCommonAreaList(data); + }); + } + + useEffect(() => { + getCommonAreas(); + }, []); + + + const deleteCommonArea = () => { + /* fetch('http://localhost:4000/community/deleteCommunity/' + community._id, { + cache: 'no-cache', + method: 'DELETE', + 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 _community = communities.filter(val => val._id !== community._id); + setCommunities(_community); + setDeleteCommunityDialog(false); + setCommunity(emptyCommunity); + toast.current.show({ severity: 'success', summary: 'Exito', detail: 'Comunidad de Viviendas Eliminada', life: 3000 }); + } + ) + .catch( + err => { + console.log('Ocurrió un error con el fetch', err) + toast.current.show({ severity: 'danger', summary: 'Error', detail: 'Comunidad de Viviendas no se pudo eliminar', life: 3000 }); + } + ); + */ + let _common_areas = commonAreaList.filter( + (val) => val._id !== commonArea._id, + ); + setCommonAreaList(_common_areas); + setDeleteCommonAreaDialog(false); + setCommonArea(emptyCommonArea); + toast.current.show({ + severity: 'success', + summary: 'Área Común Eliminada', + life: 3000, + }); + }; + + const deleteSelectedCommonAreas = () => { + let _commonareas = commonAreaList.filter( + (val) => !selectedCommonAreas.includes(val), + ); + /* selectedCommunities.map((item) => { + fetch('http://localhost:4000/user/deleteCommunity/' + item._id, { + cache: 'no-cache', + method: 'DELETE', + headers: { + 'Content-Type': 'application/json' + } + }) + })*/ + setCommonAreaList(_commonareas); + setDeleteCommonAreasDialog(false); + setSelectedCommonAreas(null); + toast.current.show({ + severity: 'success', + summary: 'Éxito', + detail: 'Áreas Comúnes Eliminadas', + life: 3000, + }); + }; + + const hideDeleteCommonAreaDialog = () => { + setDeleteCommonAreaDialog(false); + } + + const hideDeleteCommonAreasDialog = () => { + setDeleteCommonAreasDialog(false); + } + + const confirmDeleteCommonArea = (commonArea) => { + setCommonArea(commonArea); + setDeleteCommonAreaDialog(true); + } + + const confirmDeleteSelected = () => { + setDeleteCommonAreasDialog(true); + }; + + + + const actionsCommonArea = (rowData) => { + return ( +
+
+ ); + }; + + + const deleteCommonAreaDialogFooter = ( + <> +