refactor: cleanup lastCurrentTask and refactor it to one instance of lastActiveTask

This commit is contained in:
Johannes Millan 2018-01-09 18:11:43 +01:00
parent 914149dca5
commit 053100b92d
7 changed files with 46 additions and 36 deletions

View file

@ -60,7 +60,7 @@
tomorrowsNote: undefined,
theme: undefined,
currentTask: undefined,
lastCurrentTask: undefined,
lastActiveTaskTask: undefined,
currentProject: undefined,
currentSession: {
timeWorkedWithoutBreak: undefined,

View file

@ -27,7 +27,7 @@
vm.idleTime = $window.moment.duration(realIdleTime, 'milliseconds').format('hh:mm:ss');
vm.undoneTasks = Tasks.getUndoneToday(true);
vm.selectedTask = $rootScope.r.currentTask || $rootScope.r.lastCurrentTask || undefined;
vm.selectedTask = $rootScope.r.currentTask || $rootScope.r.lastActiveTaskTask || undefined;
vm.trackIdleToTask = () => {
if (vm.selectedTask) {

View file

@ -27,7 +27,7 @@
/* @ngInject */
function MainHeaderCtrl(Dialogs, Projects) {
let vm = this;
vm.lastCurrentTask = undefined;
vm.lastActiveTaskTask = undefined;
vm.allProjects = Projects.getList();

View file

@ -37,20 +37,24 @@
// handlers for dbus events
window.ipcRenderer.on(IPC_EVENT_TASK_MARK_AS_DONE, () => {
const lastActiveTask = this.getLastActiveIfStartable();
if (that.$rootScope.r.currentTask) {
that.markAsDone(that.$rootScope.r.currentTask);
that.$rootScope.$apply();
} else if (that.lastCurrentTask) {
that.markAsDone(that.lastCurrentTask);
} else if (lastActiveTask) {
that.markAsDone(lastActiveTask);
that.$rootScope.$apply();
}
});
window.ipcRenderer.on(IPC_EVENT_TASK_START, () => {
if (!that.$rootScope.r.currentTask && that.lastCurrentTask) {
that.updateCurrent(that.lastCurrentTask);
const lastActiveTask = this.getLastActiveIfStartable();
if (!that.$rootScope.r.currentTask && lastActiveTask) {
that.updateCurrent(lastActiveTask);
that.$rootScope.$apply();
} else {
that.startLastTaskOrOpenDialog();
}
});
window.ipcRenderer.on(IPC_EVENT_TASK_PAUSE, () => {
@ -107,20 +111,20 @@
}
getLastCurrent() {
return this.$rootScope.r.lastCurrentTask;
return this.$rootScope.r.lastActiveTaskTask;
}
getLastCurrentIfInTodaysList() {
const lastCurrent = this.$rootScope.r.lastCurrentTask;
if (this.isInTodaysList(lastCurrent)) {
return lastCurrent;
getLastActiveIfStartable() {
const lastActiveTask = this.$rootScope.r.lastActiveTaskTask;
if (this.isInTodaysList(lastActiveTask) && !lastActiveTask.isDone) {
return lastActiveTask;
} else {
return undefined;
}
}
setLastCurrent(task) {
this.$rootScope.r.lastCurrentTask = task;
this.$rootScope.r.lastActiveTaskTask = task;
}
// NOTE: doneBacklogTasks can't be really updated when accessed with this
@ -368,7 +372,6 @@
updateCurrent(task, isCallFromTimeTracking) {
const isCurrentTaskChanged = this.TasksUtil.isTaskChanged(task, this.$rootScope.r.currentTask);
const that = this;
this.lastCurrentTask = this.$rootScope.r.currentTask;
function moveInProgress(task) {
if (isCurrentTaskChanged) {
@ -420,14 +423,14 @@
// also save a reference to this task
if (task) {
this.$rootScope.r.lastCurrentTask = task;
this.$rootScope.r.lastActiveTaskTask = task;
}
}
if (this.IS_ELECTRON) {
window.ipcRenderer.send(IPC_EVENT_CURRENT_TASK_UPDATED, {
current: task,
lastCurrent: this.lastCurrentTask
lastActiveTask: this.$rootScope.r.lastActiveTaskTask
});
}
@ -663,15 +666,15 @@
this.updateCurrent(undefined);
}
selectLastTaskOrOpenDialog() {
startLastTaskOrOpenDialog() {
const defer = this.$q.defer();
if (!this.getCurrent()) {
const lastCurrentTask = this.getLastCurrentIfInTodaysList();
const lastActiveTaskTask = this.getLastActiveIfStartable();
if (lastCurrentTask) {
this.updateCurrent(lastCurrentTask);
defer.resolve(lastCurrentTask);
if (lastActiveTaskTask) {
this.updateCurrent(lastActiveTaskTask);
defer.resolve(lastActiveTaskTask);
} else {
this.Dialogs('TASK_SELECTION')
.then(defer.resolve)

View file

@ -56,7 +56,7 @@
// update indicator
window.ipcRenderer.send(IPC_EVENT_CURRENT_TASK_UPDATED, {
current: this.$rootScope.r.currentTask,
lastCurrent: this.Tasks.lastCurrentTask
lastActiveTask: this.Tasks.getLastActiveIfStartable()
});
if (!this.isIdle) {

View file

@ -101,7 +101,7 @@
play() {
// select task if none selected
this.Tasks.selectLastTaskOrOpenDialog()
this.Tasks.startLastTaskOrOpenDialog()
.then(() => {
this.start();
@ -165,7 +165,7 @@
}
} else {
this.data.currentCycle++;
this.selectTask()
this.Tasks.startLastTaskOrOpenDialog()
.then((task) => {
this.Notifier({
title: 'Pomodoro session #' + this.data.currentCycle + ' started',

View file

@ -86,24 +86,31 @@ function initAppListeners(app) {
function initListeners(isGnomeShellExtInstalled) {
electron.ipcMain.on('CHANGED_CURRENT_TASK', (ev, params) => {
const currentTask = params.current;
const lastCurrentTask = params.lastCurrent;
const lastActiveTaskTask = params.lastActiveTask;
if (currentTask && currentTask.title) {
const msg = createIndicatorStr(currentTask);
let msg;
if (tray) {
tray.setTitle(msg);
}
if (isGnomeShellExtInstalled) {
if (currentTask) {
msg = createIndicatorStr(currentTask);
}
if (isGnomeShellExtInstalled) {
// gnome indicator handling
if (currentTask && currentTask.title) {
dbus.setTask(currentTask.id, msg);
}
} else if (isGnomeShellExtInstalled) {
if (!currentTask && lastCurrentTask && !lastCurrentTask.isDone) {
const msg = createIndicatorStr(lastCurrentTask);
} else if (!currentTask && lastActiveTaskTask && !lastActiveTaskTask.isDone) {
const msg = createIndicatorStr(lastActiveTaskTask);
dbus.setTask('PAUSED', msg);
} else {
dbus.setTask('NONE', 'NONE');
}
} else if (tray) {
// tray handling
if (currentTask && currentTask.title) {
tray.setTitle(msg);
} else {
tray.setTitle('');
}
}
});
}