Browse Source

update checked state in db

master
strfry 2 years ago
parent
commit
dc5a8084eb
  1. 16
      model.js
  2. 9
      needs.js
  3. 1
      package.json

16
model.js

@ -1,10 +1,14 @@
//import PouchDB from 'pouchdb'
var PouchDB = require('pouchdb');
PouchDB.plugin(require('pouchdb-upsert'))
// TODO: Broken global state, needs model API for live updates
var db = null
function getModel(db_url) {
db_url = "http://exodus.strfry.org:82/hq_needs/"
var db = new PouchDB(db_url)
db = new PouchDB(db_url)
//var db = require('pouchdb')(db_url)
return new Promise((resolve, reject) => {
db.allDocs({include_docs: true}
@ -15,6 +19,8 @@ function getModel(db_url) {
})
}
var items = [
'Apfel',
'Birne',
@ -23,3 +29,11 @@ var items = [
module.exports.getModel = getModel;
module.exports.setItemState = (store, item, confirmed_state) => {
db.upsert(store, doc => {
doc.items = doc.items.map(x => { if (x.name == item) x.confirmed = confirmed_state; return x; })
return doc
}
)
}

9
needs.js

@ -13,6 +13,8 @@ var {Card, Checkbox, Icon, IconButton, SVG, ListTile, List} = require('polythene
//var {CheckboxCss} = require('polythene-css');
//CheckboxCSS.addStyle("")
var model = require('./model')
const Item = {
/*
oninit: vnode => {
@ -30,10 +32,9 @@ const Item = {
style: { color: 'limegreen'} ,
// value: model.confirmed,
defaultChecked: vnode.attrs.confirmed,
// onChange: state => vnode.attrs.confirmed = state.checked,
onChange: state => vnode.state.checked = state.checked,
// checked: state => vnode.attrs.confirmed
checked: vnode.state.checked,
onChange: state => model.setItemState('Baumarkt', vnode.attrs.name, state.checked),
checked: vnode.state.checked,
}),
})
}

1
package.json

@ -8,6 +8,7 @@
"polka": "~0.5.2",
"polythene-mithril": "^1.5.4",
"pouchdb": "^7.0.0",
"pouchdb-upsert": "^2.2.0",
"serve-static": "^1.13.2"
},
"type": "module",

Loading…
Cancel
Save