diff --git a/apps/grocery/ChangeLog b/apps/grocery/ChangeLog index 906046782..294dab597 100644 --- a/apps/grocery/ChangeLog +++ b/apps/grocery/ChangeLog @@ -1,2 +1,3 @@ 0.01: New App! 0.02: Refactor code to store grocery list in separate file +0.03: Sort selected items to bottom and enable Widgets diff --git a/apps/grocery/app.js b/apps/grocery/app.js index 481efc3d9..a68f53010 100644 --- a/apps/grocery/app.js +++ b/apps/grocery/app.js @@ -1,5 +1,6 @@ var filename = 'grocery_list.json'; var settings = require("Storage").readJSON(filename,1)|| { products: [] }; +let menu; function updateSettings() { require("Storage").writeJSON(filename, settings); @@ -11,19 +12,32 @@ function twoChat(n){ return ''+n; } -const mainMenu = settings.products.reduce(function(m, p, i){ - const name = twoChat(p.quantity)+' '+p.name; - m[name] = { - value: p.ok, - format: v => v?'[x]':'[ ]', - onchange: v => { - settings.products[i].ok = v; - updateSettings(); - } - }; - return m; -}, { - '': { 'title': 'Grocery list' } -}); +function sortMenu() { + mainMenu.sort((a,b) => { + const byValue = a.value-b.value; + return byValue !== 0 ? byValue : a.index-b.index; + }); + if (menu) { + menu.draw(); + } +} + +const mainMenu = settings.products.map((p,i) => ({ + title: twoChat(p.quantity)+' '+p.name, + 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();}; -E.showMenu(mainMenu); + +Bangle.loadWidgets(); +menu = E.showMenu(mainMenu); +Bangle.drawWidgets(); diff --git a/apps/grocery/interface.html b/apps/grocery/interface.html new file mode 100644 index 000000000..65528c8e6 --- /dev/null +++ b/apps/grocery/interface.html @@ -0,0 +1,138 @@ + + + + + + +

List of products

+ + + + + + + + + + + + +
namequantitydoneactions
+

+

Add a new product

+
+
+
+ +
+
+ +
+
+ +
+
+
+

+ + + + + + + + + + diff --git a/apps/grocery/metadata.json b/apps/grocery/metadata.json index 8c0e34dff..ef073a1b2 100644 --- a/apps/grocery/metadata.json +++ b/apps/grocery/metadata.json @@ -1,13 +1,14 @@ { "id": "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.", "icon": "grocery.png", "type": "app", "tags": "tool,outdoors,shopping,list", "supports": ["BANGLEJS", "BANGLEJS2"], "custom": "grocery.html", + "interface": "interface.html", "allow_emulator": true, "storage": [ {"name":"grocery.app.js","url":"app.js"},