Sort selected items to bottom and enable Widgets
master
Erik Andresen 2023-01-05 18:41:51 +01:00
parent 29a9687c57
commit 83e76d4001
3 changed files with 31 additions and 16 deletions

View File

@ -1,2 +1,3 @@
0.01: New App! 0.01: New App!
0.02: Refactor code to store grocery list in separate file 0.02: Refactor code to store grocery list in separate file
0.03: Sort selected items to bottom and enable Widgets

View File

@ -1,5 +1,6 @@
var filename = 'grocery_list.json'; var filename = 'grocery_list.json';
var settings = require("Storage").readJSON(filename,1)|| { products: [] }; var settings = require("Storage").readJSON(filename,1)|| { products: [] };
let menu;
function updateSettings() { function updateSettings() {
require("Storage").writeJSON(filename, settings); require("Storage").writeJSON(filename, settings);
@ -11,19 +12,32 @@ function twoChat(n){
return ''+n; return ''+n;
} }
const mainMenu = settings.products.reduce(function(m, p, i){ function sortMenu() {
const name = twoChat(p.quantity)+' '+p.name; mainMenu.sort((a,b) => {
m[name] = { const byValue = a.value-b.value;
value: p.ok, return byValue !== 0 ? byValue : a.index-b.index;
format: v => v?'[x]':'[ ]', });
onchange: v => { if (menu) {
settings.products[i].ok = v; menu.draw();
updateSettings(); }
} }
};
return m; const mainMenu = settings.products.map((p,i) => ({
}, { title: twoChat(p.quantity)+' '+p.name,
'': { 'title': 'Grocery list' } value: p.ok,
}); format: v => v?'[x]':'[ ]',
index: i,
onchange: v => {
settings.products[i].ok = v;
updateSettings();
sortMenu();
}
}));
sortMenu();
mainMenu[''] = { 'title': 'Grocery list' };
mainMenu['< Back'] = ()=>{load();}; mainMenu['< Back'] = ()=>{load();};
E.showMenu(mainMenu);
Bangle.loadWidgets();
menu = E.showMenu(mainMenu);
Bangle.drawWidgets();

View File

@ -1,7 +1,7 @@
{ {
"id": "grocery", "id": "grocery",
"name": "Grocery", "name": "Grocery",
"version": "0.02", "version": "0.03",
"description": "Simple grocery (shopping) list - Display a list of product and track if you already put them in your cart.", "description": "Simple grocery (shopping) list - Display a list of product and track if you already put them in your cart.",
"icon": "grocery.png", "icon": "grocery.png",
"type": "app", "type": "app",