admin.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /* eslint no-param-reassign: 0 */
  2. import Vue from "vue";
  3. const state = {};
  4. const getters = {};
  5. const actions = {};
  6. const mutations = {};
  7. const modules = {
  8. songs: {
  9. namespaced: true,
  10. state: {
  11. video: {
  12. player: null,
  13. paused: true,
  14. playerReady: false,
  15. autoPlayed: false,
  16. currentTime: 0
  17. },
  18. editing: {},
  19. songs: []
  20. },
  21. getters: {},
  22. actions: {
  23. editSong: ({ commit }, song) => commit("editSong", song),
  24. stopVideo: ({ commit }) => commit("stopVideo"),
  25. loadVideoById: ({ commit }, id, skipDuration) =>
  26. commit("loadVideoById", id, skipDuration),
  27. pauseVideo: ({ commit }, status) => commit("pauseVideo", status),
  28. getCurrentTime: ({ commit, state }, fixedVal) => {
  29. return new Promise(resolve => {
  30. commit("getCurrentTime", fixedVal);
  31. resolve(state.video.currentTime);
  32. });
  33. },
  34. addSong: ({ commit }, song) => commit("addSong", song),
  35. removeSong: ({ commit }, songId) => commit("removeSong", songId),
  36. updateSong: ({ commit }, updatedSong) =>
  37. commit("updateSong", updatedSong),
  38. updateSongField: ({ commit }, data) =>
  39. commit("updateSongField", data),
  40. selectDiscogsInfo: ({ commit }, discogsInfo) =>
  41. commit("selectDiscogsInfo", discogsInfo)
  42. },
  43. mutations: {
  44. editSong(state, song) {
  45. if (song.song.discogs === undefined) song.song.discogs = null;
  46. state.editing = { ...song };
  47. },
  48. stopVideo(state) {
  49. state.video.player.stopVideo();
  50. },
  51. loadVideoById(state, id, skipDuration) {
  52. state.video.player.loadVideoById(id, skipDuration);
  53. },
  54. pauseVideo(state, status) {
  55. if (status) state.video.player.pauseVideo();
  56. else state.video.player.playVideo();
  57. state.video.paused = status;
  58. },
  59. getCurrentTime(state, fixedVal) {
  60. if (!state.playerReady) state.video.currentTime = 0;
  61. else {
  62. Promise.resolve(state.video.player.getCurrentTime()).then(
  63. time => {
  64. if (fixedVal)
  65. Promise.resolve(time.toFixed(fixedVal)).then(
  66. fixedTime => {
  67. state.video.currentTime = fixedTime;
  68. }
  69. );
  70. else state.video.currentTime = time;
  71. }
  72. );
  73. }
  74. },
  75. addSong(state, song) {
  76. state.songs.push(song);
  77. },
  78. removeSong(state, songId) {
  79. state.songs = state.songs.filter(song => {
  80. return song._id !== songId;
  81. });
  82. },
  83. updateSong(state, updatedSong) {
  84. state.songs.forEach((song, index) => {
  85. if (song._id === updatedSong._id)
  86. Vue.set(state.songs, index, updatedSong);
  87. });
  88. },
  89. updateSongField(state, data) {
  90. state.editing.song[data.field] = data.value;
  91. },
  92. selectDiscogsInfo(state, discogsInfo) {
  93. state.editing.song.discogs = discogsInfo;
  94. }
  95. }
  96. },
  97. stations: {
  98. namespaced: true,
  99. state: {
  100. station: {},
  101. editing: {}
  102. },
  103. getters: {},
  104. actions: {
  105. editStation: ({ commit }, station) => commit("editStation", station)
  106. },
  107. mutations: {
  108. editStation(state, station) {
  109. state.station = station;
  110. state.editing = JSON.parse(JSON.stringify(station));
  111. }
  112. }
  113. },
  114. reports: {
  115. namespaced: true,
  116. state: {
  117. report: {}
  118. },
  119. getters: {},
  120. actions: {
  121. viewReport: ({ commit }, report) => commit("viewReport", report)
  122. },
  123. mutations: {
  124. viewReport(state, report) {
  125. state.report = report;
  126. }
  127. }
  128. },
  129. punishments: {
  130. namespaced: true,
  131. state: {
  132. punishment: {}
  133. },
  134. getters: {},
  135. actions: {
  136. viewPunishment: ({ commit }, punishment) =>
  137. commit("viewPunishment", punishment)
  138. },
  139. mutations: {
  140. viewPunishment(state, punishment) {
  141. state.punishment = punishment;
  142. }
  143. }
  144. },
  145. users: {
  146. namespaced: true,
  147. state: {
  148. editing: {}
  149. },
  150. getters: {},
  151. actions: {
  152. editUser: ({ commit }, user) => commit("editUser", user)
  153. },
  154. mutations: {
  155. editUser(state, user) {
  156. state.editing = user;
  157. }
  158. }
  159. },
  160. news: {
  161. namespaced: true,
  162. state: {
  163. editing: {}
  164. },
  165. getters: {},
  166. actions: {
  167. editNews: ({ commit }, news) => commit("editNews", news),
  168. addChange: ({ commit }, data) => commit("addChange", data),
  169. removeChange: ({ commit }, data) => commit("removeChange", data)
  170. },
  171. mutations: {
  172. editNews(state, news) {
  173. state.editing = news;
  174. },
  175. addChange(state, data) {
  176. state.editing[data.type].push(data.change);
  177. },
  178. removeChange(state, data) {
  179. state.editing[data.type].splice(data.index, 1);
  180. }
  181. }
  182. }
  183. };
  184. export default {
  185. namespaced: true,
  186. state,
  187. getters,
  188. actions,
  189. mutations,
  190. modules
  191. };