Skip to content

Commit

Permalink
Create timer component for tracking worker time.
Browse files Browse the repository at this point in the history
  • Loading branch information
lydiagu committed Apr 7, 2016
1 parent e6c9794 commit 86328fd
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 1 deletion.
2 changes: 1 addition & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var files = {
'orchestra/static/orchestra/common/components/checklist/css/checklist.scss',
'orchestra/static/orchestra/common/components/iframe/css/iframe.scss',
'orchestra/static/orchestra/common/components/quill/css/quill.scss',
'orchestra/static/orchestra/common/components/timer/timer.scss',
'orchestra/static/orchestra/common/css/orchestra.scss',
],
all_scss: [],
Expand All @@ -50,7 +51,6 @@ gulp.task('scss', function() {
return gulp.src(files.scss, {
base: './'
})
.pipe(cache('scss'))
.pipe(gulpif(!argv.production, sourcemaps.init()))
.pipe(sass())
.pipe(gulpif(!argv.production, sourcemaps.write()))
Expand Down
27 changes: 27 additions & 0 deletions 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.

67 changes: 67 additions & 0 deletions orchestra/static/orchestra/common/components/timer/directives.js
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 orchestra/static/orchestra/common/components/timer/timer.html
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 orchestra/static/orchestra/common/components/timer/timer.scss
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;
}
}
1 change: 1 addition & 0 deletions orchestra/templates/orchestra/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<link rel="stylesheet" type="text/css" href="{% static 'orchestra/common/components/checklist/lib/dragula/dragula.min.css' %}">
<link rel="stylesheet" type="text/css" href="{% static 'dist/orchestra/common/components/checklist/css/checklist.css' %}">
<link rel="stylesheet" type="text/css" href="{% static 'dist/orchestra/common/components/iframe/css/iframe.css' %}">
<link rel="stylesheet" type="text/css" href="{% static 'dist/orchestra/common/components/timer/timer.css' %}">

{% block page_stylesheets %}
{% endblock page_stylesheets %}
Expand Down
3 changes: 3 additions & 0 deletions orchestra/templates/orchestra/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
</div>
<!-- notification end -->

<work-timer task-id="1"></work_timer>

<div id="nav-options" class="dropdown">
<div class="dropdown-toggle" id="dropdown-menu-main" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
{{ user.username }}
Expand Down Expand Up @@ -72,6 +74,7 @@
<script src="{% static "orchestra/common/components/iframe/js/directives.js" %}" type="text/javascript"></script>
<script src="{% static "orchestra/common/components/project_folder/project_folder.js" %}" type="text/javascript"></script>
<script src="{% static "orchestra/common/components/team_messages/team_messages.js" %}" type="text/javascript"></script>
<script src="{% static "orchestra/common/components/timer/directives.js" %}" type="text/javascript"></script>
<script src="{% static "orchestra/task/js/module.js" %}" type="text/javascript"></script>
<script src="{% static "orchestra/task/js/controllers.js" %}" type="text/javascript"></script>
<script src="{% static "orchestra/task/js/directives.js" %}" type="text/javascript"></script>
Expand Down

0 comments on commit 86328fd

Please sign in to comment.