Browse Source

feat(AdvancedTable): Datetime before and after filters

Owen Diffey 3 years ago
parent
commit
861302be01

+ 4 - 0
backend/logic/actions/dataRequests.js

@@ -50,6 +50,10 @@ export default {
 							);
 						} else if (filterType === "exact") {
 							newQuery[filter.property] = data.toString();
+						} else if (filterType === "datetimeBefore") {
+							newQuery[filter.property] = { $lte: new Date(data) };
+						} else if (filterType === "datetimeAfter") {
+							newQuery[filter.property] = { $gte: new Date(data) };
 						}
 						return newQuery;
 					});

+ 4 - 0
backend/logic/actions/news.js

@@ -86,6 +86,10 @@ export default {
 							);
 						} else if (filterType === "exact") {
 							newQuery[filter.property] = data.toString();
+						} else if (filterType === "datetimeBefore") {
+							newQuery[filter.property] = { $lte: new Date(data) };
+						} else if (filterType === "datetimeAfter") {
+							newQuery[filter.property] = { $gte: new Date(data) };
 						}
 						return newQuery;
 					});

+ 4 - 0
backend/logic/actions/punishments.js

@@ -57,6 +57,10 @@ export default {
 							);
 						} else if (filterType === "exact") {
 							newQuery[filter.property] = data.toString();
+						} else if (filterType === "datetimeBefore") {
+							newQuery[filter.property] = { $lte: new Date(data) };
+						} else if (filterType === "datetimeAfter") {
+							newQuery[filter.property] = { $gte: new Date(data) };
 						}
 						return newQuery;
 					});

+ 4 - 0
backend/logic/actions/reports.js

@@ -89,6 +89,10 @@ export default {
 							);
 						} else if (filterType === "exact") {
 							newQuery[filter.property] = data.toString();
+						} else if (filterType === "datetimeBefore") {
+							newQuery[filter.property] = { $lte: new Date(data) };
+						} else if (filterType === "datetimeAfter") {
+							newQuery[filter.property] = { $gte: new Date(data) };
 						}
 						return newQuery;
 					});

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

@@ -198,6 +198,10 @@ export default {
 							);
 						} else if (filterType === "exact") {
 							newQuery[filter.property] = data.toString();
+						} else if (filterType === "datetimeBefore") {
+							newQuery[filter.property] = { $lte: new Date(data) };
+						} else if (filterType === "datetimeAfter") {
+							newQuery[filter.property] = { $gte: new Date(data) };
 						}
 						return newQuery;
 					});

+ 4 - 0
backend/logic/playlists.js

@@ -899,6 +899,10 @@ class _PlaylistsModule extends CoreClass {
 								);
 							} else if (filterType === "exact") {
 								newQuery[filter.property] = data.toString();
+							} else if (filterType === "datetimeBefore") {
+								newQuery[filter.property] = { $lte: new Date(data) };
+							} else if (filterType === "datetimeAfter") {
+								newQuery[filter.property] = { $gte: new Date(data) };
 							}
 							return newQuery;
 						});

+ 4 - 0
backend/logic/songs.js

@@ -237,6 +237,10 @@ class _SongsModule extends CoreClass {
 								);
 							} else if (filterType === "exact") {
 								newQuery[filter.property] = data.toString();
+							} else if (filterType === "datetimeBefore") {
+								newQuery[filter.property] = { $lte: new Date(data) };
+							} else if (filterType === "datetimeAfter") {
+								newQuery[filter.property] = { $gte: new Date(data) };
 							}
 							return newQuery;
 						});

+ 4 - 0
backend/logic/stations.js

@@ -422,6 +422,10 @@ class _StationsModule extends CoreClass {
 								);
 							} else if (filterType === "exact") {
 								newQuery[filter.property] = data.toString();
+							} else if (filterType === "datetimeBefore") {
+								newQuery[filter.property] = { $lte: new Date(data) };
+							} else if (filterType === "datetimeAfter") {
+								newQuery[filter.property] = { $gte: new Date(data) };
 							}
 							return newQuery;
 						});

+ 20 - 0
frontend/src/components/AdvancedTable.vue

@@ -113,6 +113,18 @@
 								</div>
 								<p class="control is-expanded">
 									<input
+										v-if="
+											filter.filterType &&
+											filter.filterType.startsWith(
+												'datetime'
+											)
+										"
+										v-model="filter.data"
+										class="input"
+										type="datetime-local"
+									/>
+									<input
+										v-else
 										v-model="filter.data"
 										class="input"
 										type="text"
@@ -705,6 +717,14 @@ export default {
 				regex: {
 					name: "regex",
 					displayName: "Regex"
+				},
+				datetimeBefore: {
+					name: "datetimeBefore",
+					displayName: "Before"
+				},
+				datetimeAfter: {
+					name: "datetimeAfter",
+					displayName: "After"
 				}
 			},
 			bulkPopup: {

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

@@ -244,8 +244,8 @@ export default {
 					name: "createdAt",
 					displayName: "Created At",
 					property: "createdAt",
-					filterTypes: ["contains", "exact", "regex"],
-					defaultFilterType: "contains"
+					filterTypes: ["datetimeBefore", "datetimeAfter"],
+					defaultFilterType: "datetimeBefore"
 				},
 				{
 					name: "createdFor",

+ 2 - 2
frontend/src/pages/Admin/tabs/Reports.vue

@@ -229,8 +229,8 @@ export default {
 					name: "createdAt",
 					displayName: "Created At",
 					property: "createdAt",
-					filterTypes: ["contains", "exact", "regex"],
-					defaultFilterType: "contains"
+					filterTypes: ["datetimeBefore", "datetimeAfter"],
+					defaultFilterType: "datetimeBefore"
 				}
 			]
 		};

+ 4 - 4
frontend/src/pages/Admin/tabs/Songs.vue

@@ -497,8 +497,8 @@ export default {
 					name: "requestedAt",
 					displayName: "Requested At",
 					property: "requestedAt",
-					filterTypes: ["contains", "exact", "regex"],
-					defaultFilterType: "contains"
+					filterTypes: ["datetimeBefore", "datetimeAfter"],
+					defaultFilterType: "datetimeBefore"
 				},
 				{
 					name: "verifiedBy",
@@ -511,8 +511,8 @@ export default {
 					name: "verifiedAt",
 					displayName: "Verified At",
 					property: "verifiedAt",
-					filterTypes: ["contains", "exact", "regex"],
-					defaultFilterType: "contains"
+					filterTypes: ["datetimeBefore", "datetimeAfter"],
+					defaultFilterType: "datetimeBefore"
 				},
 				{
 					name: "status",