feat(minor): Show Processlist in System Consoleversion-14
@@ -20,5 +20,46 @@ frappe.ui.form.on('System Console', { | |||||
$btn.text(__('Execute')); | $btn.text(__('Execute')); | ||||
}); | }); | ||||
}); | }); | ||||
}, | |||||
show_processlist: function(frm) { | |||||
if (frm.doc.show_processlist) { | |||||
// keep refreshing every 5 seconds | |||||
frm.events.refresh_processlist(frm); | |||||
frm.processlist_interval = setInterval(() => frm.events.refresh_processlist(frm), 5000); | |||||
} else { | |||||
if (frm.processlist_interval) { | |||||
// end it | |||||
clearInterval(frm.processlist_interval); | |||||
} | |||||
} | |||||
}, | |||||
refresh_processlist: function(frm) { | |||||
let timestamp = new Date(); | |||||
frappe.call('frappe.desk.doctype.system_console.system_console.show_processlist').then(r => { | |||||
let rows = ''; | |||||
for (let row of r.message) { | |||||
rows += `<tr> | |||||
<td>${row.Id}</td> | |||||
<td>${row.Time}</td> | |||||
<td>${row.State}</td> | |||||
<td>${row.Info}</td> | |||||
<td>${row.Progress}</td> | |||||
</tr>` | |||||
} | |||||
frm.get_field('processlist').html(` | |||||
<p class='text-muted'>Requested on: ${timestamp}</p> | |||||
<table class='table-bordered' style='width: 100%'> | |||||
<thead><tr> | |||||
<th width='10%'>Id</ht> | |||||
<th width='10%'>Time</ht> | |||||
<th width='10%'>State</ht> | |||||
<th width='60%'>Info</ht> | |||||
<th width='10%'>Progress</ht> | |||||
</tr></thead> | |||||
<tbody>${rows}</thead>`); | |||||
}); | |||||
} | } | ||||
}); | }); |
@@ -17,9 +17,13 @@ | |||||
"editable_grid": 1, | "editable_grid": 1, | ||||
"engine": "InnoDB", | "engine": "InnoDB", | ||||
"field_order": [ | "field_order": [ | ||||
"execute_section", | |||||
"console", | "console", | ||||
"commit", | "commit", | ||||
"output" | |||||
"output", | |||||
"database_processes_section", | |||||
"show_processlist", | |||||
"processlist" | |||||
], | ], | ||||
"fields": [ | "fields": [ | ||||
{ | { | ||||
@@ -40,13 +44,34 @@ | |||||
"fieldname": "commit", | "fieldname": "commit", | ||||
"fieldtype": "Check", | "fieldtype": "Check", | ||||
"label": "Commit" | "label": "Commit" | ||||
}, | |||||
{ | |||||
"fieldname": "execute_section", | |||||
"fieldtype": "Section Break", | |||||
"label": "Execute" | |||||
}, | |||||
{ | |||||
"fieldname": "database_processes_section", | |||||
"fieldtype": "Section Break", | |||||
"label": "Database Processes" | |||||
}, | |||||
{ | |||||
"default": "0", | |||||
"fieldname": "show_processlist", | |||||
"fieldtype": "Check", | |||||
"label": "Show Processlist" | |||||
}, | |||||
{ | |||||
"fieldname": "processlist", | |||||
"fieldtype": "HTML", | |||||
"label": "processlist" | |||||
} | } | ||||
], | ], | ||||
"hide_toolbar": 1, | "hide_toolbar": 1, | ||||
"index_web_pages_for_search": 1, | "index_web_pages_for_search": 1, | ||||
"issingle": 1, | "issingle": 1, | ||||
"links": [], | "links": [], | ||||
"modified": "2020-08-21 14:44:35.296877", | |||||
"modified": "2021-09-09 13:10:14.237113", | |||||
"modified_by": "Administrator", | "modified_by": "Administrator", | ||||
"module": "Desk", | "module": "Desk", | ||||
"name": "System Console", | "name": "System Console", | ||||
@@ -65,4 +90,4 @@ | |||||
"sort_field": "modified", | "sort_field": "modified", | ||||
"sort_order": "DESC", | "sort_order": "DESC", | ||||
"track_changes": 1 | "track_changes": 1 | ||||
} | |||||
} |
@@ -33,4 +33,9 @@ class SystemConsole(Document): | |||||
def execute_code(doc): | def execute_code(doc): | ||||
console = frappe.get_doc(json.loads(doc)) | console = frappe.get_doc(json.loads(doc)) | ||||
console.run() | console.run() | ||||
return console.as_dict() | |||||
return console.as_dict() | |||||
@frappe.whitelist() | |||||
def show_processlist(): | |||||
frappe.only_for('System Manager') | |||||
return frappe.db.sql('show processlist', as_dict=1) |