From 5db704f7931c0defa4072153a181605e420f4c1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=80=81=E5=B9=BF?= Date: Mon, 22 Jul 2019 17:15:24 +0800 Subject: [PATCH] Bugfix (#3007) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [Bugfix] 修复英文时间时期的bug * [bugfix] 修复session时间日期的问题 * [Bugfix] 修改时间日志格式化错误 * [Update] 修改函数名称 * [Update] 修改函数顺序 * [Update] 注释部分迁移文件内容 --- .../templates/assets/_asset_user_list.html | 4 +- apps/assets/templates/assets/asset_list.html | 2 +- apps/ops/templates/ops/adhoc_history.html | 2 +- apps/ops/templates/ops/task_adhoc.html | 2 +- apps/ops/templates/ops/task_history.html | 2 +- ...8_0025_squashed_0009_auto_20180903_1132.py | 6 +-- apps/static/js/jumpserver.js | 42 +++++++++++-------- apps/templates/_foot_js.html | 2 +- .../templates/terminal/command_list.html | 2 +- .../templates/terminal/session_list.html | 10 ++--- 10 files changed, 41 insertions(+), 33 deletions(-) diff --git a/apps/assets/templates/assets/_asset_user_list.html b/apps/assets/templates/assets/_asset_user_list.html index ca752e58d..d39c57fb3 100644 --- a/apps/assets/templates/assets/_asset_user_list.html +++ b/apps/assets/templates/assets/_asset_user_list.html @@ -51,7 +51,7 @@ function initAssetUserTable() { } else { innerHtml = '' } - var dateManual = formatDateAsCN(cellData.datetime); + var dateManual = toSafeLocalDateStr(cellData.datetime); var dataContent = testDatetime + dateManual; innerHtml = "" + innerHtml + ""; $(td).html(innerHtml); @@ -59,7 +59,7 @@ function initAssetUserTable() { }, { targets: 6, createdCell: function (td, cellData) { - var data = formatDateAsCN(cellData); + var data = toSafeLocalDateStr(cellData); $(td).html(data); }, }, diff --git a/apps/assets/templates/assets/asset_list.html b/apps/assets/templates/assets/asset_list.html index 4750a4f95..0f67a7709 100644 --- a/apps/assets/templates/assets/asset_list.html +++ b/apps/assets/templates/assets/asset_list.html @@ -159,7 +159,7 @@ function initTable() { } else { innerHtml = '' } - var dateManual = formatDateAsCN(cellData.datetime); + var dateManual = toSafeLocalDateStr(cellData.datetime); var dataContent = testDatetime + dateManual; innerHtml = "" + innerHtml + ""; $(td).html(innerHtml); diff --git a/apps/ops/templates/ops/adhoc_history.html b/apps/ops/templates/ops/adhoc_history.html index ef83e1c4f..11c52ae44 100644 --- a/apps/ops/templates/ops/adhoc_history.html +++ b/apps/ops/templates/ops/adhoc_history.html @@ -82,7 +82,7 @@ function initTable() { select: [], columnDefs: [ {targets: 1, createdCell: function (td, cellData, rowData) { - var d = formatDateAsCN(cellData); + var d = toSafeLocalDateStr(cellData); $(td).html(d); }}, {targets: 2, createdCell: function (td, cellData) { diff --git a/apps/ops/templates/ops/task_adhoc.html b/apps/ops/templates/ops/task_adhoc.html index 8dd29637f..a31397c14 100644 --- a/apps/ops/templates/ops/task_adhoc.html +++ b/apps/ops/templates/ops/task_adhoc.html @@ -109,7 +109,7 @@ $(document).ready(function () { } }}, {targets: 6, createdCell: function (td, cellData) { - var d = formatDateAsCN(cellData); + var d = toSafeLocalDateStr(cellData); $(td).html(d) }}, {targets: 7, createdCell: function (td, cellData, rowData) { diff --git a/apps/ops/templates/ops/task_history.html b/apps/ops/templates/ops/task_history.html index 054b0bf5e..d9c5a0dfa 100644 --- a/apps/ops/templates/ops/task_history.html +++ b/apps/ops/templates/ops/task_history.html @@ -88,7 +88,7 @@ function initTable() { select: [], columnDefs: [ {targets: 1, createdCell: function (td, cellData, rowData) { - var d = formatDateAsCN(cellData); + var d = toSafeLocalDateStr(cellData); $(td).html(d); }}, diff --git a/apps/perms/migrations/0002_auto_20171228_0025_squashed_0009_auto_20180903_1132.py b/apps/perms/migrations/0002_auto_20171228_0025_squashed_0009_auto_20180903_1132.py index 15915a453..cc0a646e5 100644 --- a/apps/perms/migrations/0002_auto_20171228_0025_squashed_0009_auto_20180903_1132.py +++ b/apps/perms/migrations/0002_auto_20171228_0025_squashed_0009_auto_20180903_1132.py @@ -103,9 +103,9 @@ class Migration(migrations.Migration): name='nodes', field=models.ManyToManyField(blank=True, related_name='granted_by_permissions', to='assets.Node', verbose_name='Nodes'), ), - migrations.RunPython( - code=migrate_node_permissions, - ), + # migrations.RunPython( + # code=migrate_node_permissions, + # ), migrations.RunPython( code=migrate_system_assets_relation, ), diff --git a/apps/static/js/jumpserver.js b/apps/static/js/jumpserver.js index 5931e1b7c..e11a154a7 100644 --- a/apps/static/js/jumpserver.js +++ b/apps/static/js/jumpserver.js @@ -1091,7 +1091,7 @@ function objectAttrsIsList(obj, attrs) { function objectAttrsIsDatetime(obj, attrs) { attrs.forEach(function (attr) { - obj[attr] = formatDateAsCN(obj[attr]); + obj[attr] = toSafeDateISOStr(obj[attr]); }) } @@ -1105,29 +1105,37 @@ function objectAttrsIsBool(obj, attrs) { }) } -function cleanDate(d) { - if (typeof d === 'number'){ - return d - } - if (typeof d === "string") { - d = d.replaceAll('-', '/') - } - for (var i=0; i<2; i++) { - if (isNaN(Date.parse(d))) { - d = d.split('+')[0].trimRight(); - } else { - return d +function cleanDateStr(d) { + for (var i=0;i<3;i++) { + if (!isNaN(Date.parse(d))){ + return d; + } + if (!isNaN(Number(d))) { + return d; + } + switch (i) { + case 0: + d = d.replaceAll('-', '/'); + break; + case 1: + d = d.split('+')[0].trimRight(); + break; } } - return '' + return null; } function safeDate(s) { - s = cleanDate(s); + s = cleanDateStr(s); return new Date(s) } -function formatDateAsCN(d) { +function toSafeDateISOStr(s) { + var d = safeDate(s); + return d.toISOString(); +} + +function toSafeLocalDateStr(d) { var date = safeDate(d); var date_s = date.toLocaleString(navigator.language, {hour12: false}); return date_s.split("/").join('-') @@ -1149,7 +1157,7 @@ function getTimeUnits(u) { "m": "分", "s": "秒", }; - if (navigator.language || "zh-CN") { + if (navigator.language === "zh-CN") { return units[u] } return u diff --git a/apps/templates/_foot_js.html b/apps/templates/_foot_js.html index 8dbfc0f70..4c3a99da3 100644 --- a/apps/templates/_foot_js.html +++ b/apps/templates/_foot_js.html @@ -7,7 +7,7 @@ - +