bugfix for handling update

release-neutralino
HerrHase 2 years ago
parent 69c47483fb
commit 62f8124d1c

@ -72,7 +72,6 @@ class Connector {
// if event is in handlers-object mapped call it // if event is in handlers-object mapped call it
if (this.handlers.hasOwnProperty(message.event)) { if (this.handlers.hasOwnProperty(message.event)) {
console.log(event.data)
this.handlers[message.event].call(null, this, message.data) this.handlers[message.event].call(null, this, message.data)
} }
} }

@ -38,7 +38,7 @@ class AppsHandler {
appsStore.update(data) appsStore.update(data)
.then((data) => { .then((data) => {
connector.send('pouchdb.apps.readyOne', data) connector.send('pouchdb.apps.success', data)
}) })
} }
@ -72,6 +72,7 @@ class AppsHandler {
appsStore.find() appsStore.find()
.then((data) => { .then((data) => {
console.error('send result', data)
connector.send('pouchdb.apps.ready', data) connector.send('pouchdb.apps.ready', data)
}) })
} }

@ -30,7 +30,7 @@ class AppsStore extends PouchdbHandler {
create(data) { create(data) {
return this.db.post(data) return this.db.post(data)
.then((response) => { .then((response) => {
return response return this.findOneById(response._id)
}).catch((error) => { }).catch((error) => {
console.log(error) console.log(error)
}) })
@ -43,10 +43,9 @@ class AppsStore extends PouchdbHandler {
* *
*/ */
update(data) { update(data) {
console.log(data)
return this.db.put(data) return this.db.put(data)
.then((response) => { .then((response) => {
return response return this.findOneById(response._id)
}).catch((error) => { }).catch((error) => {
console.log(error) console.log(error)
}) })
@ -82,7 +81,7 @@ class AppsStore extends PouchdbHandler {
return documents.docs[0] return documents.docs[0]
} }
}).catch((error) => { }).catch((error) => {
console.log(error) console.error(error)
}) })
} }
@ -112,12 +111,12 @@ class AppsStore extends PouchdbHandler {
return this.db.find(query).then((documents) => { return this.db.find(query).then((documents) => {
if (documents.warning) { if (documents.warning) {
console.log(documents.warning) console.warning(documents.warning)
} }
return documents.docs return documents.docs
}).catch((error) => { }).catch((error) => {
console.log(error) console.error(error)
}) })
} }

@ -132,6 +132,8 @@
// adding event for open sidebar // adding event for open sidebar
formStore.on('open', (id) => { formStore.on('open', (id) => {
this.reset()
// if id is send, load apps from pouchdb // if id is send, load apps from pouchdb
if (id) { if (id) {
Neutralino.extensions.dispatch('js.neutralino.pouchdb', 'pouchdb.apps.findOne', { Neutralino.extensions.dispatch('js.neutralino.pouchdb', 'pouchdb.apps.findOne', {
@ -166,6 +168,9 @@
appsStore.trigger('updated') appsStore.trigger('updated')
this.state.current._id = event.detail._id
this.state.current._rev = event.detail._rev
// stop loading // stop loading
this.state.loading = false this.state.loading = false
this.update() this.update()
@ -174,9 +179,12 @@
// receive from extensions database // receive from extensions database
Neutralino.events.on('pouchdb.apps.readyOne', (event) => { Neutralino.events.on('pouchdb.apps.readyOne', (event) => {
this.reset()
this.state.current = event.detail this.state.current = event.detail
if (!this.state.current.tags) {
this.state.current.tags = []
}
tagsStore.trigger('update', this.state.current.tags) tagsStore.trigger('update', this.state.current.tags)
// stop loading // stop loading
@ -232,10 +240,10 @@
data.thumbnail = this.state.current.thumbnail data.thumbnail = this.state.current.thumbnail
// send to extensions database // send to extensions database
if (data._id) { if (data._id && data._rev) {
Neutralino.extensions.dispatch('js.neutralino.pouchdb', 'pouchdb.apps.create', data)
} else {
Neutralino.extensions.dispatch('js.neutralino.pouchdb', 'pouchdb.apps.update', data) Neutralino.extensions.dispatch('js.neutralino.pouchdb', 'pouchdb.apps.update', data)
} else {
Neutralino.extensions.dispatch('js.neutralino.pouchdb', 'pouchdb.apps.create', data)
} }
}, },
@ -279,6 +287,8 @@
this.state.current = { this.state.current = {
} }
tagsStore.trigger('update', [])
} }
} }
} }

Loading…
Cancel
Save