Reports.vue 3.7 KB

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