From 26788befae287bc9d9aaea98c3c7646581075834 Mon Sep 17 00:00:00 2001 From: Eric Schubert Date: Fri, 24 May 2024 10:48:50 +0200 Subject: [PATCH] Add type filter to list work package --- cmd/list/list.go | 10 ++++++++++ cmd/list/work_packages.go | 5 +++++ components/resources/work_packages/filters.go | 20 +++++++++++++++++++ components/resources/work_packages/read.go | 3 +++ 4 files changed, 38 insertions(+) diff --git a/cmd/list/list.go b/cmd/list/list.go index ef0651c..a527414 100644 --- a/cmd/list/list.go +++ b/cmd/list/list.go @@ -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", diff --git a/cmd/list/work_packages.go b/cmd/list/work_packages.go index 036efff..fdc7172 100644 --- a/cmd/list/work_packages.go +++ b/cmd/list/work_packages.go @@ -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", @@ -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) } diff --git a/components/resources/work_packages/filters.go b/components/resources/work_packages/filters.go index 0f901ba..1b2beba 100644 --- a/components/resources/work_packages/filters.go +++ b/components/resources/work_packages/filters.go @@ -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 diff --git a/components/resources/work_packages/read.go b/components/resources/work_packages/read.go index 54cacbb..f9791b3 100644 --- a/components/resources/work_packages/read.go +++ b/components/resources/work_packages/read.go @@ -17,6 +17,7 @@ const ( Version Project Status + Type ) func Lookup(id uint64) (*models.WorkPackage, error) { @@ -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