Reports.vue 3.0 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: function() {
  66. let _this = this;
  67. io.getSocket(socket => {
  68. _this.socket = socket;
  69. if (_this.socket.connected) _this.init();
  70. _this.socket.emit("reports.index", res => {
  71. _this.reports = res.data;
  72. });
  73. _this.socket.on("event:admin.report.resolved", reportId => {
  74. _this.reports = _this.reports.filter(report => {
  75. return report._id !== reportId;
  76. });
  77. });
  78. _this.socket.on("event:admin.report.created", report => {
  79. _this.reports.push(report);
  80. });
  81. io.onConnect(() => {
  82. _this.init();
  83. });
  84. });
  85. if (this.$route.query.id) {
  86. this.socket.emit("reports.findOne", this.$route.query.id, res => {
  87. if (res.status === "success") _this.view(res.data);
  88. else
  89. Toast.methods.addToast(
  90. "Report with that ID not found",
  91. 3000
  92. );
  93. });
  94. }
  95. },
  96. computed: {
  97. ...mapState("modals", {
  98. modals: state => state.modals.admin
  99. })
  100. },
  101. methods: {
  102. init: function() {
  103. this.socket.emit("apis.joinAdminRoom", "reports", () => {});
  104. },
  105. view: function(report) {
  106. this.viewReport(report);
  107. this.openModal({ sector: "admin", modal: "viewReport" });
  108. },
  109. resolve: function(reportId) {
  110. let _this = this;
  111. this.socket.emit("reports.resolve", reportId, res => {
  112. Toast.methods.addToast(res.message, 3000);
  113. if (res.status === "success" && this.modals.viewReport)
  114. _this.closeModal({
  115. sector: "admin",
  116. modal: "viewReport"
  117. });
  118. });
  119. },
  120. ...mapActions("modals", ["openModal", "closeModal"]),
  121. ...mapActions("admin/reports", ["viewReport"])
  122. }
  123. };
  124. </script>
  125. <style lang="scss" scoped>
  126. .tag:not(:last-child) {
  127. margin-right: 5px;
  128. }
  129. td {
  130. word-wrap: break-word;
  131. max-width: 10vw;
  132. vertical-align: middle;
  133. }
  134. </style>