Browse Source

Add filter search on roast schedule

Neal Wilson 6 years ago
parent
commit
fb698e92be
1 changed files with 33 additions and 2 deletions
  1. 33
    2
      config/Windows/newbatch.xml

+ 33
- 2
config/Windows/newbatch.xml View File

@@ -15,6 +15,13 @@
15 15
         <layout type="stack" id="pages">
16 16
             <page>
17 17
                 <layout type="vertical">
18
+                    <layout type="horizontal">
19
+                        <label>Filter:</label>
20
+                        <line id="filter" />
21
+                        <label>Value:</label>
22
+                        <line id="filtervalue" />
23
+                        <stretch />
24
+                    </layout>
18 25
                     <sqlview id="batches" />
19 26
                 </layout>
20 27
             </page>
@@ -144,7 +151,31 @@
144 151
             });
145 152
             tabs.setCurrentIndex(1);
146 153
             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");
154
+            var filter = findChildObject(this, 'filter');
155
+            var filtervalue = findChildObject(this, 'filtervalue');
156
+            filter.setText(QSettings.value("script/newbatch/filter", ""));
157
+            filtervalue.setText(QSettings.value("script/newbatch/filtervalue", ""));
158
+            var updateSchedule = function() {
159
+                if(filter.text.length > 0) {
160
+                    var filterclause = "WHERE filters->>'key' = '" + filter.text + "'";
161
+                    if(filtervalue.text.length > 0) {
162
+                        filterclause += " AND filters->>'value' = '" + filtervalue.text + "'";
163
+                    }
164
+                    var q = "WITH q AS (SELECT id, data, jsonb_array_elements(data#>'{filters}') AS filters FROM scheduled_roasts WHERE machine IS NULL) SELECT id, (SELECT name FROM items WHERE id = (data#>>'{roasted}')::numeric), (data#>>'{green_weight}')::numeric FROM q " + filterclause;
165
+                    batches.setQuery(q);
166
+                } else {
167
+                    batches.setQuery("SELECT id, (SELECT name FROM items WHERE id = (data#>>'{roasted}')::numeric), (data#>>'{green_weight}')::numeric FROM scheduled_roasts WHERE machine IS NULL");
168
+                }
169
+            };
170
+            filter.editingFinished.connect(function() {
171
+                QSettings.setValue("script/newbatch/filter", filter.text);
172
+                updateSchedule();
173
+            });
174
+            filtervalue.editingFinished.connect(function() {
175
+                QSettings.setValue("script/newbatch/filtervalue", filtervalue.text);
176
+                updateSchedule();
177
+            });
178
+            updateSchedule();
148 179
             batches.setHeaderData(0, TTR("batchWindow", "ID"));
149 180
             batches.setHeaderData(1, TTR("batchWindow", "Roasted Coffee"));
150 181
             batches.setHeaderData(2, TTR("batchWindow", "Green Weight"));
@@ -154,7 +185,7 @@
154 185
             batches.editTreiggers = 0;
155 186
             var snotifier = Application.subscribe("scheduledroastschange");
156 187
             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");
188
+                updateSchedule();
158 189
             });
159 190
             var unitBox = findChildObject(this, 'unit');
160 191
             unitBox.addItem("g");

Loading…
Cancel
Save