ViewReport.vue 7.5 KB

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