Reports.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  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 { mapGetters, mapActions } from "vuex";
  184. import Toast from "toasters";
  185. import { mapModalState, mapModalActions } from "@/vuex_helpers";
  186. import ReportInfoItem from "@/components/ReportInfoItem.vue";
  187. export default {
  188. components: { ReportInfoItem },
  189. props: {
  190. modalUuid: { type: String, default: "" },
  191. modalModulePath: { type: String, default: "modals/editSong/MODAL_UUID" }
  192. },
  193. data() {
  194. return {
  195. tab: "sort-by-report",
  196. icons: {
  197. duration: "timer",
  198. video: "tv",
  199. thumbnail: "image",
  200. artists: "record_voice_over",
  201. title: "title",
  202. custom: "lightbulb"
  203. }
  204. };
  205. },
  206. computed: {
  207. ...mapModalState("MODAL_MODULE_PATH", {
  208. reports: state => state.reports
  209. }),
  210. ...mapGetters({
  211. socket: "websockets/getSocket"
  212. }),
  213. sortedByCategory() {
  214. const categories = {};
  215. this.reports.forEach(report =>
  216. report.issues.forEach(issue => {
  217. if (categories[issue.category])
  218. categories[issue.category].push({
  219. ...issue,
  220. reportId: report._id
  221. });
  222. else
  223. categories[issue.category] = [
  224. { ...issue, reportId: report._id }
  225. ];
  226. })
  227. );
  228. return categories;
  229. }
  230. },
  231. mounted() {
  232. this.socket.on(
  233. "event:admin.report.created",
  234. res => this.reports.unshift(res.data.report),
  235. { modalUuid: this.modalUuid }
  236. );
  237. this.socket.on(
  238. "event:admin.report.resolved",
  239. res => this.resolveReport(res.data.reportId),
  240. { modalUuid: this.modalUuid }
  241. );
  242. this.socket.on(
  243. "event:admin.report.issue.toggled",
  244. res => {
  245. this.reports.forEach((report, index) => {
  246. if (report._id === res.data.reportId) {
  247. const issue = this.reports[index].issues.find(
  248. issue => issue._id.toString() === res.data.issueId
  249. );
  250. issue.resolved = res.data.resolved;
  251. }
  252. });
  253. },
  254. { modalUuid: this.modalUuid }
  255. );
  256. },
  257. methods: {
  258. showTab(tab) {
  259. this.$refs[`${tab}-tab`].scrollIntoView({ block: "nearest" });
  260. this.tab = tab;
  261. },
  262. resolve(reportId) {
  263. this.socket.dispatch(
  264. "reports.resolve",
  265. reportId,
  266. res => new Toast(res.message)
  267. );
  268. },
  269. toggleIssue(reportId, issueId) {
  270. this.socket.dispatch(
  271. "reports.toggleIssue",
  272. reportId,
  273. issueId,
  274. res => {
  275. if (res.status !== "success") new Toast(res.message);
  276. }
  277. );
  278. },
  279. ...mapModalActions("MODAL_MODULE_PATH", ["resolveReport"]),
  280. ...mapActions("modalVisibility", ["closeModal"])
  281. }
  282. };
  283. </script>
  284. <style lang="less" scoped>
  285. .night-mode {
  286. .report-items .report-item {
  287. background-color: var(--dark-grey-3) !important;
  288. }
  289. .report-items .report-item .report-item-header {
  290. background-color: var(--dark-grey-2) !important;
  291. }
  292. .label,
  293. p,
  294. strong {
  295. color: var(--light-grey-2);
  296. }
  297. .tabs-container .tab-selection .button {
  298. background: var(--dark-grey) !important;
  299. color: var(--white) !important;
  300. }
  301. }
  302. .reports-tab.tabs-container {
  303. .tab-selection {
  304. display: flex;
  305. overflow-x: auto;
  306. .button {
  307. border-radius: 0;
  308. border: 0;
  309. text-transform: uppercase;
  310. font-size: 14px;
  311. color: var(--dark-grey-3);
  312. background-color: var(--light-grey-2);
  313. flex-grow: 1;
  314. height: 32px;
  315. &:not(:first-of-type) {
  316. margin-left: 5px;
  317. }
  318. }
  319. .selected {
  320. background-color: var(--primary-color) !important;
  321. color: var(--white) !important;
  322. font-weight: 600;
  323. }
  324. }
  325. .tab {
  326. padding: 15px 0;
  327. border-radius: 0;
  328. }
  329. }
  330. .no-reports {
  331. text-align: center;
  332. }
  333. .report-items {
  334. .report-item {
  335. background-color: var(--white);
  336. border: 0.5px solid var(--primary-color);
  337. border-radius: @border-radius;
  338. padding: 8px;
  339. &:not(:first-of-type) {
  340. margin-bottom: 16px;
  341. }
  342. .report-item-header {
  343. justify-content: center;
  344. text-transform: capitalize;
  345. i {
  346. margin-right: 5px;
  347. }
  348. }
  349. .report-sub-items {
  350. .report-sub-item {
  351. border: 0.5px solid var(--black);
  352. margin-top: -1px;
  353. line-height: 24px;
  354. display: flex;
  355. padding: 4px;
  356. display: flex;
  357. &:first-child {
  358. border-radius: @border-radius @border-radius 0 0;
  359. }
  360. &:last-child {
  361. border-radius: 0 0 @border-radius @border-radius;
  362. }
  363. &.report-sub-item-resolved {
  364. .report-sub-item-description,
  365. .report-sub-item-title {
  366. text-decoration: line-through;
  367. }
  368. }
  369. .report-sub-item-left-icon {
  370. margin-right: 8px;
  371. margin-top: auto;
  372. margin-bottom: auto;
  373. }
  374. .report-sub-item-info {
  375. flex: 1;
  376. display: flex;
  377. flex-direction: column;
  378. .report-sub-item-title {
  379. font-size: 14px;
  380. }
  381. .report-sub-item-description {
  382. font-size: 12px;
  383. line-height: 16px;
  384. }
  385. }
  386. .report-sub-item-actions {
  387. height: 24px;
  388. margin-left: 8px;
  389. margin-top: auto;
  390. margin-bottom: auto;
  391. }
  392. }
  393. }
  394. .resolve-icon {
  395. color: var(--green);
  396. cursor: pointer;
  397. }
  398. .unresolve-icon {
  399. color: var(--dark-red);
  400. cursor: pointer;
  401. }
  402. }
  403. }
  404. </style>