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 * find one app by id
* *
@ -154,7 +174,7 @@ class AppsDatabase extends DatabaseHandler {
return this.db.find(query).then((documents) => { return this.db.find(query).then((documents) => {
if (documents.warning) { if (documents.warning) {
console.warning(documents.warning) console.log(documents.warning)
} }
if (documents.docs.length > 0 && parameters.tags.length > 0) { if (documents.docs.length > 0 && parameters.tags.length > 0) {

@ -41,8 +41,10 @@ class TagsDatabase extends DatabaseHandler {
// check for existings tags and remove // check for existings tags and remove
// adding tags that are not removed // adding tags that are not removed
this.db.find(query).then((documents) => { this.db.find(query).then((documents) => {
console.log(documents)
return this.filterTags(documents, tags) return this.filterTags(documents, tags)
}).then(async (tags) => { }).then(async (tags) => {
console.log(tags)
if (tags.length > 0) { if (tags.length > 0) {
// adding tags to entries // adding tags to entries
@ -62,22 +64,43 @@ class TagsDatabase extends DatabaseHandler {
* *
*/ */
removeNotNeeded() { removeNotNeeded() {
this.find().then((tags) => {
const appsStore = new AppsStore()
for (let i = 0; i < tags.length; i++) { const query = {
'selector': {
const parameters = { 'name': {
tags: [] '$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) => { const appsStore = new AppsStore()
if (!documents) {
this.db.remove(tags[i]) 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) { filterTags(documents, tags) {
if (documents.docs.length > 0) { 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) const index = tags.indexOf(documents.docs[i].name)
// if found remove from tags
if (index >= 0) { if (index >= 0) {
tags.splice(index, 1) tags.splice(index, 1)
} }
@ -128,7 +154,7 @@ class TagsDatabase extends DatabaseHandler {
return this.db.find(query).then((documents) => { return this.db.find(query).then((documents) => {
if (documents.warning) { if (documents.warning) {
console.warning(documents.warning) console.log(documents.warning)
} }
return documents.docs return documents.docs

@ -85,7 +85,11 @@
</div> </div>
<!-- footer --> <!-- 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> </form>
</div> </div>
@ -125,12 +129,6 @@
...sidebarMixin, // adding basic funtion for sidebar ...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 // adding event for open sidebar
formStore.on('open', (id) => { formStore.on('open', (id) => {
tagsStore.trigger('update', [])
this.state.current = false this.state.current = false
this.state.open = true this.state.open = true
// if id is send, load apps from pouchdb // reset tags
if (id) { tagsStore.trigger('update', [])
appsStore.getOne(id)
} else {
this.update()
}
})
// creating formValidator // if id is not undefined, get data from pouchdb
this.state.validator = new FormValidator(this.$('.form'), { if (id !== undefined) {
'name': { appsStore.getOne(id)
'presence': true }
},
'command': {
'presence': true
},
'tags': {
} this.update()
}) })
// adding on success this.createValidator()
this.state.validator.onSuccess((event, data) => {
this.handleSuccess(event, data)
})
// receive from extensions database // receive from extensions database
appsStore.on('success', (data) => { appsStore.on('success', (data) => {
@ -185,6 +168,17 @@
}) })
// receive from extensions database // 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) => { appsStore.on('readyOne', (data) => {
this.state.current = data this.state.current = data
@ -200,7 +194,31 @@
this.update() 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 * choose a file for command
@ -299,6 +317,10 @@
this.update() this.update()
}, },
handleDelete() {
appsStore.remove(this.state.current)
},
/** /**
* *
* *

@ -1,12 +1,12 @@
<tiny-sidebar-form-footer> <tiny-sidebar-form-footer>
<div class="sidebar__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 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> <use xlink:href="symbol-defs.svg#icon-delete"></use>
</svg> </svg>
</button> </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 Save
<svg class="icon fill-success p-left-3" aria-hidden="true"> <svg class="icon fill-success p-left-3" aria-hidden="true">
<use xlink:href="symbol-defs.svg#icon-check"></use> <use xlink:href="symbol-defs.svg#icon-check"></use>

@ -9,9 +9,20 @@
export default { export default {
/**
* adding default values
*
*
*/
onBeforeMount() {
this.state.open = false
this.state.loading = false
this.state.current = false
},
/** /**
* close current sidebar * close current sidebar
* *
* *
*/ */
handleClose() { handleClose() {
@ -23,6 +34,8 @@ export default {
* getting css classes for sidebar * getting css classes for sidebar
* *
* *
* @return {string}
*
*/ */
getCssClasses() { getCssClasses() {
const classes = [ 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 * orderBy and run get
* *

Loading…
Cancel
Save