ViewReport.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. <template>
  2. <modal class="view-report-modal" title="View Report">
  3. <template #body v-if="report && report._id">
  4. <div class="report-item">
  5. <div id="song-and-report-items">
  6. <report-info-item
  7. :created-at="report.createdAt"
  8. :created-by="report.createdBy"
  9. />
  10. <song-item
  11. :song="song"
  12. :duration="false"
  13. :disabled-actions="['report']"
  14. />
  15. </div>
  16. <div class="report-sub-items">
  17. <div
  18. class="report-sub-item report-sub-item-unresolved"
  19. :class="[
  20. 'report',
  21. issue.resolved
  22. ? 'report-sub-item-resolved'
  23. : 'report-sub-item-unresolved'
  24. ]"
  25. v-for="(issue, issueIndex) in report.issues"
  26. :key="issueIndex"
  27. >
  28. <i
  29. class="material-icons duration-icon report-sub-item-left-icon"
  30. :content="issue.category"
  31. v-tippy
  32. >
  33. {{ icons[issue.category] }}
  34. </i>
  35. <p class="report-sub-item-info">
  36. <span class="report-sub-item-title">
  37. {{ issue.title }}
  38. </span>
  39. <span
  40. class="report-sub-item-description"
  41. v-if="issue.description"
  42. >
  43. {{ issue.description }}
  44. </span>
  45. </p>
  46. <div
  47. class="report-sub-item-actions universal-item-actions"
  48. >
  49. <i
  50. class="material-icons resolve-icon"
  51. content="Resolve"
  52. v-tippy
  53. v-if="!issue.resolved"
  54. @click="toggleIssue(issue._id)"
  55. >
  56. done
  57. </i>
  58. <i
  59. class="material-icons unresolve-icon"
  60. content="Unresolve"
  61. v-tippy
  62. v-else
  63. @click="toggleIssue(issue._id)"
  64. >
  65. remove
  66. </i>
  67. </div>
  68. </div>
  69. </div>
  70. </div>
  71. </template>
  72. <template #footer v-if="report && report._id">
  73. <a
  74. class="button is-primary material-icons icon-with-button"
  75. @click="openSong()"
  76. content="Edit Song"
  77. v-tippy
  78. >
  79. edit
  80. </a>
  81. <button
  82. v-if="report.resolved"
  83. class="button is-danger material-icons icon-with-button"
  84. @click="resolve(false)"
  85. content="Unresolve"
  86. v-tippy
  87. >
  88. remove_done
  89. </button>
  90. <button
  91. v-else
  92. class="button is-success material-icons icon-with-button"
  93. @click="resolve(true)"
  94. content="Resolve"
  95. v-tippy
  96. >
  97. done_all
  98. </button>
  99. <div class="right">
  100. <quick-confirm @confirm="remove()">
  101. <button
  102. class="button is-danger material-icons icon-with-button"
  103. content="Delete Report"
  104. v-tippy
  105. >
  106. delete_forever
  107. </button>
  108. </quick-confirm>
  109. </div>
  110. </template>
  111. </modal>
  112. </template>
  113. <script>
  114. import { mapActions, mapGetters } from "vuex";
  115. import Toast from "toasters";
  116. import ws from "@/ws";
  117. import { mapModalState } from "@/vuex_helpers";
  118. import SongItem from "@/components/SongItem.vue";
  119. import ReportInfoItem from "@/components/ReportInfoItem.vue";
  120. export default {
  121. components: { SongItem, ReportInfoItem },
  122. props: {
  123. modalUuid: { type: String, default: "" }
  124. },
  125. data() {
  126. return {
  127. icons: {
  128. duration: "timer",
  129. video: "tv",
  130. thumbnail: "image",
  131. artists: "record_voice_over",
  132. title: "title",
  133. custom: "lightbulb"
  134. },
  135. report: {},
  136. song: null
  137. };
  138. },
  139. computed: {
  140. ...mapModalState("modals/viewReport/MODAL_UUID", {
  141. reportId: state => state.reportId
  142. }),
  143. ...mapGetters({
  144. socket: "websockets/getSocket"
  145. })
  146. },
  147. mounted() {
  148. ws.onConnect(this.init);
  149. this.socket.on(
  150. "event:admin.report.resolved",
  151. res => {
  152. this.report.resolved = res.data.resolved;
  153. },
  154. { modal: "viewReport" }
  155. );
  156. this.socket.on(
  157. "event:admin.report.removed",
  158. () => this.closeModal("viewReport"),
  159. { modal: "viewReport" }
  160. );
  161. this.socket.on(
  162. "event:admin.report.issue.toggled",
  163. res => {
  164. if (this.report._id === res.data.reportId) {
  165. const issue = this.report.issues.find(
  166. issue => issue._id.toString() === res.data.issueId
  167. );
  168. issue.resolved = res.data.resolved;
  169. }
  170. },
  171. { modal: "viewReport" }
  172. );
  173. },
  174. beforeUnmount() {
  175. this.socket.dispatch("apis.leaveRoom", `view-report.${this.reportId}`);
  176. // Delete the VueX module that was created for this modal, after all other cleanup tasks are performed
  177. this.$store.unregisterModule(["modals", "viewReport", this.modalUuid]);
  178. },
  179. methods: {
  180. init() {
  181. this.socket.dispatch("reports.findOne", this.reportId, res => {
  182. if (res.status === "success") {
  183. const { report } = res.data;
  184. this.socket.dispatch(
  185. "apis.joinRoom",
  186. `view-report.${report._id}`
  187. );
  188. this.report = report;
  189. this.socket.dispatch(
  190. "songs.getSongFromSongId",
  191. this.report.song._id,
  192. res => {
  193. if (res.status === "success")
  194. this.song = res.data.song;
  195. else {
  196. new Toast(
  197. "Cannot find the report's associated song"
  198. );
  199. this.closeModal("viewReport");
  200. }
  201. }
  202. );
  203. } else {
  204. new Toast("Report with that ID not found");
  205. this.closeModal("viewReport");
  206. }
  207. });
  208. },
  209. resolve(value) {
  210. return this.resolveReport({ reportId: this.reportId, value })
  211. .then(res => {
  212. if (res.status !== "success") new Toast(res.message);
  213. })
  214. .catch(err => new Toast(err.message));
  215. },
  216. remove() {
  217. return this.removeReport(this.reportId)
  218. .then(res => {
  219. if (res.status === "success") this.closeModal("viewReport");
  220. })
  221. .catch(err => new Toast(err.message));
  222. },
  223. toggleIssue(issueId) {
  224. this.socket.dispatch(
  225. "reports.toggleIssue",
  226. this.reportId,
  227. issueId,
  228. res => {
  229. if (res.status !== "success") new Toast(res.message);
  230. }
  231. );
  232. },
  233. openSong() {
  234. this.editSong({ songId: this.report.song._id });
  235. this.openModal("editSong");
  236. },
  237. ...mapActions("admin/reports", [
  238. "indexReports",
  239. "resolveReport",
  240. "removeReport"
  241. ]),
  242. ...mapActions("modals/editSong", ["editSong"]),
  243. ...mapActions("modalVisibility", ["closeModal", "openModal"])
  244. }
  245. };
  246. </script>
  247. <style lang="less" scoped>
  248. .night-mode {
  249. .report-sub-items {
  250. background-color: var(--dark-grey-2) !important;
  251. .report-sub-item {
  252. border: 0.5px solid var(--white) !important;
  253. }
  254. }
  255. }
  256. @media screen and (min-width: 650px) {
  257. .report-info-item {
  258. margin-right: 10px !important;
  259. }
  260. }
  261. .report-item {
  262. #song-and-report-items {
  263. display: flex;
  264. flex-wrap: wrap;
  265. margin-bottom: 20px;
  266. .universal-item {
  267. width: fit-content;
  268. margin: 5px 0;
  269. }
  270. }
  271. :deep(.report-info-item) {
  272. justify-content: flex-start;
  273. .item-title-description {
  274. .item-title {
  275. font-size: 20px;
  276. font-family: Karla, Arial, sans-serif;
  277. }
  278. .item-description {
  279. font-size: 14px;
  280. line-height: 15px;
  281. font-family: Karla, Arial, sans-serif;
  282. }
  283. }
  284. }
  285. .report-sub-items {
  286. .report-sub-item {
  287. border: 1px solid var(--light-grey-3);
  288. margin-top: -1px;
  289. line-height: 24px;
  290. display: flex;
  291. padding: 8px;
  292. display: flex;
  293. &:first-child {
  294. border-radius: @border-radius @border-radius 0 0;
  295. }
  296. &:last-child {
  297. border-radius: 0 0 @border-radius @border-radius;
  298. }
  299. &.report-sub-item-resolved {
  300. .report-sub-item-description,
  301. .report-sub-item-title {
  302. text-decoration: line-through;
  303. }
  304. }
  305. .report-sub-item-left-icon {
  306. margin-right: 8px;
  307. margin-top: auto;
  308. margin-bottom: auto;
  309. }
  310. .report-sub-item-info {
  311. flex: 1;
  312. display: flex;
  313. flex-direction: column;
  314. .report-sub-item-title {
  315. font-size: 16px;
  316. }
  317. .report-sub-item-description {
  318. font-size: 14px;
  319. line-height: 16px;
  320. }
  321. }
  322. .report-sub-item-actions {
  323. height: 24px;
  324. margin-left: 8px;
  325. margin-top: auto;
  326. margin-bottom: auto;
  327. }
  328. }
  329. }
  330. .resolve-icon {
  331. color: var(--green);
  332. cursor: pointer;
  333. }
  334. .unresolve-icon {
  335. color: var(--dark-red);
  336. cursor: pointer;
  337. }
  338. }
  339. </style>