ViewReport.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. <template>
  2. <modal title="View Report">
  3. <template #body v-if="report && report._id">
  4. <div class="report-item">
  5. <div class="report-item-header">
  6. <div class="report-item-info">
  7. <div class="report-item-icon">
  8. <profile-picture
  9. :avatar="report.createdBy.avatar"
  10. :name="
  11. report.createdBy.name
  12. ? report.createdBy.name
  13. : report.createdBy.username
  14. "
  15. />
  16. </div>
  17. <div class="report-item-summary">
  18. <p class="report-item-summary-title">
  19. Reported by
  20. <router-link
  21. :to="{
  22. path: `/u/${report.createdBy.username}`
  23. }"
  24. :title="report.createdBy._id"
  25. >
  26. {{ report.createdBy.username }}
  27. </router-link>
  28. </p>
  29. <p class="report-item-summary-description">
  30. {{
  31. formatDistance(
  32. new Date(report.createdAt),
  33. new Date(),
  34. {
  35. addSuffix: true
  36. }
  37. )
  38. }}
  39. / YouTube:
  40. <a
  41. :href="
  42. 'https://www.youtube.com/watch?v=' +
  43. `${report.song.youtubeId}`
  44. "
  45. target="_blank"
  46. >
  47. {{ report.song.youtubeId }}</a
  48. >
  49. / Song ID: {{ report.song._id }}
  50. </p>
  51. </div>
  52. </div>
  53. </div>
  54. <div class="report-sub-items">
  55. <div
  56. class="report-sub-item report-sub-item-unresolved"
  57. :class="[
  58. 'report',
  59. issue.resolved
  60. ? 'report-sub-item-resolved'
  61. : 'report-sub-item-unresolved'
  62. ]"
  63. v-for="(issue, issueIndex) in report.issues"
  64. :key="issueIndex"
  65. >
  66. <i
  67. class="material-icons duration-icon report-sub-item-left-icon"
  68. :content="issue.category"
  69. v-tippy
  70. >
  71. {{ icons[issue.category] }}
  72. </i>
  73. <p class="report-sub-item-info">
  74. <span class="report-sub-item-title">
  75. {{ issue.title }}
  76. </span>
  77. <span
  78. class="report-sub-item-description"
  79. v-if="issue.description"
  80. >
  81. {{ issue.description }}
  82. </span>
  83. </p>
  84. <div
  85. class="report-sub-item-actions universal-item-actions"
  86. >
  87. <i
  88. class="material-icons resolve-icon"
  89. content="Resolve"
  90. v-tippy
  91. v-if="!issue.resolved"
  92. @click="toggleIssue(report._id, issue._id)"
  93. >
  94. done
  95. </i>
  96. <i
  97. class="material-icons unresolve-icon"
  98. content="Unresolve"
  99. v-tippy
  100. v-else
  101. @click="toggleIssue(report._id, issue._id)"
  102. >
  103. remove
  104. </i>
  105. </div>
  106. </div>
  107. </div>
  108. </div>
  109. </template>
  110. <template #footer v-if="report && report._id">
  111. <a
  112. class="button is-primary"
  113. :href="`/admin/songs?songId=${report.song._id}`"
  114. target="_blank"
  115. >
  116. <i
  117. class="material-icons icon-with-button"
  118. content="Open Song in New Tab"
  119. v-tippy
  120. >
  121. open_in_new
  122. </i>
  123. Open Song
  124. </a>
  125. <a class="button is-success" href="#" @click="resolve(report._id)">
  126. <i
  127. class="material-icons icon-with-button"
  128. content="Resolve"
  129. v-tippy
  130. >
  131. done_all
  132. </i>
  133. Resolve
  134. </a>
  135. </template>
  136. </modal>
  137. </template>
  138. <script>
  139. import { mapActions, mapGetters } from "vuex";
  140. import { formatDistance } from "date-fns";
  141. import Toast from "toasters";
  142. import ProfilePicture from "@/components/ProfilePicture.vue";
  143. import Modal from "../Modal.vue";
  144. export default {
  145. components: { Modal, ProfilePicture },
  146. props: {
  147. reportId: { type: String, default: "" },
  148. sector: { type: String, default: "admin" }
  149. },
  150. data() {
  151. return {
  152. icons: {
  153. duration: "timer",
  154. video: "tv",
  155. thumbnail: "image",
  156. artists: "record_voice_over",
  157. title: "title",
  158. custom: "lightbulb"
  159. },
  160. report: {}
  161. };
  162. },
  163. computed: {
  164. ...mapGetters({
  165. socket: "websockets/getSocket"
  166. })
  167. },
  168. mounted() {
  169. this.socket.dispatch("reports.findOne", this.reportId, res => {
  170. if (res.status === "success") {
  171. const { report } = res.data;
  172. this.socket.dispatch(
  173. "apis.joinRoom",
  174. `view-report.${report._id}`
  175. );
  176. this.report = report;
  177. } else {
  178. new Toast("Report with that ID not found");
  179. this.closeModal("viewReport");
  180. }
  181. });
  182. this.socket.on(
  183. "event:admin.report.resolved",
  184. () => this.closeModal("viewReport"),
  185. { modal: "viewReport" }
  186. );
  187. this.socket.on(
  188. "event:admin.report.issue.toggled",
  189. res => {
  190. if (this.report._id === res.data.reportId) {
  191. const issue = this.report.issues.find(
  192. issue => issue._id.toString() === res.data.issueId
  193. );
  194. issue.resolved = !issue.resolved;
  195. }
  196. },
  197. { modal: "viewReport" }
  198. );
  199. },
  200. beforeUnmount() {
  201. this.socket.dispatch("apis.leaveRoom", `view-report.${this.reportId}`);
  202. },
  203. methods: {
  204. formatDistance,
  205. resolve(reportId) {
  206. return this.resolveReport(reportId)
  207. .then(res => {
  208. if (res.status === "success") this.closeModal("viewReport");
  209. })
  210. .catch(err => new Toast(err.message));
  211. },
  212. toggleIssue(reportId, issueId) {
  213. this.socket.dispatch(
  214. "reports.toggleIssue",
  215. reportId,
  216. issueId,
  217. res => {
  218. if (res.status !== "success") new Toast(res.message);
  219. }
  220. );
  221. },
  222. ...mapActions("admin/reports", ["indexReports", "resolveReport"]),
  223. ...mapActions("modalVisibility", ["closeModal"])
  224. }
  225. };
  226. </script>
  227. <style lang="scss" scoped>
  228. .report-item {
  229. background-color: var(--white);
  230. border: 0.5px solid var(--primary-color);
  231. border-radius: 5px;
  232. padding: 8px;
  233. &:not(:first-of-type) {
  234. margin-bottom: 16px;
  235. }
  236. .report-item-header {
  237. display: flex;
  238. align-items: center;
  239. justify-content: space-between;
  240. margin-bottom: 8px;
  241. background-color: var(--light-grey);
  242. // padding: 5px;
  243. padding: 10px;
  244. border-radius: 5px;
  245. .report-item-info {
  246. display: flex;
  247. align-items: center;
  248. .report-item-icon {
  249. display: flex;
  250. align-items: center;
  251. .profile-picture,
  252. i {
  253. margin-right: 10px;
  254. width: 45px;
  255. height: 45px;
  256. }
  257. i {
  258. font-size: 30px;
  259. display: flex;
  260. align-items: center;
  261. justify-content: center;
  262. }
  263. }
  264. .report-item-summary {
  265. .report-item-summary-title {
  266. // font-size: 14px;
  267. font-size: 16px;
  268. text-transform: capitalize;
  269. }
  270. .report-item-summary-description {
  271. text-transform: capitalize;
  272. // font-size: 12px;
  273. font-size: 14px;
  274. }
  275. }
  276. }
  277. .report-item-actions {
  278. height: 24px;
  279. margin-right: 4px;
  280. }
  281. }
  282. .report-sub-items {
  283. .report-sub-item {
  284. border: 0.5px solid var(--black);
  285. margin-top: -1px;
  286. line-height: 24px;
  287. display: flex;
  288. // padding: 4px;
  289. padding: 8px;
  290. display: flex;
  291. &:first-child {
  292. border-radius: 3px 3px 0 0;
  293. }
  294. &:last-child {
  295. border-radius: 0 0 3px 3px;
  296. }
  297. &.report-sub-item-resolved {
  298. .report-sub-item-description,
  299. .report-sub-item-title {
  300. text-decoration: line-through;
  301. }
  302. }
  303. .report-sub-item-left-icon {
  304. margin-right: 8px;
  305. margin-top: auto;
  306. margin-bottom: auto;
  307. }
  308. .report-sub-item-info {
  309. flex: 1;
  310. display: flex;
  311. flex-direction: column;
  312. .report-sub-item-title {
  313. // font-size: 14px;
  314. font-size: 16px;
  315. }
  316. .report-sub-item-description {
  317. // font-size: 12px;
  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(--red);
  336. cursor: pointer;
  337. }
  338. }
  339. </style>