[pve-devel] [PATCH manager 6 1/2] manager6: web-syslog: add date span selection

Thomas Lamprecht t.lamprecht at proxmox.com
Tue Mar 15 10:55:46 CET 2016


This is the ExtJS 6 version from commit
db2dd0e4390005aa551239d0a6516539b5fa200a

Same code as there.
A issue with the date picker which can be triggered by scrolling up
and then selecting a date will be fixed in ExtJS 6.0.2 (not yet
released), a workaround is in the next patch.

Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---
 www/manager6/node/Config.js   |  3 +-
 www/manager6/panel/LogView.js | 79 ++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 76 insertions(+), 6 deletions(-)

diff --git a/www/manager6/node/Config.js b/www/manager6/node/Config.js
index 9aafc7c..49a23c6 100644
--- a/www/manager6/node/Config.js
+++ b/www/manager6/node/Config.js
@@ -160,7 +160,8 @@ Ext.define('PVE.node.Config', {
 		    title: 'Syslog',
 		    itemId: 'syslog',
 		    xtype: 'pveLogView',
-		    url: "/api2/extjs/nodes/" + nodename + "/syslog"
+		    url: "/api2/extjs/nodes/" + nodename + "/syslog",
+		    log_select_timespan: 1
 		}
 	    );
 	}
diff --git a/www/manager6/panel/LogView.js b/www/manager6/panel/LogView.js
index 825d7a2..5022a62 100644
--- a/www/manager6/panel/LogView.js
+++ b/www/manager6/panel/LogView.js
@@ -73,12 +73,20 @@ Ext.define('PVE.panel.LogView', {
     doAttemptLoad: function(start) {
         var me = this;
 
+	var req_params = {
+	    start: start,
+	    limit: me.pageSize
+	};
+
+	if (me.log_select_timespan) {
+	    // always show log until the end of the selected day
+	    req_params.until = Ext.Date.format(me.until_date, 'Y-m-d') + ' 23:59:59';
+	    req_params.since = Ext.Date.format(me.since_date, 'Y-m-d');
+	}
+
 	PVE.Utils.API2Request({
 	    url: me.url,
-	    params: {
-		start: start,
-		limit: me.pageSize
-	    },
+	    params: req_params,
 	    method: 'GET',
 	    success: function(response) {
 		PVE.Utils.setErrorMask(me, false);
@@ -106,7 +114,7 @@ Ext.define('PVE.panel.LogView', {
 		var msg = response.htmlStatus;
 		PVE.Utils.setErrorMask(me, msg);
 	    }
-	});			      
+	});
     },
 
     attemptLoad: function(start) {
@@ -169,6 +177,11 @@ Ext.define('PVE.panel.LogView', {
 	    throw "no url specified";
 	}
 
+       // show logs from today back to 3 days ago per default
+       me.until_date = new Date();
+       me.since_date = new Date();
+       me.since_date.setDate(me.until_date.getDate() - 3);
+
 	me.dataCmp = Ext.create('Ext.Component', {
 	    style: 'font:normal 11px tahoma, arial, verdana, sans-serif;' +
 		'line-height: ' + me.lineHeight.toString() + 'px; white-space: pre;'
@@ -199,6 +212,62 @@ Ext.define('PVE.panel.LogView', {
 	    }
 	});
 
+	if (me.log_select_timespan) {
+	    me.tbar = ['->','Since: ',
+		       {
+			   xtype: 'datefield',
+			   maxValue: me.until_date,
+			   value: me.since_date,
+			   name: 'since_date',
+			   format: 'Y-m-d',
+			   listeners: {
+			       select: function(field, date) {
+				   me.since_date_selected = date;
+				   var until_field = field.up().down('field[name=until_date]');
+				   if (date > until_field.getValue()) {
+				       until_field.setValue(date);
+				   }
+			       }
+			   }
+		       },
+		       'Until: ',
+		       {
+			   xtype: 'datefield',
+			   maxValue: me.until_date,
+			   value: me.until_date,
+			   name: 'until_date',
+			   format: 'Y-m-d',
+			   listeners: {
+			       select: function(field, date) {
+				   var since_field = field.up().down('field[name=since_date]');
+				   if (date < since_field.getValue()) {
+				       since_field.setValue(date);
+				   }
+			       }
+			   }
+		       },
+		       {
+			   xtype: 'button',
+			   text: 'Update',
+			   handler: function() {
+			       var until_field = me.down('field[name=until_date]');
+			       var since_field = me.down('field[name=since_date]');
+			       if (until_field.getValue() < since_field.getValue()) {
+				   Ext.Msg.alert('Error',
+						 'Since date must be less equal than Until date.');
+				   until_field.setValue(me.until_date);
+				   since_field.setValue(me.since_date);
+			       } else {
+				   me.until_date = until_field.getValue();
+				   me.since_date = since_field.getValue();
+				   me.requestUpdate();
+			       }
+			   }
+		       }
+		      ];
+	}
+
+
 	me.callParent();
     }
 });
-- 
2.1.4





More information about the pve-devel mailing list