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 9130d083..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'):
+ 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 ca8223a8..c5de3b4b 100644
--- a/web/src/components/MyEMS/Notification/Notification.js
+++ b/web/src/components/MyEMS/Notification/Notification.js
@@ -128,7 +128,7 @@ const Notification = ({ setRedirect, setRedirectUrl, t }) => {
const subjectFormatter = (dataField, { url }) => (
- {dataField}
+ {dataField}
);
@@ -143,16 +143,16 @@ const Notification = ({ setRedirect, setRedirectUrl, t }) => {
let icon = '';
let text = '';
switch (status) {
+ case 'acknowledged':
+ color = 'success';
+ icon = 'envelope-open';
+ text = t('Notification Acknowledged');
+ break;
case 'read':
color = 'success';
icon = 'envelope-open';
text = t('Notification Read');
break;
- case 'unread':
- color = 'primary';
- icon = 'envelope';
- text = t('Notification Unread');
- break;
default:
color = 'primary';
icon = 'envelope';
@@ -175,9 +175,9 @@ const Notification = ({ setRedirect, setRedirectUrl, t }) => {
handleRead(id)}>{t('Notification Mark As Read')}
- console.log('Archive: ', id)}>{t('Notification Archive')}
+ handleAcknowledged(id)}>{t('Notification Mark As Acknowledged')}
- console.log('Delete: ', id)} className="text-danger">{t('Notification Delete')}
+ handledelete(id)} className="text-danger">{t('Notification Delete')}
);
@@ -260,8 +260,7 @@ const Notification = ({ setRedirect, setRedirectUrl, t }) => {
},
body: JSON.stringify({
"data": {
- "status": 'acknowledged',
- "reply": 'ok'
+ "status": 'read'
}
}),
}).then(response => {
@@ -283,6 +282,71 @@ const Notification = ({ setRedirect, setRedirectUrl, t }) => {
});
};
+ const handleAcknowledged = (id, ) => {
+ console.log('Mark As Acknowledged: ', id)
+ let isResponseOK = false;
+ fetch(APIBaseURL + '/webmessages/' + id, {
+ method: 'PUT',
+ headers: {
+ "Content-type": "application/json",
+ "User-UUID": getCookieValue('user_uuid'),
+ "Token": getCookieValue('token')
+ },
+ body: JSON.stringify({
+ "data": {
+ "status": 'acknowledged',
+ "reply": 'OK'
+ }
+ }),
+ }).then(response => {
+ if (response.ok) {
+ isResponseOK = true;
+ return null;
+ } else {
+ return response.json();
+ }
+ }).then(json => {
+ console.log(isResponseOK);
+ if (isResponseOK) {
+
+ } else {
+ toast.error(json.description)
+ }
+ }).catch(err => {
+ console.log(err);
+ });
+ };
+
+ const handledelete = (id, ) => {
+ console.log('Delete: ', id)
+ let isResponseOK = false;
+ fetch(APIBaseURL + '/webmessages/' + id, {
+ method: 'DELETE',
+ headers: {
+ "Content-type": "application/json",
+ "User-UUID": getCookieValue('user_uuid'),
+ "Token": getCookieValue('token')
+ },
+ body: null,
+ }).then(response => {
+ if (response.ok) {
+ isResponseOK = true;
+ return null;
+ } else {
+ return response.json();
+ }
+ }).then(json => {
+ console.log(isResponseOK);
+ if (isResponseOK) {
+
+ } else {
+ toast.error(json.description)
+ }
+ }).catch(err => {
+ console.log(err);
+ });
+ };
+
return (
@@ -294,7 +358,7 @@ const Notification = ({ setRedirect, setRedirectUrl, t }) => {
-
+