diff --git a/babyblotter/settings/base.py b/babyblotter/settings/base.py index 100bf312..e51d3bc3 100644 --- a/babyblotter/settings/base.py +++ b/babyblotter/settings/base.py @@ -108,7 +108,7 @@ STATIC_URL = '/static/' STATIC_ROOT = os.path.join(BASE_DIR, 'static') STATICFILES_DIRS = [ - os.path.join(BASE_DIR, 'babyblotter/static'), + os.path.join(BASE_DIR, 'babyblotter', 'static'), ] diff --git a/babyblotter/templates/babyblotter/base.html b/babyblotter/templates/babyblotter/base.html index d368abfe..befdc487 100644 --- a/babyblotter/templates/babyblotter/base.html +++ b/babyblotter/templates/babyblotter/base.html @@ -15,6 +15,7 @@ {% block page %}{% endblock %} + {% block javascript %}{% endblock %} \ No newline at end of file diff --git a/core/static/js/timer.js b/core/static/js/timer.js new file mode 100644 index 00000000..f367e060 --- /dev/null +++ b/core/static/js/timer.js @@ -0,0 +1,65 @@ +if (typeof jQuery === 'undefined') { + throw new Error('BabyBlotter Timer requires jQuery.') +} + +var BBTimer = function ($) { + /* Baby Blotter Timer + * + * Uses a supplied ID to run a timer. The element using the ID must have + * three children with the following classes: + * * timer-seconds + * * timer-minutes + * * timer-hours + */ + var runIntervalId = null; + var timerElement = null; + + var BBTimer = { + run: function(id) { + timerElement = $('#' + id); + + if (timerElement.length == 0) { + console.error('BBTimer: Timer element not found.') + return false; + } + + if (timerElement.find('.timer-seconds').length == 0 + || timerElement.find('.timer-minutes').length == 0 + || timerElement.find('.timer-hours').length == 0) { + console.error('BBTimer: Element does not contain expected children.'); + return false; + } + + runIntervalId = setInterval(this.tick, 1000); + return runIntervalId; + }, + + tick: function() { + var s = timerElement.find('.timer-seconds'); + var seconds = Number(s.text()); + if (seconds < 59) { + s.text(seconds + 1); + return; + } + else { + s.text(0); + } + + var m = timerElement.find('.timer-minutes'); + var minutes = Number(m.text()); + if (minutes < 59) { + m.text(minutes + 1); + return; + } + else { + m.text(0); + } + + var h = timerElement.find('.timer-hours'); + var hours = Number(h.text()); + h.text(hours + 1); + } + }; + + return BBTimer; +}(jQuery); diff --git a/core/templates/core/timer_detail.html b/core/templates/core/timer_detail.html index f5c9db08..8c27e8a7 100644 --- a/core/templates/core/timer_detail.html +++ b/core/templates/core/timer_detail.html @@ -6,10 +6,10 @@ {% block content %}
-

- {{ object.current_duration|hours }}h - {{ object.current_duration|minutes }}m - {{ object.current_duration|seconds }}s +

+ {{ object.current_duration|hours }}h + {{ object.current_duration|minutes }}m + {{ object.current_duration|seconds }}s

Started {{ object.start }} by {{ object.user }}

@@ -37,4 +37,10 @@ role="button"> Delete Timer {% endif %}
+{% endblock %} + +{% block javascript %} + {% endblock %} \ No newline at end of file diff --git a/gulpfile.js b/gulpfile.js index 7b91238d..9aaea7ec 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,6 +1,20 @@ var gulp = require('gulp'); var concat = require('gulp-concat'); +/* APP FILES */ + +gulp.task('app:scripts', function() { + return gulp.src([ + 'core/static/js/timer.js' + ]) + .pipe(concat('app.js')) + .pipe(gulp.dest('babyblotter/static/babyblotter/js/')); +}); + +gulp.task('app', ['app:scripts']); + +/* VENDOR FILES */ + gulp.task('vendor:scripts', function() { return gulp.src([ 'node_modules/jquery/dist/jquery.js', @@ -32,4 +46,6 @@ gulp.task('vendor:fonts', function() { gulp.task('vendor', ['vendor:styles', 'vendor:scripts', 'vendor:fonts']); -gulp.task('default', ['vendor']); \ No newline at end of file +/* DEFAULT */ + +gulp.task('default', ['vendor', 'app']); \ No newline at end of file