mirror of https://github.com/snachodog/mybuddy.git
Adjust for changes from main rebase
This commit is contained in:
parent
613f53a4da
commit
4d1d915478
|
@ -4,9 +4,8 @@ from django.db import migrations, models
|
|||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("babybuddy", "0023_alter_settings_timezone"),
|
||||
("babybuddy", "0027_remove_standard_group"),
|
||||
]
|
||||
|
||||
operations = [
|
|
@ -93,6 +93,7 @@ class Settings(models.Model):
|
|||
return self.dashboard_refresh_rate.seconds * 1000
|
||||
return None
|
||||
|
||||
|
||||
class SiteSettings(models.Model):
|
||||
nap_start_min = models.TimeField(
|
||||
verbose_name=_("Default minimum nap start time"),
|
||||
|
|
|
@ -76,7 +76,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse"
|
||||
data-target="#navbar-app" aria-controls="navbar-app"
|
||||
data-bs-target="#navbar-app" aria-controls="navbar-app"
|
||||
aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
|
|
@ -9,7 +9,6 @@ def delete_inactive_timers(apps, schema_editor):
|
|||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("core", "0026_alter_feeding_end_alter_feeding_start_and_more"),
|
||||
]
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<a href="{% url 'core:child' current_child.slug %}">{{ current_child }}</a>
|
||||
{% if children.count > 0 %}
|
||||
<a href="#" class="ml-1 pl-1 pr-1 dropdown-toggle-split" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
<span class="sr-only">{% trans 'Switch child' %}</span>
|
||||
<span class="visually-hidden">{% trans 'Switch child' %}</span>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16">
|
||||
<path d="M3.626 6.832A.5.5 0 0 1 4 6h8a.5.5 0 0 1 .374.832l-4 4.5a.5.5 0 0 1-.748 0l-4-4.5z"></path>
|
||||
<path d="M0 2a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2V2zm15 0a1 1 0 0 0-1-1H2a1 1 0 0 0-1 1v12a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V2z"></path>
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
</div>
|
||||
</div>
|
||||
{% else %}
|
||||
<label class="sr-only">{% trans "Quick Start Timer" %}</label>
|
||||
<label class="visually-hidden">{% trans "Quick Start Timer" %}</label>
|
||||
<button class="btn m-0 p-0 text-success">
|
||||
<i class="icon-2x icon-timer" aria-hidden="true"></i>
|
||||
</button>
|
||||
|
|
|
@ -26,9 +26,6 @@
|
|||
{% if not unique_child %}
|
||||
<th>{% trans "Child" %}</th>
|
||||
{% endif %}
|
||||
<th>{% trans "Duration" %}</th>
|
||||
<th>{% trans "End" %}</th>
|
||||
<th>{% trans "Active" %}</th>
|
||||
<th>{% trans "User" %}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
@ -44,13 +41,6 @@
|
|||
{% endif %}
|
||||
</td>
|
||||
{% endif %}
|
||||
<td>{{ timer.duration|duration_string }}</td>
|
||||
<td>
|
||||
{% if timer.end %}
|
||||
{{ timer.end|datetime_short }}
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>{{ timer.active|bool_icon }}</td>
|
||||
<td>{{ timer.user_username }}</td>
|
||||
</tr>
|
||||
{% empty %}
|
||||
|
|
|
@ -11,14 +11,6 @@
|
|||
</a>
|
||||
<div class="dropdown-menu" aria-labelledby="nav-timer-menu-link">
|
||||
{% if perms.core.add_timer %}
|
||||
<div class="dropdown-item">
|
||||
<form action="{% url 'core:timer-add-quick' %}" role="form" method="post" class="d-inline">
|
||||
{% csrf_token %}
|
||||
<button class="btn text-start p-0">
|
||||
<i class="icon-timer" aria-hidden="true"></i> {% trans "Quick Start Timer" %}
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
<a class="dropdown-item" href="{% url 'core:timer-add' %}">
|
||||
<i class="icon-add" aria-hidden="true"></i> {% trans "Start Timer" %}
|
||||
</a>
|
||||
|
|
|
@ -40,11 +40,11 @@
|
|||
{% if sleeps|length > 1 %}
|
||||
<a class="carousel-control-prev" href="#sleep-days-carousel" role="button" data-slide="prev">
|
||||
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
|
||||
<span class="sr-only">{% trans "Previous" %}</span>
|
||||
<span class="visually-hidden">{% trans "Previous" %}</span>
|
||||
</a>
|
||||
<a class="carousel-control-next" href="#sleep-days-carousel" role="button" data-slide="next">
|
||||
<span class="carousel-control-next-icon" aria-hidden="true"></span>
|
||||
<span class="sr-only">{% trans "Next" %}</span>
|
||||
<span class="visually-hidden">{% trans "Next" %}</span>
|
||||
</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
|
|
@ -31,27 +31,7 @@ module.exports = {
|
|||
'node_modules/jquery/dist/jquery.js',
|
||||
'node_modules/@popperjs/core/dist/umd/popper.js',
|
||||
'node_modules/bootstrap/dist/js/bootstrap.js',
|
||||
'node_modules/masonry-layout/dist/masonry.pkgd.js',
|
||||
'node_modules/moment/moment.js',
|
||||
'node_modules/moment/locale/ca.js',
|
||||
'node_modules/moment/locale/cs.js',
|
||||
'node_modules/moment/locale/da.js',
|
||||
'node_modules/moment/locale/de.js',
|
||||
'node_modules/moment/locale/en-gb.js',
|
||||
'node_modules/moment/locale/es.js',
|
||||
'node_modules/moment/locale/fi.js',
|
||||
'node_modules/moment/locale/fr.js',
|
||||
'node_modules/moment/locale/it.js',
|
||||
'node_modules/moment/locale/hu.js',
|
||||
'node_modules/moment/locale/nl.js',
|
||||
'node_modules/moment/locale/pl.js',
|
||||
'node_modules/moment/locale/pt.js',
|
||||
'node_modules/moment/locale/ru.js',
|
||||
'node_modules/moment/locale/sv.js',
|
||||
'node_modules/moment/locale/tr.js',
|
||||
'node_modules/moment/locale/zh-cn.js',
|
||||
'node_modules/moment-timezone/builds/moment-timezone-with-data-10-year-range.js',
|
||||
'node_modules/@eonasdan/tempus-dominus/dist/js/tempus-dominus.js'
|
||||
'node_modules/masonry-layout/dist/masonry.pkgd.js'
|
||||
],
|
||||
graph: [
|
||||
'node_modules/plotly.js/dist/plotly-cartesian.js',
|
||||
|
|
|
@ -166,7 +166,7 @@ function lint() {
|
|||
*/
|
||||
function scripts() {
|
||||
const streams = [];
|
||||
const types = ['graph', 'app', 'tags_editor'];
|
||||
const types = ['vendor', 'graph', 'app', 'tags_editor'];
|
||||
types.forEach((type) => {
|
||||
streams.push(
|
||||
gulp.src(config.scriptsConfig[type])
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -7,7 +7,6 @@
|
|||
"url": "https://github.com/babybuddy/babybuddy.git"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eonasdan/tempus-dominus": "^6.4.4",
|
||||
"@popperjs/core": "^2.11.7",
|
||||
"@ronilaukkarinen/gulp-stylelint": "^14.1.1",
|
||||
"bootstrap": "^5.2.3",
|
||||
|
@ -26,8 +25,6 @@
|
|||
"gulp-uglify": "^3.0.2",
|
||||
"jquery": "^3.6.4",
|
||||
"masonry-layout": "^4.2.2",
|
||||
"moment": "^2.29.4",
|
||||
"moment-timezone": "^0.5.42",
|
||||
"npm-force-resolutions": "^0.0.10",
|
||||
"plotly.js": "^2.20.0",
|
||||
"pulltorefreshjs": "^0.1.22",
|
||||
|
|
Binary file not shown.
|
@ -1 +1 @@
|
|||
if("undefined"==typeof jQuery)throw new Error("Baby Buddy requires jQuery.");var BabyBuddy={};function preventDoubleSubmit(){return!1}BabyBuddy.PullToRefresh=function(e){return{init:function(){e.init({mainElement:"body",onRefresh:this.onRefresh})},onRefresh:function(){window.location.reload()}}}(PullToRefresh),$("form").off("submit",preventDoubleSubmit),$("form").on("submit",function(){$(this).on("submit",preventDoubleSubmit)}),BabyBuddy.Timer=function(e){var n=null,t=null,i=null,d=new Date,r=null,o={run:function(d,u){return t=d,0===(i=e("#"+u)).length?(console.error("BBTimer: Timer element not found."),!1):0===i.find(".timer-seconds").length||0===i.find(".timer-minutes").length||0===i.find(".timer-hours").length?(console.error("BBTimer: Element does not contain expected children."),!1):(n=setInterval(this.tick,1e3),void 0!==document.hidden?r="hidden":void 0!==document.msHidden?r="msHidden":void 0!==document.webkitHidden&&(r="webkitHidden"),void window.addEventListener("focus",o.handleVisibilityChange,!1))},handleVisibilityChange:function(){!document[r]&&new Date-d>1&&o.update()},tick:function(){var e=i.find(".timer-seconds"),n=Number(e.text());if(n<59)e.text(n+1);else{e.text(0);var t=i.find(".timer-minutes"),d=Number(t.text());if(d<59)t.text(d+1);else{t.text(0);var r=i.find(".timer-hours"),o=Number(r.text());r.text(o+1)}}},update:function(){e.get("/api/timers/"+t+"/",function(e){if(e&&"duration"in e){clearInterval(n);var t=e.duration.split(/[\s:.]/);5===t.length&&(t[0]=24*parseInt(t[0])+parseInt(t[1]),t[1]=t[2],t[2]=t[3]),i.find(".timer-hours").text(parseInt(t[0])),i.find(".timer-minutes").text(parseInt(t[1])),i.find(".timer-seconds").text(parseInt(t[2])),d=new Date,e.active?n=setInterval(o.tick,1e3):i.addClass("timer-stopped")}})}};return o}(jQuery),BabyBuddy.Dashboard=function(e){var n=null,t={watch:function(i,d){if(0==e("#"+i).length)return console.error("Baby Buddy: Dashboard element not found."),!1;void 0!==document.hidden?n="hidden":void 0!==document.msHidden?n="msHidden":void 0!==document.webkitHidden&&(n="webkitHidden"),void 0===window.addEventListener||void 0===document.hidden?d&&setInterval(this.update,d):(window.addEventListener("focus",t.handleVisibilityChange,!1),d&&setInterval(t.handleVisibilityChange,d))},handleVisibilityChange:function(){document[n]||t.update()},update:function(){location.reload()}};return t}(jQuery);
|
||||
if("undefined"==typeof jQuery)throw new Error("Baby Buddy requires jQuery.");var BabyBuddy={};function preventDoubleSubmit(){return!1}BabyBuddy.PullToRefresh=function(e){return{init:function(){e.init({mainElement:"body",onRefresh:this.onRefresh})},onRefresh:function(){window.location.reload()}}}(PullToRefresh),$("form").off("submit",preventDoubleSubmit),$("form").on("submit",function(){$(this).on("submit",preventDoubleSubmit)}),BabyBuddy.Timer=function(e){var n=null,t=null,i=null,d=new Date,r=null,o={run:function(d,u){return t=d,0===(i=e("#"+u)).length?(console.error("BBTimer: Timer element not found."),!1):0===i.find(".timer-seconds").length||0===i.find(".timer-minutes").length||0===i.find(".timer-hours").length?(console.error("BBTimer: Element does not contain expected children."),!1):(n=setInterval(this.tick,1e3),void 0!==document.hidden?r="hidden":void 0!==document.msHidden?r="msHidden":void 0!==document.webkitHidden&&(r="webkitHidden"),void window.addEventListener("focus",o.handleVisibilityChange,!1))},handleVisibilityChange:function(){!document[r]&&new Date-d>1&&o.update()},tick:function(){var e=i.find(".timer-seconds"),n=Number(e.text());if(n<59)e.text(n+1);else{e.text(0);var t=i.find(".timer-minutes"),d=Number(t.text());if(d<59)t.text(d+1);else{t.text(0);var r=i.find(".timer-hours"),o=Number(r.text());r.text(o+1)}}},update:function(){e.get("/api/timers/"+t+"/",function(e){if(e&&"duration"in e){clearInterval(n);var t=e.duration.split(/[\s:.]/);5===t.length&&(t[0]=24*parseInt(t[0])+parseInt(t[1]),t[1]=t[2],t[2]=t[3]),i.find(".timer-hours").text(parseInt(t[0])),i.find(".timer-minutes").text(parseInt(t[1])),i.find(".timer-seconds").text(parseInt(t[2])),d=new Date,n=setInterval(o.tick,1e3)}})}};return o}(jQuery),BabyBuddy.Dashboard=function(e){var n=null,t={watch:function(i,d){if(0==e("#"+i).length)return console.error("Baby Buddy: Dashboard element not found."),!1;void 0!==document.hidden?n="hidden":void 0!==document.msHidden?n="msHidden":void 0!==document.webkitHidden&&(n="webkitHidden"),void 0===window.addEventListener||void 0===document.hidden?d&&setInterval(this.update,d):(window.addEventListener("focus",t.handleVisibilityChange,!1),d&&setInterval(t.handleVisibilityChange,d))},handleVisibilityChange:function(){document[n]||t.update()},update:function(){location.reload()}};return t}(jQuery);
|
Binary file not shown.
|
@ -1,206 +0,0 @@
|
|||
if (typeof jQuery === 'undefined') {
|
||||
throw new Error('Baby Buddy requires jQuery.')
|
||||
}
|
||||
|
||||
/**
|
||||
* Baby Buddy Namespace
|
||||
*
|
||||
* Default namespace for the Baby Buddy app.
|
||||
*
|
||||
* @type {{}}
|
||||
*/
|
||||
var BabyBuddy = function () {
|
||||
return {};
|
||||
}();
|
||||
|
||||
/**
|
||||
* Pull to refresh.
|
||||
*
|
||||
* @type {{init: BabyBuddy.PullToRefresh.init, onRefresh: BabyBuddy.PullToRefresh.onRefresh}}
|
||||
*/
|
||||
BabyBuddy.PullToRefresh = function(ptr) {
|
||||
return {
|
||||
init: function () {
|
||||
ptr.init({
|
||||
mainElement: 'body',
|
||||
onRefresh: this.onRefresh
|
||||
});
|
||||
},
|
||||
|
||||
onRefresh: function() {
|
||||
window.location.reload();
|
||||
}
|
||||
};
|
||||
}(PullToRefresh);
|
||||
|
||||
/**
|
||||
* Fix for duplicate form submission from double pressing submit
|
||||
*/
|
||||
function preventDoubleSubmit() {
|
||||
return false;
|
||||
}
|
||||
$('form').off("submit", preventDoubleSubmit);
|
||||
$("form").on("submit", function() {
|
||||
$(this).on("submit", preventDoubleSubmit);
|
||||
});
|
||||
|
||||
/* Baby Buddy 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
|
||||
*/
|
||||
BabyBuddy.Timer = function ($) {
|
||||
var runIntervalId = null;
|
||||
var timerId = null;
|
||||
var timerElement = null;
|
||||
var lastUpdate = new Date();
|
||||
var hidden = null;
|
||||
|
||||
var Timer = {
|
||||
run: function(timer_id, element_id) {
|
||||
timerId = timer_id;
|
||||
timerElement = $('#' + element_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);
|
||||
|
||||
// If the page just came in to view, update the timer data with the
|
||||
// current actual duration. This will (potentially) help mobile
|
||||
// phones that lock with the timer page open.
|
||||
if (typeof document.hidden !== "undefined") {
|
||||
hidden = "hidden";
|
||||
}
|
||||
else if (typeof document.msHidden !== "undefined") {
|
||||
hidden = "msHidden";
|
||||
}
|
||||
else if (typeof document.webkitHidden !== "undefined") {
|
||||
hidden = "webkitHidden";
|
||||
}
|
||||
window.addEventListener('focus', Timer.handleVisibilityChange, false);
|
||||
},
|
||||
|
||||
handleVisibilityChange: function() {
|
||||
if (!document[hidden] && (new Date()) - lastUpdate > 1) {
|
||||
Timer.update();
|
||||
}
|
||||
},
|
||||
|
||||
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);
|
||||
},
|
||||
|
||||
update: function() {
|
||||
$.get('/api/timers/' + timerId + '/', function(data) {
|
||||
if (data && 'duration' in data) {
|
||||
clearInterval(runIntervalId);
|
||||
var duration = data.duration.split(/[\s:.]/)
|
||||
if (duration.length === 5) {
|
||||
duration[0] = parseInt(duration[0]) * 24 + parseInt(duration[1]);
|
||||
duration[1] = duration[2];
|
||||
duration[2] = duration[3];
|
||||
}
|
||||
timerElement.find('.timer-hours').text(parseInt(duration[0]));
|
||||
timerElement.find('.timer-minutes').text(parseInt(duration[1]));
|
||||
timerElement.find('.timer-seconds').text(parseInt(duration[2]));
|
||||
lastUpdate = new Date()
|
||||
runIntervalId = setInterval(Timer.tick, 1000);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return Timer;
|
||||
}(jQuery);
|
||||
|
||||
/* Baby Buddy Dashboard
|
||||
*
|
||||
* Provides a "watch" function to update the dashboard at one minute intervals
|
||||
* and/or on visibility state changes.
|
||||
*/
|
||||
BabyBuddy.Dashboard = function ($) {
|
||||
var runIntervalId = null;
|
||||
var dashboardElement = null;
|
||||
var hidden = null;
|
||||
|
||||
var Dashboard = {
|
||||
watch: function(element_id, refresh_rate) {
|
||||
dashboardElement = $('#' + element_id);
|
||||
|
||||
if (dashboardElement.length == 0) {
|
||||
console.error('Baby Buddy: Dashboard element not found.');
|
||||
return false;
|
||||
}
|
||||
|
||||
if (typeof document.hidden !== "undefined") {
|
||||
hidden = "hidden";
|
||||
}
|
||||
else if (typeof document.msHidden !== "undefined") {
|
||||
hidden = "msHidden";
|
||||
}
|
||||
else if (typeof document.webkitHidden !== "undefined") {
|
||||
hidden = "webkitHidden";
|
||||
}
|
||||
|
||||
if (typeof window.addEventListener === "undefined" || typeof document.hidden === "undefined") {
|
||||
if (refresh_rate) {
|
||||
runIntervalId = setInterval(this.update, refresh_rate);
|
||||
}
|
||||
}
|
||||
else {
|
||||
window.addEventListener('focus', Dashboard.handleVisibilityChange, false);
|
||||
if (refresh_rate) {
|
||||
runIntervalId = setInterval(Dashboard.handleVisibilityChange, refresh_rate);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
handleVisibilityChange: function() {
|
||||
if (!document[hidden]) {
|
||||
Dashboard.update();
|
||||
}
|
||||
},
|
||||
|
||||
update: function() {
|
||||
// TODO: Someday maybe update in place?
|
||||
location.reload();
|
||||
}
|
||||
};
|
||||
|
||||
return Dashboard;
|
||||
}(jQuery);
|
Binary file not shown.
|
@ -1,206 +1 @@
|
|||
if (typeof jQuery === 'undefined') {
|
||||
throw new Error('Baby Buddy requires jQuery.')
|
||||
}
|
||||
|
||||
/**
|
||||
* Baby Buddy Namespace
|
||||
*
|
||||
* Default namespace for the Baby Buddy app.
|
||||
*
|
||||
* @type {{}}
|
||||
*/
|
||||
var BabyBuddy = function () {
|
||||
return {};
|
||||
}();
|
||||
|
||||
/**
|
||||
* Pull to refresh.
|
||||
*
|
||||
* @type {{init: BabyBuddy.PullToRefresh.init, onRefresh: BabyBuddy.PullToRefresh.onRefresh}}
|
||||
*/
|
||||
BabyBuddy.PullToRefresh = function(ptr) {
|
||||
return {
|
||||
init: function () {
|
||||
ptr.init({
|
||||
mainElement: 'body',
|
||||
onRefresh: this.onRefresh
|
||||
});
|
||||
},
|
||||
|
||||
onRefresh: function() {
|
||||
window.location.reload();
|
||||
}
|
||||
};
|
||||
}(PullToRefresh);
|
||||
|
||||
/**
|
||||
* Fix for duplicate form submission from double pressing submit
|
||||
*/
|
||||
function preventDoubleSubmit() {
|
||||
return false;
|
||||
}
|
||||
$('form').off("submit", preventDoubleSubmit);
|
||||
$("form").on("submit", function() {
|
||||
$(this).on("submit", preventDoubleSubmit);
|
||||
});
|
||||
|
||||
/* Baby Buddy 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
|
||||
*/
|
||||
BabyBuddy.Timer = function ($) {
|
||||
var runIntervalId = null;
|
||||
var timerId = null;
|
||||
var timerElement = null;
|
||||
var lastUpdate = new Date();
|
||||
var hidden = null;
|
||||
|
||||
var Timer = {
|
||||
run: function(timer_id, element_id) {
|
||||
timerId = timer_id;
|
||||
timerElement = $('#' + element_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);
|
||||
|
||||
// If the page just came in to view, update the timer data with the
|
||||
// current actual duration. This will (potentially) help mobile
|
||||
// phones that lock with the timer page open.
|
||||
if (typeof document.hidden !== "undefined") {
|
||||
hidden = "hidden";
|
||||
}
|
||||
else if (typeof document.msHidden !== "undefined") {
|
||||
hidden = "msHidden";
|
||||
}
|
||||
else if (typeof document.webkitHidden !== "undefined") {
|
||||
hidden = "webkitHidden";
|
||||
}
|
||||
window.addEventListener('focus', Timer.handleVisibilityChange, false);
|
||||
},
|
||||
|
||||
handleVisibilityChange: function() {
|
||||
if (!document[hidden] && (new Date()) - lastUpdate > 1) {
|
||||
Timer.update();
|
||||
}
|
||||
},
|
||||
|
||||
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);
|
||||
},
|
||||
|
||||
update: function() {
|
||||
$.get('/api/timers/' + timerId + '/', function(data) {
|
||||
if (data && 'duration' in data) {
|
||||
clearInterval(runIntervalId);
|
||||
var duration = data.duration.split(/[\s:.]/)
|
||||
if (duration.length === 5) {
|
||||
duration[0] = parseInt(duration[0]) * 24 + parseInt(duration[1]);
|
||||
duration[1] = duration[2];
|
||||
duration[2] = duration[3];
|
||||
}
|
||||
timerElement.find('.timer-hours').text(parseInt(duration[0]));
|
||||
timerElement.find('.timer-minutes').text(parseInt(duration[1]));
|
||||
timerElement.find('.timer-seconds').text(parseInt(duration[2]));
|
||||
lastUpdate = new Date()
|
||||
runIntervalId = setInterval(Timer.tick, 1000);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return Timer;
|
||||
}(jQuery);
|
||||
|
||||
/* Baby Buddy Dashboard
|
||||
*
|
||||
* Provides a "watch" function to update the dashboard at one minute intervals
|
||||
* and/or on visibility state changes.
|
||||
*/
|
||||
BabyBuddy.Dashboard = function ($) {
|
||||
var runIntervalId = null;
|
||||
var dashboardElement = null;
|
||||
var hidden = null;
|
||||
|
||||
var Dashboard = {
|
||||
watch: function(element_id, refresh_rate) {
|
||||
dashboardElement = $('#' + element_id);
|
||||
|
||||
if (dashboardElement.length == 0) {
|
||||
console.error('Baby Buddy: Dashboard element not found.');
|
||||
return false;
|
||||
}
|
||||
|
||||
if (typeof document.hidden !== "undefined") {
|
||||
hidden = "hidden";
|
||||
}
|
||||
else if (typeof document.msHidden !== "undefined") {
|
||||
hidden = "msHidden";
|
||||
}
|
||||
else if (typeof document.webkitHidden !== "undefined") {
|
||||
hidden = "webkitHidden";
|
||||
}
|
||||
|
||||
if (typeof window.addEventListener === "undefined" || typeof document.hidden === "undefined") {
|
||||
if (refresh_rate) {
|
||||
runIntervalId = setInterval(this.update, refresh_rate);
|
||||
}
|
||||
}
|
||||
else {
|
||||
window.addEventListener('focus', Dashboard.handleVisibilityChange, false);
|
||||
if (refresh_rate) {
|
||||
runIntervalId = setInterval(Dashboard.handleVisibilityChange, refresh_rate);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
handleVisibilityChange: function() {
|
||||
if (!document[hidden]) {
|
||||
Dashboard.update();
|
||||
}
|
||||
},
|
||||
|
||||
update: function() {
|
||||
// TODO: Someday maybe update in place?
|
||||
location.reload();
|
||||
}
|
||||
};
|
||||
|
||||
return Dashboard;
|
||||
}(jQuery);
|
||||
if("undefined"==typeof jQuery)throw new Error("Baby Buddy requires jQuery.");var BabyBuddy={};function preventDoubleSubmit(){return!1}BabyBuddy.PullToRefresh=function(e){return{init:function(){e.init({mainElement:"body",onRefresh:this.onRefresh})},onRefresh:function(){window.location.reload()}}}(PullToRefresh),$("form").off("submit",preventDoubleSubmit),$("form").on("submit",function(){$(this).on("submit",preventDoubleSubmit)}),BabyBuddy.Timer=function(e){var n=null,t=null,i=null,d=new Date,r=null,o={run:function(d,u){return t=d,0===(i=e("#"+u)).length?(console.error("BBTimer: Timer element not found."),!1):0===i.find(".timer-seconds").length||0===i.find(".timer-minutes").length||0===i.find(".timer-hours").length?(console.error("BBTimer: Element does not contain expected children."),!1):(n=setInterval(this.tick,1e3),void 0!==document.hidden?r="hidden":void 0!==document.msHidden?r="msHidden":void 0!==document.webkitHidden&&(r="webkitHidden"),void window.addEventListener("focus",o.handleVisibilityChange,!1))},handleVisibilityChange:function(){!document[r]&&new Date-d>1&&o.update()},tick:function(){var e=i.find(".timer-seconds"),n=Number(e.text());if(n<59)e.text(n+1);else{e.text(0);var t=i.find(".timer-minutes"),d=Number(t.text());if(d<59)t.text(d+1);else{t.text(0);var r=i.find(".timer-hours"),o=Number(r.text());r.text(o+1)}}},update:function(){e.get("/api/timers/"+t+"/",function(e){if(e&&"duration"in e){clearInterval(n);var t=e.duration.split(/[\s:.]/);5===t.length&&(t[0]=24*parseInt(t[0])+parseInt(t[1]),t[1]=t[2],t[2]=t[3]),i.find(".timer-hours").text(parseInt(t[0])),i.find(".timer-minutes").text(parseInt(t[1])),i.find(".timer-seconds").text(parseInt(t[2])),d=new Date,n=setInterval(o.tick,1e3)}})}};return o}(jQuery),BabyBuddy.Dashboard=function(e){var n=null,t={watch:function(i,d){if(0==e("#"+i).length)return console.error("Baby Buddy: Dashboard element not found."),!1;void 0!==document.hidden?n="hidden":void 0!==document.msHidden?n="msHidden":void 0!==document.webkitHidden&&(n="webkitHidden"),void 0===window.addEventListener||void 0===document.hidden?d&&setInterval(this.update,d):(window.addEventListener("focus",t.handleVisibilityChange,!1),d&&setInterval(t.handleVisibilityChange,d))},handleVisibilityChange:function(){document[n]||t.update()},update:function(){location.reload()}};return t}(jQuery);
|
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue