From 812f5490dcdb15796497cdd91a13004585292c84 Mon Sep 17 00:00:00 2001 From: ibuler Date: Mon, 30 Jan 2023 15:19:05 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=20applet=20=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/static/js/jumpserver.js | 226 ++++---------------------- apps/templates/_head_css_js.html | 9 +- apps/terminal/api/applet/applet.py | 12 +- apps/terminal/models/applet/applet.py | 2 +- 4 files changed, 43 insertions(+), 206 deletions(-) diff --git a/apps/static/js/jumpserver.js b/apps/static/js/jumpserver.js index b6bb6c6a4..d78cccb74 100644 --- a/apps/static/js/jumpserver.js +++ b/apps/static/js/jumpserver.js @@ -126,7 +126,9 @@ function csrfSafeMethod(method) { function setAjaxCSRFToken() { let prefix = getCookie('SESSION_COOKIE_NAME_PREFIX'); - if (!prefix || [`""`, `''`].indexOf(prefix) > -1) { prefix = ''; } + if (!prefix || [`""`, `''`].indexOf(prefix) > -1) { + prefix = ''; + } var csrftoken = getCookie(`${prefix}csrftoken`); var sessionid = getCookie(`${prefix}sessionid`); @@ -267,7 +269,7 @@ function requestApi(props) { flash_message = false; } var dataBody = props.body || props.data; - if (typeof(dataBody) === "object") { + if (typeof (dataBody) === "object") { dataBody = JSON.stringify(dataBody) } var headers = props.headers || {} @@ -431,13 +433,13 @@ function parseTableFilter(value) { return {} } var valuesArray = value.split(':'); - for (var i=0; i"; - html += li - } - }); - html = "" - } else { - html = error.responseText - } - if (props.method === 'POST') { - $('#success_created').html(''); - $('#success_created_detail').html(''); - $('#created_failed').html(gettext("Import failed")); - $('#created_failed_detail').html(html); - } else { - $('#success_updated').html(''); - $('#success_updated_detail').html(''); - $('#updated_failed').html(gettext("Update failed")); - $('#updated_failed_detail').html(html); - } - } - }) -} - - function htmlEscape(d) { return typeof d === 'string' ? d.replace(//g, '>').replace(/"/g, '"') : @@ -1329,7 +1160,6 @@ function readFile(ref) { } - function select2AjaxInit(option) { /* { @@ -1385,9 +1215,11 @@ function usersSelect2Init(selector, url, disabledData) { if (!url) { url = '/api/v1/users/users/' } + function displayFormat(v) { - return v.name + '(' + v.username +')'; + return v.name + '(' + v.username + ')'; } + var option = { url: url, selector: selector, @@ -1402,9 +1234,11 @@ function nodesSelect2Init(selector, url, disabledData) { if (!url) { url = '/api/v1/assets/nodes/' } + function displayFormat(v) { return v.full_value; } + var option = { url: url, selector: selector, @@ -1419,12 +1253,11 @@ function showCeleryTaskLog(taskId) { window.open(url, '', 'width=900,height=600') } -function getUserLang(){ +function getUserLang() { let userLangEN = document.cookie.indexOf('django_language=en'); - if (userLangEN === -1){ + if (userLangEN === -1) { return 'zh-CN' - } - else{ + } else { return 'en-US' } } @@ -1460,8 +1293,7 @@ function initDateRangePicker(selector, options) { }; if (getUserLang() === 'zh-CN') { defaultOption.locale = zhLocale; - } - else{ + } else { // en-US defaultOption.locale = enLocale; } @@ -1470,7 +1302,9 @@ function initDateRangePicker(selector, options) { } function reloadPage() { - setTimeout( function () {window.location.reload();}, 300); + setTimeout(function () { + window.location.reload(); + }, 300); } function isEmptyObject(obj) { @@ -1494,7 +1328,7 @@ function getStatusIcon(status, mapping, title) { default: 'navy' }; if (!mapping) { - mapping = defaultMapping; + mapping = defaultMapping; } var name = mapping[status] || mapping['default']; var icon = icons[name]; @@ -1564,10 +1398,10 @@ function encryptPassword(password) { function randomString(length) { - const characters ='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; + const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; let result = ''; const charactersLength = characters.length; - for ( let i = 0; i < length; i++ ) { + for (let i = 0; i < length; i++) { result += characters.charAt(Math.floor(Math.random() * charactersLength)); } @@ -1577,11 +1411,11 @@ function randomString(length) { function testEncrypt() { const radio = [] const len2 = [] - for (let i=1;i<4096;i++) { + for (let i = 1; i < 4096; i++) { const password = randomString(i) const cipher = encryptPassword(password) len2.push([password.length, cipher.length]) - radio.push(cipher.length/password.length) + radio.push(cipher.length / password.length) } return radio } diff --git a/apps/templates/_head_css_js.html b/apps/templates/_head_css_js.html index 43378f21d..d61ee20e8 100644 --- a/apps/templates/_head_css_js.html +++ b/apps/templates/_head_css_js.html @@ -7,14 +7,13 @@ - + + - - - +