Reports.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  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 ReportInfoItem from "@/components/ReportInfoItem.vue";
  184. import { mapState, mapGetters, mapActions } from "vuex";
  185. import Toast from "toasters";
  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. console.log("being toggled twice?");
  241. this.reports.forEach((report, index) => {
  242. if (report._id === res.data.reportId) {
  243. const issue = this.reports[index].issues.find(
  244. issue => issue._id.toString() === res.data.issueId
  245. );
  246. issue.resolved = !issue.resolved;
  247. }
  248. });
  249. },
  250. { modal: "editSong" }
  251. );
  252. },
  253. methods: {
  254. showTab(tab) {
  255. this.$refs[`${tab}-tab`].scrollIntoView();
  256. this.tab = tab;
  257. },
  258. resolve(reportId) {
  259. this.socket.dispatch(
  260. "reports.resolve",
  261. reportId,
  262. res => new Toast(res.message)
  263. );
  264. },
  265. toggleIssue(reportId, issueId) {
  266. this.socket.dispatch(
  267. "reports.toggleIssue",
  268. reportId,
  269. issueId,
  270. res => {
  271. if (res.status !== "success") new Toast(res.message);
  272. }
  273. );
  274. },
  275. ...mapActions("modals/editSong", ["resolveReport"]),
  276. ...mapActions("modalVisibility", ["closeModal"])
  277. }
  278. };
  279. </script>
  280. <style lang="scss" scoped>
  281. .night-mode {
  282. .report-items .report-item {
  283. background-color: var(--dark-grey-3) !important;
  284. }
  285. .report-items .report-item .report-item-header {
  286. background-color: var(--dark-grey-2) !important;
  287. }
  288. .label,
  289. p,
  290. strong {
  291. color: var(--light-grey-2);
  292. }
  293. }
  294. .tabs-container {
  295. .tab-selection {
  296. display: flex;
  297. overflow-x: auto;
  298. .button {
  299. border-radius: 0;
  300. border: 0;
  301. text-transform: uppercase;
  302. font-size: 14px;
  303. color: var(--dark-grey-3);
  304. background-color: var(--light-grey-2);
  305. flex-grow: 1;
  306. height: 32px;
  307. &:not(:first-of-type) {
  308. margin-left: 5px;
  309. }
  310. }
  311. .selected {
  312. background-color: var(--primary-color) !important;
  313. color: var(--white) !important;
  314. font-weight: 600;
  315. }
  316. }
  317. .tab {
  318. padding: 15px 0;
  319. border-radius: 0;
  320. }
  321. }
  322. .no-reports {
  323. text-align: center;
  324. }
  325. .report-items {
  326. .report-item {
  327. background-color: var(--white);
  328. border: 0.5px solid var(--primary-color);
  329. border-radius: 5px;
  330. padding: 8px;
  331. &:not(:first-of-type) {
  332. margin-bottom: 16px;
  333. }
  334. .report-item-header {
  335. justify-content: center;
  336. text-transform: capitalize;
  337. i {
  338. margin-right: 5px;
  339. }
  340. }
  341. .report-sub-items {
  342. .report-sub-item {
  343. border: 0.5px solid var(--black);
  344. margin-top: -1px;
  345. line-height: 24px;
  346. display: flex;
  347. padding: 4px;
  348. display: flex;
  349. &:first-child {
  350. border-radius: 3px 3px 0 0;
  351. }
  352. &:last-child {
  353. border-radius: 0 0 3px 3px;
  354. }
  355. &.report-sub-item-resolved {
  356. .report-sub-item-description,
  357. .report-sub-item-title {
  358. text-decoration: line-through;
  359. }
  360. }
  361. .report-sub-item-left-icon {
  362. margin-right: 8px;
  363. margin-top: auto;
  364. margin-bottom: auto;
  365. }
  366. .report-sub-item-info {
  367. flex: 1;
  368. display: flex;
  369. flex-direction: column;
  370. .report-sub-item-title {
  371. font-size: 14px;
  372. }
  373. .report-sub-item-description {
  374. font-size: 12px;
  375. line-height: 16px;
  376. }
  377. }
  378. .report-sub-item-actions {
  379. height: 24px;
  380. margin-left: 8px;
  381. margin-top: auto;
  382. margin-bottom: auto;
  383. }
  384. }
  385. }
  386. .resolve-icon {
  387. color: var(--green);
  388. cursor: pointer;
  389. }
  390. .unresolve-icon {
  391. color: var(--red);
  392. cursor: pointer;
  393. }
  394. }
  395. }
  396. </style>