From 4d7ec5545605792c15bb93230798da424ce42905 Mon Sep 17 00:00:00 2001 From: joseph le Date: Tue, 10 Oct 2023 14:09:43 +0700 Subject: [PATCH 1/2] update edit value UI --- app/Controllers/Http/ValuesController.ts | 11 +- manage-view/src/api/apiLog.js | 5 +- manage-view/src/pages/ManageValues.jsx | 179 ++++++++++++++++++----- start/routes.ts | 6 +- 4 files changed, 157 insertions(+), 44 deletions(-) diff --git a/app/Controllers/Http/ValuesController.ts b/app/Controllers/Http/ValuesController.ts index b25372a..5291e89 100644 --- a/app/Controllers/Http/ValuesController.ts +++ b/app/Controllers/Http/ValuesController.ts @@ -24,7 +24,16 @@ export default class ValuesController { public async show({}: HttpContextContract) {} - public async edit({}: HttpContextContract) {} + public async edit({ request, response }: HttpContextContract) { + try { + const value = await KeyValue.findOrFail(request.all().id); + value.value = request.all().value; + await value.save(); + response.status(200).send("EDIT VALUE SUCCESS!"); + } catch (error) { + response.status(500).send("EDIT VALUE FAIL!"); + } + } public async update({}: HttpContextContract) {} diff --git a/manage-view/src/api/apiLog.js b/manage-view/src/api/apiLog.js index 86e8497..6717f93 100644 --- a/manage-view/src/api/apiLog.js +++ b/manage-view/src/api/apiLog.js @@ -1,7 +1,8 @@ -const API = process.env.REACT_APP_API_SERVER_ADDRESS; -// const API = "http://localhost:3333/api"; +// const API = process.env.REACT_APP_API_SERVER_ADDRESS; +const API = "http://localhost:3333/api"; export const getKeyValues = API + "/getKeyValue"; export const deleteValue = API + "/deleteValue"; export const addKeyValue = API + "/addValue"; +export const editValue = API + "/editValue"; export const getLog = API + "/log/showLog"; export const getListLog = API + "/getAllLogDetect"; \ No newline at end of file diff --git a/manage-view/src/pages/ManageValues.jsx b/manage-view/src/pages/ManageValues.jsx index 514c3b1..cbe0032 100644 --- a/manage-view/src/pages/ManageValues.jsx +++ b/manage-view/src/pages/ManageValues.jsx @@ -1,13 +1,13 @@ import axios from "axios"; import React, { useEffect, useState } from "react"; -import { addKeyValue, deleteValue, getKeyValues } from "../api/apiLog"; +import { addKeyValue, deleteValue, editValue, getKeyValues } from "../api/apiLog"; import { Link } from "react-router-dom"; const ManageValues = () => { - const [keyValue, setKeyValue] = useState([]); const [key, setKey] = useState([]); - const [addValue, setAddValue] = useState({key: "CATCH_FAULTY", value:""}); - + const [addValue, setAddValue] = useState({ key: "CATCH_FAULTY", value: "" }); + const [inputSelect, setInpuSelect] = useState(0) + const [inputValue, setInputValue] = useState("") const getValues = async () => { try { const res = await axios.post(getKeyValues); @@ -17,22 +17,22 @@ const ManageValues = () => { console.log(error); } }; - + useEffect(() => { getValues(); }, []); - + console.log(inputValue) return (
- + @@ -53,30 +58,99 @@ const ManageValues = () => { {keyValue?.map((value) => ( - + ))}
{ Key Value
{value.key} - + { + setInputValue(e.target.value) + + }} + > - + } + }} + > + Delete + + +
-
- { + setAddValue({ ...addValue, key: e.target.value }); + }} + > {key .filter((value, index, self) => { return self.indexOf(value) === index; @@ -85,27 +159,52 @@ const ManageValues = () => { ))} - { - setAddValue({...addValue, value: e.target.value}) - }}> - - + }} + > + Add +
- + + {" "} + +
-
); }; diff --git a/start/routes.ts b/start/routes.ts index 9735422..0bded1c 100644 --- a/start/routes.ts +++ b/start/routes.ts @@ -228,6 +228,10 @@ Route.post("/api/deleteValue", "ValuesController.destroy").middleware( "writeLog" ); +Route.post("/api/editValue", "ValuesController.edit").middleware( + "writeLog" +); + Route.post("/api/addValue", "ValuesController.create").middleware("writeLog"); Route.post("/api/backupProduct", async ({ request, response }) => { @@ -277,7 +281,7 @@ Route.post("/api/backupProduct", async ({ request, response }) => { } }).middleware("writeLog"); -Route.post("/api/sendMailInforDevice", async ({ request, response }) => { +Route.post("/api/sendMailInforDevice", async () => { try { sendDeviceInfora() } catch (error) { From d9eb50d6e5b48cd243d546121b10188a721224e9 Mon Sep 17 00:00:00 2001 From: joseph le Date: Tue, 10 Oct 2023 14:09:57 +0700 Subject: [PATCH 2/2] update edit value UI --- manage-view/src/api/apiLog.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/manage-view/src/api/apiLog.js b/manage-view/src/api/apiLog.js index 6717f93..da1346d 100644 --- a/manage-view/src/api/apiLog.js +++ b/manage-view/src/api/apiLog.js @@ -1,5 +1,5 @@ -// const API = process.env.REACT_APP_API_SERVER_ADDRESS; -const API = "http://localhost:3333/api"; +const API = process.env.REACT_APP_API_SERVER_ADDRESS; +// const API = "http://localhost:3333/api"; export const getKeyValues = API + "/getKeyValue"; export const deleteValue = API + "/deleteValue"; export const addKeyValue = API + "/addValue";