Reports.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  1. <template>
  2. <div class="reports-tab tabs-container">
  3. <div class="tab-selection">
  4. <button
  5. class="button is-default"
  6. ref="sort-by-report-tab"
  7. :class="{ selected: tab === 'sort-by-report' }"
  8. @click="showTab('sort-by-report')"
  9. >
  10. Sort by Report
  11. </button>
  12. <button
  13. class="button is-default"
  14. ref="sort-by-category-tab"
  15. :class="{ selected: tab === 'sort-by-category' }"
  16. @click="showTab('sort-by-category')"
  17. >
  18. Sort by Category
  19. </button>
  20. </div>
  21. <div class="tab" v-if="tab === 'sort-by-category'">
  22. <div class="report-items" v-if="reports.length > 0">
  23. <div
  24. class="report-item"
  25. v-for="(issues, category) in sortedByCategory"
  26. :key="category"
  27. >
  28. <div class="report-item-header universal-item">
  29. <i
  30. class="material-icons"
  31. :content="category"
  32. v-tippy="{ theme: 'info' }"
  33. >
  34. {{ icons[category] }}
  35. </i>
  36. <p>{{ category }} Issues</p>
  37. </div>
  38. <div class="report-sub-items">
  39. <div
  40. class="report-sub-item report-sub-item-unresolved"
  41. :class="[
  42. 'report',
  43. issue.resolved
  44. ? 'report-sub-item-resolved'
  45. : 'report-sub-item-unresolved'
  46. ]"
  47. v-for="(issue, issueIndex) in issues"
  48. :key="issueIndex"
  49. >
  50. <i
  51. class="material-icons duration-icon report-sub-item-left-icon"
  52. :content="issue.category"
  53. v-tippy
  54. >
  55. {{ icons[category] }}
  56. </i>
  57. <p class="report-sub-item-info">
  58. <span class="report-sub-item-title">
  59. {{ issue.title }}
  60. </span>
  61. <span
  62. class="report-sub-item-description"
  63. v-if="issue.description"
  64. >
  65. {{ issue.description }}
  66. </span>
  67. </p>
  68. <div
  69. class="report-sub-item-actions universal-item-actions"
  70. >
  71. <i
  72. class="material-icons resolve-icon"
  73. content="Resolve"
  74. v-tippy
  75. v-if="!issue.resolved"
  76. @click="
  77. toggleIssue(issue.reportId, issue._id)
  78. "
  79. >
  80. done
  81. </i>
  82. <i
  83. class="material-icons unresolve-icon"
  84. content="Unresolve"
  85. v-tippy
  86. v-else
  87. @click="
  88. toggleIssue(issue.reportId, issue._id)
  89. "
  90. >
  91. remove
  92. </i>
  93. </div>
  94. </div>
  95. </div>
  96. </div>
  97. </div>
  98. <p class="no-reports" v-else>There are no reports for this song.</p>
  99. </div>
  100. <div class="tab" v-if="tab === 'sort-by-report'">
  101. <div class="report-items" v-if="reports.length > 0">
  102. <div
  103. class="report-item"
  104. v-for="report in reports"
  105. :key="report._id"
  106. >
  107. <report-info-item
  108. :created-at="report.createdAt"
  109. :created-by="report.createdBy"
  110. >
  111. <template #actions>
  112. <i
  113. class="material-icons resolve-icon"
  114. content="Resolve all"
  115. v-tippy
  116. @click="resolve(report._id)"
  117. >
  118. done_all
  119. </i>
  120. </template>
  121. </report-info-item>
  122. <div class="report-sub-items">
  123. <div
  124. class="report-sub-item report-sub-item-unresolved"
  125. :class="[
  126. 'report',
  127. issue.resolved
  128. ? 'report-sub-item-resolved'
  129. : 'report-sub-item-unresolved'
  130. ]"
  131. v-for="(issue, issueIndex) in report.issues"
  132. :key="issueIndex"
  133. >
  134. <i
  135. class="material-icons duration-icon report-sub-item-left-icon"
  136. :content="issue.category"
  137. v-tippy
  138. >
  139. {{ icons[issue.category] }}
  140. </i>
  141. <p class="report-sub-item-info">
  142. <span class="report-sub-item-title">
  143. {{ issue.title }}
  144. </span>
  145. <span
  146. class="report-sub-item-description"
  147. v-if="issue.description"
  148. >
  149. {{ issue.description }}
  150. </span>
  151. </p>
  152. <div
  153. class="report-sub-item-actions universal-item-actions"
  154. >
  155. <i
  156. class="material-icons resolve-icon"
  157. content="Resolve"
  158. v-tippy
  159. v-if="!issue.resolved"
  160. @click="toggleIssue(report._id, issue._id)"
  161. >
  162. done
  163. </i>
  164. <i
  165. class="material-icons unresolve-icon"
  166. content="Unresolve"
  167. v-tippy
  168. v-else
  169. @click="toggleIssue(report._id, issue._id)"
  170. >
  171. remove
  172. </i>
  173. </div>
  174. </div>
  175. </div>
  176. </div>
  177. </div>
  178. <p class="no-reports" v-else>There are no reports for this song.</p>
  179. </div>
  180. </div>
  181. </template>
  182. <script>
  183. import { mapState, mapGetters, mapActions } from "vuex";
  184. import Toast from "toasters";
  185. import ReportInfoItem from "@/components/ReportInfoItem.vue";
  186. export default {
  187. components: { ReportInfoItem },
  188. data() {
  189. return {
  190. tab: "sort-by-report",
  191. icons: {
  192. duration: "timer",
  193. video: "tv",
  194. thumbnail: "image",
  195. artists: "record_voice_over",
  196. title: "title",
  197. custom: "lightbulb"
  198. }
  199. };
  200. },
  201. computed: {
  202. ...mapState("modals/editSong", {
  203. reports: state => state.reports
  204. }),
  205. ...mapGetters({
  206. socket: "websockets/getSocket"
  207. }),
  208. sortedByCategory() {
  209. const categories = {};
  210. this.reports.forEach(report =>
  211. report.issues.forEach(issue => {
  212. if (categories[issue.category])
  213. categories[issue.category].push({
  214. ...issue,
  215. reportId: report._id
  216. });
  217. else
  218. categories[issue.category] = [
  219. { ...issue, reportId: report._id }
  220. ];
  221. })
  222. );
  223. return categories;
  224. }
  225. },
  226. mounted() {
  227. this.socket.on(
  228. "event:admin.report.created",
  229. res => this.reports.unshift(res.data.report),
  230. { modal: "editSong" }
  231. );
  232. this.socket.on(
  233. "event:admin.report.resolved",
  234. res => this.resolveReport(res.data.reportId),
  235. { modal: "editSong" }
  236. );
  237. this.socket.on(
  238. "event:admin.report.issue.toggled",
  239. res => {
  240. this.reports.forEach((report, index) => {
  241. if (report._id === res.data.reportId) {
  242. const issue = this.reports[index].issues.find(
  243. issue => issue._id.toString() === res.data.issueId
  244. );
  245. issue.resolved = res.data.resolved;
  246. }
  247. });
  248. },
  249. { modal: "editSong" }
  250. );
  251. },
  252. methods: {
  253. showTab(tab) {
  254. this.$refs[`${tab}-tab`].scrollIntoView({ block: "nearest" });
  255. this.tab = tab;
  256. },
  257. resolve(reportId) {
  258. this.socket.dispatch(
  259. "reports.resolve",
  260. reportId,
  261. res => new Toast(res.message)
  262. );
  263. },
  264. toggleIssue(reportId, issueId) {
  265. this.socket.dispatch(
  266. "reports.toggleIssue",
  267. reportId,
  268. issueId,
  269. res => {
  270. if (res.status !== "success") new Toast(res.message);
  271. }
  272. );
  273. },
  274. ...mapActions("modals/editSong", ["resolveReport"]),
  275. ...mapActions("modalVisibility", ["closeModal"])
  276. }
  277. };
  278. </script>
  279. <style lang="less" scoped>
  280. .night-mode {
  281. .report-items .report-item {
  282. background-color: var(--dark-grey-3) !important;
  283. }
  284. .report-items .report-item .report-item-header {
  285. background-color: var(--dark-grey-2) !important;
  286. }
  287. .label,
  288. p,
  289. strong {
  290. color: var(--light-grey-2);
  291. }
  292. .tabs-container .tab-selection .button {
  293. background: var(--dark-grey) !important;
  294. color: var(--white) !important;
  295. }
  296. }
  297. .reports-tab.tabs-container {
  298. .tab-selection {
  299. display: flex;
  300. overflow-x: auto;
  301. .button {
  302. border-radius: 0;
  303. border: 0;
  304. text-transform: uppercase;
  305. font-size: 14px;
  306. color: var(--dark-grey-3);
  307. background-color: var(--light-grey-2);
  308. flex-grow: 1;
  309. height: 32px;
  310. &:not(:first-of-type) {
  311. margin-left: 5px;
  312. }
  313. }
  314. .selected {
  315. background-color: var(--primary-color) !important;
  316. color: var(--white) !important;
  317. font-weight: 600;
  318. }
  319. }
  320. .tab {
  321. padding: 15px 0;
  322. border-radius: 0;
  323. }
  324. }
  325. .no-reports {
  326. text-align: center;
  327. }
  328. .report-items {
  329. .report-item {
  330. background-color: var(--white);
  331. border: 0.5px solid var(--primary-color);
  332. border-radius: @border-radius;
  333. padding: 8px;
  334. &:not(:first-of-type) {
  335. margin-bottom: 16px;
  336. }
  337. .report-item-header {
  338. justify-content: center;
  339. text-transform: capitalize;
  340. i {
  341. margin-right: 5px;
  342. }
  343. }
  344. .report-sub-items {
  345. .report-sub-item {
  346. border: 0.5px solid var(--black);
  347. margin-top: -1px;
  348. line-height: 24px;
  349. display: flex;
  350. padding: 4px;
  351. display: flex;
  352. &:first-child {
  353. border-radius: @border-radius @border-radius 0 0;
  354. }
  355. &:last-child {
  356. border-radius: 0 0 @border-radius @border-radius;
  357. }
  358. &.report-sub-item-resolved {
  359. .report-sub-item-description,
  360. .report-sub-item-title {
  361. text-decoration: line-through;
  362. }
  363. }
  364. .report-sub-item-left-icon {
  365. margin-right: 8px;
  366. margin-top: auto;
  367. margin-bottom: auto;
  368. }
  369. .report-sub-item-info {
  370. flex: 1;
  371. display: flex;
  372. flex-direction: column;
  373. .report-sub-item-title {
  374. font-size: 14px;
  375. }
  376. .report-sub-item-description {
  377. font-size: 12px;
  378. line-height: 16px;
  379. }
  380. }
  381. .report-sub-item-actions {
  382. height: 24px;
  383. margin-left: 8px;
  384. margin-top: auto;
  385. margin-bottom: auto;
  386. }
  387. }
  388. }
  389. .resolve-icon {
  390. color: var(--green);
  391. cursor: pointer;
  392. }
  393. .unresolve-icon {
  394. color: var(--dark-red);
  395. cursor: pointer;
  396. }
  397. }
  398. }
  399. </style>