grocery: Drop grocery.html
Drop app customiser as it is redundant with download interface and the latter has more featuresmaster
parent
b6fcc5ee4c
commit
c8ef7097c0
|
|
@ -2,3 +2,4 @@
|
||||||
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
|
0.03: Sort selected items to bottom and enable Widgets
|
||||||
0.04: Add settings to edit list on device
|
0.04: Add settings to edit list on device
|
||||||
|
0.05: Drop app customiser as it is redundant with download interface
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,19 @@
|
||||||
var filename = 'grocery_list.json';
|
{
|
||||||
var settings = require("Storage").readJSON(filename,1)|| { products: [] };
|
const filename = 'grocery_list.json';
|
||||||
|
const settings = require("Storage").readJSON(filename,1)|| { products: [] };
|
||||||
let menu;
|
let menu;
|
||||||
|
|
||||||
function updateSettings() {
|
const updateSettings = function() {
|
||||||
require("Storage").writeJSON(filename, settings);
|
require("Storage").writeJSON(filename, settings);
|
||||||
Bangle.buzz();
|
Bangle.buzz();
|
||||||
}
|
};
|
||||||
|
|
||||||
function twoChat(n){
|
const twoChat = function(n) {
|
||||||
if(n<10) return '0'+n;
|
if(n<10) return '0'+n;
|
||||||
return ''+n;
|
return ''+n;
|
||||||
}
|
};
|
||||||
|
|
||||||
function sortMenu() {
|
const sortMenu = function() {
|
||||||
mainMenu.sort((a,b) => {
|
mainMenu.sort((a,b) => {
|
||||||
const byValue = a.value-b.value;
|
const byValue = a.value-b.value;
|
||||||
return byValue !== 0 ? byValue : a.index-b.index;
|
return byValue !== 0 ? byValue : a.index-b.index;
|
||||||
|
|
@ -20,7 +21,7 @@ function sortMenu() {
|
||||||
if (menu) {
|
if (menu) {
|
||||||
menu.draw();
|
menu.draw();
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
const mainMenu = settings.products.map((p,i) => ({
|
const mainMenu = settings.products.map((p,i) => ({
|
||||||
title: twoChat(p.quantity)+' '+p.name,
|
title: twoChat(p.quantity)+' '+p.name,
|
||||||
|
|
@ -35,9 +36,14 @@ const mainMenu = settings.products.map((p,i) => ({
|
||||||
}));
|
}));
|
||||||
sortMenu();
|
sortMenu();
|
||||||
|
|
||||||
mainMenu[''] = { 'title': 'Grocery list' };
|
mainMenu[''] = {
|
||||||
|
'title': 'Grocery list',
|
||||||
|
remove: () => {
|
||||||
|
},
|
||||||
|
};
|
||||||
mainMenu['< Back'] = ()=>{load();};
|
mainMenu['< Back'] = ()=>{load();};
|
||||||
|
|
||||||
Bangle.loadWidgets();
|
Bangle.loadWidgets();
|
||||||
menu = E.showMenu(mainMenu);
|
menu = E.showMenu(mainMenu);
|
||||||
Bangle.drawWidgets();
|
Bangle.drawWidgets();
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,116 +0,0 @@
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<link rel="stylesheet" href="../../css/spectre.min.css">
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
|
|
||||||
<h4>List of products</h4>
|
|
||||||
<table class="table">
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th>name</th>
|
|
||||||
<th>quantity</th>
|
|
||||||
<th>actions</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody id="products">
|
|
||||||
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
<br><br>
|
|
||||||
<h4>Add a new product</h4>
|
|
||||||
<form id="add_product_form">
|
|
||||||
<div class="columns">
|
|
||||||
<div class="column col-4 col-xs-12">
|
|
||||||
<input class="form-input input-sm" type="text" id="add_product_name" placeholder="Name">
|
|
||||||
</div>
|
|
||||||
<div class="column col-4 col-xs-12">
|
|
||||||
<input class="form-input input-sm" value="1" type="number" id="add_product_quantity" placeholder="Quantity">
|
|
||||||
</div>
|
|
||||||
<div class="column col-4 col-xs-12">
|
|
||||||
<button id="add_product_button" class="btn btn-primary btn-sm">Add</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
<br><br>
|
|
||||||
<button id="reset" class="btn btn-error">Reset</button> <button id="upload" class="btn btn-primary">Upload</button>
|
|
||||||
|
|
||||||
<script src="../../core/lib/customize.js"></script>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
|
|
||||||
var products = []
|
|
||||||
try{
|
|
||||||
var stored = localStorage.getItem('grocery-product-list')
|
|
||||||
if(stored) products = JSON.parse(stored);
|
|
||||||
}catch(e){}
|
|
||||||
|
|
||||||
var $name = document.getElementById('add_product_name')
|
|
||||||
var $form = document.getElementById('add_product_form')
|
|
||||||
var $button = document.getElementById('add_product_button')
|
|
||||||
var $quantity = document.getElementById('add_product_quantity')
|
|
||||||
var $list = document.getElementById('products')
|
|
||||||
var $reset = document.getElementById('reset')
|
|
||||||
|
|
||||||
renderProducts()
|
|
||||||
|
|
||||||
$reset.addEventListener('click', reset)
|
|
||||||
|
|
||||||
$form.addEventListener('submit', event => {
|
|
||||||
event.preventDefault()
|
|
||||||
|
|
||||||
var name = $name.value.trim()
|
|
||||||
if(!name) return;
|
|
||||||
|
|
||||||
var quantity = parseInt($quantity.value)
|
|
||||||
|
|
||||||
products.push({
|
|
||||||
name, quantity,
|
|
||||||
ok: false
|
|
||||||
})
|
|
||||||
|
|
||||||
renderProducts()
|
|
||||||
$name.value = ''
|
|
||||||
$quantity.value = 1
|
|
||||||
save()
|
|
||||||
})
|
|
||||||
|
|
||||||
function save(){
|
|
||||||
localStorage.setItem('grocery-product-list',JSON.stringify(products));
|
|
||||||
}
|
|
||||||
|
|
||||||
function reset(){
|
|
||||||
products = []
|
|
||||||
save()
|
|
||||||
renderProducts()
|
|
||||||
}
|
|
||||||
|
|
||||||
function removeProduct(index){
|
|
||||||
products = products.filter((p,i) => i!==index)
|
|
||||||
save()
|
|
||||||
renderProducts()
|
|
||||||
}
|
|
||||||
|
|
||||||
function renderProducts(){
|
|
||||||
$list.innerHTML = ''
|
|
||||||
products.forEach((product,index) => {
|
|
||||||
var $product = document.createElement('tr')
|
|
||||||
|
|
||||||
$product.innerHTML = `<td>${product.name}</td><td>${product.quantity}</td><td><button class="btn btn-error" onclick="removeProduct(${index})">remove</button></td>`
|
|
||||||
$list.appendChild($product)
|
|
||||||
})
|
|
||||||
|
|
||||||
$name.focus()
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
document.getElementById("upload").addEventListener("click", function() {
|
|
||||||
sendCustomizedApp({
|
|
||||||
storage:[
|
|
||||||
{ name:"grocery_list.json", content: JSON.stringify({products: products}) }
|
|
||||||
]
|
|
||||||
});
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
|
|
@ -80,7 +80,7 @@
|
||||||
// remove window
|
// remove window
|
||||||
Util.hideModal();
|
Util.hideModal();
|
||||||
|
|
||||||
settings = JSON.parse(data || "{products: []}");
|
settings = JSON.parse(data || '{"products": []}');
|
||||||
products = settings.products;
|
products = settings.products;
|
||||||
renderProducts();
|
renderProducts();
|
||||||
});
|
});
|
||||||
|
|
@ -89,7 +89,6 @@
|
||||||
function save(){
|
function save(){
|
||||||
settings.products = products;
|
settings.products = products;
|
||||||
Util.showModal("Saving...");
|
Util.showModal("Saving...");
|
||||||
localStorage.setItem('grocery-product-list',JSON.stringify(products));
|
|
||||||
Util.writeStorage("grocery_list.json", JSON.stringify(settings), () => {
|
Util.writeStorage("grocery_list.json", JSON.stringify(settings), () => {
|
||||||
Util.hideModal();
|
Util.hideModal();
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,12 @@
|
||||||
{
|
{
|
||||||
"id": "grocery",
|
"id": "grocery",
|
||||||
"name": "Grocery",
|
"name": "Grocery",
|
||||||
"version": "0.04",
|
"version": "0.05",
|
||||||
"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",
|
||||||
"tags": "tool,shopping,list",
|
"tags": "tool,shopping,list",
|
||||||
"supports": ["BANGLEJS", "BANGLEJS2"],
|
"supports": ["BANGLEJS", "BANGLEJS2"],
|
||||||
"custom": "grocery.html",
|
|
||||||
"interface": "interface.html",
|
"interface": "interface.html",
|
||||||
"allow_emulator": true,
|
"allow_emulator": true,
|
||||||
"dependencies": {"textinput":"type"},
|
"dependencies": {"textinput":"type"},
|
||||||
|
|
|
||||||
|
|
@ -118,7 +118,7 @@
|
||||||
/*LANG*/"Edit List": () => editlist(),
|
/*LANG*/"Edit List": () => editlist(),
|
||||||
/*LANG*/"Add item": () => {
|
/*LANG*/"Add item": () => {
|
||||||
settings.products.push({
|
settings.products.push({
|
||||||
"name":/*LANG*/"New item",
|
"name":/*LANG*/"New",
|
||||||
"quantity":1,
|
"quantity":1,
|
||||||
"ok":false
|
"ok":false
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue