admin.js 4.5 KB

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