Reports.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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)' v-if='report.issues.length > 0'>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. let _this = this;
  60. this.socket.emit('reports.resolve', reportId, res => {
  61. Toast.methods.addToast(res.message, 3000);
  62. if (res.status == 'success' && this.modals.reportIssues) _this.toggleModal();
  63. });
  64. }
  65. },
  66. ready: function () {
  67. let _this = this;
  68. io.getSocket((socket) => {
  69. _this.socket = socket;
  70. if (_this.socket.connected) _this.init();
  71. _this.socket.emit('reports.index', res => {
  72. _this.reports = res.data;
  73. });
  74. _this.socket.on('event:admin.report.resolved', reportId => {
  75. _this.reports = _this.reports.filter(report => {
  76. return report._id !== reportId;
  77. });
  78. });
  79. _this.socket.on('event:admin.report.created', report => {
  80. _this.reports.push(report);
  81. });
  82. io.onConnect(() => {
  83. _this.init();
  84. });
  85. });
  86. },
  87. components: { IssuesModal }
  88. }
  89. </script>
  90. <style lang='scss' scoped>
  91. .tag:not(:last-child) { margin-right: 5px; }
  92. td {
  93. word-wrap: break-word;
  94. max-width: 10vw;
  95. vertical-align: middle;
  96. }
  97. </style>