adding delete app

main
HerrHase 2 years ago
parent b7fdfb042c
commit e501713c99

@ -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) {

@ -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

@ -85,7 +85,11 @@
</div>
<!-- footer -->
<tiny-sidebar-form-footer id={ state.current.id ? state.current.id : false } loading={ state.loading }></tiny-sidebar-form-footer>
<tiny-sidebar-form-footer
id={ state.current._id ? state.current._id : false }
loading={ state.loading }
handle-delete={ handleDelete }>
</tiny-sidebar-form-footer>
</form>
</div>
@ -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)
},
/**
*
*

@ -1,12 +1,12 @@
<tiny-sidebar-form-footer>
<div class="sidebar__footer">
<button class="button button--danger m-bottom-0" disabled={ props.loading } if={ props.id }>
<button class="button button--danger m-bottom-0" disabled={ props.loading } type="button" if={ props.id } onclick={ () => { props.handleDelete() }}>
Delete
<svg class="icon fill-success p-left-3" aria-hidden="true">
<svg class="icon fill-danger p-left-3" aria-hidden="true">
<use xlink:href="symbol-defs.svg#icon-delete"></use>
</svg>
</button>
<button class="button m-bottom-0" type="submit" disabled={ props.loading } close>
<button class="button m-bottom-0" type="submit" disabled={ props.loading }>
Save
<svg class="icon fill-success p-left-3" aria-hidden="true">
<use xlink:href="symbol-defs.svg#icon-check"></use>

@ -9,9 +9,20 @@
export default {
/**
* adding default values
*
*
*/
onBeforeMount() {
this.state.open = false
this.state.loading = false
this.state.current = false
},
/**
* close current sidebar
*
*
*
*/
handleClose() {
@ -23,6 +34,8 @@ export default {
* getting css classes for sidebar
*
*
* @return {string}
*
*/
getCssClasses() {
const classes = [

@ -74,6 +74,21 @@ export default observable({
})
},
/**
* update app
*
* @param {object} data
*
*/
remove(data) {
const appsDatabase = new AppsDatabase()
appsDatabase.remove(data).then(() => {
this.trigger('close')
tagsStore.get()
})
},
/**
* orderBy and run get
*

Loading…
Cancel
Save