feat(calendar): show scheduled tasks using plannedAt rather than remindAt

This commit is contained in:
Johannes Millan 2021-01-06 14:47:03 +01:00
parent 5ffcbcc711
commit 2a2dec283f
5 changed files with 41 additions and 10 deletions

View File

@ -1,6 +1,5 @@
import { ChangeDetectionStrategy, Component, ViewChild } from '@angular/core';
import { CalendarOptions, FullCalendarComponent } from '@fullcalendar/angular';
import { ScheduledTaskService } from '../tasks/scheduled-task.service';
import { Observable } from 'rxjs';
import { map, withLatestFrom } from 'rxjs/operators';
import { EventInput } from '@fullcalendar/common';
@ -10,7 +9,7 @@ import { getWorklogStr } from '../../util/get-work-log-str';
import { TaskWithReminderData } from '../tasks/task.model';
import { msToString } from '../../ui/duration/ms-to-string.pipe';
const MIN_TASK_DURATION = 30 * 60 * 1000;
const MIN_TASK_DURATION = 15 * 60 * 1000;
const WEIRD_MAGIC_HOUR = 60000 * 60;
@Component({
@ -25,6 +24,7 @@ export class CalendarComponent {
private DEFAULT_CAL_OPTS: CalendarOptions = {
editable: true,
slotDuration: '00:15:00',
timeZone: 'local', // the default (unnecessary to specify)
eventResize: (calEvent: any) => {
const start = calEvent.event._instance.range.start;
@ -93,7 +93,7 @@ export class CalendarComponent {
// }],
};
calOptions$: Observable<CalendarOptions> = this._scheduledTaskService.allScheduledTasks$.pipe(
calOptions$: Observable<CalendarOptions> = this._taskService.plannedTasks$.pipe(
withLatestFrom(this._workContextService.allWorkContextColors$),
map(([tasks, colorMap]): CalendarOptions => {
const TD_STR = getWorklogStr();
@ -112,16 +112,32 @@ export class CalendarComponent {
+ msToString(task.timeSpent)
+ '/'
+ msToString(task.timeEstimate),
start: task.reminderData.remindAt,
end: task.reminderData.remindAt + ((timeToGo > (MIN_TASK_DURATION))
? timeToGo
: MIN_TASK_DURATION),
extendedProps: task,
backgroundColor: task.projectId
? colorMap[task.projectId]
: colorMap[task.tagIds[0]]
: colorMap[task.tagIds[0]],
...(task.plannedAt
? {
start: task.plannedAt,
end: (task.plannedAt as number) + ((timeToGo > (MIN_TASK_DURATION))
? timeToGo
: MIN_TASK_DURATION)
}
: {
allDay: true,
// start: TD_STR,
duration: 2000000,
start: Date.now(),
end: Date.now() + ((timeToGo > (MIN_TASK_DURATION))
? timeToGo
: MIN_TASK_DURATION)
}
)
};
});
return {
...this.DEFAULT_CAL_OPTS,
events,
@ -131,7 +147,6 @@ export class CalendarComponent {
constructor(
private _workContextService: WorkContextService,
private _scheduledTaskService: ScheduledTaskService,
private _taskService: TaskService,
) {
this.calOptions$.subscribe((v) => console.log('calOptions$', v));

View File

@ -8,6 +8,7 @@ import { devError } from '../../util/dev-error';
@Injectable({providedIn: 'root'})
export class ScheduledTaskService {
// TODO maybe remove
allScheduledTasks$: Observable<TaskWithReminderData[]> = this._reminderService.reminders$.pipe(
map((reminders) => reminders.filter(
reminder => reminder.type === 'TASK'

View File

@ -37,6 +37,11 @@ export class TaskDbEffects {
TaskActionTypes.ToggleStart,
TaskActionTypes.RoundTimeSpentForDay,
// REMINDER
TaskActionTypes.AddTaskReminder,
TaskActionTypes.UpdateTaskReminder,
TaskActionTypes.RemoveTaskReminder,
// SUB ACTIONS
TaskAttachmentActionTypes.AddTaskAttachment,
TaskAttachmentActionTypes.DeleteTaskAttachment,

View File

@ -3,6 +3,7 @@ import { TASK_FEATURE_NAME } from './task.reducer';
import { Task, TaskState, TaskWithSubTasks } from '../task.model';
import { taskAdapter } from './task.adapter';
import { devError } from '../../../util/dev-error';
import { TODAY_TAG } from '../../tag/tag.const';
// TODO fix null stuff here
@ -119,6 +120,11 @@ export const selectCurrentTaskParentOrCurrent = createSelector(selectTaskFeature
|| s.entities[s.currentTaskId]
);
export const selectPlannedTasks = createSelector(selectTaskFeatureState, (s): Task[] => s.ids
.map(id => s.entities[id] as Task)
.filter(task => task.plannedAt || task.tagIds.includes(TODAY_TAG.id))
);
export const selectAllTasks = createSelector(selectTaskFeatureState, selectAll);
export const selectScheduledTasks = createSelector(selectAllTasks, (tasks) => tasks.filter(task => task.reminderId));

View File

@ -52,7 +52,7 @@ import {
selectCurrentTaskOrParentWithData,
selectCurrentTaskParentOrCurrent,
selectIsTaskDataLoaded,
selectMainTasksWithoutTag,
selectMainTasksWithoutTag, selectPlannedTasks,
selectSelectedTask,
selectSelectedTaskId, selectStartableTasks,
selectTaskAdditionalInfoTargetPanel,
@ -145,6 +145,10 @@ export class TaskService {
select(selectStartableTasks),
);
plannedTasks$: Observable<Task[]> = this._store.pipe(
select(selectPlannedTasks),
);
// META FIELDS
// -----------
currentTaskProgress$: Observable<number> = this.currentTask$.pipe(