main
HerrHase 2 years ago
parent a57724e43a
commit b7fdfb042c

@ -18,7 +18,6 @@
* @link https://gitea.node001.net/HerrHase/potato-launcher.git * @link https://gitea.node001.net/HerrHase/potato-launcher.git
* *
*/ */
export default { export default {
/** /**

@ -108,6 +108,9 @@ class AppsDatabase extends DatabaseHandler {
find(parameters) { find(parameters) {
const query = { const query = {
'selector': {
},
'fields': [ 'fields': [
'_id', '_id',
'_rev', '_rev',

@ -1,4 +1,5 @@
import DatabaseHandler from './databaseHandler.js' import DatabaseHandler from './databaseHandler.js'
import AppsStore from './apps.js'
/** /**
* apps * apps
@ -40,28 +41,69 @@ 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) => {
if (documents.docs.length > 0) { return this.filterTags(documents, tags)
documents.docs.forEach((data) => { }).then(async (tags) => {
if (tags.length > 0) {
// getting // adding tags to entries
const index = tags.indexOf(data.name) for (let i = 0; i < tags.length; i++) {
await this.db.post({
'name': tags[i]
})
}
if (index >= 0) { this.removeNotNeeded()
tags.splice(index, 1)
}
})
} }
})
}
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 * find apps
* *

@ -18,8 +18,9 @@
<div class="field-group"> <div class="field-group">
<label class="field-label"> <label class="field-label">
name* name*
<input type="text" class="field-text" name="name" value="{ state.current.name ? state.current.name : '' }" /> <input type="text" class="field-text" name="name" value={ state.current.name } />
</label> </label>
<field-error name="name"></field-error>
</div> </div>
<!-- command --> <!-- command -->
@ -27,7 +28,7 @@
<label class="field-label"> <label class="field-label">
command* command*
<div class="field-input-group"> <div class="field-input-group">
<input class="field-text" type="text" name="command" value="{ state.current.command ? state.current.command : '' }" /> <input class="field-text" type="text" name="command" value="{ state.current.command }" />
<button class="button button--hover-icon-contrast m-bottom-0" type="button" onclick={ (event) => { handleOpenCommand(event) }}> <button class="button button--hover-icon-contrast m-bottom-0" type="button" onclick={ (event) => { handleOpenCommand(event) }}>
<svg class="icon"> <svg class="icon">
<use xlink:href="symbol-defs.svg#icon-folder" /> <use xlink:href="symbol-defs.svg#icon-folder" />
@ -52,7 +53,7 @@
<div class="field-group"> <div class="field-group">
<label class="field-label"> <label class="field-label">
description description
<textarea class="field-text" name="description" value="{ state.current.description ? state.current.description : '' }"></textarea> <textarea class="field-text" name="description" value="{ state.current.description }"></textarea>
</label> </label>
</div> </div>
@ -124,6 +125,12 @@
...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
},
/** /**
* *
* *
@ -133,15 +140,17 @@
// adding event for open sidebar // adding event for open sidebar
formStore.on('open', (id) => { formStore.on('open', (id) => {
this.reset() tagsStore.trigger('update', [])
this.state.current = false
this.state.open = true
// if id is send, load apps from pouchdb // if id is send, load apps from pouchdb
if (id) { if (id) {
appsStore.getOne(id) appsStore.getOne(id)
} else {
this.update()
} }
this.state.open = true
this.update()
}) })
// creating formValidator // creating formValidator
@ -228,6 +237,7 @@
handleSuccess(event, data) { handleSuccess(event, data) {
event.preventDefault() event.preventDefault()
this.state.current = data
this.state.loading = true this.state.loading = true
this.update() this.update()
@ -297,18 +307,6 @@
*/ */
toImage(media) { toImage(media) {
return 'data:image/png;base64,' + media return 'data:image/png;base64,' + media
},
/**
* reset data of current form
*
*/
reset() {
this.state.current = {
}
tagsStore.trigger('update', [])
} }
} }
} }

@ -9,21 +9,12 @@
export default { export default {
state: {
open: false, // if sidebar is open
loading: false, // if loading is shown
current: { // current data of form
}
},
/** /**
* close current sidebar * close current sidebar
*
* *
*/ */
handleClose() { handleClose() {
this.reset()
this.state.open = false this.state.open = false
this.update() this.update()
}, },
@ -32,7 +23,6 @@ export default {
* getting css classes for sidebar * getting css classes for sidebar
* *
* *
* @return {String}
*/ */
getCssClasses() { getCssClasses() {
const classes = [ const classes = [
@ -44,17 +34,5 @@ export default {
} }
return classes.join(' ') return classes.join(' ')
},
/**
*
*
*/
onBeforeMount() {
if (!this.hasOwnProperty('reset')) {
throw new Error('reset-Function in Form is missing')
}
this.reset()
} }
} }
Loading…
Cancel
Save