-
-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: moved category/pattern select & Search/Report query options…
… into components
- Loading branch information
Showing
10 changed files
with
351 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<template lang="pug"> | ||
div | ||
b-form-group(label="Hostname" label-cols=2) | ||
b-form-select(v-model="queryOptionsData.hostname") | ||
option(v-for="hostname in hostnameChoices") | ||
| {{hostname}} | ||
b-form-group(label="Start" label-cols=2) | ||
b-form-datepicker(v-model="queryOptionsData.start") | ||
b-form-group(label="Stop" label-cols=2) | ||
b-form-datepicker(v-model="queryOptionsData.stop") | ||
b-form-group(label="Toggles" label-cols=2) | ||
b-form-checkbox(type="checkbox" v-model="queryOptionsData.filter_afk" label="Filter AFK" description="") | ||
label Exclude time away from computer | ||
</template> | ||
|
||
<script lang="ts"> | ||
import Vue from 'vue'; | ||
import moment from 'moment'; | ||
export default Vue.extend({ | ||
name: 'QueryOptions', | ||
props: { | ||
queryOptions: { | ||
type: Object, | ||
}, | ||
}, | ||
data() { | ||
return { | ||
queryOptionsData: { | ||
hostname: '', | ||
start: moment().subtract(1, 'day').format('YYYY-MM-DD'), | ||
stop: moment().add(1, 'day').format('YYYY-MM-DD'), | ||
filter_afk: true, | ||
}, | ||
}; | ||
}, | ||
computed: { | ||
hostnameChoices() { | ||
return this.$store.getters['buckets/hosts']; | ||
}, | ||
}, | ||
watch: { | ||
queryOptionsData: { | ||
handler(value) { | ||
this.$emit('input', value); | ||
}, | ||
deep: true, | ||
}, | ||
}, | ||
async mounted() { | ||
await this.$store.dispatch('buckets/ensureBuckets'); | ||
this.queryOptionsData = { | ||
...this.queryOptionsData, | ||
hostname: this.hostnameChoices[0], | ||
...this.queryOptions, | ||
}; | ||
this.$emit('input', this.queryOptionsData); | ||
}, | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<template lang="pug"> | ||
// Based on https://bootstrap-vue.org/docs/components/form-tags#using-custom-form-components | ||
b-form-tags#tags-component-select( | ||
v-model="value" | ||
add-on-change | ||
no-outer-focus | ||
) | ||
template(v-slot="{ tags, inputAttrs, inputHandlers, disabled, removeTag }") | ||
b-form-select( | ||
v-bind="inputAttrs" | ||
v-on="inputHandlers" | ||
:disabled="disabled || options.length === 0" | ||
:options="options" | ||
) | ||
template(#first) | ||
// This is required to prevent bugs with Safari | ||
option(disabled value="") Choose a tag... | ||
ul.list-inline.d-inline-block.my-2(v-if="tags.length > 0") | ||
li.list-inline-item(v-for="tag in tags" :key="tag") | ||
b-form-tag( | ||
@remove="removeTag(tag)" | ||
:title="tag" | ||
:disabled="disabled" | ||
variant="info" | ||
) | ||
| {{ tag }} | ||
</template> | ||
|
||
<script lang="typescript"> | ||
import Vue from 'vue'; | ||
const SEP = " > "; | ||
export default Vue.extend({ | ||
data() { | ||
return { | ||
value: [], | ||
}; | ||
}, | ||
computed: { | ||
options() { | ||
const classes = this.$store.state.categories.classes; | ||
return classes.map(category => category.name.join(SEP)); | ||
} | ||
}, | ||
watch: { | ||
value(val) { | ||
const category_names = val.map(v => v.split(SEP)) | ||
this.$emit('input', category_names); | ||
}, | ||
}, | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<template lang="pug"> | ||
div | ||
// Let the user either choose a mode to use for filtering events. | ||
// Either let the user choose which of the existing categories to include, or use a custom regex. | ||
b-form-group | ||
b-form-select(v-model="mode") | ||
option(value="custom") Custom regex | ||
option(value="categories") Use existing categories | ||
|
||
// select which categories, by having a form select and a "plus" button to include them | ||
b-input-group | ||
aw-select-categories(v-if="mode == 'categories'", v-model="filterCategoriesData") | ||
b-input(v-if="mode == 'custom'" v-model="pattern" v-on:keyup.enter="generate()" placeholder="Regex pattern to search for") | ||
b-input-group-append | ||
slot(name="input-group-append") | ||
</template> | ||
|
||
<script lang="ts"> | ||
import Vue from 'vue'; | ||
const SEP = ' > '; | ||
export default Vue.extend({ | ||
name: 'SelectCategoriesOrPattern', | ||
props: { | ||
filterCategories: { | ||
type: Array, | ||
default: () => [], | ||
}, | ||
}, | ||
data() { | ||
return { | ||
mode: 'categories', | ||
pattern: '', | ||
filterCategoriesData: [], | ||
}; | ||
}, | ||
computed: { | ||
categories: function () { | ||
return this.$store.state.categories.classes; | ||
}, | ||
categoriesWithRules() { | ||
if (this.mode === 'categories') { | ||
// Get the category and all subcategories | ||
return this.categories | ||
.filter(cat => { | ||
const name = cat.name.join(SEP); | ||
for (const filterCat of this.filterCategoriesData) { | ||
if (name.includes(filterCat.join(SEP))) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
}) | ||
.filter(cat => cat.rule.type === 'regex') | ||
.map(cat => [cat.name, cat.rule]); | ||
} else if (this.mode === 'custom') { | ||
return [[['searched'], { type: 'regex', regex: this.pattern }]]; | ||
} else { | ||
console.error('Unknown mode:', this.mode); | ||
return []; | ||
} | ||
}, | ||
}, | ||
watch: { | ||
filterCategories() { | ||
this.filterCategoriesData = [...this.filterCategoriesData, ...this.filterCategories]; | ||
}, | ||
filterCategoriesData() { | ||
this.$emit('input', this.categoriesWithRules); | ||
console.log(this.categoriesWithRules); | ||
}, | ||
pattern() { | ||
this.$emit('input', this.categoriesWithRules); | ||
console.log(this.categoriesWithRules); | ||
}, | ||
}, | ||
async mounted() { | ||
await this.$store.dispatch('categories/load'); | ||
}, | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
ba70a4f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here are screenshots of this commit:
Screenshots using aw-server v0.11.0 (click to expand)
Screenshots using aw-server-rust v0.11.0 (click to expand)