Create Todo List app
parent
8ed8d91518
commit
a438fe0a65
|
|
@ -0,0 +1 @@
|
||||||
|
0.01: Initial release
|
||||||
|
|
@ -0,0 +1,40 @@
|
||||||
|
Todo List
|
||||||
|
========
|
||||||
|
|
||||||
|
This is a simple Todo List application.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
The content is loaded from a JSON file.
|
||||||
|
You can mark a task as completed.
|
||||||
|
|
||||||
|
JSON file content example:
|
||||||
|
```javascript
|
||||||
|
[
|
||||||
|
{
|
||||||
|
name: "Pro",
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
name: "Read doc",
|
||||||
|
done: true,
|
||||||
|
children: [],
|
||||||
|
}
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Pers",
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
name: "Grocery",
|
||||||
|
children: [
|
||||||
|
{ name: "Milk", done: false, children: [] },
|
||||||
|
{ name: "Eggs", done: false, children: [] },
|
||||||
|
{ name: "Cheese", done: false, children: [] },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{ name: "Workout", done: false, children: [] },
|
||||||
|
{ name: "Learn Rust", done: false, children: [] },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
require("heatshrink").decompress(atob("AEURiMQCycBC6gVDDKAPBAAYXDA4gWMiUhAgUiDBYmBiUiCAMjmQQBiczBQkRFw0T/4ABC4MzkUSmYXBl4KB+QXHBYQXDAAYLFJAsRn4LDIYIXIkIXGBQQLBRYojEmIXKmIWFiQLEC5X/IwkzFwYXNABQX/C6kxXIYXR+cRj4XTkUyaIPzbYcSVIQXJFoLRC+LZEGwQvKFQIPBDgQACF5gTBkLpEX/6/Z/6/VmfyX4UiAAa/kC4UT/4yBAAZmCX5bPDX/4MEmRIJX8sv+czAAa/PAoK/rmQPDI4h3OB4bX/aJIAFkIXGOQQALTgIXGiQwNmMRCwkAgK3EABQuFGAQAOCwwAU")
|
||||||
|
|
@ -0,0 +1,129 @@
|
||||||
|
Bangle.loadWidgets();
|
||||||
|
Bangle.drawWidgets();
|
||||||
|
|
||||||
|
// Const
|
||||||
|
let TODOLIST_FILE = "todolist.json";
|
||||||
|
let MAX_DESCRIPTION_LEN = 14;
|
||||||
|
|
||||||
|
// Clear todolist file
|
||||||
|
// require("Storage").erase(TODOLIST_FILE);
|
||||||
|
|
||||||
|
let DEFAULT_TODOLIST = [
|
||||||
|
{
|
||||||
|
name: "Pro",
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
name: "Read doc",
|
||||||
|
done: true,
|
||||||
|
children: [],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Pers",
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
name: "Grocery",
|
||||||
|
children: [
|
||||||
|
{ name: "Milk", done: false, children: [] },
|
||||||
|
{ name: "Eggs", done: false, children: [] },
|
||||||
|
{ name: "Cheese", done: false, children: [] },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{ name: "Workout", done: false, children: [] },
|
||||||
|
{ name: "Learn Rust", done: false, children: [] },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
// Load todolist
|
||||||
|
let todolist =
|
||||||
|
require("Storage").readJSON(TODOLIST_FILE, true) || DEFAULT_TODOLIST;
|
||||||
|
let menus = {};
|
||||||
|
|
||||||
|
function writeData() {
|
||||||
|
require("Storage").writeJSON(TODOLIST_FILE, todolist);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getChild(todolist, indexes) {
|
||||||
|
let childData = todolist;
|
||||||
|
for (let i = 0; i < indexes.length; i++) {
|
||||||
|
childData = childData[indexes[i]];
|
||||||
|
childData = childData.children;
|
||||||
|
}
|
||||||
|
|
||||||
|
return childData;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getName(item) {
|
||||||
|
let title = item.name.substr(0, MAX_DESCRIPTION_LEN);
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
function getParentTitle(todolist, indexes) {
|
||||||
|
let parentIndexes = indexes.slice(0, indexes.length - 1);
|
||||||
|
let lastIndex = indexes[indexes.length - 1];
|
||||||
|
let item = getItem(todolist, parentIndexes, lastIndex);
|
||||||
|
return getName(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getItem(todolist, parentIndexes, index) {
|
||||||
|
let childData = getChild(todolist, parentIndexes, index);
|
||||||
|
return childData[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleableStatus(todolist, indexes, index) {
|
||||||
|
const reminder = getItem(todolist, indexes, index);
|
||||||
|
return {
|
||||||
|
value: !!reminder.done, // !! converts undefined to false
|
||||||
|
format: (val) => (val ? "[X]" : "[-]"),
|
||||||
|
onchange: (val) => {
|
||||||
|
reminder.done = val;
|
||||||
|
writeData();
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function showSubMenu(key) {
|
||||||
|
const sub_menu = menus[key];
|
||||||
|
return E.showMenu(sub_menu);
|
||||||
|
}
|
||||||
|
|
||||||
|
function createListItem(todolist, indexes, index) {
|
||||||
|
let reminder = getItem(todolist, indexes, index);
|
||||||
|
if (reminder.children.length > 0) {
|
||||||
|
let childIndexes = [];
|
||||||
|
for (let i = 0; i < indexes.length; i++) {
|
||||||
|
childIndexes.push(indexes[i]);
|
||||||
|
}
|
||||||
|
childIndexes.push(index);
|
||||||
|
createMenus(todolist, childIndexes);
|
||||||
|
return () => showSubMenu(childIndexes);
|
||||||
|
} else {
|
||||||
|
return toggleableStatus(todolist, indexes, index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function showMainMenu() {
|
||||||
|
const mainmenu = menus[""];
|
||||||
|
return E.showMenu(mainmenu);
|
||||||
|
}
|
||||||
|
|
||||||
|
function createMenus(todolist, indexes) {
|
||||||
|
const menuItem = {};
|
||||||
|
if (indexes.length == 0) {
|
||||||
|
menuItem[""] = { title: "todolist" };
|
||||||
|
} else {
|
||||||
|
menuItem[""] = { title: getParentTitle(todolist, indexes) };
|
||||||
|
menuItem["< Back"] = () =>
|
||||||
|
showSubMenu(indexes.slice(0, indexes.length - 1));
|
||||||
|
}
|
||||||
|
for (let i = 0; i < getChild(todolist, indexes).length; i++) {
|
||||||
|
const item = getItem(todolist, indexes, i);
|
||||||
|
const name = getName(item);
|
||||||
|
menuItem[name] = createListItem(todolist, indexes, i);
|
||||||
|
}
|
||||||
|
menus[indexes] = menuItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
createMenus(todolist, []);
|
||||||
|
showMainMenu();
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 1.8 KiB |
|
|
@ -0,0 +1,23 @@
|
||||||
|
{
|
||||||
|
"id": "todolist",
|
||||||
|
"name": "TodoList",
|
||||||
|
"shortName": "TodoList",
|
||||||
|
"version": "0.01",
|
||||||
|
"type": "app",
|
||||||
|
"description": "Simple Todo List",
|
||||||
|
"icon": "app.png",
|
||||||
|
"allow_emulator": true,
|
||||||
|
"tags": "tool,todo",
|
||||||
|
"supports": ["BANGLEJS", "BANGLEJS2"],
|
||||||
|
"readme": "README.md",
|
||||||
|
"storage": [
|
||||||
|
{ "name": "todolist.app.js", "url": "app.js" },
|
||||||
|
{ "name": "todolist.img", "url": "app-icon.js", "evaluate": true }
|
||||||
|
],
|
||||||
|
"data": [{ "name": "todolist.json" }],
|
||||||
|
"screenshots": [
|
||||||
|
{ "url": "screenshot1.png" },
|
||||||
|
{ "url": "screenshot2.png" },
|
||||||
|
{ "url": "screenshot3.png" }
|
||||||
|
]
|
||||||
|
}
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 1.6 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 2.5 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 2.2 KiB |
Loading…
Reference in New Issue