Browse Source

feat: added filtering of youtubeVideo's if they're in an importJob

Kristian Vos 2 years ago
parent
commit
5f81615696

+ 40 - 1
backend/logic/actions/youtube.js

@@ -248,7 +248,46 @@ export default {
 							modelName: "youtubeVideo",
 							blacklistedProperties: [],
 							specialProperties: {},
-							specialQueries: {}
+							specialQueries: {},
+							specialFilters: {
+								importJob: importJobId => [
+									{
+										$lookup: {
+											from: "importjobs",
+											let: { youtubeId: "$youtubeId" },
+											pipeline: [
+												{
+													$match: {
+														_id: mongoose.Types.ObjectId(importJobId)
+													}
+												},
+												{
+													$addFields: {
+														importJob: {
+															$in: ["$$youtubeId", "$response.successfulVideoIds"]
+														}
+													}
+												},
+												{
+													$project: {
+														importJob: 1,
+														_id: 0
+													}
+												}
+											],
+											as: "importJob"
+										}
+									},
+									{
+										$unwind: "$importJob"
+									},
+									{
+										$set: {
+											importJob: "$importJob.importJob"
+										}
+									}
+								]
+							}
 						},
 						this
 					)

+ 4 - 1
backend/logic/db/index.js

@@ -408,7 +408,7 @@ class _DBModule extends CoreClass {
 
 					// Adds the match stage to aggregation pipeline, which is responsible for filtering
 					(pipeline, next) => {
-						const { queries, operator, specialQueries } = payload;
+						const { queries, operator, specialQueries, specialFilters } = payload;
 
 						let queryError;
 						const newQueries = queries.flatMap(query => {
@@ -439,6 +439,9 @@ class _DBModule extends CoreClass {
 								newQuery[filter.property] = { $eq: Number(data) };
 							} else if (filterType === "boolean") {
 								newQuery[filter.property] = { $eq: !!data };
+							} else if (filterType === "special") {
+								pipeline.push(...specialFilters[filter.property](data));
+								newQuery[filter.property] = { $eq: true };
 							}
 
 							if (specialQueries[filter.property]) {

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

@@ -867,6 +867,10 @@ export default {
 				boolean: {
 					name: "boolean",
 					displayName: "Boolean"
+				},
+				special: {
+					name: "special",
+					displayName: "Special"
 				}
 			},
 			addFilterValue: null,

+ 25 - 1
frontend/src/pages/Admin/Songs/Import.vue

@@ -42,7 +42,8 @@
 							>YouTube URL
 							<info-icon
 								content="YouTube playlist or channel URLs may be provided"
-						/></label>
+							/>
+						</label>
 						<div class="control is-expanded">
 							<input
 								class="input"
@@ -118,6 +119,7 @@
 							<div class="row-options">
 								<button
 									class="button is-primary icon-with-button material-icons"
+									@click="openAdvancedTable(slotProps.item)"
 									:disabled="
 										slotProps.item.removed ||
 										slotProps.item.status !== 'success'
@@ -470,6 +472,28 @@ export default {
 		// });
 	},
 	methods: {
+		openAdvancedTable(importJob) {
+			const filter = {
+				appliedFilters: [
+					{
+						data: importJob._id,
+						filter: {
+							name: "importJob",
+							displayName: "Import%20job",
+							property: "importJob",
+							filterTypes: ["special"],
+							defaultFilterType: "special"
+						},
+						filterType: { name: "special", displayName: "Special" }
+					}
+				],
+				appliedFilterOperator: "or"
+			};
+			this.$router.push({
+				path: `/admin/youtube/videos`,
+				query: { filter: JSON.stringify(filter) }
+			});
+		},
 		submitCreateImport(stage) {
 			if (stage === 2) {
 				const playlistRegex = /[\\?&]list=([^&#]*)/;

+ 7 - 0
frontend/src/pages/Admin/YouTube/Videos.vue

@@ -274,6 +274,13 @@ export default {
 					property: "createdAt",
 					filterTypes: ["datetimeBefore", "datetimeAfter"],
 					defaultFilterType: "datetimeBefore"
+				},
+				{
+					name: "importJob",
+					displayName: "Import job",
+					property: "importJob",
+					filterTypes: ["special"],
+					defaultFilterType: "special"
 				}
 			],
 			events: {