logs: Added filtering.
This commit is contained in:
@@ -3,6 +3,7 @@ const {logHeaderApi} = require("../../../../../rpdata/api/LogHeader")
|
||||
module.exports = class {
|
||||
onCreate(input) {
|
||||
this.state = {
|
||||
filter: input.filter,
|
||||
logs: input.logs,
|
||||
modal: null,
|
||||
}
|
||||
@@ -16,8 +17,40 @@ module.exports = class {
|
||||
this.state.modal = null
|
||||
}
|
||||
|
||||
onMount() {
|
||||
logHeaderApi.list({limit: 0}).then(logs => {
|
||||
addFilter(type, filter) {
|
||||
if (type === "search") {
|
||||
this.state.filter = Object.assign({}, this.state.filter, {search: filter})
|
||||
} else {
|
||||
this.state.filter = Object.assign({}, this.state.filter, {[type]: (this.state.filter[type] || []).concat(filter)})
|
||||
}
|
||||
|
||||
console.log("FILTER:", this.state.filter)
|
||||
|
||||
this.refresh()
|
||||
}
|
||||
|
||||
removeFilter(type, filter) {
|
||||
console.log(type, filter, this.state.filter)
|
||||
|
||||
if (type === "search") {
|
||||
this.state.filter = Object.assign({}, this.state.filter, {search: null})
|
||||
this.refresh()
|
||||
} else if ((this.state.filter[type] || []).length === 1) {
|
||||
this.state.filter = Object.assign({}, this.state.filter, {[type]: null})
|
||||
this.refresh()
|
||||
} else {
|
||||
const index = (this.state.filter[type] || []).indexOf(filter)
|
||||
if (index !== -1) {
|
||||
this.state.filter = Object.assign({}, this.state.filter, {[type]: this.state.filter[type].splice(0, index).concat(this.state.filter[type].splice(index + 1))},)
|
||||
this.refresh()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
refresh() {
|
||||
console.log("REFRESH", this.state.filter)
|
||||
|
||||
logHeaderApi.list(this.state.filter).then(logs => {
|
||||
this.state.logs = logs
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<background src="/assets/images/bg.png" opacity=0.25 />
|
||||
<logs-menu key="menu" on-select("open") selected=(input.selected || {}) user=input.user />
|
||||
<logs-menu key="menu" on-select("open") on-removefilter("removeFilter") selected=(input.selected || {}) user=input.user filter=state.filter characters=input.characters />
|
||||
<main>
|
||||
<logs-list logs=state.logs />
|
||||
</main>
|
||||
<add-log-modal enabled=(state.modal === "add") on-close("close") />
|
||||
<add-log-modal enabled=(state.modal === "log.add") on-close("close") />
|
||||
<add-filter-modal enabled=(state.modal === "filter.add") characters=input.characters filter=state.filter on-add("addFilter") on-close("close") />
|
||||
|
||||
Reference in New Issue
Block a user