Neal Wilson 9 years ago
parent
commit
91f0647f85
1 changed files with 29 additions and 3 deletions
  1. 29
    3
      config/Windows/history.xml

+ 29
- 3
config/Windows/history.xml View File

@@ -1,17 +1,43 @@
1 1
 <window id="history">
2 2
     <layout type="vertical">
3
+		<layout type="horizontal">
4
+			<daterange id="dates" initial="6" /><!-- Last 7 Days -->
5
+			<stretch />
6
+		</layout>
3 7
         <sqlview id="table" />
4 8
     </layout>
5 9
     <program>
6 10
         <![CDATA[
7
-			var q = "SELECT time, machine, (SELECT name FROM items WHERE id = roasted_id) AS name, unroasted_total_quantity AS green, roasted_quantity AS roasted, ((unroasted_total_quantity - roasted_quantity) / unroasted_total_quantity * 100::numeric)::numeric(12,2) AS weight_loss, duration, annotation FROM roasting_log ORDER BY time DESC";
11
+			var dateSelect = findChildObject(this, 'dates');
12
+			var dateQuery = new QSqlQuery();
13
+			dateQuery.exec("SELECT time::date FROM roasting_log WHERE time = (SELECT min(time) FROM roasting_log) OR time = (SELECT max(time) FROM roasting_log) ORDER BY time ASC");
14
+			dateQuery.next();
15
+			var lifetimeStartDate = dateQuery.value(0);
16
+			var lifetimeEndDate;
17
+			if(dateQuery.next()) {
18
+				lifetimeEndDate = dateQuery.value(0);
19
+			} else {
20
+				lifetimeEndDate = lifetimeStartDate;
21
+			}
22
+			dateSelect.setLifetimeRange(lifetimeStartDate, lifetimeEndDate);
23
+			dateQuery.invalidate();
8 24
 			var table = findChildObject(this, 'table');
9
-			table.setQuery(q);
10
-			table.hideColumn(1);
11 25
 			table.openEntryRow.connect(function(arg) {
12 26
 				var details = createWindow("batchDetails");
13 27
 				details.loadData(table, arg);
14 28
 			});
29
+			function refresh() {
30
+				var dateRange = dateSelect.currentRange();
31
+				var startDate = "'"+dateRange[0]+"'";
32
+				var endDate = "'"+dateRange[dateRange.length - 1]+"'";
33
+				var q = "SELECT time, machine, (SELECT name FROM items WHERE id = roasted_id) AS name, unroasted_total_quantity AS green, roasted_quantity AS roasted, ((unroasted_total_quantity - roasted_quantity) / unroasted_total_quantity * 100::numeric)::numeric(12,2) AS weight_loss, duration, annotation FROM roasting_log WHERE time >= " + startDate + "::date AND time < " + endDate + "::date + interval '1 day' ORDER BY time DESC";
34
+				table.setQuery(q);
35
+				table.hideColumn(1);
36
+			}
37
+			dateSelect.rangeUpdated.connect(function() {
38
+				refresh();
39
+			});
40
+			refresh();
15 41
         ]]>
16 42
     </program>
17 43
 </window>

Loading…
Cancel
Save