Reports.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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. <a
  51. class="button is-primary"
  52. href="#"
  53. @click="view(report._id)"
  54. content="Expand"
  55. v-tippy
  56. >
  57. <i class="material-icons icon-with-button">
  58. open_in_full
  59. </i>
  60. Expand
  61. </a>
  62. <a
  63. class="button is-success"
  64. href="#"
  65. @click="resolve(report._id)"
  66. content="Resolve"
  67. v-tippy
  68. >
  69. <i class="material-icons icon-with-button">
  70. done_all
  71. </i>
  72. Resolve
  73. </a>
  74. </td>
  75. </tr>
  76. </tbody>
  77. </table>
  78. </div>
  79. <view-report v-if="modals.viewReport" sector="admin" />
  80. <edit-song v-if="modals.editSong" song-type="songs" />
  81. </div>
  82. </template>
  83. <script>
  84. import { mapState, mapActions, mapGetters } from "vuex";
  85. import { defineAsyncComponent } from "vue";
  86. import Toast from "toasters";
  87. import ws from "@/ws";
  88. import ReportInfoItem from "@/components/ReportInfoItem.vue";
  89. export default {
  90. components: {
  91. ViewReport: defineAsyncComponent(() =>
  92. import("@/components/modals/ViewReport.vue")
  93. ),
  94. EditSong: defineAsyncComponent(() =>
  95. import("@/components/modals/EditSong/index.vue")
  96. ),
  97. ReportInfoItem
  98. },
  99. data() {
  100. return {
  101. reports: []
  102. };
  103. },
  104. computed: {
  105. ...mapState("modalVisibility", {
  106. modals: state => state.modals
  107. }),
  108. ...mapGetters({
  109. socket: "websockets/getSocket"
  110. })
  111. },
  112. mounted() {
  113. ws.onConnect(this.init);
  114. this.socket.on("event:admin.report.resolved", res => {
  115. this.reports = this.reports.filter(
  116. report => report._id !== res.data.reportId
  117. );
  118. });
  119. this.socket.on("event:admin.report.created", res =>
  120. this.reports.unshift(res.data.report)
  121. );
  122. },
  123. methods: {
  124. init() {
  125. this.socket.dispatch("reports.index", res => {
  126. if (res.status === "success") this.reports = res.data.reports;
  127. });
  128. this.socket.dispatch("apis.joinAdminRoom", "reports", () => {});
  129. },
  130. getCategories(issues) {
  131. const categories = [];
  132. issues.forEach(issue => {
  133. if (categories.indexOf(issue.category) === -1)
  134. categories.push(issue.category);
  135. });
  136. return categories;
  137. },
  138. view(reportId) {
  139. this.viewReport(reportId);
  140. this.openModal("viewReport");
  141. },
  142. resolve(reportId) {
  143. return this.resolveReport(reportId)
  144. .then(res => {
  145. if (res.status === "success" && this.modals.viewReport)
  146. this.closeModal("viewReport");
  147. })
  148. .catch(err => new Toast(err.message));
  149. },
  150. ...mapActions("modalVisibility", ["openModal", "closeModal"]),
  151. ...mapActions("admin/reports", ["resolveReport"]),
  152. ...mapActions("modals/viewReport", ["viewReport"])
  153. }
  154. };
  155. </script>
  156. <style lang="scss" scoped>
  157. .night-mode {
  158. .table {
  159. color: var(--light-grey-2);
  160. background-color: var(--dark-grey-3);
  161. thead tr {
  162. background: var(--dark-grey-3);
  163. td {
  164. color: var(--white);
  165. }
  166. }
  167. tbody tr:hover {
  168. background-color: var(--dark-grey-4) !important;
  169. }
  170. tbody tr:nth-child(even) {
  171. background-color: var(--dark-grey-2);
  172. }
  173. strong {
  174. color: var(--light-grey-2);
  175. }
  176. }
  177. }
  178. #options-column {
  179. a:not(:last-of-type) {
  180. margin-right: 5px;
  181. }
  182. }
  183. #categories-column {
  184. text-transform: capitalize;
  185. }
  186. td {
  187. word-wrap: break-word;
  188. max-width: 10vw;
  189. vertical-align: middle;
  190. }
  191. li {
  192. list-style: inside;
  193. }
  194. </style>