From 4263bccbba28748395bac7a9616560d4f3e2578d Mon Sep 17 00:00:00 2001 From: Khanh Ngo Date: Sun, 15 Dec 2019 21:42:08 +0700 Subject: [PATCH] Format the history popup content --- powerdnsadmin/static/custom/js/custom.js | 22 +++++++++++++--------- powerdnsadmin/templates/dashboard.html | 2 +- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/powerdnsadmin/static/custom/js/custom.js b/powerdnsadmin/static/custom/js/custom.js index 1cf0664..81d73fb 100644 --- a/powerdnsadmin/static/custom/js/custom.js +++ b/powerdnsadmin/static/custom/js/custom.js @@ -241,26 +241,30 @@ function reload_domains(url) { // pretty JSON json_library = { - replacer: function(match, pIndent, pKey, pVal, pEnd) { + replacer: function (match, pIndent, pKey, pVal, pEnd) { var key = ''; var val = ''; var str = ''; var r = pIndent || ''; - if (pKey){ - r = r + key + pKey.replace(/[": ]/g, '') + ': '; + if (pKey) { + // r = r + key + pKey.replace(/[": ]/g, '') + ': '; + // Keep the quote in the key + r = r + key + pKey.replace(/":/, '"') + ': '; } - if (pVal){ + if (pVal) { r = r + (pVal[0] == '"' ? str : val) + pVal + ''; } return r + (pEnd || ''); }, - prettyPrint: function(obj) { + prettyPrint: function (obj) { obj = obj.replace(/u'/g, "\'").replace(/'/g, "\"").replace(/(False|None)/g, "\"$1\""); var jsonData = JSON.parse(obj); - var jsonLine = /^( *)("[\w]+": )?("[^"]*"|[\w.+-]*)?([,[{])?$/mg; - return JSON.stringify(jsonData, null, 3) + // var jsonLine = /^( *)("[\w]+": )?("[^"]*"|[\w.+-]*)?([,[{])?$/mg; + // The new regex to handle case value is an empty list [] or dict {} + var jsonLine = /^( *)("[\w]+": )?("[^"]*"|[\w.+-]*)?([,[{])?/mg; + return JSON.stringify(jsonData, null, 3) .replace(/&/g, '&').replace(/\\"/g, '"') .replace(//g, '>') .replace(jsonLine, json_library.replacer); - } - }; + } +}; diff --git a/powerdnsadmin/templates/dashboard.html b/powerdnsadmin/templates/dashboard.html index 733eace..295a3f2 100755 --- a/powerdnsadmin/templates/dashboard.html +++ b/powerdnsadmin/templates/dashboard.html @@ -107,7 +107,7 @@ {{ history.msg }} {{ history.created_on }} -