From e4b9cffd1800d2bdc94d649832f6ef9caa4b0d4e Mon Sep 17 00:00:00 2001 From: "13621160019@163.com" <13621160019@163.com> Date: Wed, 28 Apr 2021 15:02:56 +0800 Subject: [PATCH] added last seen datetime to Gateway Setting in Admin UI --- admin/app/translations.js | 7 +++- admin/views/settings/gateway/gateway.html | 2 + .../settings/knowledgefile/knowledgefile.html | 7 +--- myems-api/core/gateway.py | 41 ++++++++----------- 4 files changed, 25 insertions(+), 32 deletions(-) diff --git a/admin/app/translations.js b/admin/app/translations.js index 93afe6ec..49d5fa42 100644 --- a/admin/app/translations.js +++ b/admin/app/translations.js @@ -544,6 +544,7 @@ function config($translateProvider) { GATEWAY: { GATEWAY: 'Gateway', TOKEN: 'Token', + LAST_SEEN_DATETIME: 'Last Seen Datetime', SELECT_GATEWAY: 'Select Gateway', ADD_GATEWAY: 'Add Gateway', EDIT_GATEWAY: 'Edit Gateway', @@ -1605,7 +1606,8 @@ function config($translateProvider) { }, GATEWAY: { GATEWAY: '网关', - TOKEN: 'Token', + TOKEN: '令牌', + LAST_SEEN_DATETIME: '最后在线时间', SELECT_GATEWAY: '选择网关', ADD_GATEWAY: '添加网关', EDIT_GATEWAY: '编辑网关', @@ -2655,7 +2657,8 @@ function config($translateProvider) { }, GATEWAY: { GATEWAY: 'Tor', - TOKEN: 'Zeichen', + TOKEN: 'Token', + LAST_SEEN_DATETIME: 'Zuletzt gesehen datetime', SELECT_GATEWAY: 'Wählen Sie ein Gateway', ADD_GATEWAY: 'Gateway hinzufügen', EDIT_GATEWAY: 'Gateway bearbeiten', diff --git a/admin/views/settings/gateway/gateway.html b/admin/views/settings/gateway/gateway.html index 7842bc4e..5ba5a4ed 100644 --- a/admin/views/settings/gateway/gateway.html +++ b/admin/views/settings/gateway/gateway.html @@ -14,6 +14,7 @@ {{'SETTING.ID' | translate}} {{'SETTING.NAME' | translate}} {{'GATEWAY.TOKEN' | translate}} + {{'GATEWAY.LAST_SEEN_DATETIME' | translate}} {{'SETTING.ACTION' | translate}} @@ -22,6 +23,7 @@ {{ gateway.id }} {{ gateway.name }} {{ gateway.token}} + {{ gateway.last_seen_datetime | date:'yyyy-MM-dd HH:mm:ss'}} {{'SETTING.EDIT' | translate}} {{'SETTING.DELETE' | translate}} diff --git a/admin/views/settings/knowledgefile/knowledgefile.html b/admin/views/settings/knowledgefile/knowledgefile.html index 627394d5..61321905 100644 --- a/admin/views/settings/knowledgefile/knowledgefile.html +++ b/admin/views/settings/knowledgefile/knowledgefile.html @@ -20,12 +20,9 @@ {{ knowledgefile.id }} - {{ knowledgefile.file_name }} - + {{ knowledgefile.file_name }} {{ knowledgefile.user_display_name }} - - {{ knowledgefile.upload_datetime | date:'yyyy-MM-dd HH:mm'}} + {{ knowledgefile.upload_datetime | date:'yyyy-MM-dd HH:mm'}} {{'KNOWLEDGEFILE.RESTORE' | translate}} diff --git a/myems-api/core/gateway.py b/myems-api/core/gateway.py index 5268930e..1cd28136 100644 --- a/myems-api/core/gateway.py +++ b/myems-api/core/gateway.py @@ -3,7 +3,7 @@ import simplejson as json import mysql.connector import config import uuid -from datetime import datetime +from datetime import datetime, timezone class GatewayCollection: @@ -18,7 +18,7 @@ class GatewayCollection: @staticmethod def on_get(req, resp): cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor() + cursor = cnx.cursor(dictionary=True) query = (" SELECT id, name, uuid, token, last_seen_datetime_utc " " FROM tbl_gateways " @@ -29,19 +29,14 @@ class GatewayCollection: cnx.disconnect() result = list() - now = datetime.utcnow().replace(second=0, microsecond=0, tzinfo=None) if rows is not None and len(rows) > 0: for row in rows: - last_seen_time = row[4] - if last_seen_time is not None and (now - last_seen_time).total_seconds() > 5 * 60: - status = "online" - else: - status = "offline" - meta_result = {"id": row[0], "name": row[1], "uuid": row[2], - "token": row[3], - "last_seen_datetime": row[4].timestamp() * 1000 if isinstance(row[4], - datetime) else None, - "status": status} + meta_result = {"id": row['id'], "name": row['name'], "uuid": row['uuid'], + "token": row['token'], + "last_seen_datetime": + row['last_seen_datetime_utc'].replace(tzinfo=timezone.utc).timestamp() * 1000 + if isinstance(row['last_seen_datetime_utc'], datetime) else None, + } result.append(meta_result) resp.body = json.dumps(result) @@ -105,7 +100,7 @@ class GatewayItem: description='API.INVALID_GATEWAY_ID') cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor() + cursor = cnx.cursor(dictionary=True) query = (" SELECT id, name, uuid, token, last_seen_datetime_utc " " FROM tbl_gateways " @@ -118,17 +113,13 @@ class GatewayItem: raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', description='API.GATEWAY_NOT_FOUND') - now = datetime.utcnow().replace(second=0, microsecond=0, tzinfo=None) - last_seen_time = row[4] - if last_seen_time is not None and (now - last_seen_time).total_seconds() > 5 * 60: - status = "online" - else: - status = "offline" - - result = {"id": row[0], "name": row[1], "uuid": row[2], - "token": row[3], - "last_seen_datetime": row[4].timestamp()*1000 if isinstance(row[4], datetime) else None, - "status": status} + result = {"id": row['id'], + "name": row['name'], + "uuid": row['uuid'], + "token": row['token'], + "last_seen_datetime": + row['last_seen_datetime_utc'].replace(tzinfo=timezone.utc).timestamp()*1000 + if isinstance(row['last_seen_datetime_utc'], datetime) else None} resp.body = json.dumps(result)