Bladeren bron

Add roast schedule lookup to new batch window

Neal Wilson 7 jaren geleden
bovenliggende
commit
84943d33ef
1 gewijzigde bestanden met toevoegingen van 216 en 98 verwijderingen
  1. 216
    98
      config/Windows/newbatch.xml

+ 216
- 98
config/Windows/newbatch.xml Bestand weergeven

@@ -5,111 +5,129 @@
5 5
     <menu name="Batch">
6 6
         <item id="new" shortcut="Ctrl+N">New Batch...</item>
7 7
     </menu>
8
-    <layout type="horizontal">
9
-        <splitter type="horizontal" id="splitter">
10
-            <widget id="required">
8
+    <layout type="vertical">
9
+        <layout type="horizontal">
10
+            <label>Scheduled Batch ID:</label>
11
+            <line id="search" />
12
+            <stretch />
13
+        </layout>
14
+        <tabbar id="tabs" />
15
+        <layout type="stack" id="pages">
16
+            <page>
11 17
                 <layout type="vertical">
12
-                    <layout type="horizontal">
13
-                        <label>Machine:</label>
14
-                        <line id="machine" writable="false" />
15
-                        <label>Unit:</label>
16
-                        <sqldrop id="unit" />
17
-                        <stretch />
18
-                    </layout>
19
-                    <layout type="horizontal">
20
-                        <label>Roasted Coffee:</label>
21
-                        <sqldrop data="0" display="1" showdata="true" id="roasted">
22
-                            <null />
23
-                            <query>SELECT id, name FROM items WHERE category = 'Coffee: Roasted' AND id IN (SELECT item FROM current_items) ORDER BY name</query>
24
-                        </sqldrop>
25
-                        <stretch />
26
-                    </layout>
27
-                    <label>Green Coffee:</label>
28
-                    <sqltablearray columns="3" id="greens">
29
-                        <column name="Coffee" delegate="sql" showdata="true" null="true" nulltext="Delete" nulldata="delete" data="0" display="1">SELECT id, name FROM coffees WHERE quantity &lt;&gt; 0 ORDER BY name</column>
30
-                        <column name="Weight" delegate="numeric" />
31
-                        <column name="Remaining" />
32
-                    </sqltablearray>
33
-                    <layout type="horizontal">
34
-                        <label>Green Weight:</label>
35
-                        <line id="green" writable="false">0.0</line>
36
-                    </layout>
37
-                    <layout type="horizontal">
38
-                        <button name="Load Profile" type="push" id="load" />
39
-                        <button name="No Profile" type="push" id="noprofile" />
40
-                    </layout>
41
-                    <layout type="horizontal">
42
-                        <label>Time:</label>
43
-                        <line id="time" writable="false" />
44
-                        <label>Duration:</label>
45
-                        <line id="duration" writable="false" />
46
-                    </layout>
47
-                    <layout type="horizontal">
48
-                        <label>Roasted Weight:</label>
49
-                        <line id="roast" validator="numeric">0.0</line>
50
-                        <label>Weight Loss:</label>
51
-                        <line id="wloss" writable="false" />
52
-                        <button type="check" id="approval" name="Approved" />
53
-                        <stretch />
54
-                    </layout>
55
-                    <layout type="horizontal">
56
-                        <label>Annotation:</label>
57
-                        <textarea id="annotation" />
58
-                    </layout>
59
-                    <layout type="horizontal">
60
-                        <button name="Submit" id="submit" type="push" />
61
-                        <button name="Save log as target profile" type="check" id="target" />
62
-                    </layout>
18
+                    <sqlview id="batches" />
63 19
                 </layout>
64
-            </widget>
65
-            <widget>
20
+            </page>
21
+            <page>
66 22
                 <layout type="vertical">
