From 832770521be9dcdf5753580fe4e4601f20cd53ca Mon Sep 17 00:00:00 2001 From: Johannes Millan Date: Wed, 11 Jan 2017 11:41:55 +0100 Subject: [PATCH] add better handling of jira tasks and saving the default action for transitions --- app/scripts/_app.js | 66 +++++++++++++++++++ .../jira-set-in-progress-c.html | 18 ++++- .../jira-set-in-progress-c.js | 12 +++- app/scripts/main/global-services/jira-s.js | 19 +++--- app/scripts/task-list/task-list-d.js | 2 +- app/scripts/work-view/work-view-d.js | 23 +------ 6 files changed, 106 insertions(+), 34 deletions(-) diff --git a/app/scripts/_app.js b/app/scripts/_app.js index 76a2cec369..d33c6064b5 100644 --- a/app/scripts/_app.js +++ b/app/scripts/_app.js @@ -48,6 +48,11 @@ isFirstLogin: true, defaultTransitionInProgress: undefined, defaultTransitionDone: undefined, + transitions: { + OPEN: undefined, + IN_PROGRESS: undefined, + DONE: undefined + } } }) .constant('IS_ELECTRON', (typeof window.ipcRenderer !== 'undefined')) @@ -75,6 +80,7 @@ ) .config(configMdTheme) .run(initGlobalModels) + .run(handleCurrentTaskUpdates) .run(initGlobalShortcuts); function configMdTheme($mdThemingProvider, THEMES) { @@ -141,4 +147,64 @@ }); } + function handleCurrentTaskUpdates($rootScope, $q, Jira, Tasks, IS_ELECTRON, $state) { + function doAsyncSeries(arr) { + return arr.reduce(function (promise, item) { + return promise.then(function () { + return Jira.updateStatus(item.val, item.type); + }); + }, $q.when('NOT_YET')); + } + + $rootScope.$watch('vm.r.currentTask', (mVal, oldVal) => { + // check if jira support is available + if (IS_ELECTRON) { + let dialogsAndRequests = []; + + // handle old current first + // task (id) changed or no previous task + if (!mVal || (mVal !== oldVal) && (mVal.id !== (oldVal && oldVal.id))) { + // previous was jira task + if (oldVal && oldVal.originalKey) { + // and has not been worked on + if (!oldVal.timeSpent) { + // only execute after previous request/dialog if set + dialogsAndRequests.push({ val: oldVal, type: 'OPEN' }); + } + // or has been done + if (oldVal.isDone) { + // only execute after previous request/dialog if set + dialogsAndRequests.push({ val: oldVal, type: 'DONE' }); + } + } + } + + // handle new current + // is jira task + if (mVal && mVal.originalKey) { + // current task (id) changed + if (mVal && (mVal.id !== (oldVal && oldVal.id))) { + dialogsAndRequests.push({ val: mVal, type: 'IN_PROGRESS' }); + } + } + + // TODO handle reopened + if (dialogsAndRequests.length > 0) { + doAsyncSeries(dialogsAndRequests); + } + } + + if (mVal && mVal.isDone) { + let undoneTasks = Tasks.getUndoneToday(); + + // go to daily planner if there are no undone tasks left + if (!undoneTasks || undoneTasks.length === 0) { + $state.go('daily-planner'); + } else { + Tasks.updateCurrent(undoneTasks[0]); + } + } + }, true); + } + })(); diff --git a/app/scripts/dialogs/jira-set-in-progress/jira-set-in-progress-c.html b/app/scripts/dialogs/jira-set-in-progress/jira-set-in-progress-c.html index b6b7ce02fd..292dccb4d8 100644 --- a/app/scripts/dialogs/jira-set-in-progress/jira-set-in-progress-c.html +++ b/app/scripts/dialogs/jira-set-in-progress/jira-set-in-progress-c.html @@ -1,7 +1,9 @@
-

Do you want to update the task '{{ vm.task.title }}' on jira?

+

Open + In progress + Done: Do you want to update the task '{{ vm.task.title }}' on jira?

Move to:

@@ -10,8 +12,22 @@ class="md-primary">{{ transition.name }} + + + Mark this as a default action for setting a task to + open + in progress + done. + This will be set then always, when a task is changed to + open + in progress + done. +
+ { return transition.name === (vm.task.originalStatus && vm.task.originalStatus.name); @@ -25,6 +26,15 @@ vm.updateTask = (chosenTransitionIndex) => { let transition = vm.transitions[chosenTransitionIndex]; + + if (vm.saveAsDefaultAction) { + if (!$localStorage.jiraSettings.transitions) { + $localStorage.jiraSettings.transitions = {}; + } + $localStorage.jiraSettings.transitions[type] = transition; + $localStorage.jiraSettings.allTransitions = transitions; + } + $mdDialog.hide(transition); }; diff --git a/app/scripts/main/global-services/jira-s.js b/app/scripts/main/global-services/jira-s.js index 2654918512..202a1bedfb 100644 --- a/app/scripts/main/global-services/jira-s.js +++ b/app/scripts/main/global-services/jira-s.js @@ -47,17 +47,18 @@ }); } - this.updateStatus = (task) => { + this.updateStatus = (task, type) => { if (task.originalKey && task.originalType === ISSUE_TYPE) { - //if ($localStorage.jiraSettings.defaultTransitionInProgress) { - //} else { - this.getTransitionsForIssue(task).then((response) => { - let transitions = response.response.transitions; - Dialogs('JIRA_SET_IN_PROGRESS', { transitions, task }).then((transition) => { - this.transitionIssue(task.originalId, transition); + if ($localStorage.jiraSettings.transitions && $localStorage.jiraSettings.transitions[type]) { + return this.transitionIssue(task.originalId, $localStorage.jiraSettings.transitions[type]); + } else { + this.getTransitionsForIssue(task).then((response) => { + let transitions = response.response.transitions; + return Dialogs('JIRA_SET_IN_PROGRESS', { transitions, task, type }).then((transition) => { + this.transitionIssue(task.originalId, transition); + }); }); - }); - //} + } } }; diff --git a/app/scripts/task-list/task-list-d.js b/app/scripts/task-list/task-list-d.js index 9f7d7a73ae..2c902abac7 100644 --- a/app/scripts/task-list/task-list-d.js +++ b/app/scripts/task-list/task-list-d.js @@ -37,7 +37,7 @@ } /* @ngInject */ - function TaskListCtrl(Dialogs, $mdToast, $timeout, $window, Tasks) { + function TaskListCtrl(Dialogs, $mdToast, $timeout, $window, Tasks, Jira) { let vm = this; vm.estimateTime = (task) => { diff --git a/app/scripts/work-view/work-view-d.js b/app/scripts/work-view/work-view-d.js index a95429abd2..c40946e96c 100644 --- a/app/scripts/work-view/work-view-d.js +++ b/app/scripts/work-view/work-view-d.js @@ -25,7 +25,7 @@ } /* @ngInject */ - function WorkViewCtrl(Tasks, $rootScope, $scope, $state, Dialogs, Jira) { + function WorkViewCtrl(Tasks, $rootScope, $scope, Dialogs) { let vm = this; vm.r = $rootScope.r; @@ -66,27 +66,6 @@ vm.tasksDone = Tasks.getDoneToday(); }, true); - $scope.$watch('vm.r.currentTask', (mVal, oldVal) => { - if (mVal && mVal.originalKey && (mVal !== oldVal) && (mVal.id !== (oldVal && oldVal.id))) { - // TODO this should be somewhere else - // check if jira support is available - if (window.isElectron) { - Jira.updateStatus(mVal); - } - } - - if (mVal && mVal.isDone) { - let undoneTasks = Tasks.getUndoneToday(); - - // go to daily planner if there are no undone tasks left - if (!undoneTasks || undoneTasks.length === 0) { - $state.go('daily-planner'); - } else { - Tasks.updateCurrent(undoneTasks[0]); - } - } - }, true); - // watch for total time spent today $scope.$watch('vm.r.tasks', () => { vm.totalTimeWorkedToday = Tasks.getTimeWorkedToday();