Forráskód Böngészése

feat(AdvancedTable): Select from array filter type

Owen Diffey 2 éve
szülő
commit
60f90101eb

+ 6 - 0
backend/logic/actions/users.js

@@ -186,6 +186,7 @@ export default {
 		async.waterfall(
 			[
 				next => {
+					let queryError;
 					const newQueries = queries.map(query => {
 						const { data, filter, filterType } = query;
 						const newQuery = {};
@@ -208,9 +209,14 @@ export default {
 							newQuery[filter.property] = { $gt: data };
 						} else if (filterType === "numberEquals") {
 							newQuery[filter.property] = { $eq: data };
+						} else if (filterType === "array") {
+							if (filter.property === "role" && !["admin", "default"].includes(data))
+								queryError = `${data} is not a valid ${filter.property} value`;
+							else newQuery[filter.property] = data.toString();
 						}
 						return newQuery;
 					});
+					if (queryError) next(queryError);
 
 					const queryObject = {};
 					if (newQueries.length > 0) {

+ 6 - 0
backend/logic/playlists.js

@@ -887,6 +887,7 @@ class _PlaylistsModule extends CoreClass {
 					next => {
 						const { queries, operator } = payload;
 
+						let queryError;
 						const newQueries = queries.map(query => {
 							const { data, filter, filterType } = query;
 							const newQuery = {};
@@ -909,9 +910,14 @@ class _PlaylistsModule extends CoreClass {
 								newQuery[filter.property] = { $gt: data };
 							} else if (filterType === "numberEquals") {
 								newQuery[filter.property] = { $eq: data };
+							} else if (filterType === "array") {
+								if (filter.property === "privacy" && !["public", "private"].includes(data))
+									queryError = `${data} is not a valid ${filter.property} value`;
+								else newQuery[filter.property] = data.toString();
 							}
 							return newQuery;
 						});
+						if (queryError) next(queryError);
 
 						const queryObject = {};
 						if (newQueries.length > 0) {

+ 6 - 0
backend/logic/songs.js

@@ -225,6 +225,7 @@ class _SongsModule extends CoreClass {
 					next => {
 						const { queries, operator } = payload;
 
+						let queryError;
 						const newQueries = queries.map(query => {
 							const { data, filter, filterType } = query;
 							const newQuery = {};
@@ -247,9 +248,14 @@ class _SongsModule extends CoreClass {
 								newQuery[filter.property] = { $gt: data };
 							} else if (filterType === "numberEquals") {
 								newQuery[filter.property] = { $eq: data };
+							} else if (filterType === "array") {
+								if (filter.property === "status" && !["verified", "unverified"].includes(data))
+									queryError = `${data} is not a valid ${filter.property} value`;
+								else newQuery[filter.property] = data.toString();
 							}
 							return newQuery;
 						});
+						if (queryError) next(queryError);
 
 						const queryObject = {};
 						if (newQueries.length > 0) {

+ 11 - 0
backend/logic/stations.js

@@ -410,6 +410,7 @@ class _StationsModule extends CoreClass {
 					next => {
 						const { queries, operator } = payload;
 
+						let queryError;
 						const newQueries = queries.map(query => {
 							const { data, filter, filterType } = query;
 							const newQuery = {};
@@ -432,9 +433,19 @@ class _StationsModule extends CoreClass {
 								newQuery[filter.property] = { $gt: data };
 							} else if (filterType === "numberEquals") {
 								newQuery[filter.property] = { $eq: data };
+							} else if (filterType === "array") {
+								if (
+									(filter.property === "type" && !["official", "community"].includes(data)) ||
+									(filter.property === "privacy" &&
+										!["public", "unlisted", "private"].includes(data)) ||
+									(filter.property === "playMode" && !["random", "sequential"].includes(data))
+								)
+									queryError = `${data} is not a valid ${filter.property} value`;
+								else newQuery[filter.property] = data.toString();
 							}
 							return newQuery;
 						});
+						if (queryError) next(queryError);
 
 						const queryObject = {};
 						if (newQueries.length > 0) {

+ 26 - 1
frontend/src/components/AdvancedTable.vue

@@ -111,7 +111,28 @@
 										</option>
 									</select>
 								</div>
-								<p class="control is-expanded">
+								<div
+									v-if="
+										filter.filterType.name &&
+										filter.filterType.name === 'array'
+									"
+									class="control is-expanded select"
+								>
+									<select
+										v-model="filter.data"
+										:disabled="!filter.filterType"
+									>
+										<option
+											v-for="filterValue in filter.filter
+												.filterValues"
+											:key="filterValue"
+											:value="filterValue"
+										>
+											{{ filterValue }}
+										</option>
+									</select>
+								</div>
+								<p v-else class="control is-expanded">
 									<input
 										v-if="
 											filter.filterType.name &&
@@ -753,6 +774,10 @@ export default {
 				numberEquals: {
 					name: "numberEquals",
 					displayName: "Equals"
+				},
+				array: {
+					name: "array",
+					displayName: "Is"
 				}
 			},
 			bulkPopup: {

+ 3 - 2
frontend/src/pages/Admin/tabs/Playlists.vue

@@ -230,8 +230,9 @@ export default {
 					name: "privacy",
 					displayName: "Privacy",
 					property: "privacy",
-					filterTypes: ["contains", "exact", "regex"],
-					defaultFilterType: "contains"
+					filterTypes: ["array", "regex"],
+					defaultFilterType: "array",
+					filterValues: ["public", "private"]
 				},
 				{
 					name: "createdBy",

+ 3 - 2
frontend/src/pages/Admin/tabs/Songs.vue

@@ -518,8 +518,9 @@ export default {
 					name: "status",
 					displayName: "Status",
 					property: "status",
-					filterTypes: ["contains", "exact", "regex"],
-					defaultFilterType: "exact"
+					filterTypes: ["array", "regex"],
+					defaultFilterType: "array",
+					filterValues: ["verified", "unverified"]
 				},
 				{
 					name: "likes",

+ 9 - 6
frontend/src/pages/Admin/tabs/Stations.vue

@@ -269,15 +269,17 @@ export default {
 					name: "type",
 					displayName: "Type",
 					property: "type",
-					filterTypes: ["contains", "exact", "regex"],
-					defaultFilterType: "contains"
+					filterTypes: ["array", "regex"],
+					defaultFilterType: "array",
+					filterValues: ["official", "community"]
 				},
 				{
 					name: "privacy",
 					displayName: "Privacy",
 					property: "privacy",
-					filterTypes: ["contains", "exact", "regex"],
-					defaultFilterType: "contains"
+					filterTypes: ["array", "regex"],
+					defaultFilterType: "array",
+					filterValues: ["public", "unlisted", "private"]
 				},
 				{
 					name: "owner",
@@ -290,8 +292,9 @@ export default {
 					name: "playMode",
 					displayName: "Play Mode",
 					property: "playMode",
-					filterTypes: ["contains", "exact", "regex"],
-					defaultFilterType: "contains"
+					filterTypes: ["array", "regex"],
+					defaultFilterType: "array",
+					filterValues: ["random", "sequential"]
 				},
 				{
 					name: "theme",

+ 3 - 2
frontend/src/pages/Admin/tabs/Users.vue

@@ -377,8 +377,9 @@ export default {
 						name: "role",
 						displayName: "Role",
 						property: "role",
-						filterTypes: ["contains", "exact", "regex"],
-						defaultFilterType: "contains"
+						filterTypes: ["array", "regex"],
+						defaultFilterType: "array",
+						filterValues: ["admin", "default"]
 					},
 					{
 						name: "emailAddress",