Reports.vue 2.7 KB

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