Report.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. <template>
  2. <modal title="Report">
  3. <div slot="body">
  4. <div class="columns song-types">
  5. <div v-if="previousSong !== null" class="column song-type">
  6. <div
  7. class="card is-fullwidth"
  8. :class="{ 'is-highlight-active': isPreviousSongActive }"
  9. @click="highlight('previousSong')"
  10. >
  11. <header class="card-header">
  12. <p class="card-header-title">Previous Song</p>
  13. </header>
  14. <div class="card-content">
  15. <article class="media">
  16. <figure class="media-left">
  17. <song-thumbnail
  18. class="image is-64x64"
  19. :song="previousSong"
  20. />
  21. </figure>
  22. <div class="media-content">
  23. <div class="content">
  24. <p>
  25. <strong>{{
  26. previousSong.title
  27. }}</strong>
  28. <br />
  29. <small>{{
  30. previousSong.artists.join(", ")
  31. }}</small>
  32. </p>
  33. </div>
  34. </div>
  35. </article>
  36. </div>
  37. <a
  38. href="#"
  39. class="absolute-a"
  40. @click="highlight('previousSong')"
  41. />
  42. </div>
  43. </div>
  44. <div v-if="localSong !== null" class="column song-type">
  45. <div
  46. class="card is-fullwidth"
  47. :class="{ 'is-highlight-active': isLocalSongActive }"
  48. @click="highlight('localSong')"
  49. >
  50. <header class="card-header">
  51. <p class="card-header-title">Selected Song</p>
  52. </header>
  53. <div class="card-content">
  54. <article class="media">
  55. <figure class="media-left">
  56. <song-thumbnail
  57. class="image is-64x64"
  58. :song="localSong"
  59. />
  60. </figure>
  61. <div class="media-content">
  62. <div class="content">
  63. <p>
  64. <strong>{{
  65. localSong.title
  66. }}</strong>
  67. <br />
  68. <small>{{
  69. localSong.artists.join(", ")
  70. }}</small>
  71. </p>
  72. </div>
  73. </div>
  74. </article>
  75. </div>
  76. <a
  77. href="#"
  78. class="absolute-a"
  79. @click="highlight('localSong')"
  80. />
  81. </div>
  82. </div>
  83. </div>
  84. <div class="edit-report-wrapper">
  85. <div class="columns is-multiline">
  86. <div
  87. v-for="(issue, issueIndex) in issues"
  88. class="column is-half"
  89. :key="issueIndex"
  90. >
  91. <label class="label">{{ issue.name }}</label>
  92. <p
  93. v-for="(reason, reasonIndex) in issue.reasons"
  94. class="control"
  95. :key="reasonIndex"
  96. >
  97. <label class="checkbox">
  98. <input
  99. type="checkbox"
  100. @click="toggleIssue(issue.name, reason)"
  101. />
  102. {{ reason }}
  103. </label>
  104. </p>
  105. </div>
  106. <div class="column">
  107. <label class="label">Other</label>
  108. <textarea
  109. v-model="report.description"
  110. class="textarea"
  111. maxlength="400"
  112. placeholder="Any other details..."
  113. />
  114. <div class="textarea-counter">
  115. {{ charactersRemaining }}
  116. </div>
  117. </div>
  118. </div>
  119. </div>
  120. </div>
  121. <div slot="footer">
  122. <a class="button is-success" @click="create()" href="#">
  123. <i class="material-icons save-changes">done</i>
  124. <span>&nbsp;Create</span>
  125. </a>
  126. <a class="button is-danger" href="#" @click="closeModal('report')">
  127. <span>&nbsp;Cancel</span>
  128. </a>
  129. </div>
  130. </modal>
  131. </template>
  132. <script>
  133. import { mapState, mapGetters, mapActions } from "vuex";
  134. import Toast from "toasters";
  135. import Modal from "../Modal.vue";
  136. import SongThumbnail from "../SongThumbnail.vue";
  137. export default {
  138. components: { Modal, SongThumbnail },
  139. data() {
  140. return {
  141. isPreviousSongActive: false,
  142. isLocalSongActive: true,
  143. localSong: null,
  144. report: {
  145. resolved: false,
  146. youtubeId: "",
  147. description: "",
  148. issues: [
  149. { name: "Video", reasons: [] },
  150. { name: "Title", reasons: [] },
  151. { name: "Duration", reasons: [] },
  152. { name: "Artists", reasons: [] },
  153. { name: "Thumbnail", reasons: [] }
  154. ]
  155. },
  156. issues: [
  157. {
  158. name: "Video",
  159. reasons: [
  160. "Doesn't exist",
  161. "It's private",
  162. "It's not available in my country",
  163. "Unofficial"
  164. ]
  165. },
  166. {
  167. name: "Title",
  168. reasons: ["Incorrect", "Inappropriate"]
  169. },
  170. {
  171. name: "Duration",
  172. reasons: [
  173. "Skips too soon",
  174. "Skips too late",
  175. "Starts too soon",
  176. "Starts too late"
  177. ]
  178. },
  179. {
  180. name: "Artists",
  181. reasons: ["Incorrect", "Inappropriate"]
  182. },
  183. {
  184. name: "Thumbnail",
  185. reasons: ["Incorrect", "Inappropriate", "Doesn't exist"]
  186. }
  187. ]
  188. };
  189. },
  190. computed: {
  191. charactersRemaining() {
  192. return 400 - this.report.description.length;
  193. },
  194. ...mapState({
  195. previousSong: state => state.station.previousSong,
  196. song: state => state.modals.report.song
  197. }),
  198. ...mapGetters({
  199. socket: "websockets/getSocket"
  200. })
  201. },
  202. mounted() {
  203. if (this.song !== null) {
  204. this.localSong = this.song;
  205. this.report.youtubeId = this.song.youtubeId;
  206. this.reportSong(null);
  207. }
  208. },
  209. methods: {
  210. create() {
  211. this.socket.dispatch("reports.create", this.report, res => {
  212. new Toast(res.message);
  213. if (res.status === "success") this.closeModal("report");
  214. });
  215. },
  216. highlight(type) {
  217. if (type === "localSong") {
  218. this.report.youtubeId = this.localSong.youtubeId;
  219. this.isPreviousSongActive = false;
  220. this.isLocalSongActive = true;
  221. } else if (type === "previousSong") {
  222. this.report.youtubeId = this.previousSong.youtubeId;
  223. this.isLocalSongActive = false;
  224. this.isPreviousSongActive = true;
  225. }
  226. },
  227. toggleIssue(name, reason) {
  228. for (let z = 0; z < this.report.issues.length; z += 1) {
  229. if (this.report.issues[z].name === name) {
  230. if (this.report.issues[z].reasons.indexOf(reason) > -1) {
  231. this.report.issues[z].reasons.splice(
  232. this.report.issues[z].reasons.indexOf(reason),
  233. 1
  234. );
  235. } else this.report.issues[z].reasons.push(reason);
  236. }
  237. }
  238. },
  239. ...mapActions("modals/report", ["reportSong"]),
  240. ...mapActions("modalVisibility", ["closeModal"])
  241. }
  242. };
  243. </script>
  244. <style lang="scss" scoped>
  245. h6 {
  246. margin-bottom: 15px;
  247. }
  248. .song-type:first-of-type {
  249. padding-left: 0;
  250. }
  251. .song-type:last-of-type {
  252. padding-right: 0;
  253. }
  254. .thumbnail.image.is-64x64 {
  255. min-width: 64px;
  256. margin: 0;
  257. }
  258. .media-content {
  259. display: flex;
  260. align-items: center;
  261. height: 64px;
  262. }
  263. .radio-controls .control {
  264. display: flex;
  265. align-items: center;
  266. }
  267. .textarea-counter {
  268. text-align: right;
  269. }
  270. @media screen and (min-width: 769px) {
  271. .radio-controls .control-label {
  272. padding-top: 0 !important;
  273. }
  274. }
  275. .card {
  276. border-radius: 5px;
  277. }
  278. .columns {
  279. margin-left: unset;
  280. margin-right: unset;
  281. }
  282. .is-highlight-active {
  283. border: 3px var(--primary-color) solid;
  284. }
  285. </style>