Add one-way task completion and exportable pet identity cards
This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
const completion = require("../../utils/task-completion");
|
||||
const { secure, toast } = require("../../utils/api");
|
||||
const { localDate, shiftDate } = require("../../utils/date");
|
||||
Page({
|
||||
data: {
|
||||
pets: [],
|
||||
tasks: [],
|
||||
taskBusyIds: [],
|
||||
completingAll: false,
|
||||
undoneCount: 0,
|
||||
date: localDate(),
|
||||
showForm: false,
|
||||
editingId: "",
|
||||
@@ -33,23 +37,21 @@ Page({
|
||||
this.setData({
|
||||
pets,
|
||||
tasks,
|
||||
undoneCount: tasks.filter((t) => !t.completed).length,
|
||||
done: tasks.filter((t) => t.completed).length,
|
||||
});
|
||||
} catch (e) {
|
||||
toast(e);
|
||||
}
|
||||
},
|
||||
async toggle(e) {
|
||||
const t = this.data.tasks[e.currentTarget.dataset.index];
|
||||
try {
|
||||
await secure("/tasks/" + t.id + "/completion", "PUT", {
|
||||
date: this.data.date,
|
||||
completed: !t.completed,
|
||||
});
|
||||
await this.load();
|
||||
} catch (err) {
|
||||
toast(err);
|
||||
}
|
||||
toggle(e) {
|
||||
return completion.complete(
|
||||
this,
|
||||
this.data.tasks[e.currentTarget.dataset.index],
|
||||
);
|
||||
},
|
||||
completeAll() {
|
||||
return completion.completeAll(this);
|
||||
},
|
||||
open() {
|
||||
if (!this.data.pets.length) {
|
||||
@@ -83,10 +85,14 @@ Page({
|
||||
});
|
||||
},
|
||||
changeDay(e) {
|
||||
this.setData({ date: shiftDate(this.data.date, Number(e.currentTarget.dataset.days)) });
|
||||
if (this.data.completingAll || this.data.taskBusyIds.length) return;
|
||||
this.setData({
|
||||
date: shiftDate(this.data.date, Number(e.currentTarget.dataset.days)),
|
||||
});
|
||||
this.load();
|
||||
},
|
||||
showToday() {
|
||||
if (this.data.completingAll || this.data.taskBusyIds.length) return;
|
||||
this.setData({ date: localDate() });
|
||||
this.load();
|
||||
},
|
||||
@@ -113,13 +119,17 @@ Page({
|
||||
}
|
||||
this.setData({ saving: true });
|
||||
try {
|
||||
await secure(this.data.editingId ? "/tasks/" + this.data.editingId : "/tasks", this.data.editingId ? "PUT" : "POST", {
|
||||
pet_id: this.data.pets[this.data.petIndex].id,
|
||||
title: this.data.title.trim(),
|
||||
category: this.data.category,
|
||||
time_of_day: this.data.time_of_day,
|
||||
repeat_rule: this.data.repeat_rule,
|
||||
});
|
||||
await secure(
|
||||
this.data.editingId ? "/tasks/" + this.data.editingId : "/tasks",
|
||||
this.data.editingId ? "PUT" : "POST",
|
||||
{
|
||||
pet_id: this.data.pets[this.data.petIndex].id,
|
||||
title: this.data.title.trim(),
|
||||
category: this.data.category,
|
||||
time_of_day: this.data.time_of_day,
|
||||
repeat_rule: this.data.repeat_rule,
|
||||
},
|
||||
);
|
||||
this.setData({ showForm: false, editingId: "" });
|
||||
await this.load();
|
||||
} catch (e) {
|
||||
|
||||
Reference in New Issue
Block a user