67
-                    <label>Connected Scales</label>
68
-                    <layout type="vertical" id="scales" />
69
-                    <label>Expected Weight Loss</label>
70
-                    <line id="lossspec" writable="false" />
71
-                    <label>Expected Roasted Weight</label>
72
-                    <layout type="horizontal">
73
-                        <label>Min:</label>
74
-                        <line id="minroastweight" writable="false" />
75
-                    </layout>
76
-                    <layout type="horizontal">
77
-                        <label>Expected:</label>
78
-                        <line id="expectedroastweight" writable="false" />
79
-                    </layout>
80
-                    <layout type="horizontal">
81
-                        <label>Max:</label>
82
-                        <line id="maxroastweight" writable="false" />
83
-                    </layout>
84
-                    <label>Degree of Roast</label>
85
-                    <label>Whole Bean:</label>
86
-                    <roastcoloredit id="wholecolor" />
87
-                    <label id="wholespec">-</label>
88
-                    <label>Ground:</label>
89
-                    <roastcoloredit id="groundcolor" />
90
-                    <label id="groundspec">-</label>
91
-                    <label>Specification Details</label>
92
-                    <textarea id="specnotes" />
93
-                    <layout type="horizontal">
94
-                        <label>File ID:</label>
95
-                        <line id="filenofield" writable="false" />
96
-                    </layout>
97
-                    <stretch />
23
+                    <splitter type="horizontal" id="splitter">
24
+                        <widget id="required">
25
+                            <layout type="vertical">
26
+                                <layout type="horizontal">
27
+                                    <label>Machine:</label>
28
+                                    <line id="machine" writable="false" />
29
+                                    <label>Unit:</label>
30
+                                    <sqldrop id="unit" />
31
+                                    <stretch />
32
+                                </layout>
33
+                                <layout type="horizontal">
34
+                                    <label>Roasted Coffee:</label>
35
+                                    <sqldrop data="0" display="1" showdata="true" id="roasted">
36
+                                        <null />
37
+                                        <query>SELECT id, name FROM items WHERE category = 'Coffee: Roasted' AND id IN (SELECT item FROM current_items) ORDER BY name</query>
38
+                                    </sqldrop>
39
+                                    <stretch />
40
+                                </layout>
41
+                                <label>Green Coffee:</label>
42
+                                <sqltablearray columns="3" id="greens">
43
+                                    <column name="Coffee" delegate="sql" showdata="true" null="true" nulltext="Delete" nulldata="delete" data="0" display="1">SELECT id, name FROM coffees WHERE quantity &lt;&gt; 0 ORDER BY name</column>
44
+                                    <column name="Weight" delegate="numeric" />
45
+                                    <column name="Remaining" />
46
+                                </sqltablearray>
47
+                                <layout type="horizontal">
48
+                                    <label>Green Weight:</label>
49
+                                    <line id="green" writable="false">0.0</line>
50
+                                </layout>
51
+                                <layout type="horizontal">
52
+                                    <button name="Load Profile" type="push" id="load" />
53
+                                    <button name="No Profile" type="push" id="noprofile" />
54
+                                </layout>
55
+                                <layout type="horizontal">
56
+                                    <label>Time:</label>
57
+                                    <line id="time" writable="false" />
58
+                                    <label>Duration:</label>
59
+                                    <line id="duration" writable="false" />
60
+                                </layout>
61
+                                <layout type="horizontal">
62
+                                    <label>Roasted Weight:</label>
63
+                                    <line id="roast" validator="numeric">0.0</line>
64
+                                    <label>Weight Loss:</label>
65
+                                    <line id="wloss" writable="false" />
66
+                                    <button type="check" id="approval" name="Approved" />
67
+                                    <stretch />
68
+                                </layout>
69
+                                <layout type="horizontal">
70
+                                    <label>Annotation:</label>
71
+                                    <textarea id="annotation" />
72
+                                </layout>
73
+                                <layout type="horizontal">
74
+                                    <button name="Submit" id="submit" type="push" />
75
+                                    <button name="Save log as target profile" type="check" id="target" />
76
+                                </layout>
77
+                            </layout>
78
+                        </widget>
79
+                        <widget>
80
+                            <layout type="vertical">
81
+                                <label>Connected Scales</label>
82
+                                <layout type="vertical" id="scales" />
83
+                                <label>Expected Weight Loss</label>
84
+                                <line id="lossspec" writable="false" />
85
+                                <label>Expected Roasted Weight</label>
86
+                                <layout type="horizontal">
87
+                                    <label>Min:</label>
88
+                                    <line id="minroastweight" writable="false" />
89
+                                </layout>
90
+                                <layout type="horizontal">
91
+                                    <label>Expected:</label>
92
+                                    <line id="expectedroastweight" writable="false" />
93
+                                </layout>
94
+                                <layout type="horizontal">
95
+                                    <label>Max:</label>
96
+                                    <line id="maxroastweight" writable="false" />
97
+                                </layout>
98
+                                <label>Degree of Roast</label>
99
+                                <label>Whole Bean:</label>
100
+                                <roastcoloredit id="wholecolor" />
101
+                                <label id="wholespec">-</label>
102
+                                <label>Ground:</label>
103
+                                <roastcoloredit id="groundcolor" />
104
+                                <label id="groundspec">-</label>
105
+                                <label>Specification Details</label>
106
+                                <textarea id="specnotes" />
107
+                                <layout type="horizontal">
108
+                                    <label>File ID:</label>
109
+                                    <line id="filenofield" writable="false" />
110
+                                </layout>
111
+                                <stretch />
112
+                            </layout>
113
+                        </widget>
114
+                        <widget id="tagcontainer" ignoreSizePolicy="true">
115
+                            <layout type="vertical">
116
+                                <webview id="batchTag" />
117
+                                <layout type="horizontal">
118
+                                    <printerselector id="printerlist" />
119
+                                    <button name="Print" id="printbutton" type="push" />
120
+                                </layout>
121
+                            </layout>
122
+                        </widget>
123
+                    </splitter>
98 124
                 </layout>
