admin.js 4.9 KB

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