ViewReport.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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(report._id, 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(report._id, 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 class="button is-primary" @click="openSong()">
  74. <i
  75. class="material-icons icon-with-button"
  76. content="Edit Song"
  77. v-tippy
  78. >
  79. edit
  80. </i>
  81. Edit Song
  82. </a>
  83. <a class="button is-success" href="#" @click="resolve(report._id)">
  84. <i
  85. class="material-icons icon-with-button"
  86. content="Resolve"
  87. v-tippy
  88. >
  89. done_all
  90. </i>
  91. Resolve
  92. </a>
  93. </template>
  94. </modal>
  95. </template>
  96. <script>
  97. import { mapActions, mapGetters } from "vuex";
  98. import Toast from "toasters";
  99. import Modal from "@/components/Modal.vue";
  100. import SongItem from "@/components/SongItem.vue";
  101. import ReportInfoItem from "@/components/ReportInfoItem.vue";
  102. export default {
  103. components: { Modal, SongItem, ReportInfoItem },
  104. props: {
  105. reportId: { type: String, default: "" },
  106. sector: { type: String, default: "admin" }
  107. },
  108. data() {
  109. return {
  110. icons: {
  111. duration: "timer",
  112. video: "tv",
  113. thumbnail: "image",
  114. artists: "record_voice_over",
  115. title: "title",
  116. custom: "lightbulb"
  117. },
  118. report: {},
  119. song: null
  120. };
  121. },
  122. computed: {
  123. ...mapGetters({
  124. socket: "websockets/getSocket"
  125. })
  126. },
  127. mounted() {
  128. this.socket.dispatch("reports.findOne", this.reportId, res => {
  129. if (res.status === "success") {
  130. const { report } = res.data;
  131. this.socket.dispatch(
  132. "apis.joinRoom",
  133. `view-report.${report._id}`
  134. );
  135. this.report = report;
  136. this.socket.dispatch(
  137. "songs.getSongFromSongId",
  138. this.report.song._id,
  139. res => {
  140. if (res.status === "success") this.song = res.data.song;
  141. else {
  142. new Toast(
  143. "Cannot find the report's associated song"
  144. );
  145. this.closeModal("viewReport");
  146. }
  147. }
  148. );
  149. } else {
  150. new Toast("Report with that ID not found");
  151. this.closeModal("viewReport");
  152. }
  153. });
  154. this.socket.on(
  155. "event:admin.report.resolved",
  156. () => this.closeModal("viewReport"),
  157. { modal: "viewReport" }
  158. );
  159. this.socket.on(
  160. "event:admin.report.issue.toggled",
  161. res => {
  162. if (this.report._id === res.data.reportId) {
  163. const issue = this.report.issues.find(
  164. issue => issue._id.toString() === res.data.issueId
  165. );
  166. issue.resolved = res.data.resolved;
  167. }
  168. },
  169. { modal: "viewReport" }
  170. );
  171. },
  172. beforeUnmount() {
  173. this.socket.dispatch("apis.leaveRoom", `view-report.${this.reportId}`);
  174. },
  175. methods: {
  176. resolve(reportId) {
  177. return this.resolveReport(reportId)
  178. .then(res => {
  179. if (res.status === "success") this.closeModal("viewReport");
  180. })
  181. .catch(err => new Toast(err.message));
  182. },
  183. toggleIssue(reportId, issueId) {
  184. this.socket.dispatch(
  185. "reports.toggleIssue",
  186. reportId,
  187. issueId,
  188. res => {
  189. if (res.status !== "success") new Toast(res.message);
  190. }
  191. );
  192. },
  193. openSong() {
  194. this.editSong({ _id: this.report.song._id });
  195. this.openModal("editSong");
  196. },
  197. ...mapActions("admin/reports", ["indexReports", "resolveReport"]),
  198. ...mapActions("modals/editSong", ["editSong"]),
  199. ...mapActions("modalVisibility", ["closeModal", "openModal"])
  200. }
  201. };
  202. </script>
  203. <style lang="scss" scoped>
  204. .night-mode {
  205. .report-sub-items {
  206. background-color: var(--dark-grey-2) !important;
  207. .report-sub-item {
  208. border: 0.5px solid #fff !important;
  209. }
  210. }
  211. }
  212. @media screen and (min-width: 650px) {
  213. .report-info-item {
  214. margin-right: 10px !important;
  215. }
  216. }
  217. .report-item {
  218. #song-and-report-items {
  219. display: flex;
  220. flex-wrap: wrap;
  221. margin-bottom: 20px;
  222. .universal-item {
  223. width: fit-content;
  224. margin: 5px 0;
  225. }
  226. }
  227. /deep/ .report-info-item {
  228. justify-content: flex-start;
  229. .item-title-description {
  230. .item-title {
  231. font-size: 20px;
  232. font-family: Karla, Arial, sans-serif;
  233. }
  234. .item-description {
  235. font-size: 14px;
  236. font-family: Karla, Arial, sans-serif;
  237. }
  238. }
  239. }
  240. .report-sub-items {
  241. .report-sub-item {
  242. border: 0.5px solid var(--black);
  243. margin-top: -1px;
  244. line-height: 24px;
  245. display: flex;
  246. // padding: 4px;
  247. padding: 8px;
  248. display: flex;
  249. &:first-child {
  250. border-radius: 3px 3px 0 0;
  251. }
  252. &:last-child {
  253. border-radius: 0 0 3px 3px;
  254. }
  255. &.report-sub-item-resolved {
  256. .report-sub-item-description,
  257. .report-sub-item-title {
  258. text-decoration: line-through;
  259. }
  260. }
  261. .report-sub-item-left-icon {
  262. margin-right: 8px;
  263. margin-top: auto;
  264. margin-bottom: auto;
  265. }
  266. .report-sub-item-info {
  267. flex: 1;
  268. display: flex;
  269. flex-direction: column;
  270. .report-sub-item-title {
  271. // font-size: 14px;
  272. font-size: 16px;
  273. }
  274. .report-sub-item-description {
  275. // font-size: 12px;
  276. font-size: 14px;
  277. line-height: 16px;
  278. }
  279. }
  280. .report-sub-item-actions {
  281. height: 24px;
  282. margin-left: 8px;
  283. margin-top: auto;
  284. margin-bottom: auto;
  285. }
  286. }
  287. }
  288. .resolve-icon {
  289. color: var(--green);
  290. cursor: pointer;
  291. }
  292. .unresolve-icon {
  293. color: var(--red);
  294. cursor: pointer;
  295. }
  296. }
  297. </style>