Reports.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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.songId }}
  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 :title="report.createdAt">{{
  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 ws from "../../../ws";
  72. import ViewReport from "../../../components/modals/ViewReport.vue";
  73. import UserIdToUsername from "../../../components/common/UserIdToUsername.vue";
  74. export default {
  75. components: { ViewReport, UserIdToUsername },
  76. data() {
  77. return {
  78. viewingReportId: "",
  79. reports: []
  80. };
  81. },
  82. computed: {
  83. ...mapState("modalVisibility", {
  84. modals: state => state.modals.admin
  85. }),
  86. ...mapGetters({
  87. socket: "websockets/getSocket"
  88. })
  89. },
  90. mounted() {
  91. if (this.socket.readyState === 1) this.init();
  92. ws.onConnect(() => this.init());
  93. this.socket.dispatch("reports.index", res => {
  94. this.reports = res.data;
  95. });
  96. this.socket.on("event:admin.report.resolved", reportId => {
  97. this.reports = this.reports.filter(report => {
  98. return report._id !== reportId;
  99. });
  100. });
  101. this.socket.on("event:admin.report.created", report =>
  102. this.reports.push(report)
  103. );
  104. if (this.$route.query.id) {
  105. this.socket.dispatch(
  106. "reports.findOne",
  107. this.$route.query.id,
  108. res => {
  109. if (res.status === "success") this.view(res.data);
  110. else
  111. new Toast({
  112. content: "Report with that ID not found",
  113. timeout: 3000
  114. });
  115. }
  116. );
  117. }
  118. },
  119. methods: {
  120. formatDistance,
  121. init() {
  122. this.socket.dispatch("apis.joinAdminRoom", "reports", () => {});
  123. },
  124. view(report) {
  125. // this.viewReport(report);
  126. this.viewingReportId = report._id;
  127. this.openModal({ sector: "admin", modal: "viewReport" });
  128. },
  129. resolve(reportId) {
  130. return this.resolveReport(reportId)
  131. .then(res => {
  132. if (res.status === "success" && this.modals.viewReport)
  133. this.closeModal({
  134. sector: "admin",
  135. modal: "viewReport"
  136. });
  137. })
  138. .catch(
  139. err => new Toast({ content: err.message, timeout: 5000 })
  140. );
  141. },
  142. ...mapActions("modalVisibility", ["openModal", "closeModal"]),
  143. ...mapActions("admin/reports", ["resolveReport"])
  144. }
  145. };
  146. </script>
  147. <style lang="scss" scoped>
  148. .night-mode {
  149. .table {
  150. color: var(--light-grey-2);
  151. background-color: var(--dark-grey-3);
  152. thead tr {
  153. background: var(--dark-grey-3);
  154. td {
  155. color: var(--white);
  156. }
  157. }
  158. tbody tr:hover {
  159. background-color: var(--dark-grey-4) !important;
  160. }
  161. tbody tr:nth-child(even) {
  162. background-color: var(--dark-grey-2);
  163. }
  164. strong {
  165. color: var(--light-grey-2);
  166. }
  167. }
  168. }
  169. .tag:not(:last-child) {
  170. margin-right: 5px;
  171. }
  172. td {
  173. word-wrap: break-word;
  174. max-width: 10vw;
  175. vertical-align: middle;
  176. }
  177. </style>