admin.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. },
  43. getters: {},
  44. actions: {
  45. loadStations: ({ commit }, stations) =>
  46. commit("loadStations", stations),
  47. stationRemoved: ({ commit }, stationId) =>
  48. commit("stationRemoved", stationId),
  49. stationAdded: ({ commit }, station) =>
  50. commit("stationAdded", station)
  51. },
  52. mutations: {
  53. loadStations(state, stations) {
  54. state.stations = stations;
  55. },
  56. stationAdded(state, station) {
  57. state.stations.push(station);
  58. },
  59. stationRemoved(state, stationId) {
  60. state.stations = state.stations.filter(station => {
  61. return station._id !== stationId;
  62. });
  63. }
  64. }
  65. },
  66. reports: {
  67. namespaced: true,
  68. state: {
  69. report: {}
  70. },
  71. getters: {},
  72. actions: {
  73. viewReport: ({ commit }, report) => commit("viewReport", report),
  74. /* eslint-disable-next-line no-unused-vars */
  75. resolveReport: ({ commit }, reportId) => {
  76. return new Promise((resolve, reject) => {
  77. return admin.reports
  78. .resolve(reportId)
  79. .then(res => {
  80. return resolve(res);
  81. })
  82. .catch(err => {
  83. return reject(new Error(err.message));
  84. });
  85. });
  86. }
  87. },
  88. mutations: {
  89. viewReport(state, report) {
  90. state.report = report;
  91. }
  92. }
  93. },
  94. punishments: {
  95. namespaced: true,
  96. state: {
  97. punishment: {}
  98. },
  99. getters: {},
  100. actions: {
  101. viewPunishment: ({ commit }, punishment) =>
  102. commit("viewPunishment", punishment)
  103. },
  104. mutations: {
  105. viewPunishment(state, punishment) {
  106. state.punishment = punishment;
  107. }
  108. }
  109. },
  110. users: {
  111. namespaced: true,
  112. state: {},
  113. getters: {},
  114. actions: {},
  115. mutations: {}
  116. },
  117. news: {
  118. namespaced: true,
  119. state: {
  120. editing: {},
  121. news: []
  122. },
  123. getters: {},
  124. actions: {
  125. editNews: ({ commit }, news) => commit("editNews", news),
  126. addChange: ({ commit }, data) => commit("addChange", data),
  127. removeChange: ({ commit }, data) => commit("removeChange", data),
  128. addNews: ({ commit }, news) => commit("addNews", news),
  129. removeNews: ({ commit }, newsId) => commit("removeNews", newsId),
  130. updateNews: ({ commit }, updatedNews) =>
  131. commit("updateNews", updatedNews)
  132. },
  133. mutations: {
  134. editNews(state, news) {
  135. state.editing = news;
  136. },
  137. addChange(state, data) {
  138. state.editing[data.type].push(data.change);
  139. },
  140. removeChange(state, data) {
  141. state.editing[data.type].splice(data.index, 1);
  142. },
  143. addNews(state, news) {
  144. state.news.push(news);
  145. },
  146. removeNews(state, newsId) {
  147. state.news = state.news.filter(news => {
  148. return news._id !== newsId;
  149. });
  150. },
  151. updateNews(state, updatedNews) {
  152. state.news.forEach((news, index) => {
  153. if (news._id === updatedNews._id)
  154. Vue.set(state.news, index, updatedNews);
  155. });
  156. }
  157. }
  158. }
  159. };
  160. export default {
  161. namespaced: true,
  162. state,
  163. getters,
  164. actions,
  165. mutations,
  166. modules
  167. };