1 import { Component, OnInit } from '@angular/core'
2 import { NotificationsService } from 'angular2-notifications'
3 import { SortMeta } from 'primeng/primeng'
4 import { Job } from '../../../../../../shared/index'
5 import { JobState } from '../../../../../../shared/models'
6 import { RestPagination, RestTable } from '../../../shared'
7 import { viewportHeight } from '../../../shared/misc/utils'
8 import { JobService } from '../shared'
9 import { RestExtractor } from '../../../shared/rest/rest-extractor.service'
12 selector: 'my-jobs-list',
13 templateUrl: './jobs-list.component.html',
14 styleUrls: [ './jobs-list.component.scss' ]
16 export class JobsListComponent extends RestTable implements OnInit {
17 private static JOB_STATE_LOCAL_STORAGE_STATE = 'jobs-list-state'
19 jobState: JobState = 'inactive'
20 jobStates: JobState[] = [ 'active', 'complete', 'failed', 'inactive', 'delayed' ]
24 sort: SortMeta = { field: 'createdAt', order: -1 }
25 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
28 private notificationsService: NotificationsService,
29 private restExtractor: RestExtractor,
30 private jobsService: JobService
40 onJobStateChanged () {
45 protected loadData () {
47 .getJobs(this.jobState, this.pagination, this.sort)
50 this.jobs = resultList.data
51 this.totalRecords = resultList.total
54 err => this.notificationsService.error('Error', err.message)
58 private loadJobState () {
59 const result = localStorage.getItem(JobsListComponent.JOB_STATE_LOCAL_STORAGE_STATE)
61 if (result) this.jobState = result as JobState
64 private saveJobState () {
65 localStorage.setItem(JobsListComponent.JOB_STATE_LOCAL_STORAGE_STATE, this.jobState)