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.03: Sort selected items to bottom and enable Widgets
|
||||
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;
|
||||
|
||||
function updateSettings() {
|
||||
const updateSettings = function() {
|
||||
require("Storage").writeJSON(filename, settings);
|
||||
Bangle.buzz();
|
||||
}
|
||||
};
|
||||
|
||||
function twoChat(n){
|
||||
const twoChat = function(n) {
|
||||
if(n<10) return '0'+n;
|
||||
return ''+n;
|
||||
}
|
||||
};
|
||||
|
||||
function sortMenu() {
|
||||
const sortMenu = function() {
|
||||
mainMenu.sort((a,b) => {
|
||||
const byValue = a.value-b.value;
|
||||
return byValue !== 0 ? byValue : a.index-b.index;
|
||||
|
|
@ -20,7 +21,7 @@ function sortMenu() {
|
|||
if (menu) {
|
||||
menu.draw();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const mainMenu = settings.products.map((p,i) => ({
|
||||
title: twoChat(p.quantity)+' '+p.name,
|
||||
|
|
@ -35,9 +36,14 @@ const mainMenu = settings.products.map((p,i) => ({
|
|||
}));
|
||||
sortMenu();
|
||||
|
||||
mainMenu[''] = { 'title': 'Grocery list' };
|
||||
mainMenu[''] = {
|
||||
'title': 'Grocery list',
|
||||
remove: () => {
|
||||
},
|
||||
};
|
||||
mainMenu['< Back'] = ()=>{load();};
|
||||
|
||||
Bangle.loadWidgets();
|
||||
menu = E.showMenu(mainMenu);
|
||||
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
|
||||
Util.hideModal();
|
||||
|
||||
settings = JSON.parse(data || "{products: []}");
|
||||
settings = JSON.parse(data || '{"products": []}');
|
||||
products = settings.products;
|
||||
renderProducts();
|
||||
});
|
||||
|
|
@ -89,7 +89,6 @@
|
|||
function save(){
|
||||
settings.products = products;
|
||||
Util.showModal("Saving...");
|
||||
localStorage.setItem('grocery-product-list',JSON.stringify(products));
|
||||
Util.writeStorage("grocery_list.json", JSON.stringify(settings), () => {
|
||||
Util.hideModal();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,13 +1,12 @@
|
|||
{
|
||||
"id": "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.",
|
||||
"icon": "grocery.png",
|
||||
"type": "app",
|
||||
"tags": "tool,shopping,list",
|
||||
"supports": ["BANGLEJS", "BANGLEJS2"],
|
||||
"custom": "grocery.html",
|
||||
"interface": "interface.html",
|
||||
"allow_emulator": true,
|
||||
"dependencies": {"textinput":"type"},
|
||||
|
|
|
|||
|
|
@ -118,7 +118,7 @@
|
|||
/*LANG*/"Edit List": () => editlist(),
|
||||
/*LANG*/"Add item": () => {
|
||||
settings.products.push({
|
||||
"name":/*LANG*/"New item",
|
||||
"name":/*LANG*/"New",
|
||||
"quantity":1,
|
||||
"ok":false
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue