Web: allow filtering jobs by their status

This is a very simple approach, where clicking on a job's status dot
toggles filtering by that status. There is no visual indication that this
filtering is active.

The Tabulator support for filtering from the headers is a bit buggy, see
https://github.com/olifolkerd/tabulator/issues/3745 -- I'm getting this
error even without `multiselect: true`.
This commit is contained in:
Sybren A. Stüvel 2022-05-16 15:02:38 +02:00
parent edce178c34
commit eb0bfe820b

View File

@ -60,6 +60,7 @@ export default {
}; };
return { return {
options: options, options: options,
filteredStatuses: new Set(),
}; };
}, },
mounted() { mounted() {
@ -78,7 +79,7 @@ export default {
}; };
this.tabulator = new Tabulator('#flamenco_job_list', this.options); this.tabulator = new Tabulator('#flamenco_job_list', this.options);
this.tabulator.on("rowClick", this.onRowClick); this.tabulator.on("rowClick", this.onRowClick);
this.tabulator.on("tableBuilt", this.fetchAllJobs); this.tabulator.on("tableBuilt", this._onTableBuilt);
}, },
watch: { watch: {
activeJobID(newJobID, oldJobID) { activeJobID(newJobID, oldJobID) {
@ -101,6 +102,10 @@ export default {
const tab = this.tabulator; const tab = this.tabulator;
tab.setSort(tab.getSorters()); // This triggers re-sorting. tab.setSort(tab.getSorters()); // This triggers re-sorting.
}, },
_onTableBuilt() {
this.tabulator.setFilter(this._filterByStatus);
this.fetchAllJobs();
},
fetchAllJobs() { fetchAllJobs() {
const jobsApi = new API.JobsApi(apiClient); const jobsApi = new API.JobsApi(apiClient);
const jobsQuery = {}; const jobsQuery = {};
@ -130,9 +135,29 @@ export default {
// store. There were some issues where navigating to another job would // store. There were some issues where navigating to another job would
// overwrite the old job's ID, and this prevents that. // overwrite the old job's ID, and this prevents that.
const rowData = plain(row.getData()); const rowData = plain(row.getData());
// Depending on which cell was clicked, take a different action.
const columnName = event.target.getAttribute("tabulator-field");
if (columnName == "status") {
this._toggleStatusFilter(rowData.status);
return;
}
this.$emit("tableRowClicked", rowData); this.$emit("tableRowClicked", rowData);
}, },
_toggleStatusFilter(status) {
if (!this.filteredStatuses.delete(status)) {
this.filteredStatuses.add(status);
}
this.tabulator.refreshFilter();
},
_filterByStatus(job) {
if (this.filteredStatuses.size) {
return this.filteredStatuses.has(job.status);
}
return true;
},
_reformatRow(jobID) { _reformatRow(jobID) {
// Use tab.rowManager.findRow() instead of `tab.getRow()` as the latter // Use tab.rowManager.findRow() instead of `tab.getRow()` as the latter
// logs a warning when the row cannot be found. // logs a warning when the row cannot be found.
@ -140,7 +165,7 @@ export default {
if (!row) return if (!row) return
if (row.reformat) row.reformat(); if (row.reformat) row.reformat();
else if (row.reinitialize) row.reinitialize(true); else if (row.reinitialize) row.reinitialize(true);
} },
} }
}; };
</script> </script>