admin.js 5.5 KB

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