Reports.vue 2.9 KB

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