-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create timer component for tracking worker time.
- Loading branch information
Showing
7 changed files
with
122 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
27 changes: 27 additions & 0 deletions
27
orchestra/static/dist/orchestra/common/components/timer/timer.css
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
67 changes: 67 additions & 0 deletions
67
orchestra/static/orchestra/common/components/timer/directives.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,67 @@ | ||
(function() { | ||
'use strict'; | ||
|
||
angular | ||
.module('orchestra.common.components.directives') | ||
.directive('workTimer', workTimer); | ||
|
||
function workTimer() { | ||
return { | ||
restrict: 'E', | ||
scope: { | ||
taskId: '=taskId', | ||
}, | ||
link: function(scope, el, attr) { | ||
}, | ||
controller: workTimerController, | ||
controllerAs: 'vm', | ||
templateUrl: '/static/orchestra/common/components/timer/timer.html' | ||
}; | ||
} | ||
|
||
function makeTwoDigits(i) { | ||
if (i < 10) {i = "0" + i}; // add zero in front of numbers < 10 | ||
return i; | ||
} | ||
|
||
function prettyDisplayTime(milliseconds) { | ||
var hours = Math.floor(milliseconds / 1000 / 60 / 60); | ||
milliseconds = milliseconds - hours * 1000 * 3600; | ||
var mins = Math.floor(milliseconds / 1000 / 60); | ||
milliseconds = milliseconds - mins * 1000 * 60; | ||
var secs = Math.round(milliseconds / 1000); | ||
mins = makeTwoDigits(mins); | ||
secs = makeTwoDigits(secs); | ||
return hours + ":" + mins + ":" + secs; | ||
} | ||
|
||
function workTimerController($scope, $timeout) { | ||
var vm = this; | ||
vm.taskId = $scope.taskId; | ||
vm.displayTime = ''; | ||
vm.timerRunning = false; | ||
|
||
var startTime = null; | ||
var timerPromise = null; | ||
|
||
vm.startTimer = function() { | ||
function updateTime() { | ||
var today = new Date(); | ||
var diff = today - startTime; | ||
vm.displayTime = prettyDisplayTime(diff); | ||
if (vm.timerRunning) { | ||
timerPromise = $timeout(updateTime, 500); | ||
} | ||
} | ||
|
||
startTime = new Date(); | ||
vm.timerRunning = true; | ||
updateTime(); | ||
} | ||
|
||
vm.stopTimer = function() { | ||
$timeout.cancel(timerPromise); | ||
vm.timerRunning = false; | ||
} | ||
} | ||
})(); |
5 changes: 5 additions & 0 deletions
5
orchestra/static/orchestra/common/components/timer/timer.html
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,5 @@ | ||
<div class="timer"> | ||
<a ng-if="!vm.timerRunning" class="start-timer btn" ng-click="vm.startTimer()">Start Timer</a> | ||
<a ng-if="vm.timerRunning" class="start-timer btn" ng-click="vm.stopTimer()">Stop Timer</a> | ||
<div class="time-display">{{vm.displayTime}}</div> | ||
</div> |
18 changes: 18 additions & 0 deletions
18
orchestra/static/orchestra/common/components/timer/timer.scss
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,18 @@ | ||
@import 'orchestra/static/orchestra/common/css/common'; | ||
|
||
.timer { | ||
display: inline-block; | ||
|
||
.start-timer.btn { | ||
color: white; | ||
background-color: $light-green; | ||
display: inline-block; | ||
} | ||
|
||
.time-display { | ||
font-size: 30px; | ||
color: white; | ||
margin-left: 20px; | ||
display: inline-block; | ||
} | ||
} |
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