-
-
Notifications
You must be signed in to change notification settings - Fork 991
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: optionally notify when time estimate was exceeded #69
- Loading branch information
1 parent
9fda280
commit 0f84ef8
Showing
6 changed files
with
118 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
app-src/scripts/main/global-services/estimate-exceeded-checker-s.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/** | ||
* @ngdoc service | ||
* @name superProductivity.EstimateExceededChecker | ||
* @description | ||
* # EstimateExceededChecker | ||
* Service in the superProductivity. | ||
*/ | ||
|
||
(() => { | ||
'use strict'; | ||
|
||
const EXTRA_TIME_BETWEEN_NOTIFICATIONS = 60 * 1000; | ||
|
||
class EstimateExceededChecker { | ||
/* @ngInject */ | ||
constructor($mdToast, Notifier, $rootScope, $timeout) { | ||
this.$mdToast = $mdToast; | ||
this.Notifier = Notifier; | ||
this.$rootScope = $rootScope; | ||
this.$timeout = $timeout; | ||
this.currentToastPromise = undefined; | ||
this.notificationTimeout = undefined; | ||
this.isNotificationTimeoutRunning = false; | ||
} | ||
|
||
checkTaskAndNotify(task) { | ||
if (!this.isEnabled()) { | ||
return; | ||
} | ||
|
||
if (task.timeEstimate && task.timeSpent && moment.duration(task.timeSpent) | ||
.asMinutes() > moment.duration(task.timeEstimate).asMinutes()) { | ||
this.notify(task); | ||
} | ||
} | ||
|
||
isEnabled() { | ||
return this.$rootScope.r.config && this.$rootScope.r.config.isNotifyWhenTimeEstimateExceeded; | ||
} | ||
|
||
isToastOpen() { | ||
return (this.currentToastPromise && this.currentToastPromise.$$state.status === 0); | ||
} | ||
|
||
reInitNotificationTimeout() { | ||
if (this.notificationTimeout) { | ||
this.$timeout.cancel(this.notificationTimeout); | ||
} | ||
|
||
this.isNotificationTimeoutRunning = true; | ||
this.notificationTimeout = this.$timeout(() => { | ||
this.isNotificationTimeoutRunning = false; | ||
}, EXTRA_TIME_BETWEEN_NOTIFICATIONS) | ||
} | ||
|
||
notify(task) { | ||
if (!this.isToastOpen() && !this.isNotificationTimeoutRunning) { | ||
this.reInitNotificationTimeout(); | ||
|
||
const msg = `You exceeded your estimated time for "${task.title}".`; | ||
const toast = this.$mdToast.simple() | ||
.textContent(msg) | ||
.action('Add 1/2 hour') | ||
.hideDelay(10000) | ||
.position('bottom'); | ||
|
||
this.currentToastPromise = this.$mdToast.show(toast) | ||
.then((response) => { | ||
if (response === 'ok') { | ||
task.timeEstimate = moment.duration(task.timeEstimate); | ||
task.timeEstimate.add(moment.duration({ minutes: 30 })); | ||
} | ||
}); | ||
|
||
this.Notifier({ | ||
title: 'Time estimate exceeded!', | ||
message: msg, | ||
sound: true, | ||
wait: true | ||
}); | ||
} | ||
} | ||
} | ||
|
||
angular | ||
.module('superProductivity') | ||
.service('EstimateExceededChecker', EstimateExceededChecker); | ||
|
||
// hacky fix for ff | ||
EstimateExceededChecker.$$ngIsClass = true; | ||
})(); |
17 changes: 17 additions & 0 deletions
17
app-src/scripts/main/global-services/estimate-exceeded-checker-s.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
'use strict'; | ||
|
||
describe('Service: EstimateExceededChecker', () => { | ||
// load the service's module | ||
beforeEach(module('superProductivity')); | ||
|
||
// instantiate service | ||
let EstimateExceededChecker; | ||
beforeEach(inject((_EstimateExceededChecker_) => { | ||
EstimateExceededChecker = _EstimateExceededChecker_; | ||
})); | ||
|
||
it('should be defined', () => { | ||
expect(true).toBe(true); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters