jobs.component.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import { SortMeta } from 'primeng/api'
  2. import { Component, OnInit } from '@angular/core'
  3. import { Notifier, RestPagination, RestTable } from '@app/core'
  4. import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage'
  5. import { I18n } from '@ngx-translate/i18n-polyfill'
  6. import { Job, JobState, JobType } from '@shared/models'
  7. import { JobStateClient } from '../../../../types/job-state-client.type'
  8. import { JobTypeClient } from '../../../../types/job-type-client.type'
  9. import { JobService } from './job.service'
  10. @Component({
  11. selector: 'my-jobs',
  12. templateUrl: './jobs.component.html',
  13. styleUrls: [ './jobs.component.scss' ]
  14. })
  15. export class JobsComponent extends RestTable implements OnInit {
  16. private static LOCAL_STORAGE_STATE = 'jobs-list-state'
  17. private static LOCAL_STORAGE_TYPE = 'jobs-list-type'
  18. jobState: JobStateClient = 'waiting'
  19. jobStates: JobStateClient[] = [ 'active', 'completed', 'failed', 'waiting', 'delayed' ]
  20. jobType: JobTypeClient = 'all'
  21. jobTypes: JobTypeClient[] = [
  22. 'all',
  23. 'activitypub-follow',
  24. 'activitypub-http-broadcast',
  25. 'activitypub-http-fetcher',
  26. 'activitypub-http-unicast',
  27. 'email',
  28. 'video-transcoding',
  29. 'video-file-import',
  30. 'video-import',
  31. 'videos-views',
  32. 'activitypub-refresher',
  33. 'video-redundancy'
  34. ]
  35. jobs: Job[] = []
  36. totalRecords: number
  37. sort: SortMeta = { field: 'createdAt', order: -1 }
  38. pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
  39. constructor (
  40. private notifier: Notifier,
  41. private jobsService: JobService,
  42. private i18n: I18n
  43. ) {
  44. super()
  45. }
  46. ngOnInit () {
  47. this.loadJobStateAndType()
  48. this.initialize()
  49. }
  50. getIdentifier () {
  51. return 'JobsComponent'
  52. }
  53. onJobStateOrTypeChanged () {
  54. this.pagination.start = 0
  55. this.loadData()
  56. this.saveJobStateAndType()
  57. }
  58. protected loadData () {
  59. this.jobsService
  60. .getJobs(this.jobState, this.jobType, this.pagination, this.sort)
  61. .subscribe(
  62. resultList => {
  63. this.jobs = resultList.data
  64. this.totalRecords = resultList.total
  65. },
  66. err => this.notifier.error(err.message)
  67. )
  68. }
  69. private loadJobStateAndType () {
  70. const state = peertubeLocalStorage.getItem(JobsComponent.LOCAL_STORAGE_STATE)
  71. if (state) this.jobState = state as JobState
  72. const type = peertubeLocalStorage.getItem(JobsComponent.LOCAL_STORAGE_TYPE)
  73. if (type) this.jobType = type as JobType
  74. }
  75. private saveJobStateAndType () {
  76. peertubeLocalStorage.setItem(JobsComponent.LOCAL_STORAGE_STATE, this.jobState)
  77. peertubeLocalStorage.setItem(JobsComponent.LOCAL_STORAGE_TYPE, this.jobType)
  78. }
  79. }