Reports.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <template>
  2. <div>
  3. <page-metadata title="Admin | Reports" />
  4. <div class="container">
  5. <table class="table is-striped">
  6. <thead>
  7. <tr>
  8. <td>Summary</td>
  9. <td>YouTube / Song ID</td>
  10. <td>Categories Included</td>
  11. <td>Options</td>
  12. </tr>
  13. </thead>
  14. <tbody>
  15. <tr v-for="report in reports" :key="report._id">
  16. <td>
  17. <report-info-item
  18. :created-at="report.createdAt"
  19. :created-by="report.createdBy"
  20. />
  21. </td>
  22. <td>
  23. <span>
  24. <a
  25. :href="
  26. 'https://www.youtube.com/watch?v=' +
  27. `${report.song.youtubeId}`
  28. "
  29. target="_blank"
  30. >
  31. {{ report.song.youtubeId }}</a
  32. >
  33. <br />
  34. {{ report.song._id }}
  35. </span>
  36. </td>
  37. <td id="categories-column">
  38. <ul>
  39. <li
  40. v-for="category in getCategories(
  41. report.issues
  42. )"
  43. :key="category"
  44. >
  45. {{ category }}
  46. </li>
  47. </ul>
  48. </td>
  49. <td id="options-column">
  50. <button
  51. class="button is-primary"
  52. @click="view(report._id)"
  53. content="Expand"
  54. v-tippy
  55. >
  56. <i class="material-icons icon-with-button">
  57. open_in_full
  58. </i>
  59. Expand
  60. </button>
  61. <button
  62. class="button is-success"
  63. @click="resolve(report._id)"
  64. content="Resolve"
  65. v-tippy
  66. >
  67. <i class="material-icons icon-with-button">
  68. done_all
  69. </i>
  70. Resolve
  71. </button>
  72. </td>
  73. </tr>
  74. </tbody>
  75. </table>
  76. </div>
  77. <view-report v-if="modals.viewReport" sector="admin" />
  78. <edit-song v-if="modals.editSong" song-type="songs" />
  79. <report v-if="modals.report" />
  80. </div>
  81. </template>
  82. <script>
  83. import { mapState, mapActions, mapGetters } from "vuex";
  84. import { defineAsyncComponent } from "vue";
  85. import Toast from "toasters";
  86. import ws from "@/ws";
  87. import ReportInfoItem from "@/components/ReportInfoItem.vue";
  88. export default {
  89. components: {
  90. ViewReport: defineAsyncComponent(() =>
  91. import("@/components/modals/ViewReport.vue")
  92. ),
  93. Report: defineAsyncComponent(() =>
  94. import("@/components/modals/Report.vue")
  95. ),
  96. EditSong: defineAsyncComponent(() =>
  97. import("@/components/modals/EditSong/index.vue")
  98. ),
  99. ReportInfoItem
  100. },
  101. data() {
  102. return {
  103. reports: []
  104. };
  105. },
  106. computed: {
  107. ...mapState("modalVisibility", {
  108. modals: state => state.modals
  109. }),
  110. ...mapGetters({
  111. socket: "websockets/getSocket"
  112. })
  113. },
  114. mounted() {
  115. ws.onConnect(this.init);
  116. this.socket.on("event:admin.report.resolved", res => {
  117. this.reports = this.reports.filter(
  118. report => report._id !== res.data.reportId
  119. );
  120. });
  121. this.socket.on("event:admin.report.created", res =>
  122. this.reports.unshift(res.data.report)
  123. );
  124. },
  125. methods: {
  126. init() {
  127. this.socket.dispatch("reports.index", res => {
  128. if (res.status === "success") this.reports = res.data.reports;
  129. });
  130. this.socket.dispatch("apis.joinAdminRoom", "reports", () => {});
  131. },
  132. getCategories(issues) {
  133. const categories = [];
  134. issues.forEach(issue => {
  135. if (categories.indexOf(issue.category) === -1)
  136. categories.push(issue.category);
  137. });
  138. return categories;
  139. },
  140. view(reportId) {
  141. this.viewReport(reportId);
  142. this.openModal("viewReport");
  143. },
  144. resolve(reportId) {
  145. return this.resolveReport(reportId)
  146. .then(res => {
  147. if (res.status === "success" && this.modals.viewReport)
  148. this.closeModal("viewReport");
  149. })
  150. .catch(err => new Toast(err.message));
  151. },
  152. ...mapActions("modalVisibility", ["openModal", "closeModal"]),
  153. ...mapActions("admin/reports", ["resolveReport"]),
  154. ...mapActions("modals/viewReport", ["viewReport"])
  155. }
  156. };
  157. </script>
  158. <style lang="scss" scoped>
  159. .night-mode {
  160. .table {
  161. color: var(--light-grey-2);
  162. background-color: var(--dark-grey-3);
  163. thead tr {
  164. background: var(--dark-grey-3);
  165. td {
  166. color: var(--white);
  167. }
  168. }
  169. tbody tr:hover {
  170. background-color: var(--dark-grey-4) !important;
  171. }
  172. tbody tr:nth-child(even) {
  173. background-color: var(--dark-grey-2);
  174. }
  175. strong {
  176. color: var(--light-grey-2);
  177. }
  178. }
  179. }
  180. #options-column {
  181. a:not(:last-of-type) {
  182. margin-right: 5px;
  183. }
  184. }
  185. #categories-column {
  186. text-transform: capitalize;
  187. }
  188. td {
  189. word-wrap: break-word;
  190. max-width: 10vw;
  191. vertical-align: middle;
  192. }
  193. li {
  194. list-style: inside;
  195. }
  196. </style>