Reports.vue 3.9 KB

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