From c1f785eff1d916739e5852764f69d9925d5ae273 Mon Sep 17 00:00:00 2001 From: mfnefd Date: Tue, 24 Dec 2024 03:25:52 +0400 Subject: [PATCH] =?UTF-8?q?add:=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D1=81=D1=82=D1=80=D0=B0=D0=BD=D0=B8=D1=86?= =?UTF-8?q?=D0=B0=20=D1=82=D0=B5=D0=BF=D0=BB=D0=B8=D1=86=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cucumber-frontend/src/App.tsx | 2 + .../greenhouse/GreenhouseCommandTable.tsx | 20 ++++ .../greenhouse/GreenhouseDataDisplay.tsx | 46 +++++++++ .../greenhouse/GreenhouseManager.tsx | 26 +++++ .../greenhouse/GreenhouseSettingsForm.tsx | 97 +++++++++++++++++++ .../src/core/services/greenhouse-service.ts | 52 ++++++++++ .../src/pages/GreenHousePage.tsx | 39 ++++++++ 7 files changed, 282 insertions(+) create mode 100644 cucumber-frontend/src/components/greenhouse/GreenhouseCommandTable.tsx create mode 100644 cucumber-frontend/src/components/greenhouse/GreenhouseDataDisplay.tsx create mode 100644 cucumber-frontend/src/components/greenhouse/GreenhouseManager.tsx create mode 100644 cucumber-frontend/src/components/greenhouse/GreenhouseSettingsForm.tsx create mode 100644 cucumber-frontend/src/core/services/greenhouse-service.ts create mode 100644 cucumber-frontend/src/pages/GreenHousePage.tsx diff --git a/cucumber-frontend/src/App.tsx b/cucumber-frontend/src/App.tsx index 3f11fb8..1f2299b 100644 --- a/cucumber-frontend/src/App.tsx +++ b/cucumber-frontend/src/App.tsx @@ -7,6 +7,7 @@ import {AppLayout} from './components/Layout'; import { ProfilePage } from './pages/Profile'; import { GreenHouseListPage } from './pages/GreenHouseListPage'; import { ReportPage } from './pages/ReportPage'; +import GreenHousePage from './pages/GreenHousePage'; function App() { return ( @@ -18,6 +19,7 @@ function App() { } /> } /> } /> + } /> } /> diff --git a/cucumber-frontend/src/components/greenhouse/GreenhouseCommandTable.tsx b/cucumber-frontend/src/components/greenhouse/GreenhouseCommandTable.tsx new file mode 100644 index 0000000..dd20620 --- /dev/null +++ b/cucumber-frontend/src/components/greenhouse/GreenhouseCommandTable.tsx @@ -0,0 +1,20 @@ +import { Table } from "antd"; +import { HistoryData } from "../../core/services/greenhouse-service"; + +export interface GreenhouseCommandTableProps { + history: HistoryData[], + className: string +} + +const GreenhouseCommandHistoryTable = (props: GreenhouseCommandTableProps) => { + const { history, className } = props; + return ( + + ); +} + +export default GreenhouseCommandHistoryTable; \ No newline at end of file diff --git a/cucumber-frontend/src/components/greenhouse/GreenhouseDataDisplay.tsx b/cucumber-frontend/src/components/greenhouse/GreenhouseDataDisplay.tsx new file mode 100644 index 0000000..470bb34 --- /dev/null +++ b/cucumber-frontend/src/components/greenhouse/GreenhouseDataDisplay.tsx @@ -0,0 +1,46 @@ +import { GreenhouseInfo } from "../../core/api/data-contracts"; + +export interface GreehouseDataDisplayProps { + info: GreenhouseInfo +} + +const GreenhouseDataDisplay = (props: GreehouseDataDisplayProps) => { + const { info } = props; + return ( +
+

Данные теплицы

+
+
+
+

Процент влажности почвы:

+

{info.percentWater}%

+
+
+

Температура почвы:

+

{info.soilTemperature}°C

+
+
+

Статус вентиля:

+

+ {info.pumpStatus ? 'Открыт' : 'Закрыт'} +

+
+
+

Статус нагревателя:

+

+ {info.heatingStatus ? 'Включен' : 'Выключен'} +

+
+
+

Статус автополива:

+

+ {info.autoWateringStatus ? 'Активирован' : 'Деактивирован'} +

+
+
+
+
+ ); +} + +export default GreenhouseDataDisplay; \ No newline at end of file diff --git a/cucumber-frontend/src/components/greenhouse/GreenhouseManager.tsx b/cucumber-frontend/src/components/greenhouse/GreenhouseManager.tsx new file mode 100644 index 0000000..26085d7 --- /dev/null +++ b/cucumber-frontend/src/components/greenhouse/GreenhouseManager.tsx @@ -0,0 +1,26 @@ +import { Switch } from "antd"; +import { useState } from "react"; + + +export interface GreenhouseManagerProps { + +} + +const GreenhouseManager = (props: GreenhouseManagerProps) => { + + return ( +
+

Управление

+
+ + +
+
+ + +
+
+ ); +}; + +export default GreenhouseManager; \ No newline at end of file diff --git a/cucumber-frontend/src/components/greenhouse/GreenhouseSettingsForm.tsx b/cucumber-frontend/src/components/greenhouse/GreenhouseSettingsForm.tsx new file mode 100644 index 0000000..b4f9048 --- /dev/null +++ b/cucumber-frontend/src/components/greenhouse/GreenhouseSettingsForm.tsx @@ -0,0 +1,97 @@ +import { useState } from "react"; +import { Greenhouse, HeatingMode, WateringMode } from "../../core/api/data-contracts"; +import { Select, Button, Form, Input } from "antd"; + +export interface GreenhouseSettingsFormProps { + updateSettings: (settings: Greenhouse) => void, + id: number +} + +const GreenhouseSettingsForm = (props: GreenhouseSettingsFormProps) => { + const { updateSettings, id } = props; + const [settings, setSettings] = useState({ + id: Number(id!), + wateringMode: WateringMode.Value0, + heatingMode: HeatingMode.Value0, + }); + return ( +
+

Настройки

+
updateSettings({ ...settings, ...values })} + onFinishFailed={(error: any) => console.log(error)} + > + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ ); +}; + +export default GreenhouseSettingsForm; \ No newline at end of file diff --git a/cucumber-frontend/src/core/services/greenhouse-service.ts b/cucumber-frontend/src/core/services/greenhouse-service.ts new file mode 100644 index 0000000..8aa5cd1 --- /dev/null +++ b/cucumber-frontend/src/core/services/greenhouse-service.ts @@ -0,0 +1,52 @@ +import { Greenhouse, GreenhouseInfo } from "../api/data-contracts"; + +export type HistoryData = { + id: number, + action: string, + startAt: string, + endAt: string +} + +export default class GreenhouseService { + private static _info: GreenhouseInfo = {} as GreenhouseInfo; + public getData(id: number): GreenhouseInfo { + if (GreenhouseService._info.id) return GreenhouseService._info; + + let info = { + id: id, + percentWater: randomInt(50, 60), + soilTemperature: randomInt(17, 28), + pumpStatus: randomInt(0, 1) == 1, + heatingStatus: randomInt(0, 1) == 1, + autoWateringStatus: randomInt(0, 1) == 1 + }; + GreenhouseService._info = info; + return info; + } + + public setSettings(settings: Greenhouse): boolean { + let newInfo = { + id: settings.id, + percentWater: randomInt(50, 60), + soilTemperature: randomInt(17, 28), + pumpStatus: randomInt(0, 1) == 1, + heatingStatus: settings.heatingMode, + autoWateringStatus: settings.wateringMode + } as GreenhouseInfo; + GreenhouseService._info = newInfo; + return true; + } + + public getCommandsHistory(id: number): HistoryData[] { + return [ + { id: 1, action: "Открыт вентиль", startAt: new Date().toLocaleDateString(), endAt: new Date().toLocaleDateString() }, + { id: 2, action: "Закрыт вентиль", startAt: new Date().toLocaleDateString(), endAt: new Date().toLocaleDateString()}, + { id: 3, action: "Включен нагреватель", startAt: new Date().toLocaleDateString(), endAt: new Date().toLocaleDateString()}, + { id: 3, action: "выключен нагреватель", startAt: new Date().toLocaleDateString(), endAt: new Date().toLocaleDateString()}, + ] + } +} + +function randomInt(min: number, max: number): number { + return Math.floor(Math.random() * (max - min + 1) + min); + } \ No newline at end of file diff --git a/cucumber-frontend/src/pages/GreenHousePage.tsx b/cucumber-frontend/src/pages/GreenHousePage.tsx new file mode 100644 index 0000000..25e439b --- /dev/null +++ b/cucumber-frontend/src/pages/GreenHousePage.tsx @@ -0,0 +1,39 @@ +import { useState } from 'react'; +import GreenhouseService, { HistoryData } from '../core/services/greenhouse-service'; +import { Greenhouse, GreenhouseInfo, HeatingMode, WateringMode } from '../core/api/data-contracts'; +import { useNavigate, useParams } from 'react-router-dom'; +import GreenhouseDataDisplay from '../components/greenhouse/GreenhouseDataDisplay'; +import GreenhouseSettingsForm from '../components/greenhouse/GreenhouseSettingsForm'; +import GreenhouseManager from '../components/greenhouse/GreenhouseManager'; +import GreenhouseCommandHistoryTable from '../components/greenhouse/GreenhouseCommandTable'; + +const GreenHousePage = () => { + const { id } = useParams(); + let service = new GreenhouseService(); + + const [info, setInfo] = useState(service.getData(Number(id!))); + const [history, setHistory] = useState(service.getCommandsHistory(Number(id!))); + + + const updateSettings = (settings: Greenhouse) => { + const success = service.setSettings(settings); + if (success) { + alert('Настройки успешно обновлены'); + } else { + alert('Ошибка обновления настроек'); + } + }; + + return ( +
+
+ + + +
+ +
+ ); +} + +export default GreenHousePage; \ No newline at end of file