added last seen datetime to Gateway Setting in Admin UI

pull/39/MERGE
13621160019@163.com 2021-04-28 15:02:56 +08:00
parent f73936a452
commit e4b9cffd18
4 changed files with 25 additions and 32 deletions

View File

@ -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',

View File

@ -14,6 +14,7 @@
<th class="text-center">{{'SETTING.ID' | translate}}</th>
<th class="text-center">{{'SETTING.NAME' | translate}}</th>
<th class="text-center">{{'GATEWAY.TOKEN' | translate}}</th>
<th class="text-center">{{'GATEWAY.LAST_SEEN_DATETIME' | translate}}</th>
<th class="text-center">{{'SETTING.ACTION' | translate}}</th>
</tr>
</thead>
@ -22,6 +23,7 @@
<td class="text-center">{{ gateway.id }}</td>
<td class="text-center">{{ gateway.name }}</td>
<td class="text-center">{{ gateway.token}}</td>
<td class="text-center">{{ gateway.last_seen_datetime | date:'yyyy-MM-dd HH:mm:ss'}}</td>
<td class="text-center">
<a class="btn btn-primary btn-rounded btn-xs" ng-click="editGateway(gateway)" >{{'SETTING.EDIT' | translate}}</a>
<a ng-click="deleteGateway(gateway)" class="btn btn-danger btn-rounded btn-xs" >{{'SETTING.DELETE' | translate}}</a>

View File

@ -20,12 +20,9 @@
<tbody>
<tr ng-repeat="knowledgefile in knowledgefiles">
<td class="text-center">{{ knowledgefile.id }}</td>
<td class="text-center"><a href="./upload/{{knowledgefile.uuid}}"
download="{{knowledgefile.file_name}}">{{ knowledgefile.file_name }}</a>
</td>
<td class="text-center"><a href="./upload/{{knowledgefile.uuid}}" download="{{knowledgefile.file_name}}">{{ knowledgefile.file_name }}</a></td>
<td class="text-center">{{ knowledgefile.user_display_name }}</td>
<td class="text-center">
{{ knowledgefile.upload_datetime | date:'yyyy-MM-dd HH:mm'}}</td>
<td class="text-center">{{ knowledgefile.upload_datetime | date:'yyyy-MM-dd HH:mm'}}</td>
<td class="text-center">
<a ng-click="restoreKnowledgeFile(knowledgefile)"
class="btn btn-danger btn-rounded btn-xs">{{'KNOWLEDGEFILE.RESTORE' | translate}}</a>

View File

@ -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)