diff --git a/src/js/database/apps.js b/src/js/database/apps.js
index 11edd5a..dc76d5c 100644
--- a/src/js/database/apps.js
+++ b/src/js/database/apps.js
@@ -64,6 +64,26 @@ class AppsDatabase extends DatabaseHandler {
})
}
+ /**
+ *
+ * @param {object} data
+ * @return {object}
+ *
+ */
+ remove(data) {
+ return this.db.remove(data)
+ .then(async (response) => {
+
+ const tagsDatabase = new TagsDatabase()
+
+ await tagsDatabase.removeNotNeeded()
+
+ return true
+ }).catch((error) => {
+ console.error(error)
+ })
+ }
+
/**
* find one app by id
*
@@ -154,7 +174,7 @@ class AppsDatabase extends DatabaseHandler {
return this.db.find(query).then((documents) => {
if (documents.warning) {
- console.warning(documents.warning)
+ console.log(documents.warning)
}
if (documents.docs.length > 0 && parameters.tags.length > 0) {
diff --git a/src/js/database/tags.js b/src/js/database/tags.js
index 464963d..4fa509b 100644
--- a/src/js/database/tags.js
+++ b/src/js/database/tags.js
@@ -41,8 +41,10 @@ class TagsDatabase extends DatabaseHandler {
// check for existings tags and remove
// adding tags that are not removed
this.db.find(query).then((documents) => {
+ console.log(documents)
return this.filterTags(documents, tags)
}).then(async (tags) => {
+ console.log(tags)
if (tags.length > 0) {
// adding tags to entries
@@ -62,22 +64,43 @@ class TagsDatabase extends DatabaseHandler {
*
*/
removeNotNeeded() {
- this.find().then((tags) => {
- const appsStore = new AppsStore()
- for (let i = 0; i < tags.length; i++) {
-
- const parameters = {
- tags: []
+ const query = {
+ 'selector': {
+ 'name': {
+ '$exists': true
}
+ }, 'fields': [
+ '_id',
+ '_rev',
+ 'name'
+ ]
+ }
- parameters.tags.push(tags[i].name)
+ this.db.find(query).then((tags) => {
+ console.log(tags.docs)
+ if (tags.docs.length > 0) {
- appsStore.find(parameters).then((documents) => {
- if (!documents) {
- this.db.remove(tags[i])
+ const appsStore = new AppsStore()
+
+ for (let i = 0; i < tags.docs.length; i++) {
+
+ //
+ const parameters = {
+ tags: [],
+ sort: 'name'
}
- })
+
+ parameters.tags.push(tags.docs[i].name)
+ console.log(parameters)
+
+ appsStore.find(parameters).then(async (documents) => {
+ if (!documents.docs) {
+ await this.db.remove(tags.docs[i])
+ }
+ })
+
+ }
}
})
}
@@ -92,9 +115,12 @@ class TagsDatabase extends DatabaseHandler {
*/
filterTags(documents, tags) {
if (documents.docs.length > 0) {
- for (let i; i < documents.docs.length; i++) {
+ for (let i = 0; i < documents.docs.length; i++) {
+
+ // check for name in tags
const index = tags.indexOf(documents.docs[i].name)
+ // if found remove from tags
if (index >= 0) {
tags.splice(index, 1)
}
@@ -128,7 +154,7 @@ class TagsDatabase extends DatabaseHandler {
return this.db.find(query).then((documents) => {
if (documents.warning) {
- console.warning(documents.warning)
+ console.log(documents.warning)
}
return documents.docs
diff --git a/src/js/forms/apps.riot b/src/js/forms/apps.riot
index b2cd1c9..7d6d712 100644
--- a/src/js/forms/apps.riot
+++ b/src/js/forms/apps.riot
@@ -85,7 +85,11 @@
-
+
+
@@ -125,12 +129,6 @@
...sidebarMixin, // adding basic funtion for sidebar
- state: {
- open: false, // if sidebar is open
- loading: false, // if loading is shown
- current: false
- },
-
/**
*
*
@@ -140,36 +138,21 @@
// adding event for open sidebar
formStore.on('open', (id) => {
- tagsStore.trigger('update', [])
-
this.state.current = false
this.state.open = true
- // if id is send, load apps from pouchdb
- if (id) {
- appsStore.getOne(id)
- } else {
- this.update()
- }
- })
+ // reset tags
+ tagsStore.trigger('update', [])
- // creating formValidator
- this.state.validator = new FormValidator(this.$('.form'), {
- 'name': {
- 'presence': true
- },
- 'command': {
- 'presence': true
- },
- 'tags': {
+ // if id is not undefined, get data from pouchdb
+ if (id !== undefined) {
+ appsStore.getOne(id)
+ }
- }
+ this.update()
})
- // adding on success
- this.state.validator.onSuccess((event, data) => {
- this.handleSuccess(event, data)
- })
+ this.createValidator()
// receive from extensions database
appsStore.on('success', (data) => {
@@ -185,6 +168,17 @@
})
// receive from extensions database
+ appsStore.on('close', (data) => {
+
+ appsStore.trigger('update')
+
+ this.state.open = false
+
+ // stop loading
+ this.state.loading = false
+ this.update()
+ })
+
appsStore.on('readyOne', (data) => {
this.state.current = data
@@ -200,7 +194,31 @@
this.update()
})
- },
+ },
+
+ /**
+ * creating Validator for form
+ *
+ *
+ */
+ createValidator() {
+ this.state.validator = new FormValidator(this.$('.form'), {
+ 'name': {
+ 'presence': true
+ },
+ 'command': {
+ 'presence': true
+ },
+ 'tags': {
+
+ }
+ })
+
+ // adding on success
+ this.state.validator.onSuccess((event, data) => {
+ this.handleSuccess(event, data)
+ })
+ },
/**
* choose a file for command
@@ -299,6 +317,10 @@
this.update()
},
+ handleDelete() {
+ appsStore.remove(this.state.current)
+ },
+
/**
*
*
diff --git a/src/js/forms/footer.riot b/src/js/forms/footer.riot
index 5ddf211..bd5bac6 100644
--- a/src/js/forms/footer.riot
+++ b/src/js/forms/footer.riot
@@ -1,12 +1,12 @@