Browse Source

feat: added songId column/filter/property to youtube videos admin table/page

Kristian Vos 2 years ago
parent
commit
cb7aed37fe
2 changed files with 59 additions and 1 deletions
  1. 39 1
      backend/logic/actions/youtube.js
  2. 20 0
      frontend/src/pages/Admin/YouTube/Videos.vue

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

@@ -273,7 +273,45 @@ export default {
 							operator,
 							modelName: "youtubeVideo",
 							blacklistedProperties: [],
-							specialProperties: {},
+							specialProperties: {
+								songId: [
+									// Fetch songs from songs collection with a matching youtubeId
+									{
+										$lookup: {
+											from: "songs",
+											localField: "youtubeId",
+											foreignField: "youtubeId",
+											as: "song"
+										}
+									},
+									// Turn the array of songs returned in the last step into one object, since only one song should have been returned maximum
+									{
+										$unwind: {
+											path: "$song",
+											preserveNullAndEmptyArrays: true
+										}
+									},
+									// Add new field songId, which grabs the song object's _id and tries turning it into a string
+									{
+										$addFields: {
+											songId: {
+												$convert: {
+													input: "$song._id",
+													to: "string",
+													onError: "",
+													onNull: ""
+												}
+											}
+										}
+									},
+									// Cleanup, don't return the song object for any further steps
+									{
+										$project: {
+											song: 0
+										}
+									}
+								]
+							},
 							specialQueries: {},
 							specialFilters: {
 								importJob: importJobId => [

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

@@ -88,6 +88,14 @@ const columns = ref([
 		sortProperty: "createdAt",
 		defaultWidth: 200,
 		defaultVisibility: "hidden"
+	},
+	{
+		name: "songId",
+		displayName: "Song ID",
+		properties: ["songId"],
+		sortProperty: "songId",
+		defaultWidth: 220,
+		defaultVisibility: "hidden"
 	}
 ]);
 const filters = ref([
@@ -145,6 +153,13 @@ const filters = ref([
 		property: "importJob",
 		filterTypes: ["special"],
 		defaultFilterType: "special"
+	},
+	{
+		name: "songId",
+		displayName: "Song ID",
+		property: "songId",
+		filterTypes: ["contains", "exact", "regex"],
+		defaultFilterType: "contains"
 	}
 ]);
 const events = ref({
@@ -355,6 +370,11 @@ const confirmAction = ({ message, action, params }) => {
 					getDateFormatted(slotProps.item.createdAt)
 				}}</span>
 			</template>
+			<template #column-songId="slotProps">
+				<span :title="slotProps.item.songId">{{
+					slotProps.item.songId
+				}}</span>
+			</template>
 			<template #bulk-actions="slotProps">
 				<div class="bulk-actions">
 					<i