feat: add scheduler jobs component (#346)

Fixes: #177
This commit is contained in:
pwai
2018-12-10 22:20:51 +05:30
committed by Abhay Chawla
parent 24db7caed5
commit e19229eb84
10 changed files with 319 additions and 4 deletions
@@ -0,0 +1,98 @@
/** Angular Imports */
import { Component, OnInit, ViewChild } from '@angular/core';
import { MatTableDataSource, MatPaginator, MatSort } from '@angular/material';
import { ActivatedRoute } from '@angular/router';
import { SelectionModel } from '@angular/cdk/collections';
/** rxjs Imports */
import { of } from 'rxjs';
/**
* Manage scheduler jobs component.
*/
@Component({
selector: 'mifosx-manage-scheduler-jobs',
templateUrl: './manage-scheduler-jobs.component.html',
styleUrls: ['./manage-scheduler-jobs.component.scss']
})
export class ManageSchedulerJobsComponent implements OnInit {
/** Jobs data. */
jobData: any;
/** Scheduler data */
schedulerData: any;
/** Columns to be displayed in manage scheduler jobs table. */
displayedColumns: string[] = ['select', 'displayName', 'nextRunTime', 'previousRunTime', 'previousRunStatus', 'currentlyRunning', 'errorLog'];
/** Data source for manage scheduler jobs table. */
dataSource: MatTableDataSource<any>;
/** Initialize Selection */
selection = new SelectionModel<any>(true, []);
/** Paginator for table. */
@ViewChild(MatPaginator) paginator: MatPaginator;
/** Sorter for manage scheduler jobs table. */
@ViewChild(MatSort) sort: MatSort;
/**
* Retrieves the scheduler jobs data from `resolve`.
* @param {ActivatedRoute} route Activated Route.
*/
constructor(private route: ActivatedRoute) {
this.route.data.subscribe((data: { jobsScheduler: any }) => {
this.jobData = data.jobsScheduler[0];
this.schedulerData = data.jobsScheduler[1];
});
}
/**
* Filters data in manage scheduler jobs table based on passed value.
* @param {string} filterValue Value to filter data.
*/
applyFilter(filterValue: string) {
this.dataSource.filter = filterValue.trim().toLowerCase();
}
/**
* Whether the number of selected elements matches the total number of rows.
*/
isAllSelected() {
const numSelected = this.selection.selected.length;
const numRows = this.dataSource.data.length;
return numSelected === numRows;
}
/**
* Selects all rows if they are not all selected; otherwise clear selection.
*/
masterToggle() {
this.isAllSelected() ?
this.selection.clear() :
this.dataSource.data.forEach(row => this.selection.select(row));
}
/**
* Sets the manage scheduler jobs table.
*/
ngOnInit() {
this.setJobs();
this.dataSource.sortingDataAccessor = (item, property) => {
switch (property) {
case 'previousRunStatus': return item.lastRunHistory.status;
case 'errorLog': return item.lastRunHistory.status;
case 'previousRunTime': return new Date(item.lastRunHistory.jobRunStartTime);
case 'nextRunTime': return new Date(item.nextRunTime);
default: return item[property];
}
};
}
/**
* Initializes the data source, paginator and sorter for manage scheduler jobs table.
*/
setJobs() {
this.dataSource = new MatTableDataSource(this.jobData);
this.dataSource.paginator = this.paginator;
this.dataSource.sort = this.sort;
}
}