diff --git a/src/js/components/appsFormButton.riot b/src/js/components/appsFormButton.riot index a7b3bf2..8be9ee6 100644 --- a/src/js/components/appsFormButton.riot +++ b/src/js/components/appsFormButton.riot @@ -18,7 +18,6 @@ * @link https://gitea.node001.net/HerrHase/potato-launcher.git * */ - export default { /** diff --git a/src/js/database/apps.js b/src/js/database/apps.js index a6198c8..11edd5a 100644 --- a/src/js/database/apps.js +++ b/src/js/database/apps.js @@ -108,6 +108,9 @@ class AppsDatabase extends DatabaseHandler { find(parameters) { const query = { + 'selector': { + + }, 'fields': [ '_id', '_rev', diff --git a/src/js/database/tags.js b/src/js/database/tags.js index bd23cdb..464963d 100644 --- a/src/js/database/tags.js +++ b/src/js/database/tags.js @@ -1,4 +1,5 @@ import DatabaseHandler from './databaseHandler.js' +import AppsStore from './apps.js' /** * apps @@ -40,28 +41,69 @@ class TagsDatabase extends DatabaseHandler { // check for existings tags and remove // adding tags that are not removed this.db.find(query).then((documents) => { - if (documents.docs.length > 0) { - documents.docs.forEach((data) => { + return this.filterTags(documents, tags) + }).then(async (tags) => { + if (tags.length > 0) { - // getting - const index = tags.indexOf(data.name) + // adding tags to entries + for (let i = 0; i < tags.length; i++) { + await this.db.post({ + 'name': tags[i] + }) + } - if (index >= 0) { - tags.splice(index, 1) - } - }) + this.removeNotNeeded() } + }) + } - if (tags.length > 0) { - tags.forEach((tag) => { - this.db.post({ - 'name': tag - }) + /** + * + * + */ + removeNotNeeded() { + this.find().then((tags) => { + const appsStore = new AppsStore() + + for (let i = 0; i < tags.length; i++) { + + const parameters = { + tags: [] + } + + parameters.tags.push(tags[i].name) + + appsStore.find(parameters).then((documents) => { + if (!documents) { + this.db.remove(tags[i]) + } }) } }) } + /** + * filter tags, if they are already exists + * + * @param {array} documents + * @param {array} tags + * @return {array} + * + */ + filterTags(documents, tags) { + if (documents.docs.length > 0) { + for (let i; i < documents.docs.length; i++) { + const index = tags.indexOf(documents.docs[i].name) + + if (index >= 0) { + tags.splice(index, 1) + } + } + } + + return tags + } + /** * find apps * diff --git a/src/js/forms/apps.riot b/src/js/forms/apps.riot index eff0a84..b2cd1c9 100644 --- a/src/js/forms/apps.riot +++ b/src/js/forms/apps.riot @@ -18,8 +18,9 @@
+
@@ -27,7 +28,7 @@