Reports.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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>Created By</td>
  10. <td>Created At</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. :userId="report.createdBy"
  27. :link="true"
  28. />
  29. </td>
  30. <td>
  31. <span>{{ report.createdAt }}</span>
  32. </td>
  33. <td>
  34. <span>{{ report.description }}</span>
  35. </td>
  36. <td>
  37. <a
  38. class="button is-warning"
  39. href="#"
  40. @click="view(report)"
  41. >View</a
  42. >
  43. <a
  44. class="button is-primary"
  45. href="#"
  46. @click="resolve(report._id)"
  47. >Resolve</a
  48. >
  49. </td>
  50. </tr>
  51. </tbody>
  52. </table>
  53. </div>
  54. <issues-modal v-if="modals.viewReport" />
  55. </div>
  56. </template>
  57. <script>
  58. import { mapState, mapActions } from "vuex";
  59. import { Toast } from "vue-roaster";
  60. import io from "../../io";
  61. import IssuesModal from "../Modals/IssuesModal.vue";
  62. import UserIdToUsername from "../UserIdToUsername.vue";
  63. export default {
  64. components: { IssuesModal, UserIdToUsername },
  65. data() {
  66. return {
  67. reports: []
  68. };
  69. },
  70. mounted() {
  71. io.getSocket(socket => {
  72. this.socket = socket;
  73. if (this.socket.connected) this.init();
  74. this.socket.emit("reports.index", res => {
  75. this.reports = res.data;
  76. });
  77. this.socket.on("event:admin.report.resolved", reportId => {
  78. this.reports = this.reports.filter(report => {
  79. return report._id !== reportId;
  80. });
  81. });
  82. this.socket.on("event:admin.report.created", report => {
  83. this.reports.push(report);
  84. });
  85. io.onConnect(() => {
  86. this.init();
  87. });
  88. });
  89. if (this.$route.query.id) {
  90. this.socket.emit("reports.findOne", this.$route.query.id, res => {
  91. if (res.status === "success") this.view(res.data);
  92. else
  93. Toast.methods.addToast(
  94. "Report with that ID not found",
  95. 3000
  96. );
  97. });
  98. }
  99. },
  100. computed: {
  101. ...mapState("modals", {
  102. modals: state => state.modals.admin
  103. })
  104. },
  105. methods: {
  106. init() {
  107. this.socket.emit("apis.joinAdminRoom", "reports", () => {});
  108. },
  109. view(report) {
  110. this.viewReport(report);
  111. this.openModal({ sector: "admin", modal: "viewReport" });
  112. },
  113. resolve(reportId) {
  114. this.socket.emit("reports.resolve", reportId, res => {
  115. Toast.methods.addToast(res.message, 3000);
  116. if (res.status === "success" && this.modals.viewReport)
  117. this.closeModal({
  118. sector: "admin",
  119. modal: "viewReport"
  120. });
  121. });
  122. },
  123. ...mapActions("modals", ["openModal", "closeModal"]),
  124. ...mapActions("admin/reports", ["viewReport"])
  125. }
  126. };
  127. </script>
  128. <style lang="scss" scoped>
  129. @import "styles/global.scss";
  130. .tag:not(:last-child) {
  131. margin-right: 5px;
  132. }
  133. td {
  134. word-wrap: break-word;
  135. max-width: 10vw;
  136. vertical-align: middle;
  137. }
  138. </style>