admin.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. songs: []
  13. },
  14. getters: {},
  15. actions: {
  16. addSong: ({ commit }, song) => commit("addSong", song),
  17. removeSong: ({ commit }, songId) => commit("removeSong", songId),
  18. updateSong: ({ commit }, updatedSong) =>
  19. commit("updateSong", updatedSong)
  20. },
  21. mutations: {
  22. addSong(state, song) {
  23. state.songs.push(song);
  24. },
  25. removeSong(state, songId) {
  26. state.songs = state.songs.filter(song => {
  27. return song._id !== songId;
  28. });
  29. },
  30. updateSong(state, updatedSong) {
  31. state.songs.forEach((song, index) => {
  32. if (song._id === updatedSong._id)
  33. Vue.set(state.songs, index, updatedSong);
  34. });
  35. }
  36. }
  37. },
  38. stations: {
  39. namespaced: true,
  40. state: {
  41. stations: [],
  42. station: {},
  43. editing: {}
  44. },
  45. getters: {},
  46. actions: {
  47. editStation: ({ commit }, station) =>
  48. commit("editStation", station),
  49. loadStations: ({ commit }, stations) =>
  50. commit("loadStations", stations),
  51. stationRemoved: ({ commit }, stationId) =>
  52. commit("stationRemoved", stationId),
  53. stationAdded: ({ commit }, station) =>
  54. commit("stationAdded", station)
  55. },
  56. mutations: {
  57. editStation(state, station) {
  58. state.station = station;
  59. state.editing = JSON.parse(JSON.stringify(station));
  60. },
  61. loadStations(state, stations) {
  62. state.stations = stations;
  63. },
  64. stationAdded(state, station) {
  65. state.stations.push(station);
  66. },
  67. stationRemoved(state, stationId) {
  68. state.stations = state.stations.filter(station => {
  69. return station._id !== stationId;
  70. });
  71. }
  72. }
  73. },
  74. reports: {
  75. namespaced: true,
  76. state: {
  77. report: {}
  78. },
  79. getters: {},
  80. actions: {
  81. viewReport: ({ commit }, report) => commit("viewReport", report),
  82. /* eslint-disable-next-line no-unused-vars */
  83. resolveReport: ({ commit }, reportId) => {
  84. return new Promise((resolve, reject) => {
  85. return admin.reports
  86. .resolve(reportId)
  87. .then(res => {
  88. return resolve(res);
  89. })
  90. .catch(err => {
  91. return reject(new Error(err.message));
  92. });
  93. });
  94. }
  95. },
  96. mutations: {
  97. viewReport(state, report) {
  98. state.report = report;
  99. }
  100. }
  101. },
  102. punishments: {
  103. namespaced: true,
  104. state: {
  105. punishment: {}
  106. },
  107. getters: {},
  108. actions: {
  109. viewPunishment: ({ commit }, punishment) =>
  110. commit("viewPunishment", punishment)
  111. },
  112. mutations: {
  113. viewPunishment(state, punishment) {
  114. state.punishment = punishment;
  115. }
  116. }
  117. },
  118. users: {
  119. namespaced: true,
  120. state: {
  121. editing: {}
  122. },
  123. getters: {},
  124. actions: {
  125. editUser: ({ commit }, user) => commit("editUser", user)
  126. },
  127. mutations: {
  128. editUser(state, user) {
  129. state.editing = user;
  130. }
  131. }
  132. },
  133. news: {
  134. namespaced: true,
  135. state: {
  136. editing: {},
  137. news: []
  138. },
  139. getters: {},
  140. actions: {
  141. editNews: ({ commit }, news) => commit("editNews", news),
  142. addChange: ({ commit }, data) => commit("addChange", data),
  143. removeChange: ({ commit }, data) => commit("removeChange", data),
  144. addNews: ({ commit }, news) => commit("addNews", news),
  145. removeNews: ({ commit }, newsId) => commit("removeNews", newsId),
  146. updateNews: ({ commit }, updatedNews) =>
  147. commit("updateNews", updatedNews)
  148. },
  149. mutations: {
  150. editNews(state, news) {
  151. state.editing = news;
  152. },
  153. addChange(state, data) {
  154. state.editing[data.type].push(data.change);
  155. },
  156. removeChange(state, data) {
  157. state.editing[data.type].splice(data.index, 1);
  158. },
  159. addNews(state, news) {
  160. state.news.push(news);
  161. },
  162. removeNews(state, newsId) {
  163. state.news = state.news.filter(news => {
  164. return news._id !== newsId;
  165. });
  166. },
  167. updateNews(state, updatedNews) {
  168. state.news.forEach((news, index) => {
  169. if (news._id === updatedNews._id)
  170. Vue.set(state.news, index, updatedNews);
  171. });
  172. }
  173. }
  174. }
  175. };
  176. export default {
  177. namespaced: true,
  178. state,
  179. getters,
  180. actions,
  181. mutations,
  182. modules
  183. };