mirror of
https://github.com/johannesjo/super-productivity.git
synced 2026-08-01 20:12:11 +00:00
70 lines
1.7 KiB
JavaScript
70 lines
1.7 KiB
JavaScript
/**
|
|
* @ngdoc directive
|
|
* @name superProductivity.directive:workView
|
|
* @description
|
|
* # workView
|
|
*/
|
|
|
|
(function () {
|
|
'use strict';
|
|
|
|
angular
|
|
.module('superProductivity')
|
|
.directive('workView', workView);
|
|
|
|
/* @ngInject */
|
|
function workView() {
|
|
return {
|
|
templateUrl: 'scripts/work-view/work-view-d.html',
|
|
bindToController: true,
|
|
controller: WorkViewCtrl,
|
|
controllerAs: 'vm',
|
|
restrict: 'E',
|
|
scope: true
|
|
};
|
|
}
|
|
|
|
/* @ngInject */
|
|
function WorkViewCtrl(Tasks, $rootScope, $scope, Dialogs) {
|
|
let vm = this;
|
|
|
|
function mergeDoneAndUndone() {
|
|
// we need to re-merge because of splitting up the tasks into two
|
|
if (vm.tasksUndone && vm.tasksDone) {
|
|
let newTaskList = vm.tasksDone.concat(vm.tasksUndone);
|
|
Tasks.updateToday(newTaskList);
|
|
}
|
|
}
|
|
|
|
vm.openAddTask = () => {
|
|
Dialogs('ADD_TASK');
|
|
};
|
|
|
|
vm.onItemMovedUndone = () => {
|
|
// mark all items in list to done
|
|
for (let i = 0; i < vm.tasksDone.length; i++) {
|
|
let task = vm.tasksDone[i];
|
|
task.isDone = true;
|
|
}
|
|
|
|
};
|
|
vm.onItemMovedDone = () => {
|
|
// mark all items in list to undone
|
|
for (let i = 0; i < vm.tasksUndone.length; i++) {
|
|
let task = vm.tasksUndone[i];
|
|
task.isDone = false;
|
|
}
|
|
};
|
|
|
|
$scope.$watch('vm.tasksDone', mergeDoneAndUndone, true);
|
|
$scope.$watch('vm.tasksUndone', mergeDoneAndUndone, true);
|
|
|
|
$scope.$watch('r.tasks', () => {
|
|
vm.tasksUndone = Tasks.getUndoneToday();
|
|
vm.tasksDone = Tasks.getDoneToday();
|
|
vm.totalTimeWorkedToday = Tasks.getTimeWorkedToday();
|
|
vm.totalEstimationRemaining = Tasks.calcRemainingTime(vm.tasksUndone);
|
|
}, true);
|
|
}
|
|
|
|
})();
|