Allow to select AND or OR for tags filter
This is because Oriol thinks that there may be cases where you want to search invoices and such that have any of the selected labels, not all of them, so we agreed on adding an option to choose. The idea is that it will be a toggle, but this requires JavaScript and this commit adds it as a dropdown as a first non-JavaScript step.
This commit is contained in:
parent
8c592cfe5e
commit
8f7933ffe2
|
@ -79,7 +79,11 @@ func mustCollectInvoiceEntries(ctx context.Context, conn *Conn, company *Company
|
||||||
maybeAppendWhere("invoice_date >= $%d", filters.FromDate.String(), nil)
|
maybeAppendWhere("invoice_date >= $%d", filters.FromDate.String(), nil)
|
||||||
maybeAppendWhere("invoice_date <= $%d", filters.ToDate.String(), nil)
|
maybeAppendWhere("invoice_date <= $%d", filters.ToDate.String(), nil)
|
||||||
if len(filters.Tags.Tags) > 0 {
|
if len(filters.Tags.Tags) > 0 {
|
||||||
appendWhere("invoice.tags && $%d", filters.Tags)
|
if filters.TagsCondition.String() == "and" {
|
||||||
|
appendWhere("invoice.tags @> $%d", filters.Tags)
|
||||||
|
} else {
|
||||||
|
appendWhere("invoice.tags && $%d", filters.Tags)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
rows := conn.MustQuery(ctx, fmt.Sprintf(`
|
rows := conn.MustQuery(ctx, fmt.Sprintf(`
|
||||||
select invoice.slug
|
select invoice.slug
|
||||||
|
@ -144,6 +148,7 @@ type invoiceFilterForm struct {
|
||||||
FromDate *InputField
|
FromDate *InputField
|
||||||
ToDate *InputField
|
ToDate *InputField
|
||||||
Tags *TagsField
|
Tags *TagsField
|
||||||
|
TagsCondition *SelectField
|
||||||
}
|
}
|
||||||
|
|
||||||
func newInvoiceFilterForm(ctx context.Context, conn *Conn, locale *Locale, company *Company) *invoiceFilterForm {
|
func newInvoiceFilterForm(ctx context.Context, conn *Conn, locale *Locale, company *Company) *invoiceFilterForm {
|
||||||
|
@ -181,6 +186,15 @@ func newInvoiceFilterForm(ctx context.Context, conn *Conn, locale *Locale, compa
|
||||||
Name: "tags",
|
Name: "tags",
|
||||||
Label: pgettext("input", "Tags", locale),
|
Label: pgettext("input", "Tags", locale),
|
||||||
},
|
},
|
||||||
|
TagsCondition: &SelectField{
|
||||||
|
Name: "tags_condition",
|
||||||
|
Label: pgettext("input", "Tags Condition", locale),
|
||||||
|
Selected: []string{"and"},
|
||||||
|
Options: []*SelectOption{
|
||||||
|
{Value: "and", Label: pgettext("logical", "AND", locale)},
|
||||||
|
{Value: "or", Label: pgettext("logical", "OR", locale)},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,6 +208,7 @@ func (form *invoiceFilterForm) Parse(r *http.Request) error {
|
||||||
form.FromDate.FillValue(r)
|
form.FromDate.FillValue(r)
|
||||||
form.ToDate.FillValue(r)
|
form.ToDate.FillValue(r)
|
||||||
form.Tags.FillValue(r)
|
form.Tags.FillValue(r)
|
||||||
|
form.TagsCondition.FillValue(r)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
{{ template "input-field" .ToDate }}
|
{{ template "input-field" .ToDate }}
|
||||||
{{ template "input-field" .InvoiceNumber }}
|
{{ template "input-field" .InvoiceNumber }}
|
||||||
{{ template "tags-field" .Tags }}
|
{{ template "tags-field" .Tags }}
|
||||||
|
{{ template "select-field" .TagsCondition }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
<button type="submit">{{( pgettext "Filter" "action" )}}</button>
|
<button type="submit">{{( pgettext "Filter" "action" )}}</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
Loading…
Reference in New Issue