99
-            </widget>
100
-            <widget id="tagcontainer" ignoreSizePolicy="true">
101
-                <layout type="vertical">
102
-                    <webview id="batchTag" />
103
-                    <layout type="horizontal">
104
-                        <printerselector id="printerlist" />
105
-                        <button name="Print" id="printbutton" type="push" />
106
-                    </layout>
107
-                </layout>
108
-            </widget>
109
-        </splitter>
125
+            </page>
126
+        </layout>
110 127
     </layout>
111 128
     <program>
112 129
         <![CDATA[
130
+            var scheduledID = 0;
113 131
             var window = this;
114 132
             var splitter = findChildObject(this, 'splitter');
115 133
             window.aboutToClose.connect(function() {
@@ -117,6 +135,27 @@
117 135
             });
118 136
             splitter.setCollapsible(0, false);
119 137
             splitter.restoreState("script/newbatch/splitter");
138
+            var tabs = findChildObject(this, 'tabs');
139
+            tabs.addTab(TTR("batchWindow", "Schedule"));
140
+            tabs.addTab(TTR("batchWindow", "Batch"));
141
+            var pages = findChildObject(this, 'pages');
142
+            tabs.currentChanged.connect(function(index) {
143
+                pages.setCurrentIndex(index);
144
+            });
145
+            tabs.setCurrentIndex(1);
146
+            var batches = findChildObject(this, 'batches');
147
+            batches.setQuery("SELECT id, (SELECT name FROM items WHERE id = (data#>>'{roasted}')::numeric), (data#>>'{green_weight}')::numeric FROM scheduled_roasts WHERE machine IS NULL");
148
+            batches.setHeaderData(0, TTR("batchWindow", "ID"));
149
+            batches.setHeaderData(1, TTR("batchWindow", "Roasted Coffee"));
150
+            batches.setHeaderData(2, TTR("batchWindow", "Green Weight"));
151
+            batches.alternatingRowColors = true;
152
+            batches.selectionMode = 1;
153
+            batches.selectionBehavior = 1;
154
+            batches.editTreiggers = 0;
155
+            var snotifier = Application.subscribe("scheduledroastschange");
156
+            snotifier.notify.connect(function() {
157
+                batches.setQuery("SELECT id, (SELECT name FROM items WHERE id = (data#>>'{roasted}')::numeric), (data#>>'{green_weight}')::numeric FROM scheduled_roasts WHERE machine IS NULL");
158
+            });
120 159
             var unitBox = findChildObject(this, 'unit');
121 160
             unitBox.addItem("g");
122 161
             unitBox.addItem("Kg");
@@ -459,6 +498,14 @@
459 498
             }
460 499
             var duration = findChildObject(this, 'duration');
461 500
             var timefield = findChildObject(this, 'time');
501
+            var markTaken = function(id) {
502
+                var query = new QSqlQuery();
503
+                query.prepare("UPDATE scheduled_roasts SET machine = :mid WHERE id = :id");
504
+                query.bind(":mid", selectedRoasterID);
505
+                query.bind(":id", scheduledID);
506
+                query.exec();
507
+                query = query.invalidate();
508
+            }
462 509
             profilebutton.clicked.connect(function() {
463 510
                 var proceed = false;
464 511
                 if(validateCapacity()) {
@@ -476,6 +523,9 @@
476 523
                 }
477 524
             });
478 525
             var doLoadProfile = function() {
526
+                if(scheduledID > 0) {
527
+                    markTaken();
528
+                }
479 529
                 batch.windowModified = true;
480 530
                 currentBatchInfo = batch;
481 531
                 query = new QSqlQuery();
@@ -567,6 +617,9 @@
567 617
                 currentBatchInfo = batch;
568 618
                 navigationwindow.loggingWindow.raise();
569 619
                 navigationwindow.loggingWindow.activateWindow();
620
+                if(scheduledID > 0) {
621
+                    markTaken();
622
+                }
570 623
             }
571 624
             var submitbutton = findChildObject(this, 'submit');
572 625
             var notes = findChildObject(this, 'annotation');
@@ -695,6 +748,14 @@
695 748
                     query.bind(":item", roasted.currentData());
696 749
                     query.exec();
697 750
                 }
