Fixed bug where task time was not properly set with values of 0

Fixed issue where time field was not properly populated in the schedule dialog
GlassedSilver-add-security-policy
Isaac Abadi 4 years ago
parent 0bc2193f25
commit 0585943d67

@ -42,9 +42,9 @@ function scheduleJob(task_key, schedule) {
if (schedule['type'] === 'timestamp') { if (schedule['type'] === 'timestamp') {
converted_schedule = new Date(schedule['data']['timestamp']); converted_schedule = new Date(schedule['data']['timestamp']);
} else if (schedule['type'] === 'recurring') { } else if (schedule['type'] === 'recurring') {
const dayOfWeek = schedule['data']['dayOfWeek'] ? schedule['data']['dayOfWeek'] : null; const dayOfWeek = schedule['data']['dayOfWeek'] != null ? schedule['data']['dayOfWeek'] : null;
const hour = schedule['data']['hour'] ? schedule['data']['hour'] : null; const hour = schedule['data']['hour'] != null ? schedule['data']['hour'] : null;
const minute = schedule['data']['minute'] ? schedule['data']['minute'] : null; const minute = schedule['data']['minute'] != null ? schedule['data']['minute'] : null;
converted_schedule = new scheduler.RecurrenceRule(null, null, null, dayOfWeek, hour, minute); converted_schedule = new scheduler.RecurrenceRule(null, null, null, dayOfWeek, hour, minute);
} else { } else {
logger.error(`Failed to schedule job '${task_key}' as the type '${schedule['type']}' is invalid.`) logger.error(`Failed to schedule job '${task_key}' as the type '${schedule['type']}' is invalid.`)

@ -1,6 +1,6 @@
import { Component, Inject, OnInit } from '@angular/core'; import { Component, Inject, OnInit } from '@angular/core';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import { Schedule } from 'api-types'; import { Schedule, Task } from 'api-types';
import { PostsService } from 'app/posts.services'; import { PostsService } from 'app/posts.services';
@Component({ @Component({
@ -18,7 +18,7 @@ export class UpdateTaskScheduleDialogComponent implements OnInit {
date = null; date = null;
today = new Date(); today = new Date();
constructor(@Inject(MAT_DIALOG_DATA) public data: any, private dialogRef: MatDialogRef<UpdateTaskScheduleDialogComponent>, private postsService: PostsService) { constructor(@Inject(MAT_DIALOG_DATA) public data: {task: Task}, private dialogRef: MatDialogRef<UpdateTaskScheduleDialogComponent>, private postsService: PostsService) {
this.processTask(this.data.task); this.processTask(this.data.task);
this.postsService.getTask(this.data.task.key).subscribe(res => { this.postsService.getTask(this.data.task.key).subscribe(res => {
this.processTask(res['task']); this.processTask(res['task']);
@ -28,7 +28,7 @@ export class UpdateTaskScheduleDialogComponent implements OnInit {
ngOnInit(): void { ngOnInit(): void {
} }
processTask(task) { processTask(task: Task): void {
if (!task['schedule']) { if (!task['schedule']) {
this.enabled = false; this.enabled = false;
return; return;
@ -39,7 +39,11 @@ export class UpdateTaskScheduleDialogComponent implements OnInit {
this.recurring = schedule['type'] === Schedule.type.RECURRING; this.recurring = schedule['type'] === Schedule.type.RECURRING;
if (this.recurring) { if (this.recurring) {
this.time = `${schedule['data']['hour']}:${schedule['data']['minute']}`; const hour = schedule['data']['hour'];
const minute = schedule['data']['minute'];
// add padding 0s if necessary to hours and minutes
this.time = (hour < 10 ? '0' : '') + hour + ':' + (minute < 10 ? '0' : '') + minute;
if (schedule['data']['dayOfWeek']) { if (schedule['data']['dayOfWeek']) {
this.days_of_week = schedule['data']['dayOfWeek']; this.days_of_week = schedule['data']['dayOfWeek'];
@ -75,7 +79,6 @@ export class UpdateTaskScheduleDialogComponent implements OnInit {
} }
} else { } else {
this.date.setHours(hours, minutes); this.date.setHours(hours, minutes);
console.log(this.date);
schedule['data'] = {timestamp: this.date.getTime()}; schedule['data'] = {timestamp: this.date.getTime()};
} }
this.dialogRef.close(schedule); this.dialogRef.close(schedule);

Loading…
Cancel
Save