Reports.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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 } from "vuex";
  69. import { formatDistance } from "date-fns";
  70. import Toast from "toasters";
  71. import io from "../../../io";
  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. },
  87. mounted() {
  88. io.getSocket(socket => {
  89. this.socket = socket;
  90. if (this.socket.connected) this.init();
  91. this.socket.emit("reports.index", res => {
  92. this.reports = res.data;
  93. });
  94. this.socket.on("event:admin.report.resolved", reportId => {
  95. this.reports = this.reports.filter(report => {
  96. return report._id !== reportId;
  97. });
  98. });
  99. this.socket.on("event:admin.report.created", report => {
  100. this.reports.push(report);
  101. });
  102. io.onConnect(() => {
  103. this.init();
  104. });
  105. });
  106. if (this.$route.query.id) {
  107. this.socket.emit("reports.findOne", this.$route.query.id, res => {
  108. if (res.status === "success") this.view(res.data);
  109. else
  110. new Toast({
  111. content: "Report with that ID not found",
  112. timeout: 3000
  113. });
  114. });
  115. }
  116. },
  117. methods: {
  118. formatDistance,
  119. init() {
  120. this.socket.emit("apis.joinAdminRoom", "reports", () => {});
  121. },
  122. view(report) {
  123. // this.viewReport(report);
  124. this.viewingReportId = report._id;
  125. this.openModal({ sector: "admin", modal: "viewReport" });
  126. },
  127. resolve(reportId) {
  128. return this.resolveReport(reportId)
  129. .then(res => {
  130. if (res.status === "success" && this.modals.viewReport)
  131. this.closeModal({
  132. sector: "admin",
  133. modal: "viewReport"
  134. });
  135. })
  136. .catch(
  137. err => new Toast({ content: err.message, timeout: 5000 })
  138. );
  139. },
  140. ...mapActions("modalVisibility", ["openModal", "closeModal"]),
  141. ...mapActions("admin/reports", ["resolveReport"])
  142. }
  143. };
  144. </script>
  145. <style lang="scss" scoped>
  146. @import "../../../styles/global.scss";
  147. .night-mode {
  148. .table {
  149. color: $night-mode-text;
  150. background-color: $night-mode-bg-secondary;
  151. thead tr {
  152. background: $night-mode-bg-secondary;
  153. td {
  154. color: #fff;
  155. }
  156. }
  157. tbody tr:hover {
  158. background-color: #111 !important;
  159. }
  160. tbody tr:nth-child(even) {
  161. background-color: #444;
  162. }
  163. strong {
  164. color: $night-mode-text;
  165. }
  166. }
  167. }
  168. .tag:not(:last-child) {
  169. margin-right: 5px;
  170. }
  171. td {
  172. word-wrap: break-word;
  173. max-width: 10vw;
  174. vertical-align: middle;
  175. }
  176. </style>