Browse Source

chore: update time format

JustSong 2 years ago
parent
commit
9307be249a

+ 5 - 0
common/constants.go

@@ -93,6 +93,11 @@ const (
 	SendEmailToOthersDisallowed = 2
 )
 
+const (
+	SaveMessageToDatabaseAllowed    = 1
+	SaveMessageToDatabaseDisallowed = 2
+)
+
 const (
 	MessageSendStatusUnknown = 0
 	MessageSendStatusPending = 1

+ 8 - 3
controller/user.go

@@ -635,6 +635,10 @@ func ManageUser(c *gin.Context) {
 		user.SendEmailToOthers = common.SendEmailToOthersAllowed
 	case "disallow_send_email_to_others":
 		user.SendEmailToOthers = common.SendEmailToOthersDisallowed
+	case "allow_save_message_to_database":
+		user.SaveMessageToDatabase = common.SaveMessageToDatabaseAllowed
+	case "disallow_save_message_to_database":
+		user.SaveMessageToDatabase = common.SaveMessageToDatabaseDisallowed
 	}
 
 	if err := user.Update(false); err != nil {
@@ -645,9 +649,10 @@ func ManageUser(c *gin.Context) {
 		return
 	}
 	clearUser := model.User{
-		Role:              user.Role,
-		Status:            user.Status,
-		SendEmailToOthers: user.SendEmailToOthers,
+		Role:                  user.Role,
+		Status:                user.Status,
+		SendEmailToOthers:     user.SendEmailToOthers,
+		SaveMessageToDatabase: user.SaveMessageToDatabase,
 	}
 	c.JSON(http.StatusOK, gin.H{
 		"success": true,

+ 3 - 5
web/src/components/MessagesTable.js

@@ -1,6 +1,6 @@
 import React, { useEffect, useState } from 'react';
 import { Button, Form, Label, Modal, Pagination, Table } from 'semantic-ui-react';
-import { API, openPage, showError, showSuccess, showWarning } from '../helpers';
+import { API, openPage, showError, showSuccess, showWarning, timestamp2string } from '../helpers';
 
 import { ITEMS_PER_PAGE } from '../constants';
 
@@ -70,13 +70,11 @@ function renderChannel(channel) {
 }
 
 function renderTimestamp(timestamp) {
-  const date = new Date(timestamp * 1000);
   return (
     <>
-      {date.getFullYear()}-{date.getMonth() + 1}-{date.getDate()}{' '}
-      {date.getHours()}:{date.getMinutes()}:{date.getSeconds()}
+      {timestamp2string(timestamp)}
     </>
-  );
+  )
 }
 
 function renderStatus(status) {

+ 38 - 0
web/src/helpers/utils.js

@@ -102,3 +102,41 @@ export function removeTrailingSlash(url) {
     return url;
   }
 }
+
+export function timestamp2string(timestamp) {
+  let date = new Date(timestamp * 1000);
+  let year = date.getFullYear().toString();
+  let month = (date.getMonth() + 1).toString();
+  let day = date.getDate().toString();
+  let hour = date.getHours().toString();
+  let minute = date.getMinutes().toString();
+  let second = date.getSeconds().toString();
+  if (month.length === 1) {
+    month = '0' + month;
+  }
+  if (day.length === 1) {
+    day = '0' + day;
+  }
+  if (hour.length === 1) {
+    hour = '0' + hour;
+  }
+  if (minute.length === 1) {
+    minute = '0' + minute;
+  }
+  if (second.length === 1) {
+    second = '0' + second;
+  }
+  return (
+    year +
+    '-' +
+    month +
+    '-' +
+    day +
+    ' ' +
+    hour +
+    ':' +
+    minute +
+    ':' +
+    second
+  );
+}

+ 2 - 3
web/src/pages/Home/index.js

@@ -1,6 +1,6 @@
 import React, { useContext, useEffect } from 'react';
 import { Card, Grid, Header, Segment } from 'semantic-ui-react';
-import { API, showError, showNotice } from '../../helpers';
+import { API, showError, showNotice, timestamp2string } from '../../helpers';
 import { StatusContext } from '../../context/Status';
 
 const Home = () => {
@@ -22,8 +22,7 @@ const Home = () => {
 
   const getStartTimeString = () => {
     const timestamp = statusState?.status?.start_time;
-    const date = new Date(timestamp * 1000);
-    return date.toLocaleString();
+    return timestamp2string(timestamp);
   };
 
   useEffect(() => {