Reports.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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="toggleModal(report)"
  36. >Issues Modal</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.report" />
  50. </div>
  51. </template>
  52. <script>
  53. import { Toast } from "vue-roaster";
  54. import io from "../../io";
  55. import IssuesModal from "../Modals/IssuesModal.vue";
  56. import UserIdToUsername from "../UserIdToUsername.vue";
  57. export default {
  58. components: { IssuesModal, UserIdToUsername },
  59. data() {
  60. return {
  61. reports: [],
  62. modals: {
  63. report: false
  64. }
  65. };
  66. },
  67. mounted: function() {
  68. let _this = this;
  69. io.getSocket(socket => {
  70. _this.socket = socket;
  71. if (_this.socket.connected) _this.init();
  72. _this.socket.emit("reports.index", res => {
  73. _this.reports = res.data;
  74. });
  75. _this.socket.on("event:admin.report.resolved", reportId => {
  76. _this.reports = _this.reports.filter(report => {
  77. return report._id !== reportId;
  78. });
  79. });
  80. _this.socket.on("event:admin.report.created", report => {
  81. _this.reports.push(report);
  82. });
  83. io.onConnect(() => {
  84. _this.init();
  85. });
  86. });
  87. if (this.$route.query.id) {
  88. this.socket.emit("reports.findOne", this.$route.query.id, res => {
  89. if (res.status === "success") _this.toggleModal(res.data);
  90. else
  91. Toast.methods.addToast(
  92. "Report with that ID not found",
  93. 3000
  94. );
  95. });
  96. }
  97. },
  98. methods: {
  99. init: function() {
  100. this.socket.emit("apis.joinAdminRoom", "reports", () => {});
  101. },
  102. toggleModal: function(report) {
  103. this.modals.report = !this.modals.report;
  104. if (this.modals.report) this.editing = report;
  105. },
  106. resolve: function(reportId) {
  107. let _this = this;
  108. this.socket.emit("reports.resolve", reportId, res => {
  109. Toast.methods.addToast(res.message, 3000);
  110. if (res.status === "success" && this.modals.report)
  111. _this.toggleModal();
  112. });
  113. }
  114. }
  115. };
  116. </script>
  117. <style lang="scss" scoped>
  118. .tag:not(:last-child) {
  119. margin-right: 5px;
  120. }
  121. td {
  122. word-wrap: break-word;
  123. max-width: 10vw;
  124. vertical-align: middle;
  125. }
  126. </style>