-
Notifications
You must be signed in to change notification settings - Fork 540
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Input to run Jobs with Parameters (#1850)
Co-authored-by: Jose Alberto Hernandez <[email protected]>
- Loading branch information
1 parent
c53870e
commit b50ac45
Showing
12 changed files
with
336 additions
and
1 deletion.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
...ge-jobs/scheduler-jobs/custom-parameters-popover/custom-parameters-popover.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<h1 mat-dialog-title>Edit Job Custom Parameters</h1> | ||
|
||
<mat-dialog-content> | ||
<div class="jobs-container"> | ||
<div *ngFor="let job of selectedJobs"> | ||
<mifosx-custom-parameters-table | ||
[displayName]="job.displayName" | ||
[jobId]="job.id" | ||
[jobParameters]="job.jobParameters" | ||
(retrieveData)="runSelectedJobs($event)" | ||
> | ||
</mifosx-custom-parameters-table> | ||
</div> | ||
</div> | ||
</mat-dialog-content> | ||
|
||
<mat-list> | ||
<mat-list-item *ngFor="let message of messages" class="message" [ngClass]="{'green' : message.status}"> | ||
{{message.message}} | ||
</mat-list-item> | ||
</mat-list> | ||
|
||
<mat-dialog-actions> | ||
<button mat-raised-button color="primary" (click)="runSelectedJobs()"> | ||
<fa-icon icon="play" class="m-r-10"></fa-icon> | ||
Run Selected Jobs | ||
</button> | ||
<button mat-raised-button color="warn" [mat-dialog-close]="{ show: 0 }"> | ||
Close Custom Parameters | ||
</button> | ||
</mat-dialog-actions> |
9 changes: 9 additions & 0 deletions
9
...ge-jobs/scheduler-jobs/custom-parameters-popover/custom-parameters-popover.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.message { | ||
height: auto; | ||
font-weight: 500; | ||
color: #f44366; | ||
} | ||
|
||
.message.green { | ||
color: #32cd32; | ||
} |
25 changes: 25 additions & 0 deletions
25
...jobs/scheduler-jobs/custom-parameters-popover/custom-parameters-popover.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { CustomParametersPopoverComponent } from './custom-parameters-popover.component'; | ||
|
||
describe('CustomParametersPopoverComponent', () => { | ||
let component: CustomParametersPopoverComponent; | ||
let fixture: ComponentFixture<CustomParametersPopoverComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
declarations: [ CustomParametersPopoverComponent ] | ||
}) | ||
.compileComponents(); | ||
}); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(CustomParametersPopoverComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
93 changes: 93 additions & 0 deletions
93
...nage-jobs/scheduler-jobs/custom-parameters-popover/custom-parameters-popover.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import { SelectionModel } from '@angular/cdk/collections'; | ||
import { Component, Inject, OnInit, QueryList, ViewChildren } from '@angular/core'; | ||
import { MAT_DIALOG_DATA } from '@angular/material/dialog'; | ||
import { CustomParametersTableComponent } from './custom-parameters-table/custom-parameters-table.component'; | ||
import { SystemService } from 'app/system/system.service'; | ||
|
||
interface SelectedJobsDataType { | ||
selectedJobs: SelectionModel<JobDataType>; | ||
parameterValue: string; | ||
} | ||
|
||
export interface JobIdAndParameterType { | ||
jobId: string; | ||
displayName: string; | ||
jobParameters: JobParameterType[]; | ||
} | ||
|
||
export interface RunJobWithParamPayloadType { | ||
jobParameters: JobParameterType[]; | ||
} | ||
|
||
export interface JobParameterType { | ||
jobParameterName: string; | ||
jobParameterValue: string; | ||
} | ||
|
||
interface JobDataType { | ||
active: boolean; | ||
cronExpression: string; | ||
currentlyRunning: boolean; | ||
displayName: string; | ||
jobId: number; | ||
lastRunHistory: { | ||
jobRunEndTime: string; | ||
jobRunStartTime: string; | ||
status: string; | ||
triggerType: string; | ||
version: number; | ||
}; | ||
nextRunTime: string; | ||
jobParameters: JobParameterType[]; | ||
} | ||
|
||
@Component({ | ||
selector: 'mifosx-custom-parameters-popover', | ||
templateUrl: './custom-parameters-popover.component.html', | ||
styleUrls: ['./custom-parameters-popover.component.scss'] | ||
}) | ||
export class CustomParametersPopoverComponent implements OnInit { | ||
|
||
/* Job table childer */ | ||
@ViewChildren(CustomParametersTableComponent) tableComponents: QueryList<CustomParametersTableComponent>; | ||
|
||
/* Initialize Selected Jobs */ | ||
selectedJobs: JobDataType[] = []; | ||
/* Show modal or not */ | ||
show: number; | ||
/* API call response message */ | ||
messages: { message: string; status: number }[] = []; | ||
|
||
constructor(private systemService: SystemService, @Inject(MAT_DIALOG_DATA) public data: SelectedJobsDataType) { } | ||
|
||
ngOnInit(): void { | ||
this.selectedJobs = this.data.selectedJobs.selected.map((jobJSON) => ({ | ||
...jobJSON, | ||
jobParameters: [] | ||
})); | ||
} | ||
|
||
/** | ||
* Run all selected jobs with job parameters from table | ||
*/ | ||
runSelectedJobs(): void { | ||
this.messages = []; | ||
const tableData: JobIdAndParameterType[] = []; | ||
this.tableComponents.forEach((tableComponent) => { | ||
tableData.push(tableComponent.getTableData()); | ||
}); | ||
|
||
tableData.forEach((job) => { | ||
this.systemService.runSelectedJobWithParameters(job.jobId, | ||
{ jobParameters: job.jobParameters } | ||
) | ||
.then((response) => { | ||
this.messages.push({ | ||
message: `${job.displayName}: ${response.statusText} (${response.status})`, | ||
status: response.ok | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
.../custom-parameters-popover/custom-parameters-table/custom-parameters-table.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<div> | ||
<h2>Job: {{ displayName }}</h2> | ||
<table mat-table [dataSource]="updatedJobParameters"> | ||
<ng-container matColumnDef="parameterName"> | ||
<th mat-header-cell *matHeaderCellDef>Parameter Name</th> | ||
<td mat-cell *matCellDef="let element; index as i"> | ||
<mat-form-field> | ||
<input matInput type="text" placeholder="Parameter Name" [(ngModel)]="element.parameterName" /> | ||
</mat-form-field> | ||
</td> | ||
</ng-container> | ||
|
||
<ng-container matColumnDef="parameterValue"> | ||
<th mat-header-cell *matHeaderCellDef>Parameter Value</th> | ||
<td mat-cell *matCellDef="let element; index as i"> | ||
<mat-form-field> | ||
<input matInput type="text" placeholder="Parameter Value" [(ngModel)]="element.parameterValue" /> | ||
</mat-form-field> | ||
</td> | ||
</ng-container> | ||
|
||
<ng-container matColumnDef="actions"> | ||
<th mat-header-cell *matHeaderCellDef></th> | ||
<td mat-cell *matCellDef="let row; let rowIndex = index"> | ||
<button type="button" mat-icon-button color="warn" | ||
(click)="deleteParameter(rowIndex)" matTooltip="Delete" | ||
matTooltipPosition="left"> | ||
<fa-icon icon="trash"></fa-icon> | ||
</button> | ||
</td> | ||
</ng-container> | ||
|
||
<tr mat-header-row *matHeaderRowDef="columnsToDisplay" class="first-row"></tr> | ||
<tr mat-row *matRowDef="let updatedJobParameters; columns: columnsToDisplay"></tr> | ||
</table> | ||
|
||
<button mat-button (click)="addParameter()"> | ||
<fa-icon icon="plus" class="m-r-10"></fa-icon> | ||
Add Parameter | ||
</button> | ||
</div> |
13 changes: 13 additions & 0 deletions
13
.../custom-parameters-popover/custom-parameters-table/custom-parameters-table.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
table td { | ||
padding-right: 50px; | ||
} | ||
|
||
.jobs-container { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 10px; | ||
} | ||
|
||
.jobs-container table td { | ||
padding-right: 50px; | ||
} |
25 changes: 25 additions & 0 deletions
25
...stom-parameters-popover/custom-parameters-table/custom-parameters-table.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { CustomParametersTableComponent } from './custom-parameters-table.component'; | ||
|
||
describe('CustomParametersTableComponent', () => { | ||
let component: CustomParametersTableComponent; | ||
let fixture: ComponentFixture<CustomParametersTableComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
declarations: [ CustomParametersTableComponent ] | ||
}) | ||
.compileComponents(); | ||
}); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(CustomParametersTableComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
68 changes: 68 additions & 0 deletions
68
...bs/custom-parameters-popover/custom-parameters-table/custom-parameters-table.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; | ||
import { JobIdAndParameterType, JobParameterType } from '../custom-parameters-popover.component'; | ||
|
||
@Component({ | ||
selector: 'mifosx-custom-parameters-table', | ||
templateUrl: './custom-parameters-table.component.html', | ||
styleUrls: ['./custom-parameters-table.component.scss'] | ||
}) | ||
export class CustomParametersTableComponent implements OnInit { | ||
|
||
/* Job name for table title */ | ||
@Input() displayName: string; | ||
/* Job id for table */ | ||
@Input() jobId: string; | ||
/* Array of custom job parameters */ | ||
@Input() jobParameters: JobParameterType[]; | ||
/* Listener to return jobs */ | ||
@Output() retrieveJob: EventEmitter<JobParameterType[]> = new EventEmitter<JobParameterType[]>(); | ||
|
||
/* Job parameters copy updated by user input */ | ||
updatedJobParameters: JobParameterType[]; | ||
/* Columns for the table */ | ||
columnsToDisplay: string[] = ['parameterName', 'parameterValue', 'actions']; | ||
|
||
constructor() { } | ||
|
||
ngOnInit(): void { | ||
this.updatedJobParameters = this.jobParameters; | ||
this.updatedJobParameters.push({ | ||
jobParameterName: '', | ||
jobParameterValue: '' | ||
}); | ||
} | ||
|
||
addParameter(): void { | ||
this.updatedJobParameters = [ | ||
...this.updatedJobParameters, | ||
{ | ||
jobParameterName: '', | ||
jobParameterValue: '' | ||
} | ||
]; | ||
} | ||
|
||
deleteParameter(index: number): void { | ||
let idx = 0; | ||
const jobParameters: JobParameterType[] = []; | ||
for ( ; idx < this.updatedJobParameters.length; idx++ ) { | ||
if (idx !== index) { | ||
jobParameters.push(this.updatedJobParameters[idx]); | ||
} | ||
} | ||
this.updatedJobParameters = jobParameters; | ||
} | ||
|
||
/** | ||
* Gets the jobId and jobParameters array | ||
* @returns jobId and jobParameters array | ||
*/ | ||
getTableData(): JobIdAndParameterType { | ||
return { | ||
jobId: this.jobId, | ||
displayName: this.displayName, | ||
jobParameters: this.updatedJobParameters | ||
}; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters