longJobs.ts 1019 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { defineStore } from "pinia";
  2. export const useLongJobsStore = defineStore("longJobs", {
  3. state: (): {
  4. activeJobs: {
  5. id: string;
  6. name: string;
  7. status: string;
  8. message: string;
  9. }[];
  10. removedJobIds: string[];
  11. } => ({
  12. activeJobs: [],
  13. removedJobIds: []
  14. }),
  15. actions: {
  16. setJob({ id, name, status, message }) {
  17. if (this.removedJobIds.indexOf(id) === -1)
  18. if (!this.activeJobs.find(activeJob => activeJob.id === id))
  19. this.activeJobs.push({
  20. id,
  21. name,
  22. status,
  23. message
  24. });
  25. else
  26. this.activeJobs.forEach((activeJob, index) => {
  27. if (activeJob.id === id) {
  28. this.activeJobs[index] = {
  29. ...this.activeJobs[index],
  30. status,
  31. message
  32. };
  33. }
  34. });
  35. },
  36. setJobs(jobs) {
  37. this.activeJobs = jobs;
  38. },
  39. removeJob(jobId) {
  40. this.activeJobs.forEach((activeJob, index) => {
  41. if (activeJob.id === jobId) {
  42. this.activeJobs.splice(index, 1);
  43. this.removedJobIds.push(jobId);
  44. }
  45. });
  46. }
  47. }
  48. });