add better handling of jira tasks and saving the default action for transitions

This commit is contained in:
Johannes Millan 2017-01-11 11:41:55 +01:00
parent 1deb957b10
commit 832770521b
6 changed files with 106 additions and 34 deletions

View file

@ -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);
}
})();

View file

@ -1,7 +1,9 @@
<md-dialog aria-label="Jira Set In Progress Dialog">
<form ng-submit="vm.updateTask(vm.chosenTransitionIndex)">
<md-dialog-content layout-padding>
<p>Do you want to update the task '<strong>{{ vm.task.title }}</strong>' on jira?</p>
<p><strong ng-if="vm.type==='OPEN'">Open</strong>
<strong ng-if="vm.type==='IN_PROGRESS'">In progress</strong>
<strong ng-if="vm.type==='DONE'">Done</strong>: Do you want to update the task '<strong>{{ vm.task.title }}</strong>' on jira?</p>
<p>Move to:</p>
<md-radio-group ng-model="vm.chosenTransitionIndex">
@ -10,8 +12,22 @@
class="md-primary">{{ transition.name }}
</md-radio-button>
</md-radio-group>
<md-checkbox md-no-ink
ng-model="vm.saveAsDefaultAction"
aria-label="save as default action">
Mark this as a default action for setting a task to
<strong ng-if="vm.type==='OPEN'">open</strong>
<strong ng-if="vm.type==='IN_PROGRESS'">in progress</strong>
<strong ng-if="vm.type==='DONE'">done</strong>.
This will be set then always, when a task is changed to
<strong ng-if="vm.type==='OPEN'">open</strong>
<strong ng-if="vm.type==='IN_PROGRESS'">in progress</strong>
<strong ng-if="vm.type==='DONE'">done</strong>.
</md-checkbox>
</md-dialog-content>
<md-dialog-actions>
<md-button ng-click="vm.cancel()"
type="button"

View file

@ -14,10 +14,11 @@
.controller('JiraSetInProgressCtrl', JiraSetInProgressCtrl);
/* @ngInject */
function JiraSetInProgressCtrl($mdDialog, task, transitions, $window) {
function JiraSetInProgressCtrl($mdDialog, task, transitions, type, $window, $localStorage) {
let vm = this;
vm.transitions = transitions;
vm.task = task;
vm.type = type;
vm.chosenTransitionIndex = $window._.findIndex(vm.transitions, (transition) => {
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);
};

View file

@ -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);
});
});
});
//}
}
}
};

View file

@ -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) => {

View file

@ -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();