admin.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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. stationRemoved: ({ commit }, stationId) =>
  110. commit("stationRemoved", stationId),
  111. stationAdded: ({ commit }, station) =>
  112. commit("stationAdded", station)
  113. },
  114. mutations: {
  115. editStation(state, station) {
  116. state.station = station;
  117. state.editing = JSON.parse(JSON.stringify(station));
  118. },
  119. stationAdded(state, station) {
  120. state.stations.push(station);
  121. },
  122. stationRemoved(state, stationId) {
  123. state.stations = state.stations.filter(station => {
  124. return station._id !== stationId;
  125. });
  126. }
  127. }
  128. },
  129. reports: {
  130. namespaced: true,
  131. state: {
  132. report: {}
  133. },
  134. getters: {},
  135. actions: {
  136. viewReport: ({ commit }, report) => commit("viewReport", report),
  137. /* eslint-disable-next-line no-unused-vars */
  138. resolveReport: ({ commit }, reportId) => {
  139. return new Promise((resolve, reject) => {
  140. return admin.reports
  141. .resolve(reportId)
  142. .then(res => {
  143. return resolve(res);
  144. })
  145. .catch(err => {
  146. return reject(new Error(err.message));
  147. });
  148. });
  149. }
  150. },
  151. mutations: {
  152. viewReport(state, report) {
  153. state.report = report;
  154. }
  155. }
  156. },
  157. punishments: {
  158. namespaced: true,
  159. state: {
  160. punishment: {}
  161. },
  162. getters: {},
  163. actions: {
  164. viewPunishment: ({ commit }, punishment) =>
  165. commit("viewPunishment", punishment)
  166. },
  167. mutations: {
  168. viewPunishment(state, punishment) {
  169. state.punishment = punishment;
  170. }
  171. }
  172. },
  173. users: {
  174. namespaced: true,
  175. state: {
  176. editing: {}
  177. },
  178. getters: {},
  179. actions: {
  180. editUser: ({ commit }, user) => commit("editUser", user)
  181. },
  182. mutations: {
  183. editUser(state, user) {
  184. state.editing = user;
  185. }
  186. }
  187. },
  188. news: {
  189. namespaced: true,
  190. state: {
  191. editing: {}
  192. },
  193. getters: {},
  194. actions: {
  195. editNews: ({ commit }, news) => commit("editNews", news),
  196. addChange: ({ commit }, data) => commit("addChange", data),
  197. removeChange: ({ commit }, data) => commit("removeChange", data)
  198. },
  199. mutations: {
  200. editNews(state, news) {
  201. state.editing = news;
  202. },
  203. addChange(state, data) {
  204. state.editing[data.type].push(data.change);
  205. },
  206. removeChange(state, data) {
  207. state.editing[data.type].splice(data.index, 1);
  208. }
  209. }
  210. }
  211. };
  212. export default {
  213. namespaced: true,
  214. state,
  215. getters,
  216. actions,
  217. mutations,
  218. modules
  219. };