Format the history popup content

This commit is contained in:
Khanh Ngo 2019-12-15 21:42:08 +07:00
parent 5ac58d5503
commit 4263bccbba
No known key found for this signature in database
GPG Key ID: A945965CD6351844
2 changed files with 14 additions and 10 deletions

View File

@ -241,26 +241,30 @@ function reload_domains(url) {
// pretty JSON // pretty JSON
json_library = { json_library = {
replacer: function(match, pIndent, pKey, pVal, pEnd) { replacer: function (match, pIndent, pKey, pVal, pEnd) {
var key = '<span class=json-key>'; var key = '<span class=json-key>';
var val = '<span class=json-value>'; var val = '<span class=json-value>';
var str = '<span class=json-string>'; var str = '<span class=json-string>';
var r = pIndent || ''; var r = pIndent || '';
if (pKey){ if (pKey) {
r = r + key + pKey.replace(/[": ]/g, '') + '</span>: '; // r = r + key + pKey.replace(/[": ]/g, '') + '</span>: ';
// Keep the quote in the key
r = r + key + pKey.replace(/":/, '"') + '</span>: ';
} }
if (pVal){ if (pVal) {
r = r + (pVal[0] == '"' ? str : val) + pVal + '</span>'; r = r + (pVal[0] == '"' ? str : val) + pVal + '</span>';
} }
return r + (pEnd || ''); return r + (pEnd || '');
}, },
prettyPrint: function(obj) { prettyPrint: function (obj) {
obj = obj.replace(/u'/g, "\'").replace(/'/g, "\"").replace(/(False|None)/g, "\"$1\""); obj = obj.replace(/u'/g, "\'").replace(/'/g, "\"").replace(/(False|None)/g, "\"$1\"");
var jsonData = JSON.parse(obj); var jsonData = JSON.parse(obj);
var jsonLine = /^( *)("[\w]+": )?("[^"]*"|[\w.+-]*)?([,[{])?$/mg; // var jsonLine = /^( *)("[\w]+": )?("[^"]*"|[\w.+-]*)?([,[{])?$/mg;
return JSON.stringify(jsonData, null, 3) // 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, '&amp;').replace(/\\"/g, '&quot;') .replace(/&/g, '&amp;').replace(/\\"/g, '&quot;')
.replace(/</g, '&lt;').replace(/>/g, '&gt;') .replace(/</g, '&lt;').replace(/>/g, '&gt;')
.replace(jsonLine, json_library.replacer); .replace(jsonLine, json_library.replacer);
} }
}; };

View File

@ -107,7 +107,7 @@
<td>{{ history.msg }}</td> <td>{{ history.msg }}</td>
<td>{{ history.created_on }}</td> <td>{{ history.created_on }}</td>
<td width="6%"> <td width="6%">
<button type="button" class="btn btn-flat btn-primary history-info-button" value='{{ history.detail|replace("[]","None") }}'> <button type="button" class="btn btn-flat btn-primary history-info-button" value='{{ history.detail }}'>
Info&nbsp;<i class="fa fa-info"></i> Info&nbsp;<i class="fa fa-info"></i>
</button> </button>
</td> </td>