From 24be1e9f6a66ea638ed653e1d23b40412aea7c54 Mon Sep 17 00:00:00 2001 From: HerrHase Date: Sun, 4 Sep 2022 21:43:06 +0200 Subject: [PATCH] adding a few fixes and new logic for tags --- extensions/pouchdb/connector.js | 1 + extensions/pouchdb/handlers/apps.js | 20 +++- extensions/pouchdb/index.js | 2 + extensions/pouchdb/package.json | 2 +- extensions/pouchdb/stores/apps.js | 50 ++++++-- extensions/pouchdb/stores/pouchdbHandler.js | 26 ++-- extensions/pouchdb/stores/tags.js | 126 ++++++++++++++++++++ neutralino.config.json | 6 +- resources/index.html | 1 + src/js/app.js | 31 ++++- src/js/components/appsFormButton.riot | 4 +- src/js/components/closeButton.riot | 2 +- src/js/components/fields/tags.riot | 71 ++++++----- src/js/forms/apps.riot | 110 +++++++++++------ src/js/forms/footer.riot | 2 +- src/js/forms/header.riot | 4 +- src/js/mixins/sidebarForm.js | 4 +- src/js/stores/form.js | 13 +- src/js/stores/tags.js | 14 +++ src/js/views/apps.riot | 35 ++++-- src/scss/_helpers.scss | 3 + src/scss/components/_badge.scss | 9 ++ src/scss/components/_bar.scss | 6 + src/scss/components/_buttons.scss | 8 ++ src/scss/components/_field-tags.scss | 5 +- src/scss/components/_field.scss | 20 ++++ src/scss/components/_sidebar.scss | 23 ++++ src/scss/styles.scss | 7 +- 28 files changed, 487 insertions(+), 118 deletions(-) create mode 100644 extensions/pouchdb/stores/tags.js create mode 100644 src/js/stores/tags.js create mode 100644 src/scss/_helpers.scss create mode 100644 src/scss/components/_badge.scss create mode 100644 src/scss/components/_bar.scss create mode 100644 src/scss/components/_sidebar.scss 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 @@
+
diff --git a/src/js/app.js b/src/js/app.js index fd4deae..d0de906 100644 --- a/src/js/app.js +++ b/src/js/app.js @@ -3,6 +3,7 @@ import * as riot from 'riot' import TinyLoading from '@tiny-components/loading/src/loading.riot' import TinySidebarFormHeader from './forms/header.riot' import TinySidebarFormFooter from './forms/footer.riot' +import TinyNotification from '@tiny-components/notification/src/notification.riot' import FieldError from '@tiny-components/validator/src/fieldError.riot' @@ -16,18 +17,46 @@ riot.register('field-error', FieldError) riot.register('tiny-loading', TinyLoading) riot.register('tiny-sidebar-form-header', TinySidebarFormHeader) riot.register('tiny-sidebar-form-footer', TinySidebarFormFooter) +riot.register('tiny-notification', TinyNotification) + riot.register('potato-field-tags', potatoFieldTags) riot.register('potato-apps-view', potatoAppsView) riot.register('potato-close-button', potatoCloseButton) // adding events for Neutralino -Neutralino.events.on('ready', () => { +Neutralino.events.on('ready', async () => { + + // @TODO thats mad, it is only a workaround, don't judge me, i will do better + // its no possible to create a hole path, solving this with array and a recursive function + try { + const result = await Neutralino.filesystem.getStats('./.storage') + + if (result) { + try { + await Neutralino.filesystem.createDirectory('./.storage/pouchdb') + } catch(error) { + + } + } + } catch(error) { + if (error.code === 'NE_FS_NOPATHE') { + try { + await Neutralino.filesystem.createDirectory('./.storage') + await Neutralino.filesystem.createDirectory('./.storage/pouchdb') + } catch(error) { + + } + } + } + riot.mount('potato-apps-view') + riot.mount('tiny-notification') }) // let it rain Neutralino.init() +// workaround to prevent a stack overflow window._arrayBufferToBase64 = function _arrayBufferToBase64(buffer) { var binary = ''; diff --git a/src/js/components/appsFormButton.riot b/src/js/components/appsFormButton.riot index e04beac..a7b3bf2 100644 --- a/src/js/components/appsFormButton.riot +++ b/src/js/components/appsFormButton.riot @@ -1,5 +1,5 @@ - + + + + + +
0 } class="field-error"> +
    +
  • + { error } +
  • +
+