Reports.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <template>
  2. <div>
  3. <metadata title="Admin | Reports" />
  4. <div class="container">
  5. <table class="table is-striped">
  6. <thead>
  7. <tr>
  8. <td>Song ID</td>
  9. <td>Author</td>
  10. <td>Time of report</td>
  11. <td>Description</td>
  12. <td>Options</td>
  13. </tr>
  14. </thead>
  15. <tbody>
  16. <tr v-for="report in reports" :key="report._id">
  17. <td>
  18. <span>
  19. {{ report.song.youtubeId }}
  20. <br />
  21. {{ report.song._id }}
  22. </span>
  23. </td>
  24. <td>
  25. <user-id-to-username
  26. :user-id="report.createdBy"
  27. :link="true"
  28. />
  29. </td>
  30. <td>
  31. <span
  32. :content="report.createdAt"
  33. v-tippy="{ theme: 'info' }"
  34. >{{
  35. formatDistance(
  36. new Date(report.createdAt),
  37. new Date(),
  38. { addSuffix: true }
  39. )
  40. }}</span
  41. >
  42. </td>
  43. <td>
  44. <span>{{ report.description }}</span>
  45. </td>
  46. <td>
  47. <a
  48. class="button is-warning"
  49. href="#"
  50. @click="view(report)"
  51. >View</a
  52. >
  53. <a
  54. class="button is-primary"
  55. href="#"
  56. @click="resolve(report._id)"
  57. >Resolve</a
  58. >
  59. </td>
  60. </tr>
  61. </tbody>
  62. </table>
  63. </div>
  64. <view-report
  65. v-if="modals.viewReport"
  66. :report-id="viewingReportId"
  67. sector="admin"
  68. />
  69. </div>
  70. </template>
  71. <script>
  72. import { mapState, mapActions, mapGetters } from "vuex";
  73. import { formatDistance } from "date-fns";
  74. import Toast from "toasters";
  75. import UserIdToUsername from "@/components/UserIdToUsername.vue";
  76. import ws from "@/ws";
  77. export default {
  78. components: {
  79. ViewReport: () => import("@/components/modals/ViewReport.vue"),
  80. UserIdToUsername
  81. },
  82. data() {
  83. return {
  84. viewingReportId: "",
  85. reports: []
  86. };
  87. },
  88. computed: {
  89. ...mapState("modalVisibility", {
  90. modals: state => state.modals
  91. }),
  92. ...mapGetters({
  93. socket: "websockets/getSocket"
  94. })
  95. },
  96. mounted() {
  97. if (this.socket.readyState === 1) this.init();
  98. ws.onConnect(() => this.init());
  99. this.socket.dispatch("reports.index", res => {
  100. if (res.status === "success") this.reports = res.data.reports;
  101. });
  102. this.socket.on("event:admin.report.resolved", res => {
  103. this.reports = this.reports.filter(report => {
  104. return report._id !== res.data.reportId;
  105. });
  106. });
  107. this.socket.on("event:admin.report.created", res =>
  108. this.reports.push(res.data.report)
  109. );
  110. if (this.$route.query.id) {
  111. this.socket.dispatch(
  112. "reports.findOne",
  113. this.$route.query.id,
  114. res => {
  115. if (res.status === "success") this.view(res.data.report);
  116. else new Toast("Report with that ID not found");
  117. }
  118. );
  119. }
  120. },
  121. methods: {
  122. formatDistance,
  123. init() {
  124. this.socket.dispatch("apis.joinAdminRoom", "reports", () => {});
  125. },
  126. view(report) {
  127. // this.viewReport(report);
  128. this.viewingReportId = report._id;
  129. this.openModal("viewReport");
  130. },
  131. resolve(reportId) {
  132. return this.resolveReport(reportId)
  133. .then(res => {
  134. if (res.status === "success" && this.modals.viewReport)
  135. this.closeModal("viewReport");
  136. })
  137. .catch(err => new Toast(err.message));
  138. },
  139. ...mapActions("modalVisibility", ["openModal", "closeModal"]),
  140. ...mapActions("admin/reports", ["resolveReport"])
  141. }
  142. };
  143. </script>
  144. <style lang="scss" scoped>
  145. .night-mode {
  146. .table {
  147. color: var(--light-grey-2);
  148. background-color: var(--dark-grey-3);
  149. thead tr {
  150. background: var(--dark-grey-3);
  151. td {
  152. color: var(--white);
  153. }
  154. }
  155. tbody tr:hover {
  156. background-color: var(--dark-grey-4) !important;
  157. }
  158. tbody tr:nth-child(even) {
  159. background-color: var(--dark-grey-2);
  160. }
  161. strong {
  162. color: var(--light-grey-2);
  163. }
  164. }
  165. }
  166. .tag:not(:last-child) {
  167. margin-right: 5px;
  168. }
  169. td {
  170. word-wrap: break-word;
  171. max-width: 10vw;
  172. vertical-align: middle;
  173. }
  174. </style>