Report.vue 6.4 KB

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