longJobs.ts 1.1 KB

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