751
+                if(scheduledID > 0) {
752
+                    query.prepare("UPDATE scheduled_roasts SET machine = :mid, time = :time WHERE id = :id");
753
+                    query.bind(":mid", selectedRoasterID);
754
+                    query.bind(":time", timefield.text);
755
+                    query.bind(":id", scheduledID);
756
+                    query.exec();
757
+                }
758
+                
698 759
                 query = query.invalidate();
699 760
                 batch.windowModified = false;
700 761
                 batch.close();
@@ -794,6 +855,63 @@
794 855
             printbutton.clicked.connect(function() {
795 856
                 batchTag.print(printers.currentText);
796 857
             });
858
+            var loadBatch = function(id) {
859
+                var query = new QSqlQuery();
860
+                query.prepare("SELECT data FROM scheduled_roasts WHERE id = :id");
861
+                query.bind(":id", id);
862
+                query.exec();
863
+                if(query.next()) {
864
+                    scheduledID = id;
865
+                    tabs.setCurrentIndex(1);
866
+                    var d = JSON.parse(query.value(0));
867
+                    if(d.roasted) {
868
+                        roasted.currentIndex = roasted.findData(d.roasted);
869
+                    }
870
+                    if(d.greens) {
871
+                        query.prepare("SELECT name FROM items WHERE id = :id");
872
+                        for(var i = 0; i < d.greens.length; i++) {
873
+                            query.bind(":id", d.greens[i].id);
874
+                            query.exec();
875
+                            if(query.next()) {
876
+                                table.setData(i, 0, query.value(0), 0);
877
+                                table.setData(i, 0, d.greens[i].id, 32);
878
+                                switch(unitBox.currentIndex) {
879
+                                    case 0:
880
+                                        table.setData(i, 1, convertFromPounds(d.greens[i].weight, "g"), 0);
881
+                                        break;
882
+                                    case 1:
883
+                                        table.setData(i, 1, convertFromPounds(d.greens[i].weight, "Kg"), 0);
884
+                                        break;
885
+                                    case 2:
886
+                                        table.setData(i, 1, convertFromPounds(d.greens[i].weight, "oz"), 0);
887
+                                        break;
888
+                                    default:
889
+                                        table.setData(i, 1, d.greens[i].weight, 0);
890
+                                        break;
891
+                                }
892
+                            }
893
+                        }
894
+                    }
895
+                } else {
896
+                    displayInfo(TTR("batchWindow", "Search Failed"),
897
+                                TTR("batchWindow", "Scheduled batch ID not found."));
898
+                }
899
+                query = query.invalidate();
900
+                drawTag();
901
+            };
902
+            batches.selectEntry.connect(function(id) {
903
+                loadBatch(id);
904
+            });
905
+            var search = findChildObject(this, 'search');
906
+            search.returnPressed.connect(function() {
907
+                if(search.text.length == 0) {
908
+                    return;
909
+                }
910
+                if(Number(search.text)) {
911
+                    loadBatch(Number(search.text));
912
+                }
913
+                search.text = "";
914
+            });
797 915
         ]]>
798 916
     </program>
799 917
 </window>

Laden…
Annuleren
Opslaan