Report.vue 6.7 KB

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