Browse Source

Simplify scheduled batch filtering

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

+ 7
- 6
config/Windows/newbatch.xml View File

@@ -156,16 +156,17 @@
156 156
             filter.setText(QSettings.value("script/newbatch/filter", ""));
157 157
             filtervalue.setText(QSettings.value("script/newbatch/filtervalue", ""));
158 158
             var updateSchedule = function() {
159
+                var filterclause = "";
159 160
                 if(filter.text.length > 0) {
160
-                    var filterclause = "WHERE filters->>'key' = '" + filter.text + "'";
161
+                    filterclause = " AND data->'filters' @> "
162
+                    filterclause += "'[{\"key\":\"" + filter.text + '"';
161 163
                     if(filtervalue.text.length > 0) {
162
-                        filterclause += " AND filters->>'value' = '" + filtervalue.text + "'";
164
+                        filterclause += ',"value":"' + filtervalue.text + '"';
163 165
                     }
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");
166
+                    filterclause += "}]'";
168 167
                 }
168
+                var q = "SELECT id, (SELECT name FROM items WHERE id = (data#>>'{roasted}')::numeric), (data#>>'{green_weight}')::numeric FROM scheduled_roasts WHERE machine IS NULL" + filterclause;
169
+                batches.setQuery(q);
169 170
             };
170 171
             filter.editingFinished.connect(function() {
171 172
                 QSettings.setValue("script/newbatch/filter", filter.text);

Loading…
Cancel
Save