Prechádzať zdrojové kódy

feat(Admin/Playlists): Create missing genre playlists button

Owen Diffey 3 rokov pred
rodič
commit
cb09249e60

+ 46 - 0
backend/logic/actions/playlists.js

@@ -1981,5 +1981,51 @@ export default {
 				});
 			}
 		);
+	}),
+
+	/**
+	 * Create missing genre playlists
+	 *
+	 * @param {object} session - the session object automatically added by socket.io
+	 * @param {Function} cb - gets called with the result
+	 */
+	createMissingGenrePlaylists: isAdminRequired(async function index(session, cb) {
+		async.waterfall(
+			[
+				next => {
+					PlaylistsModule.runJob("CREATE_MISSING_GENRE_PLAYLISTS", this)
+						.then(() => {
+							next();
+						})
+						.catch(err => {
+							next(err);
+						});
+				}
+			],
+			async err => {
+				if (err) {
+					err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
+
+					this.log(
+						"ERROR",
+						"PLAYLIST_CREATE_MISSING_GENRE_PLAYLISTS",
+						`Creating missing genre playlists failed for user "${session.userId}". "${err}"`
+					);
+
+					return cb({ status: "error", message: err });
+				}
+
+				this.log(
+					"SUCCESS",
+					"PLAYLIST_CREATE_MISSING_GENRE_PLAYLISTS",
+					`Successfully created missing genre playlists for user "${session.userId}".`
+				);
+
+				return cb({
+					status: "success",
+					message: "Missing genre playlists have been successfully created"
+				});
+			}
+		);
 	})
 };

+ 22 - 0
frontend/src/pages/Admin/tabs/Playlists.vue

@@ -43,6 +43,14 @@
 						Clear and refill all genre playlists
 					</button>
 				</confirm>
+				<confirm
+					placement="bottom"
+					@confirm="createMissingGenrePlaylists()"
+				>
+					<button class="button is-danger">
+						Create missing genre playlists
+					</button>
+				</confirm>
 			</div>
 			<table class="table">
 				<thead>
@@ -271,6 +279,20 @@ export default {
 				}
 			);
 		},
+		createMissingGenrePlaylists() {
+			this.socket.dispatch(
+				"playlists.createMissingGenrePlaylists",
+				data => {
+					console.log(data.message);
+					if (data.status !== "success")
+						new Toast({
+							content: `Error: ${data.message}`,
+							timeout: 8000
+						});
+					else new Toast({ content: data.message, timeout: 4000 });
+				}
+			);
+		},
 		...mapActions("modalVisibility", ["openModal"]),
 		...mapActions("user/playlists", ["editPlaylist"]),
 		...mapActions("admin/playlists", [