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
+2
View File
@@ -25,6 +25,7 @@ import {
faCommentAlt,
faEdit,
faEnvelope,
faExclamationCircle,
faEye,
faEyeSlash,
faFileAlt,
@@ -88,6 +89,7 @@ library.add(
faCommentAlt,
faEdit,
faEnvelope,
faExclamationCircle,
faEye,
faEyeSlash,
faFileAlt,
@@ -0,0 +1,98 @@
<div class="container m-b-20" fxLayout="row" fxLayoutGap="20px">
<h2 class="no-m">Scheduler Status: {{ schedulerData.active === true ? 'Active' : 'Inactive' }}</h2>
<button mat-raised-button class="suspend">
<fa-icon icon="times-circle"></fa-icon>&nbsp;&nbsp;
Suspend
</button>
</div>
<div class="container">
<div fxLayout="row" fxLayoutGap="20px">
<mat-form-field fxFlex>
<mat-label>Filter</mat-label>
<input matInput (keyup)="applyFilter($event.target.value)">
</mat-form-field>
</div>
<div class="mat-elevation-z8">
<table mat-table [dataSource]="dataSource" matSort>
<ng-container matColumnDef="select">
<th mat-header-cell *matHeaderCellDef>
<mat-checkbox (change)="$event ? masterToggle() : null"
[checked]="selection.hasValue() && isAllSelected()"
[indeterminate]="selection.hasValue() && !isAllSelected()">
</mat-checkbox>
</th>
<td mat-cell *matCellDef="let row">
<mat-checkbox (click)="$event.stopPropagation()"
(change)="$event ? selection.toggle(row) : null"
[checked]="selection.isSelected(row)">
</mat-checkbox>
</td>
</ng-container>
<ng-container matColumnDef="displayName">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Name </th>
<td mat-cell *matCellDef="let job"> {{ job.displayName }} </td>
</ng-container>
<ng-container matColumnDef="nextRunTime">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Next Run </th>
<td mat-cell *matCellDef="let job"> {{ job.nextRunTime }} </td>
</ng-container>
<ng-container matColumnDef="previousRunTime">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Previous Run </th>
<td mat-cell *matCellDef="let job"> {{ job.lastRunHistory.jobRunStartTime }} </td>
</ng-container>
<ng-container matColumnDef="previousRunStatus">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Previous Run Status </th>
<td mat-cell *matCellDef="let job">
<fa-icon *ngIf="job.lastRunHistory.status === 'success'" class="success" matTooltip="Successful" matTooltipPosition="right" icon="check-circle" size="lg"></fa-icon>
<fa-icon *ngIf="!(job.lastRunHistory.status == 'success')" class="fail" matTooltip="Failed" matTooltipPosition="right" icon="times-circle" size="lg"></fa-icon>
</td>
</ng-container>
<ng-container matColumnDef="currentlyRunning">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Currently Running </th>
<td mat-cell *matCellDef="let job">
<div [className]="job.currentlyRunning === true ? 'currently-running' : 'not-currently-running'">
<fa-icon matTooltip="{{ job.currentlyRunning === true ? 'Yes' : 'No' }}" matTooltipPosition="right" icon="circle" size="lg"></fa-icon>
</div>
</td>
</ng-container>
<ng-container matColumnDef="errorLog">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Error Log </th>
<td mat-cell *matCellDef="let job">
<button mat-icon-button class="errorlog" *ngIf="!(job.lastRunHistory.status == 'success')" matTooltip="Error Log" matTooltipPosition="right" >
<fa-icon icon="exclamation-circle" size="lg"></fa-icon>
</button>
</td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;" class="select-row"></tr>
</table>
<mat-paginator [pageSizeOptions]="[10, 25, 50, 100]" showFirstLastButtons></mat-paginator>
</div>
</div>
<div class="container" fxLayout="row" fxLayoutGap="20px">
<button mat-raised-button color="primary">
<fa-icon icon="play"></fa-icon>&nbsp;&nbsp;
Run Selected Jobs
</button>
<button mat-raised-button color="primary">
<fa-icon icon="sync"></fa-icon>&nbsp;&nbsp;
Refresh
</button>
</div>
@@ -0,0 +1,32 @@
table {
width: 100%;
.select-row:hover {
cursor: pointer;
}
}
.success {
color: #32cd32;
}
.fail {
color: #f44366;
}
.currently-running {
color: #32cd32;
}
.not-currently-running {
color: #f44366;
}
.errorlog {
color: #ffa726;
}
.suspend {
background: #ffa726;
color: #ffffff;
}
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ManageSchedulerJobsComponent } from './manage-scheduler-jobs.component';
describe('ManageSchedulerJobsComponent', () => {
let component: ManageSchedulerJobsComponent;
let fixture: ComponentFixture<ManageSchedulerJobsComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ ManageSchedulerJobsComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(ManageSchedulerJobsComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -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;
}
}
@@ -0,0 +1,33 @@
/** Angular Imports */
import { Injectable } from '@angular/core';
import { Resolve } from '@angular/router';
/** rxjs Imports */
import { Observable, forkJoin } from 'rxjs';
/** Custom Services */
import { SystemService } from '../system.service';
/**
* Manage Scheduler Jobs data resolver.
*/
@Injectable()
export class ManageSchedulerJobsResolver implements Resolve<Object> {
/**
* @param {SystemService} systemService System service.
*/
constructor(private systemService: SystemService) {}
/**
* Returns the manage scheduler jobs data.
* @returns {Observable<any>}
*/
resolve() {
return forkJoin(
this.systemService.getJobs(),
this.systemService.getScheduler()
);
}
}
+13 -2
View File
@@ -14,6 +14,7 @@ import { ManageDataTablesComponent } from './manage-data-tables/manage-data-tabl
import { ManageHooksComponent } from './manage-hooks/manage-hooks.component';
import { RolesAndPermissionsComponent } from './roles-and-permissions/roles-and-permissions.component';
import { ManageSurveysComponent } from './manage-surveys/manage-surveys.component';
import { ManageSchedulerJobsComponent } from './manage-scheduler-jobs/manage-scheduler-jobs.component';
/** Custom Resolvers */
import { CodesResolver } from './codes/codes.resolver';
@@ -21,6 +22,7 @@ import { ManageDataTablesResolver } from './manage-data-tables/manage-data-table
import { ManageHooksResolver } from './manage-hooks/manage-hooks.resolver';
import { RolesAndPermissionsResolver } from './roles-and-permissions/roles-and-permissions.resolver';
import { ManageSurveysResolver } from './manage-surveys/manage-surveys.resolver';
import { ManageSchedulerJobsResolver } from './manage-scheduler-jobs/manage-scheduler-jobs.resolver';
const routes: Routes = [
Route.withShell([
@@ -87,7 +89,15 @@ const routes: Routes = [
surveys: ManageSurveysResolver
},
data: { title: extract('Manage Surveys'), breadcrumb: 'Manage Surveys' },
}
},
{
path: 'scheduler-jobs',
component: ManageSchedulerJobsComponent,
resolve: {
jobsScheduler: ManageSchedulerJobsResolver
},
data: { title: extract('Manage Scheduler Jobs'), breadcrumb: 'Manage Scheduler Jobs' },
},
]
}
])
@@ -101,7 +111,8 @@ const routes: Routes = [
ManageDataTablesResolver,
ManageHooksResolver,
RolesAndPermissionsResolver,
ManageSurveysResolver
ManageSurveysResolver,
ManageSchedulerJobsResolver,
]
})
export class SystemRoutingModule { }
+1 -1
View File
@@ -88,7 +88,7 @@
<p matLine>Add new report and classify reports</p>
</mat-list-item>
<mat-list-item>
<mat-list-item [routerLink]="['scheduler-jobs']">
<mat-icon matListIcon>
<fa-icon icon="clock" size="sm"></fa-icon>
</mat-icon>
+3 -1
View File
@@ -14,6 +14,7 @@ import { ManageDataTablesComponent } from './manage-data-tables/manage-data-tabl
import { ManageHooksComponent } from './manage-hooks/manage-hooks.component';
import { RolesAndPermissionsComponent } from './roles-and-permissions/roles-and-permissions.component';
import { ManageSurveysComponent } from './manage-surveys/manage-surveys.component';
import { ManageSchedulerJobsComponent } from './manage-scheduler-jobs/manage-scheduler-jobs.component';
@NgModule({
imports: [
@@ -28,7 +29,8 @@ import { ManageSurveysComponent } from './manage-surveys/manage-surveys.componen
ManageDataTablesComponent,
ManageHooksComponent,
RolesAndPermissionsComponent,
ManageSurveysComponent
ManageSurveysComponent,
ManageSchedulerJobsComponent
]
})
export class SystemModule { }
+14
View File
@@ -53,6 +53,20 @@ export class SystemService {
return this.http.get('/surveys');
}
/**
* @returns {Observable<any>} Fetches Jobs.
*/
getJobs(): Observable<any> {
return this.http.get('/jobs');
}
/**
* @returns {Observable<any>} Fetches Scheduler.
*/
getScheduler(): Observable<any> {
return this.http.get('/scheduler');
}
/**
* @param {any} code Code to be created.
* @returns {Observable<any>}