Reports.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. <template>
  2. <div>
  3. <metadata title="Admin | Reports" />
  4. <div class="container">
  5. <table class="table is-striped">
  6. <thead>
  7. <tr>
  8. <td>Summary</td>
  9. <td>YouTube / Song ID</td>
  10. <td>Categories Included</td>
  11. <td>Options</td>
  12. </tr>
  13. </thead>
  14. <tbody>
  15. <tr v-for="report in reports" :key="report._id">
  16. <td>
  17. <div class="report-item-header">
  18. <div class="report-item-info">
  19. <div class="report-item-icon">
  20. <profile-picture
  21. :avatar="report.createdBy.avatar"
  22. :name="
  23. report.createdBy.name
  24. ? report.createdBy.name
  25. : report.createdBy.username
  26. "
  27. />
  28. </div>
  29. <div class="report-item-summary">
  30. <p class="report-item-summary-title">
  31. Reported by
  32. <router-link
  33. :to="{
  34. path: `/u/${report.createdBy.username}`
  35. }"
  36. :title="report.createdBy._id"
  37. >
  38. {{ report.createdBy.username }}
  39. </router-link>
  40. </p>
  41. <p
  42. class="report-item-summary-description"
  43. >
  44. {{
  45. formatDistance(
  46. new Date(report.createdAt),
  47. new Date(),
  48. {
  49. addSuffix: true
  50. }
  51. )
  52. }}
  53. </p>
  54. </div>
  55. </div>
  56. </div>
  57. </td>
  58. <td>
  59. <span>
  60. <a
  61. :href="
  62. 'https://www.youtube.com/watch?v=' +
  63. `${report.song.youtubeId}`
  64. "
  65. target="_blank"
  66. >
  67. {{ report.song.youtubeId }}</a
  68. >
  69. <br />
  70. {{ report.song._id }}
  71. </span>
  72. </td>
  73. <td id="categories-column">
  74. <ul>
  75. <li
  76. v-for="category in getCategories(
  77. report.issues
  78. )"
  79. :key="category"
  80. >
  81. {{ category }}
  82. </li>
  83. </ul>
  84. </td>
  85. <td id="options-column">
  86. <a
  87. class="button is-primary"
  88. href="#"
  89. @click="view(report)"
  90. content="Expand"
  91. v-tippy
  92. >
  93. <i class="material-icons icon-with-button">
  94. open_in_full
  95. </i>
  96. Expand
  97. </a>
  98. <a
  99. class="button is-success "
  100. href="#"
  101. @click="resolve(report._id)"
  102. content="Resolve"
  103. v-tippy
  104. >
  105. <i class="material-icons icon-with-button">
  106. done_all
  107. </i>
  108. Resolve
  109. </a>
  110. </td>
  111. </tr>
  112. </tbody>
  113. </table>
  114. </div>
  115. <view-report
  116. v-if="modals.viewReport"
  117. :report-id="viewingReportId"
  118. sector="admin"
  119. />
  120. <edit-song v-if="modals.editSong" song-type="songs" />
  121. </div>
  122. </template>
  123. <script>
  124. import { mapState, mapActions, mapGetters } from "vuex";
  125. import { formatDistance } from "date-fns";
  126. import { defineAsyncComponent } from "vue";
  127. import Toast from "toasters";
  128. import ProfilePicture from "@/components/ProfilePicture.vue";
  129. import ws from "@/ws";
  130. export default {
  131. components: {
  132. ViewReport: defineAsyncComponent(() =>
  133. import("@/components/modals/ViewReport.vue")
  134. ),
  135. EditSong: defineAsyncComponent(() =>
  136. import("@/components/modals/EditSong/index.vue")
  137. ),
  138. ProfilePicture
  139. },
  140. data() {
  141. return {
  142. viewingReportId: "",
  143. reports: []
  144. };
  145. },
  146. computed: {
  147. ...mapState("modalVisibility", {
  148. modals: state => state.modals
  149. }),
  150. ...mapGetters({
  151. socket: "websockets/getSocket"
  152. })
  153. },
  154. mounted() {
  155. if (this.socket.readyState === 1) this.init();
  156. ws.onConnect(() => this.init());
  157. this.socket.dispatch("reports.index", res => {
  158. if (res.status === "success") this.reports = res.data.reports;
  159. });
  160. this.socket.on("event:admin.report.resolved", res => {
  161. this.reports = this.reports.filter(report => {
  162. return report._id !== res.data.reportId;
  163. });
  164. });
  165. this.socket.on("event:admin.report.created", res =>
  166. this.reports.unshift(res.data.report)
  167. );
  168. // if (this.$route.query.id) {
  169. // this.socket.dispatch(
  170. // "reports.findOne",
  171. // this.$route.query.id,
  172. // res => {
  173. // if (res.status === "success") this.view(res.data.report);
  174. // else new Toast("Report with that ID not found");
  175. // }
  176. // );
  177. // }
  178. },
  179. methods: {
  180. formatDistance,
  181. init() {
  182. this.socket.dispatch("apis.joinAdminRoom", "reports", () => {});
  183. },
  184. getCategories(issues) {
  185. const categories = [];
  186. issues.forEach(issue => {
  187. if (categories.indexOf(issue.category) === -1)
  188. categories.push(issue.category);
  189. });
  190. return categories;
  191. },
  192. view(report) {
  193. this.viewingReportId = report._id;
  194. this.openModal("viewReport");
  195. },
  196. resolve(reportId) {
  197. return this.resolveReport(reportId)
  198. .then(res => {
  199. if (res.status === "success" && this.modals.viewReport)
  200. this.closeModal("viewReport");
  201. })
  202. .catch(err => new Toast(err.message));
  203. },
  204. ...mapActions("modalVisibility", ["openModal", "closeModal"]),
  205. ...mapActions("admin/reports", ["resolveReport"])
  206. }
  207. };
  208. </script>
  209. <style lang="scss" scoped>
  210. .night-mode {
  211. .table {
  212. color: var(--light-grey-2);
  213. background-color: var(--dark-grey-3);
  214. thead tr {
  215. background: var(--dark-grey-3);
  216. td {
  217. color: var(--white);
  218. }
  219. }
  220. tbody tr:hover {
  221. background-color: var(--dark-grey-4) !important;
  222. }
  223. tbody tr:nth-child(even) {
  224. background-color: var(--dark-grey-2);
  225. }
  226. strong {
  227. color: var(--light-grey-2);
  228. }
  229. }
  230. .report-item-header {
  231. background-color: var(--dark-grey-4) !important;
  232. }
  233. }
  234. #options-column {
  235. a:not(:last-of-type) {
  236. margin-right: 5px;
  237. }
  238. }
  239. #categories-column {
  240. text-transform: capitalize;
  241. }
  242. td {
  243. word-wrap: break-word;
  244. max-width: 10vw;
  245. vertical-align: middle;
  246. }
  247. li {
  248. list-style: inside;
  249. }
  250. .report-item-header {
  251. display: flex;
  252. align-items: center;
  253. justify-content: space-between;
  254. margin-bottom: 8px;
  255. background-color: var(--light-grey);
  256. padding: 5px;
  257. border-radius: 5px;
  258. .report-item-info {
  259. display: flex;
  260. align-items: center;
  261. .report-item-icon {
  262. display: flex;
  263. align-items: center;
  264. .profile-picture,
  265. i {
  266. margin-right: 10px;
  267. width: 45px;
  268. height: 45px;
  269. }
  270. i {
  271. font-size: 30px;
  272. display: flex;
  273. align-items: center;
  274. justify-content: center;
  275. }
  276. }
  277. .report-item-summary {
  278. .report-item-summary-title {
  279. font-size: 14px;
  280. text-transform: capitalize;
  281. }
  282. .report-item-summary-description {
  283. text-transform: capitalize;
  284. font-size: 12px;
  285. }
  286. }
  287. }
  288. }
  289. </style>