ViewReport.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <template>
  2. <modal title="View Report">
  3. <template #body v-if="report && report._id">
  4. <router-link
  5. v-if="$route.query.returnToSong"
  6. class="button is-dark back-to-song"
  7. :to="{
  8. path: '/admin/songs',
  9. query: { id: report.youtubeId }
  10. }"
  11. >
  12. <i class="material-icons">keyboard_return</i> &nbsp; Edit Song
  13. </router-link>
  14. <article class="message">
  15. <div class="message-body">
  16. <strong>Song ID:</strong>
  17. {{ report.song.youtubeId }} / {{ report.song._id }}
  18. <br />
  19. <strong>Author:</strong>
  20. <user-id-to-username
  21. :user-id="report.createdBy"
  22. :alt="report.createdBy"
  23. />
  24. <br />
  25. <strong>Time of report:</strong>
  26. <span
  27. :content="report.createdAt"
  28. v-tippy="{ theme: 'info' }"
  29. >
  30. {{
  31. formatDistance(
  32. new Date(report.createdAt),
  33. new Date(),
  34. {
  35. addSuffix: true
  36. }
  37. )
  38. }}
  39. </span>
  40. <br />
  41. <span v-if="report.description">
  42. <strong>Description:</strong>
  43. {{ report.description }}
  44. </span>
  45. </div>
  46. </article>
  47. <table v-if="report.issues.length > 0" class="table is-narrow">
  48. <thead>
  49. <tr>
  50. <td>Issue</td>
  51. <td>Reasons</td>
  52. </tr>
  53. </thead>
  54. <tbody>
  55. <tr v-for="issue in report.issues" :key="issue.name">
  56. <td>
  57. <span>{{ issue.name }}</span>
  58. </td>
  59. <td>
  60. <span>{{ issue.reasons }}</span>
  61. </td>
  62. </tr>
  63. </tbody>
  64. </table>
  65. </template>
  66. <template #footer v-if="report && report._id">
  67. <a class="button is-primary" href="#" @click="resolve(report._id)">
  68. <span>Resolve</span>
  69. </a>
  70. <a
  71. class="button is-primary"
  72. :href="`/admin/songs?songId=${report.song._id}`"
  73. target="_blank"
  74. >
  75. <span>Go to song</span>
  76. </a>
  77. </template>
  78. </modal>
  79. </template>
  80. <script>
  81. import { mapActions, mapGetters, mapState } from "vuex";
  82. import { formatDistance } from "date-fns";
  83. import Toast from "toasters";
  84. import UserIdToUsername from "../UserIdToUsername.vue";
  85. import Modal from "../Modal.vue";
  86. export default {
  87. components: { Modal, UserIdToUsername },
  88. props: {
  89. reportId: { type: String, default: "" },
  90. sector: { type: String, default: "admin" }
  91. },
  92. computed: {
  93. ...mapState("modals/viewReport", {
  94. report: state => state.report
  95. }),
  96. ...mapGetters({
  97. socket: "websockets/getSocket"
  98. })
  99. },
  100. mounted() {
  101. if (this.$route.query.returnToSong) {
  102. this.closeModal("editSong");
  103. }
  104. this.socket.dispatch(`reports.findOne`, this.reportId, res => {
  105. if (res.status === "success") {
  106. const { report } = res.data;
  107. this.viewReport(report);
  108. } else {
  109. new Toast("Report with that ID not found");
  110. this.closeModal("viewReport");
  111. }
  112. });
  113. },
  114. methods: {
  115. formatDistance,
  116. resolve(reportId) {
  117. return this.resolveReport(reportId)
  118. .then(res => {
  119. if (res.status === "success") this.closeModal("viewReport");
  120. })
  121. .catch(err => new Toast(err.message));
  122. },
  123. ...mapActions("modals/viewReport", ["viewReport", "resolveReport"]),
  124. ...mapActions("modalVisibility", ["closeModal"])
  125. }
  126. };
  127. </script>
  128. <style lang="scss" scoped>
  129. .night-mode {
  130. .message,
  131. .table {
  132. color: var(--light-grey-2);
  133. background-color: var(--dark-grey-3);
  134. }
  135. .table tr:hover {
  136. filter: brightness(95%);
  137. }
  138. }
  139. .back-to-song {
  140. display: flex;
  141. margin-bottom: 20px;
  142. }
  143. </style>