diff --git a/extensions/pouchdb/connector.js b/extensions/pouchdb/connector.js index 79b595b..c6dc308 100644 --- a/extensions/pouchdb/connector.js +++ b/extensions/pouchdb/connector.js @@ -72,6 +72,7 @@ class Connector { // if event is in handlers-object mapped call it if (this.handlers.hasOwnProperty(message.event)) { + console.log(event.data) this.handlers[message.event].call(null, this, message.data) } } diff --git a/extensions/pouchdb/handlers/apps.js b/extensions/pouchdb/handlers/apps.js index 9634fe9..3924583 100644 --- a/extensions/pouchdb/handlers/apps.js +++ b/extensions/pouchdb/handlers/apps.js @@ -38,7 +38,25 @@ class AppsHandler { appsStore.update(data) .then((data) => { - connector.send('pouchdb.apps.success', data) + connector.send('pouchdb.apps.readyOne', data) + }) + } + + /** + * use update in appStore and send event with result to app + * + * @param {object} data + * @return {object} + * + */ + findOne(connector, data) { + const appsStore = new AppsStore() + + appsStore.findOneById(data.id) + .then((data) => { + if (data) { + connector.send('pouchdb.apps.readyOne', data) + } }) } diff --git a/extensions/pouchdb/index.js b/extensions/pouchdb/index.js index cb38433..bebd34d 100644 --- a/extensions/pouchdb/index.js +++ b/extensions/pouchdb/index.js @@ -9,6 +9,8 @@ const appsHandler = new AppsHandler // create connector and add handlers for events const connector = new Connector({ 'pouchdb.apps.create': appsHandler.create, + 'pouchdb.apps.update': appsHandler.update, + 'pouchdb.apps.findOne': appsHandler.findOne, 'pouchdb.apps.find': appsHandler.find }) diff --git a/extensions/pouchdb/package.json b/extensions/pouchdb/package.json index d15c83d..d1d656f 100644 --- a/extensions/pouchdb/package.json +++ b/extensions/pouchdb/package.json @@ -1,5 +1,5 @@ { - "name": "database", + "private": true, "version": "1.0.0", "main": "index.js", "license": "MIT", diff --git a/extensions/pouchdb/stores/apps.js b/extensions/pouchdb/stores/apps.js index 2f66487..478e74f 100644 --- a/extensions/pouchdb/stores/apps.js +++ b/extensions/pouchdb/stores/apps.js @@ -8,7 +8,18 @@ import PouchdbHandler from './pouchdbHandler.js' * @link https://gitea.node001.net/HerrHase/tellme-bot.git * */ -class AppsDatabase extends PouchdbHandler { +class AppsStore extends PouchdbHandler { + + constructor() { + super() + + // add index for apps + this.createIndex([ + 'name', + 'description', + 'tags' + ]) + } /** * @@ -17,12 +28,11 @@ class AppsDatabase extends PouchdbHandler { * */ create(data) { - data['type'] = 'apps' - return this.db.post(data) .then((response) => { - console.log(response) return response + }).catch((error) => { + console.log(error) }) } @@ -35,8 +45,15 @@ class AppsDatabase extends PouchdbHandler { */ findOneById(id) { const query = { + 'fields': [ + '_id', + 'name', + 'command', + 'description', + 'thumbnail', + 'tags' + ], 'selector': { - 'type': 'apps', '_id' : id } } @@ -47,6 +64,8 @@ class AppsDatabase extends PouchdbHandler { } else { return documents.docs[0] } + }).catch((error) => { + console.log(error) }) } @@ -58,16 +77,33 @@ class AppsDatabase extends PouchdbHandler { */ find() { const query = { + 'fields': [ + '_id', + 'name', + 'command', + 'description', + 'thumbnail', + 'tags', + 'started_date' + ], 'selector': { - 'type': 'apps' + 'name': { + '$exists': true + } } } return this.db.find(query).then((documents) => { + if (documents.warning) { + console.log(documents.warning) + } + return documents.docs + }).catch((error) => { + console.log(error) }) } } -export default AppsDatabase \ No newline at end of file +export default AppsStore \ No newline at end of file diff --git a/extensions/pouchdb/stores/pouchdbHandler.js b/extensions/pouchdb/stores/pouchdbHandler.js index 880ed37..7991f30 100644 --- a/extensions/pouchdb/stores/pouchdbHandler.js +++ b/extensions/pouchdb/stores/pouchdbHandler.js @@ -2,11 +2,11 @@ import PouchDB from 'pouchdb' import PouchDBfind from 'pouchdb-find' /** - * PouchdbHandler + * PouchdbHandler, for create * - * @author Björn Hase, me@herr-hase.wtf - * @license http://opensource.org/licenses/MIT The MIT License - * @link https://gitea.node001.net/HerrHase/super-hog + * @author Björn Hase + * @license https://www.gnu.org/licenses/gpl-3.0.en.html GPL-3 + * @link https://gitea.node001.net/HerrHase/potato-launcher.git * */ @@ -22,14 +22,15 @@ class PouchdbHandler { this.db = new PouchDB('.storage/pouchdb/apps', { revs_limit: 0 }) + } - // create fields for index - const fields = [ - 'type', - 'name', - 'description', - 'tags' - ] + /** + * adding index for current class + * + * @param {array} fields + * + */ + createIndex(fields) { // adding index try { @@ -41,8 +42,9 @@ class PouchdbHandler { }) } catch (error) { - console.log(error); + console.log(error) } + } } diff --git a/extensions/pouchdb/stores/tags.js b/extensions/pouchdb/stores/tags.js new file mode 100644 index 0000000..4809a32 --- /dev/null +++ b/extensions/pouchdb/stores/tags.js @@ -0,0 +1,126 @@ +import PouchdbHandler from './pouchdbHandler.js' + +/** + * apps + * + * @author Björn Hase + * @license hhttps://www.gnu.org/licenses/gpl-3.0.en.html GPL-3 + * @link https://gitea.node001.net/HerrHase/tellme-bot.git + * + */ +class TagsDatabase extends PouchdbHandler { + + constructor() { + super() + + // add index for apps + this.createIndex([ + 'name' + ]) + } + + /** + * + * + * @param {object} data + * + */ + async create(tags) { + + const query = { + 'selector': { + 'name': { + '$in': tags + } + }, 'fields': [ + 'name' + ] + } + + // check for existings tags and remove + // adding tags that are not removed + this.db.find(query).then((documents) => { + if (documents.docs && documents.docs.length > 0) { + documents.docs.forEach(data, () => { + + const index = tags.indexOf(data.name) + + if (index >= 0) { + tags.splice(index, 1) + } + }) + } + + if (tags.length > 0) { + tags.forEach((tag) => { + await this.db.post({ + 'name': tag + }) + }) + } + }) + } + + /** + * + * + * @param {object} data + * + */ + async remove(tags) { + + const query = { + 'selector': { + 'name': { + '$in': tags + } + }, 'fields': [ + 'name' + ] + } + + // check for existings tags and remove + // adding tags that are not removed + this.db.find(query).then((documents) => { + if (documents.docs && documents.docs.length > 0) { + documents.docs.forEach(data, () => { + + const index = tags.indexOf(data.name) + + if (index >= 0) { + tags.splice(index, 1) + } + }) + } + + if (tags.length > 0) { + tags.forEach((tag) => { + await this.db.post({ + 'name': tag + }) + }) + } + }) + } + + /** + * find apps + * + * @return {mixed} + * + */ + find() { + const query = { + 'fields': [ + 'name' + ] + } + + return this.db.find(query).then((documents) => { + return documents.docs + }) + } + +} + +export default AppsDatabase \ No newline at end of file diff --git a/neutralino.config.json b/neutralino.config.json index 3ce2ba5..196b27f 100644 --- a/neutralino.config.json +++ b/neutralino.config.json @@ -24,7 +24,7 @@ ], "modes": { "window": { - "title": "shiny-dashboard", + "title": "Potato Launcher", "fullScreen": false, "alwaysOnTop": false, "icon": "/resources/icons/appIcon.png", @@ -37,7 +37,7 @@ } }, "cli": { - "binaryName": "shiny-dashboard", + "binaryName": "potato-launcher", "resourcesPath": "/build/", "extensionsPath": "/extensions/", "clientLibrary": "/resources/js/neutralino.js", @@ -46,7 +46,7 @@ }, "extensions": [ { - "id": "js.neutralino.database", + "id": "js.neutralino.pouchdb", "command": "node ${NL_PATH}/extensions/pouchdb/index.js" } ] diff --git a/resources/index.html b/resources/index.html index 3b5b8e0..178c8b2 100644 --- a/resources/index.html +++ b/resources/index.html @@ -9,6 +9,7 @@