Skip to content

Commit

Permalink
Add type filter to list work package
Browse files Browse the repository at this point in the history
  • Loading branch information
Kharonus committed May 24, 2024
1 parent 67f8193 commit 26788be
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
10 changes: 10 additions & 0 deletions cmd/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ keywords 'open', 'closed', a single ID or a comma separated array of IDs, i.e.
prefixed with an '!' the list is instead filtered to not have the specified
status.`)

workPackagesCmd.Flags().StringVarP(
&typeFilter,
"type",
"t",
"",
`Show only work packages having the specified types. The value can be a single
ID or a comma separated array of IDs, i.e. '7,13'. Multiple values are
concatenated with a logical 'OR'. If the IDs are prefixed with an '!' the list
is instead filtered to not have the specified status.`)

workPackagesCmd.Flags().BoolVarP(
&showTotal,
"total",
Expand Down
5 changes: 5 additions & 0 deletions cmd/list/work_packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var projectId uint64
var version string
var showTotal bool
var statusFilter string
var typeFilter string

var workPackagesCmd = &cobra.Command{
Use: "workpackages",
Expand Down Expand Up @@ -60,6 +61,10 @@ func filterOptions() *map[work_packages.FilterOption]string {
options[work_packages.Status] = validateStatusFilterValue(statusFilter)
}

if len(typeFilter) > 0 {
options[work_packages.Type] = validateStatusFilterValue(typeFilter)
}

if len(version) > 0 {
options[work_packages.Version] = validatedVersionId(version)
}
Expand Down
20 changes: 20 additions & 0 deletions components/resources/work_packages/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,26 @@ func VersionFilter(version string) requests.Filter {
}
}

func TypeFilter(workPackageType string) requests.Filter {
var operator string
var values []string

switch {
case strings.Index(workPackageType, "!") == 0:
operator = "!"
values = strings.Split(workPackageType[1:], ",")
default:
operator = "="
values = strings.Split(workPackageType, ",")
}

return requests.Filter{
Operator: operator,
Name: "type",
Values: values,
}
}

func StatusFilter(status string) requests.Filter {
var operator string
var values []string
Expand Down
3 changes: 3 additions & 0 deletions components/resources/work_packages/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const (
Version
Project
Status
Type
)

func Lookup(id uint64) (*models.WorkPackage, error) {
Expand All @@ -40,6 +41,8 @@ func All(filterOptions *map[FilterOption]string) (*models.WorkPackageCollection,
filters = append(filters, VersionFilter(value))
case Status:
filters = append(filters, StatusFilter(value))
case Type:
filters = append(filters, TypeFilter(value))
case Project:
n, _ := strconv.ParseUint(value, 10, 64)
projectId = &n
Expand Down

0 comments on commit 26788be

Please sign in to comment.