From 37abfaf7b2748392cbd266528225bdbd085145be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D0=B8=D1=88=D0=B8=D0=BD=D0=B0=29?= <Аришина)@DESKTOP-OUE59OV> Date: Wed, 20 Nov 2024 11:56:13 +0400 Subject: [PATCH] =?UTF-8?q?=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=20=D0=B4=D0=BE?= =?UTF-8?q?=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cucumber-frontend/src/App.tsx | 2 + cucumber-frontend/src/models/IGreenGouse.tsx | 13 ++ .../src/models/Support/HeatingMode.ts | 4 + .../src/models/Support/WateringMode.ts | 4 + .../src/pages/GreenHouseListPage.tsx | 128 ++++++++++++++++++ 5 files changed, 151 insertions(+) create mode 100644 cucumber-frontend/src/models/IGreenGouse.tsx create mode 100644 cucumber-frontend/src/models/Support/HeatingMode.ts create mode 100644 cucumber-frontend/src/models/Support/WateringMode.ts create mode 100644 cucumber-frontend/src/pages/GreenHouseListPage.tsx diff --git a/cucumber-frontend/src/App.tsx b/cucumber-frontend/src/App.tsx index f3bfa31..f22ff4f 100644 --- a/cucumber-frontend/src/App.tsx +++ b/cucumber-frontend/src/App.tsx @@ -5,6 +5,7 @@ import {LoginPage} from './pages/Login'; import {RegisterPage} from './pages/Register'; import {AppLayout} from './components/Layout'; import { ProfilePage } from './pages/Profile'; +import { GreenHouseListPage } from './pages/GreenHouseListPage'; function App() { return ( @@ -15,6 +16,7 @@ function App() { } /> } /> } /> + } /> diff --git a/cucumber-frontend/src/models/IGreenGouse.tsx b/cucumber-frontend/src/models/IGreenGouse.tsx new file mode 100644 index 0000000..d63a71d --- /dev/null +++ b/cucumber-frontend/src/models/IGreenGouse.tsx @@ -0,0 +1,13 @@ +import IFarm from "./IFarm"; +import { HeatingMode } from "./Support/HeatingMode"; +import { WateringMode } from "./Support/WateringMode"; + +export interface IGreenhouse { + id: number; + recommendedTemperature: number; + wateringMode: WateringMode; + heatingMode: HeatingMode; + farmId: number; + farm?: IFarm; +} + diff --git a/cucumber-frontend/src/models/Support/HeatingMode.ts b/cucumber-frontend/src/models/Support/HeatingMode.ts new file mode 100644 index 0000000..57610d8 --- /dev/null +++ b/cucumber-frontend/src/models/Support/HeatingMode.ts @@ -0,0 +1,4 @@ +export enum HeatingMode { + Manual, + Auto +} \ No newline at end of file diff --git a/cucumber-frontend/src/models/Support/WateringMode.ts b/cucumber-frontend/src/models/Support/WateringMode.ts new file mode 100644 index 0000000..b3fe0bd --- /dev/null +++ b/cucumber-frontend/src/models/Support/WateringMode.ts @@ -0,0 +1,4 @@ +export enum WateringMode { + Manual, + Auto +} \ No newline at end of file diff --git a/cucumber-frontend/src/pages/GreenHouseListPage.tsx b/cucumber-frontend/src/pages/GreenHouseListPage.tsx new file mode 100644 index 0000000..e68ea81 --- /dev/null +++ b/cucumber-frontend/src/pages/GreenHouseListPage.tsx @@ -0,0 +1,128 @@ +import React, { useState, useEffect } from 'react'; +import { Modal, Button, Table, Form, Input, Select, Space } from 'antd'; + +interface IGreenhouse { + id: number; + name: string; + recommendedTemperature: number; + wateringMode: 'Manual' | 'Auto'; + heatingMode: 'Manual' | 'Auto'; +} + +export function GreenHouseListPage() { + const [greenhouses, setGreenhouses] = useState([]); + const [isModalVisible, setIsModalVisible] = useState(false); + const [editingGreenhouse, setEditingGreenhouse] = useState(null); + const [form] = Form.useForm(); + + + useEffect(() => { + fetchGreenhouses(); + }, []); + + const fetchGreenhouses = async () => { + // Fetch data from API + }; + + const handleAddOrEditSubmit = () => { + form.validateFields().then((values) => { + if (editingGreenhouse) { + setGreenhouses(greenhouses.map(g => g.id === editingGreenhouse.id ? { ...g, ...values } : g)); + } else { + setGreenhouses([...greenhouses, { id: Date.now(), ...values }]); + } + setIsModalVisible(false); + setEditingGreenhouse(null); + form.resetFields(); + }); + }; + + const handleDelete = (id: number) => { + setGreenhouses(greenhouses.filter(g => g.id !== id)); + }; + + const handleModalOpen = (greenhouse?: IGreenhouse) => { + setEditingGreenhouse(greenhouse || null); + setIsModalVisible(true); + if (greenhouse) { + form.setFieldsValue(greenhouse); + } + }; + const columns = [ + { + title: 'Название', + dataIndex: 'name', + key: 'name', + }, + { + title: 'Температура', + dataIndex: 'recommendedTemperature', + key: 'recommendedTemperature', + }, + { + title: 'Режим полива', + dataIndex: 'wateringMode', + key: 'wateringMode', + render: (text: string) => text === 'Manual' ? 'Вручную' : 'Автоматически', + }, + { + title: 'Режим отопления', + dataIndex: 'heatingMode', + key: 'heatingMode', + render: (text: string) => text === 'Manual' ? 'Вручную' : 'Автоматически', + }, + { + title: 'Действия', + key: 'action', + render: (_: any, record: IGreenhouse) => ( + + + + + ), + }, + ]; + return ( +
+

Список теплиц

+ + + + + + { + setIsModalVisible(false); + form.resetFields(); + setEditingGreenhouse(null); + }} + > +
+ + + + + + + + + + + + + +
+ + ); +}; \ No newline at end of file