ViewReport.vue 6.6 KB

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