From 1e652da94db29fae91339f32d82ac1d067e4eb9f Mon Sep 17 00:00:00 2001 From: "13621160019@163.com" <13621160019@163.com> Date: Sat, 12 Feb 2022 15:53:55 +0800 Subject: [PATCH] updated Web Message actions in API and Notification Page in Web UI --- myems-api/README.md | 36 +++++++++++++++---- myems-api/core/webmessage.py | 14 +++++--- .../MyEMS/Notification/Notification.js | 5 ++- .../components/navbar/NotificationDropdown.js | 3 +- web/src/i18n.js | 4 +++ 5 files changed, 46 insertions(+), 16 deletions(-) diff --git a/myems-api/README.md b/myems-api/README.md index cd83bda4..59a028e7 100644 --- a/myems-api/README.md +++ b/myems-api/README.md @@ -2144,21 +2144,45 @@ Result in JSON | message | string | Web Message Body | | created_datetime| float | Web Message Created Datetime (POSIX timestamp * 1000)| | status | string | Status ('new', 'acknowledged', 'timeout') | -| reply | string | User's Reply text, allow null | +| reply | string | User's Reply text, required for 'acknowledged' status, otherwise allow null | ```bash -curl -i -H "User-UUID: 793f1bb4-6e25-4242-8cdc-2f662b25484f" -H "Token: GET-TOKEN-AFTER-LOGIN" -X GET {{base_url}}/webmessages/{id} +curl --location --request GET '{{base_url}}/webmessages/{id}' \ +--header 'User-UUID: dcdb67d1-6116-4987-916f-6fc6cf2bc0e4' \ +--header 'Token: 24bb236244f26784fb1397344d926b4871e87a90096eae926a0e448396dbd3ff4a2f70f727089f025238cb47bdbccdc877ef4a50fad8f05a4e5100c5d3eb0d3c' ``` * GET Web Messages by Datetime Range ```bash -curl -i -H "User-UUID: 793f1bb4-6e25-4242-8cdc-2f662b25484f" -H "Token: GET-TOKEN-AFTER-LOGIN" -X GET {{base_url}}/webmessages?startdatetime={startdatetime}&enddatetime={enddatetime} +curl --location --request GET '{{base_url}}/webmessages?startdatetime=2021-12-11T00:00:00&enddatetime=2021-12-21T00:00:00' \ +--header 'User-UUID: dcdb67d1-6116-4987-916f-6fc6cf2bc0e4' \ +--header 'Token: 9ac434f394c735092cfeb083612e533ca33ca6db4815ebb0c3ff47896d7eaa610e7dc312c04279253f817d65d1ef379378d4a5d07150faee5f6d899adb8b7ca7' ``` * GET New Web Messages ```bash -curl -i -H "User-UUID: 793f1bb4-6e25-4242-8cdc-2f662b25484f" -H "Token: GET-TOKEN-AFTER-LOGIN" -X GET {{base_url}}/webmessagesnew +curl --location --request GET '{{base_url}}/webmessagesnew' \ +--header 'User-UUID: dcdb67d1-6116-4987-916f-6fc6cf2bc0e4' \ +--header 'Token: 9bcd171e4f4169f1f45791aeadc8f90cfe8694be92f21af7bf95673f8cc910ca7a91bfd4a577d48d0720155de497eb02baab614be5c6c83891f1a856f9cf666a' ``` -* DELETE a Web Message by ID +* PUT Update a Web Message (Acknowledge) ```bash -curl -i -H "User-UUID: 793f1bb4-6e25-4242-8cdc-2f662b25484f" -H "Token: GET-TOKEN-AFTER-LOGIN" -X DELETE {{base_url}}/webmessages/{id} +curl --location --request PUT '{{base_url}}/webmessages/{id}' \ +--header 'User-UUID: dcdb67d1-6116-4987-916f-6fc6cf2bc0e4' \ +--header 'Token: 9bcd171e4f4169f1f45791aeadc8f90cfe8694be92f21af7bf95673f8cc910ca7a91bfd4a577d48d0720155de497eb02baab614be5c6c83891f1a856f9cf666a' \ +--header 'Content-Type: text/plain' \ +--data-raw '{"data":{"status":"acknowledged", "reply":"this is my reply"}}' +``` +* PUT Update a Web Message (Mark As Read) +```bash +curl --location --request PUT '{{base_url}}/webmessages/{id}' \ +--header 'User-UUID: dcdb67d1-6116-4987-916f-6fc6cf2bc0e4' \ +--header 'Token: 9bcd171e4f4169f1f45791aeadc8f90cfe8694be92f21af7bf95673f8cc910ca7a91bfd4a577d48d0720155de497eb02baab614be5c6c83891f1a856f9cf666a' \ +--header 'Content-Type: text/plain' \ +--data-raw '{"data":{"status":"read"}}' +``` +* DELETE a Web Message by ID +```bash +curl --location --request DELETE '{{base_url}}/webmessages/{id}' \ +--header 'User-UUID: dcdb67d1-6116-4987-916f-6fc6cf2bc0e4' \ +--header 'Token: 24bb236244f26784fb1397344d926b4871e87a90096eae926a0e448396dbd3ff4a2f70f727089f025238cb47bdbccdc877ef4a50fad8f05a4e5100c5d3eb0d3c' ``` ### Wechat Message diff --git a/myems-api/core/webmessage.py b/myems-api/core/webmessage.py index e701ad50..a24b2961 100644 --- a/myems-api/core/webmessage.py +++ b/myems-api/core/webmessage.py @@ -367,17 +367,21 @@ class WebMessageItem: if 'status' not in new_values['data'].keys() or \ not isinstance(new_values['data']['status'], str) or \ len(str.strip(new_values['data']['status'])) == 0 or \ - str.strip(new_values['data']['status']) not in ('new', 'acknowledged', 'timeout', 'read'): + str.strip(new_values['data']['status']) not in ('new', 'acknowledged', 'read'): raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_STATUS') status = str.strip(new_values['data']['status']) - if 'reply' not in new_values['data'].keys() or \ - not isinstance(new_values['data']['reply'], str) or \ - len(str.strip(new_values['data']['reply'])) == 0: + # reply is required for 'acknowledged' status + if status == 'acknowledged' and \ + ('reply' not in new_values['data'].keys() or + not isinstance(new_values['data']['reply'], str) or + len(str.strip(new_values['data']['reply'])) == 0): raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_REPLY') - reply = str.strip(new_values['data']['reply']) + reply = str.strip(new_values['data']['reply']) + else: + reply = None # Verify User Session token = req.headers.get('TOKEN') diff --git a/web/src/components/MyEMS/Notification/Notification.js b/web/src/components/MyEMS/Notification/Notification.js index a8451fb7..c5de3b4b 100644 --- a/web/src/components/MyEMS/Notification/Notification.js +++ b/web/src/components/MyEMS/Notification/Notification.js @@ -260,8 +260,7 @@ const Notification = ({ setRedirect, setRedirectUrl, t }) => { }, body: JSON.stringify({ "data": { - "status": 'read', - "reply": 'ok' + "status": 'read' } }), }).then(response => { @@ -296,7 +295,7 @@ const Notification = ({ setRedirect, setRedirectUrl, t }) => { body: JSON.stringify({ "data": { "status": 'acknowledged', - "reply": 'ok' + "reply": 'OK' } }), }).then(response => { diff --git a/web/src/components/navbar/NotificationDropdown.js b/web/src/components/navbar/NotificationDropdown.js index 3e0b7861..002a0f89 100644 --- a/web/src/components/navbar/NotificationDropdown.js +++ b/web/src/components/navbar/NotificationDropdown.js @@ -95,8 +95,7 @@ const NotificationDropdown = ({ t }) => { }, body: JSON.stringify({ "data": { - "status": 'read', - "reply": 'ok' + "status": 'read' } }), }).then(response => { diff --git a/web/src/i18n.js b/web/src/i18n.js index 4cff2222..ac8bf937 100644 --- a/web/src/i18n.js +++ b/web/src/i18n.js @@ -315,8 +315,10 @@ const resources = { 'Notification Message': 'Message', 'Notification Status': 'Status', 'Notification Mark As Read': 'Mark As Read', + 'Notification Mark As Acknowledged': 'Acknowledge', 'Notification Unread': 'Unread', 'Notification Read': 'Read', + 'Notification Acknowledged': 'Acknowledged', 'Notification Archive': 'Archive', 'Notification Delete': 'Delete', 'Notification Apply': 'Apply', @@ -1101,8 +1103,10 @@ const resources = { 'Notification Message': 'Nachricht', 'Notification Status': 'Status', 'Notification Mark As Read': 'Mark as read', + 'Notification Mark As Acknowledged': 'Bestätigen', 'Notification Unread': 'Ungelesene', 'Notification Read': 'Lesen', + 'Notification Acknowledged': 'Anerkannt', 'Notification Archive': 'Archiv', 'Notification Delete': 'Löschen', 'Notification Apply': 'Anwenden',