longJobs.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /* eslint no-param-reassign: 0 */
  2. const state = {
  3. activeJobs: [
  4. // {
  5. // id: 1,
  6. // name: "test",
  7. // status: "success",
  8. // message: "test"
  9. // }
  10. ]
  11. };
  12. const getters = {};
  13. const actions = {
  14. setJob: ({ commit }, job) => commit("setJob", job),
  15. setJobs: ({ commit }, jobs) => commit("setJobs", jobs),
  16. removeJob: ({ commit }, job) => commit("removeJob", job)
  17. };
  18. const mutations = {
  19. setJob(state, { id, name, status, message }) {
  20. if (status === "started")
  21. state.activeJobs.push({
  22. id,
  23. name,
  24. status
  25. });
  26. else
  27. state.activeJobs.forEach((activeJob, index) => {
  28. if (activeJob.id === id) {
  29. state.activeJobs[index] = {
  30. ...state.activeJobs[index],
  31. status,
  32. message
  33. };
  34. }
  35. });
  36. },
  37. setJobs(state, jobs) {
  38. state.activeJobs = jobs;
  39. },
  40. removeJob(state, jobId) {
  41. state.activeJobs.forEach((activeJob, index) => {
  42. if (activeJob.id === jobId) {
  43. state.activeJobs.splice(index, 1);
  44. }
  45. });
  46. }
  47. };
  48. export default {
  49. namespaced: true,
  50. state,
  51. getters,
  52. actions,
  53. mutations
  54. };