lint: lint all js and sjon files with prettier

This commit is contained in:
billybonks 2024-02-06 16:26:41 +08:00 committed by Christopher Charbonneau Wells
parent e141492db7
commit f28df6ecf3
10 changed files with 662 additions and 692 deletions

View File

@ -1,16 +1,10 @@
{ {
"extends": "stylelint-config-recommended-scss", "extends": "stylelint-config-recommended-scss",
"plugins": [ "plugins": ["stylelint-order", "stylelint-scss"],
"stylelint-order",
"stylelint-scss"
],
"rules": { "rules": {
"at-rule-no-vendor-prefix": true, "at-rule-no-vendor-prefix": true,
"media-feature-name-no-vendor-prefix": true, "media-feature-name-no-vendor-prefix": true,
"order/order": [ "order/order": ["declarations", "rules"],
"declarations",
"rules"
],
"property-no-vendor-prefix": true, "property-no-vendor-prefix": true,
"selector-no-vendor-prefix": true, "selector-no-vendor-prefix": true,
"value-no-vendor-prefix": true "value-no-vendor-prefix": true

View File

@ -12,8 +12,7 @@
{ {
"model": "core.child", "model": "core.child",
"pk": 1, "pk": 1,
"fields": "fields": {
{
"first_name": "Fake", "first_name": "Fake",
"last_name": "Child", "last_name": "Child",
"birth_date": "2017-11-11", "birth_date": "2017-11-11",
@ -24,8 +23,7 @@
{ {
"model": "core.pumping", "model": "core.pumping",
"pk": 1, "pk": 1,
"fields": "fields": {
{
"child": 1, "child": 1,
"amount": 5.0, "amount": 5.0,
"start": "2017-11-17T17:52:00Z", "start": "2017-11-17T17:52:00Z",
@ -37,8 +35,7 @@
{ {
"model": "core.pumping", "model": "core.pumping",
"pk": 2, "pk": 2,
"fields": "fields": {
{
"child": 1, "child": 1,
"amount": 9.0, "amount": 9.0,
"start": "2017-11-17T20:03:00Z", "start": "2017-11-17T20:03:00Z",
@ -50,8 +47,7 @@
{ {
"model": "core.diaperchange", "model": "core.diaperchange",
"pk": 2, "pk": 2,
"fields": "fields": {
{
"child": 1, "child": 1,
"time": "2017-11-18T16:00:00Z", "time": "2017-11-18T16:00:00Z",
"wet": false, "wet": false,
@ -63,8 +59,7 @@
{ {
"model": "core.diaperchange", "model": "core.diaperchange",
"pk": 3, "pk": 3,
"fields": "fields": {
{
"child": 1, "child": 1,
"time": "2017-11-18T19:00:00Z", "time": "2017-11-18T19:00:00Z",
"wet": true, "wet": true,
@ -77,8 +72,7 @@
{ {
"model": "core.diaperchange", "model": "core.diaperchange",
"pk": 4, "pk": 4,
"fields": "fields": {
{
"child": 1, "child": 1,
"time": "2017-11-17T13:00:00Z", "time": "2017-11-17T13:00:00Z",
"wet": false, "wet": false,
@ -90,8 +84,7 @@
{ {
"model": "core.diaperchange", "model": "core.diaperchange",
"pk": 5, "pk": 5,
"fields": "fields": {
{
"child": 1, "child": 1,
"time": "2017-11-17T16:00:00Z", "time": "2017-11-17T16:00:00Z",
"wet": false, "wet": false,
@ -103,8 +96,7 @@
{ {
"model": "core.diaperchange", "model": "core.diaperchange",
"pk": 6, "pk": 6,
"fields": "fields": {
{
"child": 1, "child": 1,
"time": "2017-11-16T15:00:00Z", "time": "2017-11-16T15:00:00Z",
"wet": true, "wet": true,
@ -116,8 +108,7 @@
{ {
"model": "core.diaperchange", "model": "core.diaperchange",
"pk": 7, "pk": 7,
"fields": "fields": {
{
"child": 1, "child": 1,
"time": "2017-11-16T18:00:00Z", "time": "2017-11-16T18:00:00Z",
"wet": true, "wet": true,
@ -129,8 +120,7 @@
{ {
"model": "core.diaperchange", "model": "core.diaperchange",
"pk": 8, "pk": 8,
"fields": "fields": {
{
"child": 1, "child": 1,
"time": "2017-11-15T15:00:00Z", "time": "2017-11-15T15:00:00Z",
"wet": false, "wet": false,
@ -142,8 +132,7 @@
{ {
"model": "core.diaperchange", "model": "core.diaperchange",
"pk": 9, "pk": 9,
"fields": "fields": {
{
"child": 1, "child": 1,
"time": "2017-11-15T13:00:00Z", "time": "2017-11-15T13:00:00Z",
"wet": true, "wet": true,
@ -155,8 +144,7 @@
{ {
"model": "core.diaperchange", "model": "core.diaperchange",
"pk": 10, "pk": 10,
"fields": "fields": {
{
"child": 1, "child": 1,
"time": "2017-11-15T16:00:00Z", "time": "2017-11-15T16:00:00Z",
"wet": true, "wet": true,
@ -168,8 +156,7 @@
{ {
"model": "core.diaperchange", "model": "core.diaperchange",
"pk": 11, "pk": 11,
"fields": "fields": {
{
"child": 1, "child": 1,
"time": "2017-11-15T21:00:00Z", "time": "2017-11-15T21:00:00Z",
"wet": true, "wet": true,
@ -181,8 +168,7 @@
{ {
"model": "core.diaperchange", "model": "core.diaperchange",
"pk": 12, "pk": 12,
"fields": "fields": {
{
"child": 1, "child": 1,
"time": "2017-11-14T15:00:00Z", "time": "2017-11-14T15:00:00Z",
"wet": true, "wet": true,
@ -194,8 +180,7 @@
{ {
"model": "core.diaperchange", "model": "core.diaperchange",
"pk": 13, "pk": 13,
"fields": "fields": {
{
"child": 1, "child": 1,
"time": "2017-11-13T14:00:00Z", "time": "2017-11-13T14:00:00Z",
"wet": true, "wet": true,
@ -207,8 +192,7 @@
{ {
"model": "core.diaperchange", "model": "core.diaperchange",
"pk": 14, "pk": 14,
"fields": "fields": {
{
"child": 1, "child": 1,
"time": "2017-11-13T18:00:00Z", "time": "2017-11-13T18:00:00Z",
"wet": true, "wet": true,
@ -220,8 +204,7 @@
{ {
"model": "core.diaperchange", "model": "core.diaperchange",
"pk": 15, "pk": 15,
"fields": "fields": {
{
"child": 1, "child": 1,
"time": "2017-11-12T15:00:00Z", "time": "2017-11-12T15:00:00Z",
"wet": true, "wet": true,
@ -233,8 +216,7 @@
{ {
"model": "core.diaperchange", "model": "core.diaperchange",
"pk": 16, "pk": 16,
"fields": "fields": {
{
"child": 1, "child": 1,
"time": "2017-11-11T15:00:00Z", "time": "2017-11-11T15:00:00Z",
"wet": true, "wet": true,
@ -246,8 +228,7 @@
{ {
"model": "core.feeding", "model": "core.feeding",
"pk": 1, "pk": 1,
"fields": "fields": {
{
"child": 1, "child": 1,
"start": "2017-11-18T09:00:00Z", "start": "2017-11-18T09:00:00Z",
"end": "2017-11-18T09:30:00Z", "end": "2017-11-18T09:30:00Z",
@ -260,8 +241,7 @@
{ {
"model": "core.feeding", "model": "core.feeding",
"pk": 2, "pk": 2,
"fields": "fields": {
{
"child": 1, "child": 1,
"start": "2017-11-18T11:30:00Z", "start": "2017-11-18T11:30:00Z",
"end": "2017-11-18T12:00:00Z", "end": "2017-11-18T12:00:00Z",
@ -274,8 +254,7 @@
{ {
"model": "core.feeding", "model": "core.feeding",
"pk": 3, "pk": 3,
"fields": "fields": {
{
"child": 1, "child": 1,
"start": "2017-11-18T14:00:00Z", "start": "2017-11-18T14:00:00Z",
"end": "2017-11-18T14:15:00Z", "end": "2017-11-18T14:15:00Z",
@ -289,8 +268,7 @@
{ {
"model": "core.feeding", "model": "core.feeding",
"pk": 4, "pk": 4,
"fields": "fields": {
{
"child": 1, "child": 1,
"start": "2017-11-17T14:00:00Z", "start": "2017-11-17T14:00:00Z",
"end": "2017-11-17T14:15:00Z", "end": "2017-11-17T14:15:00Z",
@ -304,8 +282,7 @@
{ {
"model": "core.feeding", "model": "core.feeding",
"pk": 5, "pk": 5,
"fields": "fields": {
{
"child": 1, "child": 1,
"start": "2017-11-11T14:00:00Z", "start": "2017-11-11T14:00:00Z",
"end": "2017-11-11T14:15:00Z", "end": "2017-11-11T14:15:00Z",
@ -319,8 +296,7 @@
{ {
"model": "core.feeding", "model": "core.feeding",
"pk": 6, "pk": 6,
"fields": "fields": {
{
"child": 1, "child": 1,
"start": "2017-11-11T05:00:00Z", "start": "2017-11-11T05:00:00Z",
"end": "2017-11-11T05:15:00Z", "end": "2017-11-11T05:15:00Z",
@ -334,8 +310,7 @@
{ {
"model": "core.note", "model": "core.note",
"pk": 1, "pk": 1,
"fields": "fields": {
{
"child": 1, "child": 1,
"note": "Fake note.", "note": "Fake note.",
"time": "2017-11-18T03:45:00Z" "time": "2017-11-18T03:45:00Z"
@ -344,8 +319,7 @@
{ {
"model": "core.sleep", "model": "core.sleep",
"pk": 1, "pk": 1,
"fields": "fields": {
{
"child": 1, "child": 1,
"start": "2017-11-17T20:30:00Z", "start": "2017-11-17T20:30:00Z",
"end": "2017-11-18T05:30:00Z", "end": "2017-11-18T05:30:00Z",
@ -356,8 +330,7 @@
{ {
"model": "core.sleep", "model": "core.sleep",
"pk": 2, "pk": 2,
"fields": "fields": {
{
"child": 1, "child": 1,
"start": "2017-11-18T15:00:00Z", "start": "2017-11-18T15:00:00Z",
"end": "2017-11-18T17:00:00Z", "end": "2017-11-18T17:00:00Z",
@ -368,8 +341,7 @@
{ {
"model": "core.sleep", "model": "core.sleep",
"pk": 3, "pk": 3,
"fields": "fields": {
{
"child": 1, "child": 1,
"start": "2017-11-18T19:00:00Z", "start": "2017-11-18T19:00:00Z",
"end": "2017-11-19T04:30:00Z", "end": "2017-11-19T04:30:00Z",
@ -380,8 +352,7 @@
{ {
"model": "core.sleep", "model": "core.sleep",
"pk": 4, "pk": 4,
"fields": "fields": {
{
"child": 1, "child": 1,
"start": "2017-11-19T08:00:00Z", "start": "2017-11-19T08:00:00Z",
"end": "2017-11-19T09:30:00Z", "end": "2017-11-19T09:30:00Z",
@ -393,8 +364,7 @@
{ {
"model": "core.temperature", "model": "core.temperature",
"pk": 1, "pk": 1,
"fields": "fields": {
{
"child": 1, "child": 1,
"temperature": 98.6, "temperature": 98.6,
"time": "2017-11-17T17:52:00Z", "time": "2017-11-17T17:52:00Z",
@ -404,8 +374,7 @@
{ {
"model": "core.timer", "model": "core.timer",
"pk": 1, "pk": 1,
"fields": "fields": {
{
"name": "Fake timer", "name": "Fake timer",
"start": "2017-11-18T04:30:00Z", "start": "2017-11-18T04:30:00Z",
"user": 1 "user": 1
@ -414,8 +383,7 @@
{ {
"model": "core.tummytime", "model": "core.tummytime",
"pk": 1, "pk": 1,
"fields": "fields": {
{
"child": 1, "child": 1,
"start": "2017-11-18T15:00:00Z", "start": "2017-11-18T15:00:00Z",
"end": "2017-11-18T15:03:00Z", "end": "2017-11-18T15:03:00Z",
@ -426,8 +394,7 @@
{ {
"model": "core.tummytime", "model": "core.tummytime",
"pk": 2, "pk": 2,
"fields": "fields": {
{
"child": 1, "child": 1,
"start": "2017-11-18T17:15:30Z", "start": "2017-11-18T17:15:30Z",
"end": "2017-11-18T17:16:45Z", "end": "2017-11-18T17:16:45Z",
@ -438,8 +405,7 @@
{ {
"model": "core.tummytime", "model": "core.tummytime",
"pk": 3, "pk": 3,
"fields": "fields": {
{
"child": 1, "child": 1,
"start": "2017-11-18T20:30:00Z", "start": "2017-11-18T20:30:00Z",
"end": "2017-11-18T20:30:45Z", "end": "2017-11-18T20:30:45Z",
@ -450,8 +416,7 @@
{ {
"model": "core.weight", "model": "core.weight",
"pk": 1, "pk": 1,
"fields": "fields": {
{
"child": 1, "child": 1,
"weight": 8.5, "weight": 8.5,
"date": "2017-11-11" "date": "2017-11-11"
@ -460,8 +425,7 @@
{ {
"model": "core.weight", "model": "core.weight",
"pk": 2, "pk": 2,
"fields": "fields": {
{
"child": 1, "child": 1,
"weight": 9.5, "weight": 9.5,
"date": "2017-11-18", "date": "2017-11-18",
@ -471,8 +435,7 @@
{ {
"model": "core.height", "model": "core.height",
"pk": 1, "pk": 1,
"fields": "fields": {
{
"child": 1, "child": 1,
"height": 9.5, "height": 9.5,
"date": "2017-11-11" "date": "2017-11-11"
@ -481,8 +444,7 @@
{ {
"model": "core.height", "model": "core.height",
"pk": 2, "pk": 2,
"fields": "fields": {
{
"child": 1, "child": 1,
"height": 10.5, "height": 10.5,
"date": "2017-11-18", "date": "2017-11-18",
@ -492,8 +454,7 @@
{ {
"model": "core.headcircumference", "model": "core.headcircumference",
"pk": 1, "pk": 1,
"fields": "fields": {
{
"child": 1, "child": 1,
"head_circumference": 5.5, "head_circumference": 5.5,
"date": "2017-11-11" "date": "2017-11-11"
@ -502,8 +463,7 @@
{ {
"model": "core.headcircumference", "model": "core.headcircumference",
"pk": 2, "pk": 2,
"fields": "fields": {
{
"child": 1, "child": 1,
"head_circumference": 6.5, "head_circumference": 6.5,
"date": "2017-11-18", "date": "2017-11-18",
@ -513,8 +473,7 @@
{ {
"model": "core.bmi", "model": "core.bmi",
"pk": 1, "pk": 1,
"fields": "fields": {
{
"child": 1, "child": 1,
"bmi": 25.5, "bmi": 25.5,
"date": "2017-11-11" "date": "2017-11-11"
@ -523,8 +482,7 @@
{ {
"model": "core.bmi", "model": "core.bmi",
"pk": 2, "pk": 2,
"fields": "fields": {
{
"child": 1, "child": 1,
"bmi": 26.5, "bmi": 26.5,
"date": "2017-11-18", "date": "2017-11-18",
@ -534,8 +492,7 @@
{ {
"model": "core.tag", "model": "core.tag",
"pk": 1, "pk": 1,
"fields": "fields": {
{
"name": "a name", "name": "a name",
"slug": "a-name", "slug": "a-name",
"color": "#FF0000", "color": "#FF0000",

View File

@ -1,5 +1,5 @@
if (typeof jQuery === 'undefined') { if (typeof jQuery === "undefined") {
throw new Error('Baby Buddy requires jQuery.') throw new Error("Baby Buddy requires jQuery.");
} }
/** /**
@ -9,29 +9,29 @@ if (typeof jQuery === 'undefined') {
* *
* @type {{}} * @type {{}}
*/ */
var BabyBuddy = function () { var BabyBuddy = (function () {
return {}; return {};
}(); })();
/** /**
* Pull to refresh. * Pull to refresh.
* *
* @type {{init: BabyBuddy.PullToRefresh.init, onRefresh: BabyBuddy.PullToRefresh.onRefresh}} * @type {{init: BabyBuddy.PullToRefresh.init, onRefresh: BabyBuddy.PullToRefresh.onRefresh}}
*/ */
BabyBuddy.PullToRefresh = function(ptr) { BabyBuddy.PullToRefresh = (function (ptr) {
return { return {
init: function () { init: function () {
ptr.init({ ptr.init({
mainElement: 'body', mainElement: "body",
onRefresh: this.onRefresh onRefresh: this.onRefresh,
}); });
}, },
onRefresh: function () { onRefresh: function () {
window.location.reload(); window.location.reload();
} },
}; };
}(PullToRefresh); })(PullToRefresh);
/** /**
* Fix for duplicate form submission from double pressing submit * Fix for duplicate form submission from double pressing submit
@ -39,7 +39,7 @@ BabyBuddy.PullToRefresh = function(ptr) {
function preventDoubleSubmit() { function preventDoubleSubmit() {
return false; return false;
} }
$('form').off("submit", preventDoubleSubmit); $("form").off("submit", preventDoubleSubmit);
$("form").on("submit", function () { $("form").on("submit", function () {
$(this).on("submit", preventDoubleSubmit); $(this).on("submit", preventDoubleSubmit);
}); });

View File

@ -17,17 +17,19 @@
* @return {String} The contrasting color (black or white) * @return {String} The contrasting color (black or white)
*/ */
function computeComplementaryColor(hexcolor) { function computeComplementaryColor(hexcolor) {
// If a leading # is provided, remove it // If a leading # is provided, remove it
if (hexcolor.slice(0, 1) === '#') { if (hexcolor.slice(0, 1) === "#") {
hexcolor = hexcolor.slice(1); hexcolor = hexcolor.slice(1);
} }
// If a three-character hexcode, make six-character // If a three-character hexcode, make six-character
if (hexcolor.length === 3) { if (hexcolor.length === 3) {
hexcolor = hexcolor.split('').map(function (hex) { hexcolor = hexcolor
.split("")
.map(function (hex) {
return hex + hex; return hex + hex;
}).join(''); })
.join("");
} }
// Convert to RGB value // Convert to RGB value
@ -36,22 +38,24 @@
let b = parseInt(hexcolor.substr(4, 2), 16); let b = parseInt(hexcolor.substr(4, 2), 16);
// Get YIQ ratio // Get YIQ ratio
let yiq = ((r * 299) + (g * 587) + (b * 114)) / 1000; let yiq = (r * 299 + g * 587 + b * 114) / 1000;
// Check contrast // Check contrast
return (yiq >= 128) ? '#101010' : '#EFEFEF'; return yiq >= 128 ? "#101010" : "#EFEFEF";
} }
// CSRF token should always be present because it is auto-included with // CSRF token should always be present because it is auto-included with
// every tag-editor widget // every tag-editor widget
const CSRF_TOKEN = document.querySelector('input[name="csrfmiddlewaretoken"]').value; const CSRF_TOKEN = document.querySelector(
'input[name="csrfmiddlewaretoken"]',
).value;
function doReq(method, uri, data, success, fail) { function doReq(method, uri, data, success, fail) {
// TODO: prefer jQuery based requests for now // TODO: prefer jQuery based requests for now
const req = new XMLHttpRequest(); const req = new XMLHttpRequest();
req.addEventListener('load', () => { req.addEventListener("load", () => {
if ((req.status >= 200) && (req.status < 300)) { if (req.status >= 200 && req.status < 300) {
success(req.responseText, req); success(req.responseText, req);
} else { } else {
fail(req.responseText, req); fail(req.responseText, req);
@ -80,11 +84,11 @@
*/ */
class TaggingBase { class TaggingBase {
constructor(widget) { constructor(widget) {
this.prototype = widget.querySelector('.prototype-tag'); this.prototype = widget.querySelector(".prototype-tag");
this.listeners = []; this.listeners = [];
this.modalElement = widget.querySelector('.tag-editor-error-modal'); this.modalElement = widget.querySelector(".tag-editor-error-modal");
this.modalBodyNode = this.modalElement.querySelector('.modal-body'); this.modalBodyNode = this.modalElement.querySelector(".modal-body");
// Clean whitespace text nodes between spans // Clean whitespace text nodes between spans
for (const n of this.modalBodyNode.childNodes) { for (const n of this.modalBodyNode.childNodes) {
@ -95,17 +99,19 @@
} }
showModal(msg) { showModal(msg) {
const selectedMessage = this.modalBodyNode.querySelector(`span[data-message='${msg}']`); const selectedMessage = this.modalBodyNode.querySelector(
`span[data-message='${msg}']`,
);
if (!selectedMessage) { if (!selectedMessage) {
selectedMessage = this.modalBodyNode.childNodes[0]; selectedMessage = this.modalBodyNode.childNodes[0];
} }
for (const n of this.modalBodyNode.childNodes) { for (const n of this.modalBodyNode.childNodes) {
n.classList.add('d-none'); n.classList.add("d-none");
} }
selectedMessage.classList.remove('d-none'); selectedMessage.classList.remove("d-none");
jQuery(this.modalElement).modal('show'); jQuery(this.modalElement).modal("show");
} }
addTagListUpdatedListener(c) { addTagListUpdatedListener(c) {
@ -119,7 +125,8 @@
} }
updateTag(tag, name, color, actionSymbol) { updateTag(tag, name, color, actionSymbol) {
const actionTextNode = tag.querySelector('.add-remove-icon').childNodes[0]; const actionTextNode =
tag.querySelector(".add-remove-icon").childNodes[0];
name = name || tag.getAttribute("data-value"); name = name || tag.getAttribute("data-value");
color = color || tag.getAttribute("data-color"); color = color || tag.getAttribute("data-color");
@ -130,7 +137,10 @@
tag.setAttribute("data-color", color); tag.setAttribute("data-color", color);
const textColor = computeComplementaryColor(color); const textColor = computeComplementaryColor(color);
tag.setAttribute('style', `background-color: ${color}; color: ${textColor};`); tag.setAttribute(
"style",
`background-color: ${color}; color: ${textColor};`,
);
actionTextNode.textContent = actionSymbol; actionTextNode.textContent = actionSymbol;
} }
@ -146,7 +156,7 @@
list.appendChild(tag); list.appendChild(tag);
this.callTagListUpdatedListeners(); this.callTagListUpdatedListeners();
} }
}; }
/** /**
* Handler for the edit field allowing to dynamically create new tags. * Handler for the edit field allowing to dynamically create new tags.
@ -171,17 +181,20 @@
this.widget = widget; this.widget = widget;
this.taggingBase = taggingBase; this.taggingBase = taggingBase;
this.apiTagsUrl = widget.getAttribute('data-tags-url'); this.apiTagsUrl = widget.getAttribute("data-tags-url");
this.createTagInputs = widget.querySelector('.create-tag-inputs'); this.createTagInputs = widget.querySelector(".create-tag-inputs");
this.addTagInput = this.createTagInputs.querySelector('input[type="text"]'); this.addTagInput =
this.addTagButton = this.createTagInputs.querySelector('#add-tag'); this.createTagInputs.querySelector('input[type="text"]');
this.addTagButton = this.createTagInputs.querySelector("#add-tag");
this.addTagInput.value = ""; this.addTagInput.value = "";
this.onInsertNewTag = onInsertNewTag; this.onInsertNewTag = onInsertNewTag;
this.addTagButton.addEventListener('click', () => this.onCreateTagClicked()); this.addTagButton.addEventListener("click", () =>
this.addTagInput.addEventListener('keydown', (e) => { this.onCreateTagClicked(),
);
this.addTagInput.addEventListener("keydown", (e) => {
const key = e.key.toLowerCase(); const key = e.key.toLowerCase();
if (key === "enter") { if (key === "enter") {
e.preventDefault(); e.preventDefault();
@ -206,7 +219,7 @@
}; };
if (!tagName) { if (!tagName) {
fail('invalid-tag-name'); fail("invalid-tag-name");
return; return;
} }
@ -217,27 +230,35 @@
}; };
const data = JSON.stringify({ const data = JSON.stringify({
'name': this.addTagInput.value name: this.addTagInput.value,
}); });
doReq("GET", `${this.apiTagsUrl}?name=${uriTagName}`, null, doReq(
"GET",
`${this.apiTagsUrl}?name=${uriTagName}`,
null,
(text) => { (text) => {
const json = JSON.parse(text); const json = JSON.parse(text);
if (json.count) { if (json.count) {
const tagJson = json.results[0]; const tagJson = json.results[0];
addTag(tagJson.name, tagJson.color); addTag(tagJson.name, tagJson.color);
} else { } else {
doReq("POST", this.apiTagsUrl, data, doReq(
"POST",
this.apiTagsUrl,
data,
(text) => { (text) => {
const tagJson = JSON.parse(text); const tagJson = JSON.parse(text);
addTag(tagJson.name, tagJson.color); addTag(tagJson.name, tagJson.color);
}, () => fail("tag-creation-failed") },
() => fail("tag-creation-failed"),
); );
} }
}, () => fail("tag-checking-failed") },
() => fail("tag-checking-failed"),
); );
} }
}; }
/** /**
* JavaScript implementation for the tags editor. * JavaScript implementation for the tags editor.
@ -256,11 +277,13 @@
this.widget = tagEditorRoot; this.widget = tagEditorRoot;
this.taggingBase = new TaggingBase(this.widget); this.taggingBase = new TaggingBase(this.widget);
this.addTagControl = new AddNewTagControl( this.addTagControl = new AddNewTagControl(
this.widget, this.taggingBase, (t) => this.insertNewTag(t) this.widget,
this.taggingBase,
(t) => this.insertNewTag(t),
); );
this.currentTags = this.widget.querySelector('.current_tags'); this.currentTags = this.widget.querySelector(".current_tags");
this.newTags = this.widget.querySelector('.new-tags'); this.newTags = this.widget.querySelector(".new-tags");
this.inputElement = this.widget.querySelector('input[type="hidden"]'); this.inputElement = this.widget.querySelector('input[type="hidden"]');
for (const tag of this.newTags.querySelectorAll(".tag")) { for (const tag of this.newTags.querySelectorAll(".tag")) {
@ -271,9 +294,7 @@
} }
this.updateInputList(); this.updateInputList();
this.taggingBase.addTagListUpdatedListener( this.taggingBase.addTagListUpdatedListener(() => this.updateInputList());
() => this.updateInputList()
);
} }
/** /**
@ -306,10 +327,10 @@
tag.parentNode.removeChild(tag); tag.parentNode.removeChild(tag);
this.taggingBase.insertTag(newParent, tag); this.taggingBase.insertTag(newParent, tag);
tag.removeEventListener('click', callback); tag.removeEventListener("click", callback);
onClicked(tag); onClicked(tag);
} }
tag.addEventListener('click', callback.bind(this)); tag.addEventListener("click", callback.bind(this));
} }
/** /**
@ -332,7 +353,9 @@
*/ */
configureAddTag(tag) { configureAddTag(tag) {
this.taggingBase.updateTag(tag, null, null, "+"); this.taggingBase.updateTag(tag, null, null, "+");
this.registerNewCallback(tag, this.currentTags, () => this.configureRemoveTag(tag)); this.registerNewCallback(tag, this.currentTags, () =>
this.configureRemoveTag(tag),
);
this.updateInputList(); this.updateInputList();
} }
@ -341,13 +364,15 @@
*/ */
configureRemoveTag(tag) { configureRemoveTag(tag) {
this.taggingBase.updateTag(tag, null, null, "-"); this.taggingBase.updateTag(tag, null, null, "-");
this.registerNewCallback(tag, this.newTags, () => this.configureAddTag(tag)); this.registerNewCallback(tag, this.newTags, () =>
this.configureAddTag(tag),
);
this.updateInputList(); this.updateInputList();
} }
}; }
window.addEventListener('load', () => { window.addEventListener("load", () => {
for (const el of document.querySelectorAll('.babybuddy-tags-editor')) { for (const el of document.querySelectorAll(".babybuddy-tags-editor")) {
new TagsEditor(el); new TagsEditor(el);
} }
}); });

View File

@ -6,7 +6,7 @@
* * timer-minutes * * timer-minutes
* * timer-hours * * timer-hours
*/ */
BabyBuddy.Timer = function ($) { BabyBuddy.Timer = (function ($) {
var runIntervalId = null; var runIntervalId = null;
var timerId = null; var timerId = null;
var timerElement = null; var timerElement = null;
@ -16,17 +16,19 @@ BabyBuddy.Timer = function ($) {
var Timer = { var Timer = {
run: function (timer_id, element_id) { run: function (timer_id, element_id) {
timerId = timer_id; timerId = timer_id;
timerElement = $('#' + element_id); timerElement = $("#" + element_id);
if (timerElement.length === 0) { if (timerElement.length === 0) {
console.error('BBTimer: Timer element not found.'); console.error("BBTimer: Timer element not found.");
return false; return false;
} }
if (timerElement.find('.timer-seconds').length === 0 if (
|| timerElement.find('.timer-minutes').length === 0 timerElement.find(".timer-seconds").length === 0 ||
|| timerElement.find('.timer-hours').length === 0) { timerElement.find(".timer-minutes").length === 0 ||
console.error('BBTimer: Element does not contain expected children.'); timerElement.find(".timer-hours").length === 0
) {
console.error("BBTimer: Element does not contain expected children.");
return false; return false;
} }
@ -37,67 +39,63 @@ BabyBuddy.Timer = function ($) {
// phones that lock with the timer page open. // phones that lock with the timer page open.
if (typeof document.hidden !== "undefined") { if (typeof document.hidden !== "undefined") {
hidden = "hidden"; hidden = "hidden";
} } else if (typeof document.msHidden !== "undefined") {
else if (typeof document.msHidden !== "undefined") {
hidden = "msHidden"; hidden = "msHidden";
} } else if (typeof document.webkitHidden !== "undefined") {
else if (typeof document.webkitHidden !== "undefined") {
hidden = "webkitHidden"; hidden = "webkitHidden";
} }
window.addEventListener('focus', Timer.handleVisibilityChange, false); window.addEventListener("focus", Timer.handleVisibilityChange, false);
}, },
handleVisibilityChange: function () { handleVisibilityChange: function () {
if (!document[hidden] && (new Date()) - lastUpdate > 1) { if (!document[hidden] && new Date() - lastUpdate > 1) {
Timer.update(); Timer.update();
} }
}, },
tick: function () { tick: function () {
var s = timerElement.find('.timer-seconds'); var s = timerElement.find(".timer-seconds");
var seconds = Number(s.text()); var seconds = Number(s.text());
if (seconds < 59) { if (seconds < 59) {
s.text(seconds + 1); s.text(seconds + 1);
return; return;
} } else {
else {
s.text(0); s.text(0);
} }
var m = timerElement.find('.timer-minutes'); var m = timerElement.find(".timer-minutes");
var minutes = Number(m.text()); var minutes = Number(m.text());
if (minutes < 59) { if (minutes < 59) {
m.text(minutes + 1); m.text(minutes + 1);
return; return;
} } else {
else {
m.text(0); m.text(0);
} }
var h = timerElement.find('.timer-hours'); var h = timerElement.find(".timer-hours");
var hours = Number(h.text()); var hours = Number(h.text());
h.text(hours + 1); h.text(hours + 1);
}, },
update: function () { update: function () {
$.get('/api/timers/' + timerId + '/', function(data) { $.get("/api/timers/" + timerId + "/", function (data) {
if (data && 'duration' in data) { if (data && "duration" in data) {
clearInterval(runIntervalId); clearInterval(runIntervalId);
var duration = data.duration.split(/[\s:.]/) var duration = data.duration.split(/[\s:.]/);
if (duration.length === 5) { if (duration.length === 5) {
duration[0] = parseInt(duration[0]) * 24 + parseInt(duration[1]); duration[0] = parseInt(duration[0]) * 24 + parseInt(duration[1]);
duration[1] = duration[2]; duration[1] = duration[2];
duration[2] = duration[3]; duration[2] = duration[3];
} }
timerElement.find('.timer-hours').text(parseInt(duration[0])); timerElement.find(".timer-hours").text(parseInt(duration[0]));
timerElement.find('.timer-minutes').text(parseInt(duration[1])); timerElement.find(".timer-minutes").text(parseInt(duration[1]));
timerElement.find('.timer-seconds').text(parseInt(duration[2])); timerElement.find(".timer-seconds").text(parseInt(duration[2]));
lastUpdate = new Date() lastUpdate = new Date();
runIntervalId = setInterval(Timer.tick, 1000); runIntervalId = setInterval(Timer.tick, 1000);
} }
}); });
} },
}; };
return Timer; return Timer;
}(jQuery); })(jQuery);

View File

@ -3,39 +3,46 @@
* Provides a "watch" function to update the dashboard at one minute intervals * Provides a "watch" function to update the dashboard at one minute intervals
* and/or on visibility state changes. * and/or on visibility state changes.
*/ */
BabyBuddy.Dashboard = function ($) { BabyBuddy.Dashboard = (function ($) {
var runIntervalId = null; var runIntervalId = null;
var dashboardElement = null; var dashboardElement = null;
var hidden = null; var hidden = null;
var Dashboard = { var Dashboard = {
watch: function (element_id, refresh_rate) { watch: function (element_id, refresh_rate) {
dashboardElement = $('#' + element_id); dashboardElement = $("#" + element_id);
if (dashboardElement.length == 0) { if (dashboardElement.length == 0) {
console.error('Baby Buddy: Dashboard element not found.'); console.error("Baby Buddy: Dashboard element not found.");
return false; return false;
} }
if (typeof document.hidden !== "undefined") { if (typeof document.hidden !== "undefined") {
hidden = "hidden"; hidden = "hidden";
} } else if (typeof document.msHidden !== "undefined") {
else if (typeof document.msHidden !== "undefined") {
hidden = "msHidden"; hidden = "msHidden";
} } else if (typeof document.webkitHidden !== "undefined") {
else if (typeof document.webkitHidden !== "undefined") {
hidden = "webkitHidden"; hidden = "webkitHidden";
} }
if (typeof window.addEventListener === "undefined" || typeof document.hidden === "undefined") { if (
typeof window.addEventListener === "undefined" ||
typeof document.hidden === "undefined"
) {
if (refresh_rate) { if (refresh_rate) {
runIntervalId = setInterval(this.update, refresh_rate); runIntervalId = setInterval(this.update, refresh_rate);
} }
} } else {
else { window.addEventListener(
window.addEventListener('focus', Dashboard.handleVisibilityChange, false); "focus",
Dashboard.handleVisibilityChange,
false,
);
if (refresh_rate) { if (refresh_rate) {
runIntervalId = setInterval(Dashboard.handleVisibilityChange, refresh_rate); runIntervalId = setInterval(
Dashboard.handleVisibilityChange,
refresh_rate,
);
} }
} }
}, },
@ -49,8 +56,8 @@ BabyBuddy.Dashboard = function ($) {
update: function () { update: function () {
// TODO: Someday maybe update in place? // TODO: Someday maybe update in place?
location.reload(); location.reload();
} },
}; };
return Dashboard; return Dashboard;
}(jQuery); })(jQuery);

View File

@ -1,89 +1,78 @@
const basePath = 'babybuddy/static/babybuddy/'; const basePath = "babybuddy/static/babybuddy/";
module.exports = { module.exports = {
basePath: basePath, basePath: basePath,
extrasConfig: { extrasConfig: {
fonts: { fonts: {
dest: basePath + 'font/', dest: basePath + "font/",
files: 'babybuddy/static_src/fontello/font/*' files: "babybuddy/static_src/fontello/font/*",
}, },
images: { images: {
dest: basePath + 'img/', dest: basePath + "img/",
files: '**/static_src/img/**/*' files: "**/static_src/img/**/*",
}, },
logo: { logo: {
dest: basePath + 'logo/', dest: basePath + "logo/",
files: 'babybuddy/static_src/logo/**/*' files: "babybuddy/static_src/logo/**/*",
}, },
root: { root: {
dest: basePath + 'root/', dest: basePath + "root/",
files: 'babybuddy/static_src/root/*' files: "babybuddy/static_src/root/*",
} },
}, },
glyphFontConfig: { glyphFontConfig: {
configFile: 'babybuddy/static_src/fontello/config.json', configFile: "babybuddy/static_src/fontello/config.json",
dest: 'babybuddy/static_src/fontello' dest: "babybuddy/static_src/fontello",
}, },
scriptsConfig: { scriptsConfig: {
dest: basePath + 'js/', dest: basePath + "js/",
vendor: [ vendor: [
'node_modules/pulltorefreshjs/dist/index.umd.js', "node_modules/pulltorefreshjs/dist/index.umd.js",
'node_modules/jquery/dist/jquery.js', "node_modules/jquery/dist/jquery.js",
'node_modules/@popperjs/core/dist/umd/popper.js', "node_modules/@popperjs/core/dist/umd/popper.js",
'node_modules/bootstrap/dist/js/bootstrap.js', "node_modules/bootstrap/dist/js/bootstrap.js",
'node_modules/masonry-layout/dist/masonry.pkgd.js' "node_modules/masonry-layout/dist/masonry.pkgd.js",
], ],
graph: [ graph: [
'node_modules/plotly.js/dist/plotly-cartesian.js', "node_modules/plotly.js/dist/plotly-cartesian.js",
'node_modules/plotly.js/dist/plotly-locale-ca.js', "node_modules/plotly.js/dist/plotly-locale-ca.js",
'node_modules/plotly.js/dist/plotly-locale-cs.js', "node_modules/plotly.js/dist/plotly-locale-cs.js",
'node_modules/plotly.js/dist/plotly-locale-de.js', "node_modules/plotly.js/dist/plotly-locale-de.js",
'node_modules/plotly.js/dist/plotly-locale-da.js', "node_modules/plotly.js/dist/plotly-locale-da.js",
'node_modules/plotly.js/dist/plotly-locale-es.js', "node_modules/plotly.js/dist/plotly-locale-es.js",
'node_modules/plotly.js/dist/plotly-locale-fi.js', "node_modules/plotly.js/dist/plotly-locale-fi.js",
'node_modules/plotly.js/dist/plotly-locale-fr.js', "node_modules/plotly.js/dist/plotly-locale-fr.js",
'node_modules/plotly.js/dist/plotly-locale-hu.js', "node_modules/plotly.js/dist/plotly-locale-hu.js",
'node_modules/plotly.js/dist/plotly-locale-it.js', "node_modules/plotly.js/dist/plotly-locale-it.js",
'node_modules/plotly.js/dist/plotly-locale-no.js', "node_modules/plotly.js/dist/plotly-locale-no.js",
'node_modules/plotly.js/dist/plotly-locale-nl.js', "node_modules/plotly.js/dist/plotly-locale-nl.js",
'node_modules/plotly.js/dist/plotly-locale-pl.js', "node_modules/plotly.js/dist/plotly-locale-pl.js",
'node_modules/plotly.js/dist/plotly-locale-pt-br.js', "node_modules/plotly.js/dist/plotly-locale-pt-br.js",
'node_modules/plotly.js/dist/plotly-locale-pt-pt.js', "node_modules/plotly.js/dist/plotly-locale-pt-pt.js",
'node_modules/plotly.js/dist/plotly-locale-ru.js', "node_modules/plotly.js/dist/plotly-locale-ru.js",
'node_modules/plotly.js/dist/plotly-locale-sv.js', "node_modules/plotly.js/dist/plotly-locale-sv.js",
'node_modules/plotly.js/dist/plotly-locale-tr.js', "node_modules/plotly.js/dist/plotly-locale-tr.js",
'node_modules/plotly.js/dist/plotly-locale-uk.js', "node_modules/plotly.js/dist/plotly-locale-uk.js",
'node_modules/plotly.js/dist/plotly-locale-zh-cn.js', "node_modules/plotly.js/dist/plotly-locale-zh-cn.js",
], ],
app: [ app: [
'babybuddy/static_src/js/babybuddy.js', "babybuddy/static_src/js/babybuddy.js",
'api/static_src/js/*.js', "api/static_src/js/*.js",
'core/static_src/js/*.js', "core/static_src/js/*.js",
'dashboard/static_src/js/*.js' "dashboard/static_src/js/*.js",
], ],
tags_editor: [ tags_editor: ["babybuddy/static_src/js/tags_editor.js"],
'babybuddy/static_src/js/tags_editor.js'
]
}, },
stylesConfig: { stylesConfig: {
dest: basePath + 'css/', dest: basePath + "css/",
app: 'babybuddy/static_src/scss/babybuddy.scss', app: "babybuddy/static_src/scss/babybuddy.scss",
ignore: [ ignore: ["babybuddy.scss"],
'babybuddy.scss'
]
}, },
testsConfig: { testsConfig: {
isolated: [ isolated: ["babybuddy.tests.tests_views.ViewsTestCase.test_password_reset"],
'babybuddy.tests.tests_views.ViewsTestCase.test_password_reset'
],
}, },
watchConfig: { watchConfig: {
scriptsGlob: [ scriptsGlob: ["*/static_src/js/**/*.js", "!babybuddy/static/js/"],
'*/static_src/js/**/*.js', stylesGlob: ["*/static_src/scss/**/*.scss"],
'!babybuddy/static/js/' },
],
stylesGlob: [
'*/static_src/scss/**/*.scss'
]
}
}; };