longJobs.js 1.0 KB

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