Skip to content

Commit

Permalink
added lock keys
Browse files Browse the repository at this point in the history
  • Loading branch information
kimamov committed Feb 5, 2021
1 parent 8342680 commit 34ca72e
Show file tree
Hide file tree
Showing 21 changed files with 188 additions and 111 deletions.
2 changes: 1 addition & 1 deletion client/.eslintcache

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion client/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import UserList from './components/user/UserList';
import UserCreate from './components/user/UserCreate';
import UserEdit from './components/user/UserEdit';
import LockList from './components/lock/LockList';
import LockShow from './components/lock/LockShow';
import LockCreate from './components/lock/LockCreate';
import LockEdit from './components/lock/LockEdit';
import BuildingList from './components/building/BuildingList';
Expand All @@ -44,7 +45,8 @@ function App() {
{permissions=>[
<Resource icon={LocationCity} name="building" list={BuildingList} create={BuildingCreate}/>,
<Resource icon={LocationCity} name="apartment" list={ApartmentList} create={ApartmentCreate}/>,
<Resource icon={Lock} name="lock" list={LockList} create={LockCreate} edit={LockEdit} options={{label: 'Locks'}}/>,
<Resource icon={Lock} name="lock" list={LockList} create={LockCreate} edit={LockEdit} show={LockShow} options={{label: 'Locks'}}/>,
<Resource icon={Lock} name="lockkey" options={{label: 'Locks'}}/>,
<Resource icon={Fingerprint} name="reader" list={ReaderList} show={ReaderShow} edit={ReaderEdit} options={{label: 'Controllers'}}/>,
<Resource icon={VpnKey} name="key" list={KeyList} create={KeyCreate} edit={KeyEdit} show={KeyShow}/>,
<Resource icon={FiberNew} name="newkey" list={NewKeyList} options={{label: 'Unknown Keys'}}/>,
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/apartment/ApartmentCreate.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// in posts.js
import * as React from "react";
import { Create, SimpleForm, TextInput, BooleanInput, DateTimeInput, ReferenceInput, SelectInput } from 'react-admin';
import { Create, SimpleForm, TextInput, ReferenceInput, SelectInput } from 'react-admin';



Expand Down
2 changes: 1 addition & 1 deletion client/src/components/building/BuildingCreate.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// in posts.js
import * as React from "react";
import { Create, SimpleForm, TextInput, BooleanInput, DateTimeInput, ReferenceInput, SelectInput } from 'react-admin';
import { Create, SimpleForm, TextInput } from 'react-admin';



Expand Down
2 changes: 1 addition & 1 deletion client/src/components/building/BuildingList.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// in posts.js
import * as React from "react";
import { List, Datagrid, TextField, EditButton, NumberField, ReferenceField} from 'react-admin';
import { List, Datagrid, TextField, EditButton} from 'react-admin';
import KeyActions from "./KeyActions";

export const BuildingList = (props) => (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,37 @@
import { Box, Typography } from '@material-ui/core'
import { Box } from '@material-ui/core'
import React from 'react'
import LockCell from '../../../dashboard/LockCell'

const LockOrNull=({lock})=>lock? <LockCell lock={lock}/> : null;

const ApartmentOne = ({apartment={}, props}) => {
// sort locks by their slot on the reader
const sortedLocks=apartment.locks && apartment.locks.length
? apartment.locks.sort((lockA, lockB)=>lockA.slot-lockB.slot)
: []
console.log(sortedLocks)

/* const halfIndex=Math.floor(sortedLocks.length / 2);
const arrayFirstHalf=sortedLocks.slice(0, halfIndex);
const arraySecondHalf=sortedLocks.slice(halfIndex, sortedLocks.length); */

return (
<Box marginX="auto">
<Typography align="center" variant="h6">{apartment.name}</Typography>
<Box display="flex" margin={2}>
<Box id="links" display="flex" flexDirection="column">
<LockCell lock={sortedLocks[0]}/>
<LockCell lock={sortedLocks[1]}/>
</Box>
<LockCell lock={apartment.apartmentLock }/>
<Box id="rechts" display="flex" justifyContent="stretch" flexDirection="column">
<LockCell lock={sortedLocks[2]}/>
<LockCell lock={sortedLocks[3]}/>
<LockCell lock={sortedLocks[4]}/>
<LockCell lock={sortedLocks[5]}/>
{/* <Typography align="center" variant="h6">{apartment.name}</Typography> */}
<Box margin={2} display="flex" flexDirection="column">
<LockCell
customLabel={apartment?.apartmentLock?.name}
lock={apartment.apartmentLock}
/>
<Box display="flex" flex={1}>
<Box id="links" display="flex" flexDirection="column" flex={1}>
<LockCell lock={sortedLocks[0]}/>
<LockCell lock={sortedLocks[1]}/>
<LockCell lock={sortedLocks[2]}/>
</Box>
<Box id="rechts" display="flex" flexDirection="column" flex={1}>
<LockCell lock={sortedLocks[3]}/>
<LockCell lock={sortedLocks[4]}/>
<LockCell lock={sortedLocks[5]}/>
</Box>
</Box>
</Box>
</Box>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import LockCell from '../../../dashboard/LockCell'


const BuildingRosenstrasse = (props) => {
const [modalOpen, setOpen]=useState(false);
const [building, setBuilding]=useState({});
/* get data for building rosenstrasse */
useEffect(() => {
Expand Down
4 changes: 2 additions & 2 deletions client/src/components/dashboard/LockCell.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {useState, useRef} from 'react'
import React from 'react'
import Box from '@material-ui/core/Box'
import { styled, Menu, MenuItem } from '@material-ui/core';
import {Add} from '@material-ui/icons';
Expand Down Expand Up @@ -56,7 +56,7 @@ const ValidLockCell=({
const openLock=async()=>{
try {
notify(`started opening lock ${lock.name}`, "info")
const res=await fetch(`${"http:https://localhost:5000/api"}/opendoor/${lock.readerId}?port=${lock.slot}`)
await fetch(`${"http:https://localhost:5000/api"}/opendoor/${lock.readerId}?port=${lock.slot}`)
//const json=await res.json();
notify(`successfully opened lock ${lock.name}`, "info")
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/dashboard/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Card, CardContent, CardHeader, Typography } from '@material-ui/core'
import { Card, CardContent, CardHeader } from '@material-ui/core'
import React from 'react'
import BuildingRosenstrasse from '../building/customViews/rosenstrasse/BuildingRosenstrasse'

Expand Down
52 changes: 0 additions & 52 deletions client/src/components/lock/KeyActions.jsx

This file was deleted.

2 changes: 0 additions & 2 deletions client/src/components/lock/LockList.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
// in posts.js
import * as React from "react";
import { List, Datagrid, TextField, EditButton, NumberField, ReferenceField} from 'react-admin';
import KeyActions from "./KeyActions";

export const LockList = (props) => (
<List
actions={<KeyActions/>}
{...props}
>
<Datagrid rowClick="show">
Expand Down
30 changes: 17 additions & 13 deletions client/src/components/lock/LockShow.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import {Datagrid, Show, SimpleShowLayout, ArrayField, BooleanField, NumberField, DateField, TextField} from 'react-admin';
import {Show, SimpleShowLayout, NumberField, TextField, ReferenceField, ReferenceManyField, Datagrid} from 'react-admin';



Expand All @@ -10,21 +10,25 @@ const LockShow = (props) => {
<Show title=" " {...props}>
<SimpleShowLayout {...props}>
<TextField source="name"/>
<TextField source="uid" />
<NumberField source="acctype" />
<NumberField source="acctype2" />
<NumberField source="acctype3" />
<NumberField source="acctype4" />
<DateField source="validUntil" showTime locales="de"/>
<BooleanField source="isOneTimeCode" />
<TextField source="type" />
<NumberField source="slot"/>
<ReferenceField label="Building" reference="building" source="buildingId" link="show">
<TextField source="name"/>
</ReferenceField>
<ReferenceField label="Apartment" reference="apartment" source="apartmentId" link="show">
<TextField source="name"/>
</ReferenceField>
<ReferenceField label="Reader" reference="reader" source="readerId" link="show">
<TextField source="readerName"/>
</ReferenceField>

<ArrayField label="KEY IS ON THESE READERS" source="readerKeys" >
<ReferenceManyField label="Keys" reference="lockkey" target="id">
<Datagrid>
<TextField label="name" source="reader.readerName" />
<TextField label="local ip" source="reader.ip" />
<DateField label="last ping" source="reader.lastPing" showTime locales="de"/>
<ReferenceField reference="key" source="keyId" link="show">
<TextField source="name"/>
</ReferenceField>
</Datagrid>
</ArrayField>
</ReferenceManyField>
</SimpleShowLayout>
</Show>
)
Expand Down
15 changes: 7 additions & 8 deletions client/src/components/reader/ReaderShow.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import React, {useState} from 'react'
import { Toolbar, SaveButton, Create, SimpleForm, ReferenceField,ReferenceInput, SelectInput, Datagrid, Show, SimpleShowLayout, TextField, DateField, ArrayField, BooleanField, ReferenceManyField, NumberField, useNotify, useRefresh, BooleanInput } from 'react-admin';
import { LockOpen} from '@material-ui/icons';
import { Toolbar, SaveButton, Create, SimpleForm, ReferenceField ,ReferenceManyField,ReferenceInput, SelectInput, Datagrid, Show, SimpleShowLayout, TextField, DateField, ArrayField, BooleanField, NumberField, useNotify, BooleanInput, ShowButton } from 'react-admin';
import ReaderShowActions from './ReaderShowActions'
import TextButtonField from '../customFields/TextButtonField';
import { Button } from '@material-ui/core';


Expand All @@ -18,7 +16,7 @@ const ShowPropsExtractor=({children, ...props})=>{
const [showDevice, setShow] = useState(false)


const openDoor=async(port)=>{
/* const openDoor=async(port)=>{
try {
const serverAdress=process.env.REACT_APP_SERVER || "http:https://locaholst:5000";
const response=await fetch(`${serverAdress}/opendoor/${props.record.id}?port=${port}`)
Expand All @@ -28,7 +26,7 @@ const ShowPropsExtractor=({children, ...props})=>{
console.log(error)
notify("could not open door", "error")
}
}
} */

const readerKeyRowStyle = (record, _index) => {
const keys=props?.record?.readerKeys;
Expand Down Expand Up @@ -63,12 +61,13 @@ const ShowPropsExtractor=({children, ...props})=>{
<TextField source="name"/>
</ReferenceField>

<ArrayField label="CONNECTED LOCKS" source="locks" >
<ReferenceManyField reference="lock" target="readerId">
<Datagrid>
<TextField label="name" source="name" />
<TextField label="name" source="name"/>
<NumberField source="slot" />
<ShowButton/>
</Datagrid>
</ArrayField>
</ReferenceManyField>

{/* <TextButtonField onClick={()=>openDoor(1)} label="Relay 1 (acctype)" variant="contained" source="acctypeName">
<LockOpen/>
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/reader/ReaderShowActions.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { DeleteForever, LockOpen, SystemUpdate} from '@material-ui/icons';
import { DeleteForever, SystemUpdate} from '@material-ui/icons';
import {
TopToolbar,
Button,
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/user/UserCreate.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from "react";
import { Create, SimpleForm, TextInput, BooleanInput, DateTimeInput, ReferenceInput, SelectInput } from 'react-admin';
import { Create, SimpleForm, TextInput } from 'react-admin';



Expand Down
4 changes: 0 additions & 4 deletions src/controllers/buildingController.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import { getRepository } from "typeorm"
import { Request, Response } from "express"
import { Reader } from "../entity/Reader"
import { client } from "../mqtt/connection";
import { Key } from "../entity/Key";
import getList from "../util/getList";
import dateToUnix from "../util/dateToUnix";
import { ReaderKey } from "../entity/ReaderKey";
import { Lock } from "../entity/Lock";
import { Building } from "../entity/Building";


Expand Down
2 changes: 1 addition & 1 deletion src/controllers/lockController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export async function getLocks(req: Request, res: Response) {
export async function getLock(req: Request, res: Response){
try {
const {id}=req.params;
const result = await getRepository(Lock).findOne(id, {relations: ["keys", "reader", "building", "apartment", "apartmentLock", "buildingLock", ]})
const result = await getRepository(Lock).findOne(id/* , {relations: ["keys", "reader", "building", "apartment", "apartmentLock", "buildingLock", ]} */)

if(!result){
return res.status(404).send({message: `could not find lock with the provided id ${id}`})
Expand Down
Loading

0 comments on commit 34ca72e

Please sign in to comment.