ViewReport.vue 7.5 KB

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