ViewReport.vue 8.0 KB

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