Browse Source

EditSong Modal now shows how many reports there are for that song

theflametrooper 8 years ago
parent
commit
2266cf4247
2 changed files with 38 additions and 1 deletions
  1. 23 1
      backend/logic/actions/reports.js
  2. 15 0
      frontend/components/Modals/EditSong.vue

+ 23 - 1
backend/logic/actions/reports.js

@@ -67,7 +67,6 @@ module.exports = {
 	 * @param {Function} cb - gets called with the result
 	 */
 	index: hooks.adminRequired((session, cb) => {
-
 		async.waterfall([
 			(next) => {
 				db.models.report.find({ resolved: false }).sort({ released: 'desc' }).exec(next);
@@ -82,6 +81,29 @@ module.exports = {
 		});
 	}),
 
+	/**
+	 * Gets all reports for a songId
+	 *
+	 * @param {Object} session - the session object automatically added by socket.io
+	 * @param {String} songId - the id of the song to index reports for
+	 * @param {Function} cb - gets called with the result
+	 */
+	getReportsForSong: hooks.adminRequired((session, songId, cb) => {
+		async.waterfall([
+			(next) => {
+				db.models.report.find({ songId, resolved: false }).sort({ released: 'desc' }).exec(next);
+			}
+		], (err, reports) => {
+			if (err) {
+				logger.error("REPORTS_GETFORSONG", `Indexing reports for song "${songId}" failed. "${err.message}"`);
+				return cb({ 'status': 'failure', 'message': 'Something went wrong'});
+			} else {
+				logger.success("REPORTS_GETFORSONG", `Indexing report for song "{songId}" successful.`);
+				return cb({ status: 'success', data: reports.length });
+			}
+		});
+	}),
+
 	/**
 	 * Resolves a report
 	 *

+ 15 - 0
frontend/components/Modals/EditSong.vue

@@ -2,6 +2,11 @@
 	<div>
 		<modal title='Edit Song'>
 			<div slot='body'>
+				<span class="tag is-info is-medium reports" v-if="reports > 0">
+					{{ reports }}
+					<span v-if="reports > 1">&nbsp;Reports&nbsp;</span>
+					<span v-else>&nbsp;Report&nbsp;</span>
+				</span>
 				<h5 class='has-text-centered'>Video Preview</h5>
 				<div class='video-container'>
 					<div id='player'></div>
@@ -123,6 +128,7 @@
 					song: {},
 					type: ''
 				},
+				reports: 0,
 				video: {
 					player: null,
 					paused: false,
@@ -261,6 +267,7 @@
 				this.$parent.modals.editSong = false;
 			},
 			editSong: function (song, index, type) {
+				let _this = this;
 				this.video.player.loadVideoById(song._id, this.editing.song.skipDuration);
 				let newSong = {};
 				for (let n in song) {
@@ -271,6 +278,9 @@
 					song: newSong,
 					type
 				};
+				_this.socket.emit('reports.getReportsForSong', song._id, res => {
+					if (res.status === 'success') _this.reports = res.data;
+				});
 				this.$parent.toggleModal();
 			}
 		}
@@ -407,4 +417,9 @@
 	.save-changes { color: #fff; }
 
 	.tag:not(:last-child) { margin-right: 5px; }
+
+	.reports {
+		margin: 0 auto;
+		display: flex;
+	}
 </style>