Frontend: Add button to show all labels

Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
Michael Mayer 2019-12-17 07:13:09 +01:00
parent 4ab44c5c23
commit ed182537f1
4 changed files with 22 additions and 7 deletions

View file

@ -19,6 +19,13 @@
<v-spacer></v-spacer>
<v-btn v-if="!filter.all" icon @click.stop="showAll" class="hidden-xs-only">
<v-icon>visibility</v-icon>
</v-btn>
<v-btn v-else icon @click.stop="showImportant" class="hidden-xs-only">
<v-icon>visibility_off</v-icon>
</v-btn>
<v-btn icon @click.stop="refresh" class="hidden-xs-only">
<v-icon>refresh</v-icon>
</v-btn>
@ -98,6 +105,7 @@
const query = this.$route.query;
this.filter.q = query['q'] ? query['q'] : '';
this.filter.all = query['all'] ? query['all'] : '';
this.lastFilter = {};
this.routeName = this.$route.name;
this.search();
@ -107,7 +115,8 @@
const query = this.$route.query;
const routeName = this.$route.name;
const q = query['q'] ? query['q'] : '';
const filter = {q: q};
const all = query['all'] ? query['all'] : '';
const filter = {q: q, all: all};
const settings = {};
return {
@ -127,6 +136,14 @@
};
},
methods: {
showAll() {
this.filter.all = "true";
this.updateQuery();
},
showImportant() {
this.filter.all = "";
this.updateQuery();
},
clearQuery() {
this.filter.q = '';
this.updateQuery();

View file

@ -19,7 +19,7 @@ type LabelSearch struct {
Slug string `form:"slug"`
Name string `form:"name"`
Priority int `form:"priority"`
All bool `form:"all"`
Favorites bool `form:"favorites"`
Count int `form:"count" binding:"required"`

View file

@ -16,7 +16,7 @@ func TestLabelSearchForm(t *testing.T) {
func TestParseQueryStringLabel(t *testing.T) {
t.Run("valid query", func(t *testing.T) {
form := &LabelSearch{Query: "name:cat favorites:true count:10 priority:4 query:\"query text\""}
form := &LabelSearch{Query: "name:cat favorites:true count:10 all:false query:\"query text\""}
err := form.ParseQueryString()
@ -26,7 +26,7 @@ func TestParseQueryStringLabel(t *testing.T) {
assert.Equal(t, "cat", form.Name)
assert.Equal(t, true, form.Favorites)
assert.Equal(t, 10, form.Count)
assert.Equal(t, 4, form.Priority)
assert.Equal(t, false, form.All)
assert.Equal(t, "query text", form.Query)
})
t.Run("valid query 2", func(t *testing.T) {

View file

@ -133,9 +133,7 @@ func (s *Repo) Labels(f form.LabelSearch) (results []LabelResult, err error) {
q = q.Where("labels.label_favorite = 1")
}
if f.Priority != 0 {
q = q.Where("labels.label_priority > ?", f.Priority)
} else {
if !f.All {
q = q.Where("labels.label_priority >= 0 OR labels.label_favorite = 1")
}