Repository navigation
Expand file tree
/
Copy pathmain.logic
More file actions
65 lines (60 loc) · 1.51 KB
/
Copy pathmain.logic
File metadata and controls
65 lines (60 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
let title = "";
let lane = "Design";
let filter = "all";
let rows = [];
let shown = [];
let activeCount = 0;
let doneCount = 0;
let totalCount = 0;
let message = "Your sample workspace is ready. Try adding a task.";
let error = "";
function refresh() {
rows = db.query("tasks");
activeCount = 0;
doneCount = 0;
shown = [];
for (let i = 0; i < rows.length; i = i + 1) {
let record = rows[i];
if (record.data.done) doneCount = doneCount + 1;
else activeCount = activeCount + 1;
if (filter === "all" || (filter === "active" && !record.data.done) || (filter === "done" && record.data.done)) {
shown.push(record);
}
}
totalCount = rows.length;
}
function addTask() {
const clean = String(title || "").trim();
if (!clean) {
error = "Give your task a name first.";
return;
}
if (clean.length > 100) {
error = "Keep the task name under 100 characters.";
return;
}
db.create("tasks", { title: clean, lane: lane, done: false });
title = "";
error = "";
filter = "all";
refresh();
message = "Task saved to the collection. Your dashboard is up to date.";
}
function toggleTask(id) {
for (let i = 0; i < rows.length; i = i + 1) {
if (rows[i].id === id) {
const next = !rows[i].data.done;
db.update(id, { done: next });
message = next ? "Task completed. Your totals have updated." : "Task reopened. Back on your list.";
break;
}
}
refresh();
}
function showTasks(value) {
filter = value;
refresh();
}
function _init() {
refresh();
}