Skip to content

Commit

Permalink
finally fixed form issue i think
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Sorensen committed Feb 19, 2024
1 parent a87347a commit b33c581
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 31 deletions.
14 changes: 10 additions & 4 deletions app/src/main/electron-event-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ ipcMain.on(OPEN_TASK_LOG_FILE_EVENT, (event, task: Task) => {

const logFileListeners:{[key:string]: StatWatcher } = {}

ipcMain.on(START_LISTENING_TO_LOG_FILE, (event, task:Task)=>{

ipcMain.on(START_LISTENING_TO_LOG_FILE, logFileListener );

function logFileListener(event:Event, task:Task){
if(!task) return;
const logFileController = new LogFileController(task.logFilePath);
if(logFileListeners[task.id]) logFileListeners[task.id].removeAllListeners();
Expand All @@ -112,12 +115,15 @@ ipcMain.on(START_LISTENING_TO_LOG_FILE, (event, task:Task)=>{
mainWindow.webContents.send(TASK_LOG_FILE_UPDATED, text)
})
logFileListeners[task.id] = watcher;
})
}

ipcMain.on(STOP_LISTENING_TO_LOG_FILE, (event, task:Task)=>{
try{
if(!task) return;
logFileListeners[task.id].removeAllListeners();
for(const key in logFileListeners){
logFileListeners[key].removeAllListeners();
ipcMain.on(START_LISTENING_TO_LOG_FILE, logFileListener );
}

}catch(e){
console.log('could not stop listening to task')
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export function taskLogger(task: Task, _process: ChildProcess) {
const logFilePath = task.logFilePath;
const logFileWriteStream = createWriteStream(logFilePath, {flags: 'a'});
_process.stdout.pipe(logFileWriteStream);
_process.stderr.pipe(logFileWriteStream);
return logFileWriteStream;
}

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/scheduleRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ export class ScheduleRunner {
});
this.scheduleController.startTask({
...task,
pids: [...task.pids, _process.pid],
pids: [...task?.pids ?? [], _process.pid],
});
// _process.unref();
return _process;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const _taskFormReducer = createReducer(
triggers: state.triggers?.map((_trigger, i) => {
if (index === i) return trigger;
return trigger;
}),
}) ?? [],
})),
on(resetTaskForm, (state, data) => initialTaskFormState)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@

<!-- only the first trigger -->
<div fxLayout="row" fxLayoutGap="16px" fxLayoutAlign="start center">
<div formArrayName="triggers">
<div formArrayName="triggers" *ngIf="triggers?.controls">
<ng-container
*ngFor="let trigger of triggers.controls | slice: 0:1; let i = index"
*ngFor="let trigger of triggers.controls | slice: 0:1; let i = index;"
>
<div
fxLayout="row"
[formGroupName]="i"
[formGroup]="trigger"
#triggerGroup
fxLayout="row"
fxLayoutGap="16px"
fxLayoutAlign="start center"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,21 @@
import { Component, OnInit } from '@angular/core';
import { Store } from '@ngrx/store';
import {
addPathToTaskFormCommand,
addTask,
saveTask,
updateTaskForm,
updateTaskFormCommand,
updateTaskFormDescription,
updateTaskFormName,
updateTaskFormTrigger,

} from 'src/app/@core/store/actions/schedule.actions';

import { remote } from 'electron';
import {
selectTaskFormCommand,
selectTaskFormDescription,
selectTaskFormTriggers,
selectTaskFormName,

selectTaskForm,
selectFirstTaskFormTriggerType,
} from 'src/app/@core/store/selectors/taskForm.schedule';
import { Task, TriggerType, UTrigger } from '../../../../../main/types';
import { MatDialog } from '@angular/material/dialog';
import { AdvancedTaskFormDialogueComponent } from 'src/app/dialogues/advanced-task-form-dialogue/advanced-task-form-dialogue.component';
import { FormArray, FormBuilder, FormGroup } from '@angular/forms';
import { FormArray, FormBuilder, FormControl, FormGroup } from '@angular/forms';
import { take } from 'rxjs/operators';
import { initialTaskFormState } from '../../@core/store/reducers/taskForm.reducer';
import { resetTaskForm } from 'src/app/@core/store/actions/schedule.actions';
Expand All @@ -34,7 +26,7 @@ import { Router } from '@angular/router';
styleUrls: ['./task-form.component.scss'],
})
export class TaskFormComponent implements OnInit {
taskForm: FormGroup;
taskForm: FormGroup
task: Partial<Task>;
intervalOptions = [
{
Expand All @@ -52,8 +44,9 @@ export class TaskFormComponent implements OnInit {
];
triggerType: TriggerType;


get triggers() {
return this.taskForm.get('triggers') as FormArray;
return this.taskForm.get('triggers') as FormArray<FormGroup>;
}

getTriggerValue() {
Expand All @@ -68,21 +61,35 @@ export class TaskFormComponent implements OnInit {
) {}

ngOnInit(): void {
this.taskForm = this.fb.group({
arguments: this.fb.array([this.fb.group("")]),
triggers:this.fb.array([this.fb.group({
type: 'interval',
value: 1000 * 60 * 60 * 24,
next: Date.now() + (1000 * 60 * 60 * 24)
})])
});
this.store
.select(selectTaskForm)
// .pipe(take(1))
.subscribe((task) => {
console.log(task);
this.task = task;
this.taskForm = this.fb.group({
...task,
arguments: task.arguments
? this.fb.array(task.arguments?.map((arg) => this.fb.control(arg)))
: [],
triggers: task.triggers
? this.fb.array(
task.triggers?.map((trigger) => this.fb.group(trigger))
)
: [],
arguments: this.fb.array(task.arguments?.reduce((accumulator,argument)=>{
if(!argument) return accumulator;
accumulator.push(this.fb.group(argument))
return accumulator;
}, [] as unknown[]) ?? []),

pids: [task.pids],
triggers: this.fb.array(task.triggers?.reduce((accumulator,trigger)=>{
if(!trigger) return accumulator;
accumulator.push(this.fb.group(trigger))
return accumulator;
}, [] as unknown[]) ?? [])

});
this.triggerType = task.triggers ? task.triggers[0].type : 'interval';
this.taskForm.valueChanges.subscribe((taskForm) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@ export class TaskLogsComponent implements OnInit, AfterViewInit, OnDestroy{
ngOnInit(){
this.route.parent?.parent?.params.subscribe(parentParams => {
const taskId = parentParams.id
console.log("ROUTE UPDATED", taskId);

if(!taskId) return;
this.store.select(selectTaskById(taskId)).pipe(take(1)).subscribe(task => {
console.log("RECEIVED TASK");
console.log(task);
if(!task) return;
this.task = task;
this.startListeningToLogFile(task)
Expand All @@ -53,6 +57,7 @@ export class TaskLogsComponent implements OnInit, AfterViewInit, OnDestroy{
}

startListeningToLogFile(task:Task){
console.log("START LISTENING TO LOG FILE", task.id);
ipcRenderer.send(START_LISTENING_TO_LOG_FILE, task);
}

Expand All @@ -62,6 +67,7 @@ export class TaskLogsComponent implements OnInit, AfterViewInit, OnDestroy{
}

ngOnDestroy(): void {
console.log('ON DESTROY CALLED');
this.stopListeningToLogFile();
ipcRenderer.removeListener(TASK_LOG_FILE_UPDATED, this.onTaskFileUpdated.bind(this));
}
Expand Down

0 comments on commit b33c581

Please sign in to comment.