Skip to content

Commit

Permalink
Autofill note (#176)
Browse files Browse the repository at this point in the history
* feat: autofill note

* refactor: remove undefined check note

Co-authored-by: Adrian Kunz <clashsoft@hotmail.com>

---------

Co-authored-by: Adrian Kunz <clashsoft@hotmail.com>
  • Loading branch information
Morphclue and Clashsoft authored Jul 14, 2024
1 parent bfc4435 commit c09ef8b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ <h4 class="modal-title" id="modal-title">Autofill</h4>
type="time"
>
</div>
<div class="mb-3 ">
<div class="mb-3">
<label for="pause">Break between Events</label>
<input class="form-control"
id="pause"
Expand All @@ -50,6 +50,15 @@ <h4 class="modal-title" id="modal-title">Autofill</h4>
min="1"
>
</div>
<div class="mb-3">
<label for="note">Note</label>
<textarea class="form-control"
id="note"
formControlName="note"
rows="3"
placeholder="You can add a note for all autofill events here."
></textarea>
</div>
</div>
</div>
</form>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export class AutofillModalComponent implements OnInit {
duration: new FormControl('00:15', Validators.required),
pause: new FormControl('00:00', Validators.required),
repeat: new FormControl(1, Validators.required),
note: new FormControl(''),
});
endTime: string = '';

Expand Down Expand Up @@ -76,6 +77,7 @@ export class AutofillModalComponent implements OnInit {
const durationValue = this.modalForm.get('duration')?.value;
const pauseValue = this.modalForm.get('pause')?.value;
const repeat = this.modalForm.get('repeat')?.value;
const note = this.modalForm.get('note')?.value ?? undefined;

if (!dateValue || !repeat || !startTimeValue || !durationValue || !pauseValue) {
return;
Expand All @@ -91,13 +93,13 @@ export class AutofillModalComponent implements OnInit {
start.setHours(startTime[0], startTime[1], 0, 0);
let end = new Date(start);
end = addMinutes(end, duration);
this.chooseDateService.addEvent(start, end);
this.chooseDateService.addEvent(start, end, note);
for (let j = 0; j < repeat - 1; j++) {
start = new Date(end);
start = addMinutes(start, pause);
end = new Date(start);
end = addMinutes(end, duration);
this.chooseDateService.addEvent(start, end);
this.chooseDateService.addEvent(start, end, note);
}
}
}
Expand Down
11 changes: 6 additions & 5 deletions apps/frontend/src/app/poll/services/choose-date.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export class ChooseDateService {
});
}

addEvent(start: Date, end: Date) {
addEvent(start: Date, end: Date, note?: string) {
this.events = [...this.events, {
title: `${format(start, 'HH:mm')} - ${format(end, 'HH:mm')}`,
start: start,
Expand All @@ -101,15 +101,16 @@ export class ChooseDateService {
},
meta: {
tmpEvent: true,
note,
},
}];
}

postpone(postponeDays: number) {
this.events = this.events.map(event => ({
...event,
start: addDays(event.start, postponeDays),
end: addDays(event.end!, postponeDays),
}));
...event,
start: addDays(event.start, postponeDays),
end: addDays(event.end!, postponeDays),
}));
}
}

0 comments on commit c09ef8b

Please sign in to comment.