Reports.vue 2.9 KB

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