ViewReport.vue 7.6 KB

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