Reports.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <template>
  2. <div class='container'>
  3. <table class='table is-striped'>
  4. <thead>
  5. <tr>
  6. <td>Song ID</td>
  7. <td>Created By</td>
  8. <td>Created At</td>
  9. <td>Description</td>
  10. <td>Options</td>
  11. </tr>
  12. </thead>
  13. <tbody>
  14. <tr v-for='(index, report) in reports' track-by='$index'>
  15. <td>
  16. <span>{{ report.songId }}</span>
  17. </td>
  18. <td>
  19. <span>{{ report.createdBy }}</span>
  20. </td>
  21. <td>
  22. <span>{{ report.createdAt }}</span>
  23. </td>
  24. <td>
  25. <span>{{ report.description }}</span>
  26. </td>
  27. <td>
  28. <a class='button is-warning' href='#' @click='toggleModal(report)'>Issues</a>
  29. <a class='button is-primary' href='#' @click='resolve(report._id)'>Resolve</a>
  30. </td>
  31. </tr>
  32. </tbody>
  33. </table>
  34. </div>
  35. <issues-modal v-if='modals.reportIssues'></issues-modal>
  36. </template>
  37. <script>
  38. import { Toast } from 'vue-roaster';
  39. import io from '../../io';
  40. import IssuesModal from '../Modals/IssuesModal.vue';
  41. export default {
  42. data() {
  43. return {
  44. reports: [],
  45. modals: {
  46. reportIssues: false
  47. }
  48. }
  49. },
  50. methods: {
  51. init: function() {
  52. this.socket.emit('apis.joinAdminRoom', 'reports', data => {});
  53. },
  54. toggleModal: function (report) {
  55. this.modals.reportIssues = !this.modals.reportIssues;
  56. if (this.modals.reportIssues) this.editing = report;
  57. },
  58. resolve: function (reportId) {
  59. this.socket.emit('reports.resolve', reportId, res => {
  60. Toast.methods.addToast(res.message, 3000);
  61. });
  62. }
  63. },
  64. ready: function () {
  65. let _this = this;
  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. },
  85. components: { IssuesModal }
  86. }
  87. </script>
  88. <style lang='scss' scoped>
  89. .tag:not(:last-child) { margin-right: 5px; }
  90. td {
  91. word-wrap: break-word;
  92. max-width: 10vw;
  93. vertical-align: middle;
  94. }
  95. </style>