feat: add component for change cron expression
This commit is contained in:
@ -0,0 +1,16 @@
|
||||
<app-configuration-card [title]="'Cron для обновление расписания'"
|
||||
[isSaveEnabled]="cronExpression != cronExpressionBefore"
|
||||
[saveFunction]="saveFunction()"
|
||||
(onSaveFunction)="onSave($event)">
|
||||
<mat-form-field color="accent">
|
||||
<mat-label>cron</mat-label>
|
||||
<input matInput type="text" [(ngModel)]="cronExpression"/>
|
||||
</mat-form-field>
|
||||
|
||||
<p>Следующие запуски:</p>
|
||||
<ul>
|
||||
@for (date of nextRunDates; track $index) {
|
||||
<li>{{ date }}</li>
|
||||
}
|
||||
</ul>
|
||||
</app-configuration-card>
|
@ -0,0 +1,48 @@
|
||||
import {Component} from '@angular/core';
|
||||
import {ConfigurationCardComponent} from "@component/admin/configuration-card/configuration-card.component";
|
||||
import {ScheduleService} from "@api/v1/configuration/schedule.service";
|
||||
import {MatInputModule} from "@angular/material/input";
|
||||
import {FormsModule, ReactiveFormsModule} from "@angular/forms";
|
||||
import {Observable} from "rxjs";
|
||||
import {CronUpdateScheduleResponse} from "@api/v1/configuration/cronUpdateScheduleResponse";
|
||||
|
||||
@Component({
|
||||
selector: 'app-cron-update-schedule',
|
||||
imports: [
|
||||
ConfigurationCardComponent,
|
||||
MatInputModule,
|
||||
ReactiveFormsModule,
|
||||
FormsModule
|
||||
],
|
||||
templateUrl: './cron-update-schedule.component.html',
|
||||
providers: [ScheduleService]
|
||||
})
|
||||
export class CronUpdateScheduleComponent {
|
||||
protected nextRunDates: string[] = [];
|
||||
protected cronExpression: string = '';
|
||||
protected cronExpressionBefore: string = '';
|
||||
|
||||
constructor(private api: ScheduleService) {
|
||||
api.getCronUpdateSchedule().subscribe(data => {
|
||||
this.nextRunDates = data.nextStart?.map(x => this.convertDateToString(x)) ?? [];
|
||||
this.cronExpression = data.cron;
|
||||
this.cronExpressionBefore = data.cron;
|
||||
});
|
||||
}
|
||||
|
||||
private convertDateToString(data: Date): string {
|
||||
data = new Date(data);
|
||||
return data.toLocaleDateString() + ' ' + data.toLocaleTimeString();
|
||||
}
|
||||
|
||||
protected saveFunction() {
|
||||
return () => this.api.postCronUpdateSchedule(this.cronExpression);
|
||||
}
|
||||
|
||||
protected onSave(data: Observable<CronUpdateScheduleResponse>): void {
|
||||
data.subscribe(apiData => {
|
||||
this.nextRunDates = apiData.nextStart?.map(x => this.convertDateToString(x)) ?? [];
|
||||
this.cronExpressionBefore = apiData.cron;
|
||||
});
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user