Browse Source

refactor(AdvancedTable): changes to applying filters

Kristian Vos 2 years ago
parent
commit
9eb6f0e7a1
2 changed files with 17 additions and 12 deletions
  1. 4 2
      backend/logic/songs.js
  2. 13 10
      frontend/src/components/AdvancedTable.vue

+ 4 - 2
backend/logic/songs.js

@@ -238,8 +238,10 @@ class _SongsModule extends CoreClass {
 			});
 
 			const queryObject = {};
-			if (operator === "and") queryObject.$and = newQueries;
-			else queryObject.$or = newQueries;
+			if (newQueries.length > 0) {
+				if (operator === "and") queryObject.$and = newQueries;
+				else if (operator === "or") queryObject.$or = newQueries;
+			}
 
 			async.waterfall(
 				[

+ 13 - 10
frontend/src/components/AdvancedTable.vue

@@ -76,7 +76,6 @@
 											class="input"
 											type="text"
 											placeholder="Search value"
-											@keyup.enter="getData()"
 											:disabled="!query.filterType"
 										/>
 									</p>
@@ -139,7 +138,7 @@
 								<div class="control is-expanded">
 									<button
 										class="button is-info"
-										@click="getData()"
+										@click="applyFilterAndGetData()"
 									>
 										<i
 											class="
@@ -159,7 +158,7 @@
 								<div class="control is-expanded">
 									<button
 										class="button is-info"
-										@click="getData()"
+										@click="applyFilterAndGetData()"
 									>
 										<i
 											class="
@@ -553,7 +552,9 @@ export default {
 				};
 			},
 			advancedQuery: [],
+			appliedFilters: [],
 			queryOperator: "or",
+			appliedFilterOperator: "or",
 			queryOperators: [
 				{
 					name: "or",
@@ -663,8 +664,8 @@ export default {
 				this.pageSize,
 				this.properties,
 				this.sort,
-				this.advancedQuery,
-				this.queryOperator,
+				this.appliedFilters,
+				this.appliedFilterOperator,
 				res => {
 					console.log(111, res);
 					if (res.status === "success") {
@@ -782,11 +783,6 @@ export default {
 		removeQueryItem(index) {
 			this.advancedQuery.splice(index, 1);
 		},
-		resetQuery() {
-			this.advancedQuery = [];
-			this.queryOperator = "or";
-			this.getData();
-		},
 		columnResizingMouseDown(column, event) {
 			this.resizing.resizing = true;
 			this.resizing.resizingColumn = column;
@@ -879,6 +875,13 @@ export default {
 		resetBulkActionsPosition() {
 			this.bulkPopup.top = document.body.clientHeight - 56;
 			this.bulkPopup.left = document.body.clientWidth / 2 - 200;
+		},
+		applyFilterAndGetData() {
+			this.appliedFilters = JSON.parse(
+				JSON.stringify(this.advancedQuery)
+			);
+			this.appliedFilterOperator = this.queryOperator;
+			this.getData();
 		}
 	}
 };