2020-11-01 14:50:59 +03:00
|
|
|
package models
|
|
|
|
|
|
|
|
type Filters struct {
|
|
|
|
Project string
|
|
|
|
OS string
|
|
|
|
Language string
|
|
|
|
Editor string
|
|
|
|
Machine string
|
|
|
|
}
|
|
|
|
|
|
|
|
type FilterElement struct {
|
|
|
|
Type uint8
|
|
|
|
Key string
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewFiltersWith(entity uint8, key string) *Filters {
|
|
|
|
switch entity {
|
|
|
|
case SummaryProject:
|
|
|
|
return &Filters{Project: key}
|
|
|
|
case SummaryOS:
|
2020-11-07 20:39:36 +03:00
|
|
|
return &Filters{OS: key}
|
2020-11-01 14:50:59 +03:00
|
|
|
case SummaryLanguage:
|
2020-11-07 20:39:36 +03:00
|
|
|
return &Filters{Language: key}
|
2020-11-01 14:50:59 +03:00
|
|
|
case SummaryEditor:
|
2020-11-07 20:39:36 +03:00
|
|
|
return &Filters{Editor: key}
|
2020-11-01 14:50:59 +03:00
|
|
|
case SummaryMachine:
|
2020-11-07 20:39:36 +03:00
|
|
|
return &Filters{Machine: key}
|
2020-11-01 14:50:59 +03:00
|
|
|
}
|
|
|
|
return &Filters{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *Filters) First() (bool, uint8, string) {
|
|
|
|
if f.Project != "" {
|
|
|
|
return true, SummaryProject, f.Project
|
|
|
|
} else if f.OS != "" {
|
|
|
|
return true, SummaryOS, f.OS
|
|
|
|
} else if f.Language != "" {
|
|
|
|
return true, SummaryLanguage, f.Language
|
|
|
|
} else if f.Editor != "" {
|
|
|
|
return true, SummaryEditor, f.Editor
|
|
|
|
} else if f.Machine != "" {
|
|
|
|
return true, SummaryMachine, f.Machine
|
|
|
|
}
|
|
|
|
return false, 0, ""
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *Filters) All() []*FilterElement {
|
|
|
|
all := make([]*FilterElement, 0)
|
|
|
|
|
|
|
|
if f.Project != "" {
|
|
|
|
all = append(all, &FilterElement{Type: SummaryProject, Key: f.Project})
|
|
|
|
}
|
|
|
|
if f.Editor != "" {
|
|
|
|
all = append(all, &FilterElement{Type: SummaryEditor, Key: f.Editor})
|
|
|
|
}
|
|
|
|
if f.Language != "" {
|
|
|
|
all = append(all, &FilterElement{Type: SummaryLanguage, Key: f.Language})
|
|
|
|
}
|
|
|
|
if f.Machine != "" {
|
|
|
|
all = append(all, &FilterElement{Type: SummaryMachine, Key: f.Machine})
|
|
|
|
}
|
|
|
|
if f.OS != "" {
|
|
|
|
all = append(all, &FilterElement{Type: SummaryOS, Key: f.OS})
|
|
|
|
}
|
|
|
|
|
|
|
|
return all
|
|
|
|
}
|