From: Marcin Haba Date: Wed, 20 Nov 2019 19:56:48 +0000 (+0100) Subject: baculum: Add auto-refreshing job tables X-Git-Tag: Release-9.6.0~66 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=25b07e40aad3292ae84dd2ee597f95bbe5a27251;p=thirdparty%2Fbacula.git baculum: Add auto-refreshing job tables --- diff --git a/gui/baculum/protected/Web/JavaScript/misc.js b/gui/baculum/protected/Web/JavaScript/misc.js index d73b25170..7263cc6ca 100644 --- a/gui/baculum/protected/Web/JavaScript/misc.js +++ b/gui/baculum/protected/Web/JavaScript/misc.js @@ -1050,6 +1050,61 @@ function sort_natural(a, b) { return a.localeCompare(b, undefined, {numeric: true}); } +function update_job_table(table_obj, new_data) { + var rows = table_obj.rows(); + var old_jobs = {}; + table_obj.data().toArray().forEach(function(job) { + old_jobs[job.jobid] = job; + }); + var new_jobs = {}; + new_data.forEach(function(job) { + new_jobs[job.jobid] = job; + }); + + var job_add_mod = {}; + for (var jobid in new_jobs) { + if (!old_jobs.hasOwnProperty(jobid) || new_jobs[jobid].jobstatus != old_jobs[jobid].jobstatus) { + job_add_mod[jobid] = new_jobs[jobid]; + } + } + var job_rm = {}; + for (var jobid in old_jobs) { + if (!new_jobs.hasOwnProperty(jobid)) { + job_rm[jobid] = old_jobs[jobid]; + } + } + + var rows_rm_idxs = []; + var rows_list = rows.toArray(); + var jobid; + for (var i = 0; i < rows_list[0].length; i++) { + row = rows_list[0][i]; + jobid = table_obj.row(row).data().jobid + if (job_add_mod.hasOwnProperty(jobid)) { + // update modified row + table_obj.row(row).data(job_add_mod[jobid]).draw(); + // remove modified jobs from table + delete job_add_mod[jobid]; + continue; + } + if (job_rm.hasOwnProperty(jobid)) { + // get rows to remove + rows_rm_idxs.push(row); + continue; + } + }; + + // remove old rows + if (rows_rm_idxs.length > 0) { + table_obj.rows(rows_rm_idxs).remove().draw(); + } + + // add new rows + for (var jobid in job_add_mod) { + table_obj.row.add(job_add_mod[jobid]).draw(); + } +} + $(function() { W3SideBar.init(); set_sbbr_compatibility(); diff --git a/gui/baculum/protected/Web/Layouts/Main.tpl b/gui/baculum/protected/Web/Layouts/Main.tpl index 9f58667b3..4617ccb5d 100644 --- a/gui/baculum/protected/Web/Layouts/Main.tpl +++ b/gui/baculum/protected/Web/Layouts/Main.tpl @@ -66,6 +66,7 @@ var last_callback_time = 0; var callback_time_offset = 0; var oData; var MonitorCalls = []; +var MonitorCallsInterval = []; $(function() { if (is_small) { W3SideBar.close(); @@ -110,6 +111,10 @@ $(function() { for (var i = 0; i < calls_len; i++) { MonitorCalls[i](); } + var calls_interval_len = MonitorCallsInterval.length; + for (var i = 0; i < calls_interval_len; i++) { + MonitorCallsInterval[i](); + } if (calls_len > 0) { Formatters.set_formatters(); } diff --git a/gui/baculum/protected/Web/Pages/ClientView.page b/gui/baculum/protected/Web/Pages/ClientView.page index b327b9a1f..8d8522ba2 100644 --- a/gui/baculum/protected/Web/Pages/ClientView.page +++ b/gui/baculum/protected/Web/Pages/ClientView.page @@ -569,19 +569,14 @@ var oJobForClientList = { job_list: 'job_for_client_list', job_list_body: 'job_for_client_list_body' }, - clientid: 0, data: [], table: null, - init: function(clientid) { - this.clientid = clientid; - this.prepare_data(); - this.set_table(); - }, - prepare_data: function() { - for (var i = 0; i < oData.jobs.length; i++) { - if (oData.jobs[i].clientid == this.clientid) { - this.data.push(oData.jobs[i]); - } + init: function() { + this.data = oData.jobs; + if (this.table) { + update_job_table(this.table, this.data); + } else { + this.set_table(); } }, set_table: function() { @@ -700,9 +695,13 @@ var oJobForClientList = { }); } }; -MonitorParams = {jobs: null}; +MonitorParams = { + jobs: { + client: ['<%=$this->getClientName()%>'] + } +}; $(function() { - MonitorCalls.push(function() { oJobForClientList.init(<%=$this->getClientId()%>); }); + MonitorCallsInterval.push(function() { oJobForClientList.init(); }); }); diff --git a/gui/baculum/protected/Web/Pages/Monitor.php b/gui/baculum/protected/Web/Pages/Monitor.php index da6d0e8cc..7cea73cc2 100644 --- a/gui/baculum/protected/Web/Pages/Monitor.php +++ b/gui/baculum/protected/Web/Pages/Monitor.php @@ -49,9 +49,16 @@ class Monitor extends BaculumWebPage { if (is_array($params) && key_exists('jobs', $params)) { $job_params = array('jobs'); $job_query = array(); - if (is_array($params['jobs']) && key_exists('name', $params['jobs']) && is_array($params['jobs']['name'])) { - for ($i = 0; $i < count($params['jobs']['name']); $i++) { - $job_query['name'] = $params['jobs']['name'][$i]; + if (is_array($params['jobs'])) { + if (key_exists('name', $params['jobs']) && is_array($params['jobs']['name'])) { + for ($i = 0; $i < count($params['jobs']['name']); $i++) { + $job_query['name'] = $params['jobs']['name'][$i]; + } + } + if (key_exists('client', $params['jobs']) && is_array($params['jobs']['client'])) { + for ($i = 0; $i < count($params['jobs']['client']); $i++) { + $job_query['client'] = $params['jobs']['client'][$i]; + } } } if ($this->Request->contains('use_limit') && $this->Request['use_limit'] == 1) {