Explorar o código

refactor: added tags to songs admin table

Kristian Vos %!s(int64=2) %!d(string=hai) anos
pai
achega
d43753c7e2

+ 37 - 1
backend/logic/actions/songs.js

@@ -1770,5 +1770,41 @@ export default {
 				}
 			}
 		);
-	})
+	}),
+
+	/**
+	 * Gets a list of all tags
+	 *
+	 * @param session
+	 * @param cb
+	 */
+	 getTags: isAdminRequired(function getModule(session, cb) {
+		async.waterfall(
+			[
+				next => {
+					SongsModule.runJob("GET_TAGS", this)
+						.then(res => {
+							next(null, res.tags);
+						})
+						.catch(next);
+				}
+			],
+			async (err, tags) => {
+				if (err && err !== true) {
+					err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
+					this.log("ERROR", "GET_TAGS", `User ${session.userId} failed to get tags. '${err}'`);
+					cb({ status: "error", message: err });
+				} else {
+					this.log("SUCCESS", "GET_TAGS", `User ${session.userId} has successfully got the tags.`);
+					cb({
+						status: "success",
+						message: "Successfully got tags.",
+						data: {
+							items: tags
+						}
+					});
+				}
+			}
+		);
+	}),
 };

+ 21 - 0
backend/logic/songs.js

@@ -1511,6 +1511,27 @@ class _SongsModule extends CoreClass {
 			);
 		});
 	}
+
+	/**
+	 * Gets a list of all tags
+	 *
+	 * @returns {Promise} - returns promise (reject, resolve)
+	 */
+	 GET_TAGS() {
+		return new Promise((resolve, reject) => {
+			async.waterfall(
+				[
+					next => {
+						SongsModule.SongModel.distinct("tags", next);
+					}
+				],
+				(err, tags) => {
+					if (err) reject(err);
+					resolve({ tags });
+				}
+			);
+		});
+	}
 }
 
 export default new _SongsModule();

+ 20 - 0
frontend/src/pages/Admin/tabs/Songs.vue

@@ -125,6 +125,11 @@
 						slotProps.item.genres.join(", ")
 					}}</span>
 				</template>
+				<template #column-tags="slotProps">
+					<span :title="slotProps.item.tags.join(', ')">{{
+						slotProps.item.tags.join(", ")
+					}}</span>
+				</template>
 				<template #column-likes="slotProps">
 					<span :title="slotProps.item.likes">{{
 						slotProps.item.likes
@@ -359,6 +364,12 @@ export default {
 					properties: ["genres"],
 					sortable: false
 				},
+				{
+					name: "tags",
+					displayName: "Tags",
+					properties: ["tags"],
+					sortable: false
+				},
 				{
 					name: "likes",
 					displayName: "Likes",
@@ -497,6 +508,15 @@ export default {
 					autosuggest: true,
 					autosuggestDataAction: "songs.getGenres"
 				},
+				{
+					name: "tags",
+					displayName: "Tags",
+					property: "tags",
+					filterTypes: ["contains", "exact", "regex"],
+					defaultFilterType: "contains",
+					autosuggest: true,
+					autosuggestDataAction: "songs.getTags"
+				},
 				{
 					name: "thumbnail",
 					displayName: "Thumbnail",