Reports.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 Modal</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.report'></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. report: 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.report = !this.modals.report;
  56. if (this.modals.report) 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.report) _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. if (this.$route.query.id) {
  87. this.socket.emit('reports.findOne', this.$route.query.id, res => {
  88. if (res.status === 'success') _this.toggleModal(res.data);
  89. else Toast.methods.addToast('Report with that ID not found', 3000);
  90. });
  91. }
  92. },
  93. components: { IssuesModal }
  94. }
  95. </script>
  96. <style lang='scss' scoped>
  97. .tag:not(:last-child) { margin-right: 5px; }
  98. td {
  99. word-wrap: break-word;
  100. max-width: 10vw;
  101. vertical-align: middle;
  102. }
  103. </style>