-
Notifications
You must be signed in to change notification settings - Fork 378
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Co-authored-by: shuofan <fanshuo2015@gmail.com>
- Loading branch information
Showing
8 changed files
with
410 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...es/dop/component-protocol/components/issue-dashboard/bar/ownerHorizontalBarChart/model.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright (c) 2021 Terminus, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package ownerHorizontalBarChart | ||
|
||
import ( | ||
"github.com/erda-project/erda-infra/providers/component-protocol/cptype" | ||
"github.com/erda-project/erda/bundle" | ||
"github.com/erda-project/erda/modules/dop/component-protocol/components/issue-dashboard/common" | ||
"github.com/erda-project/erda/modules/dop/services/issuestate" | ||
"github.com/erda-project/erda/modules/openapi/component-protocol/components/base" | ||
) | ||
|
||
type ComponentAction struct { | ||
sdk *cptype.SDK | ||
bdl *bundle.Bundle | ||
issueStateSvc *issuestate.IssueState | ||
State State `json:"state,omitempty"` | ||
base.DefaultProvider | ||
} | ||
|
||
type State struct { | ||
Values common.FilterConditions `json:"values,omitempty"` | ||
} |
133 changes: 133 additions & 0 deletions
133
...s/dop/component-protocol/components/issue-dashboard/bar/ownerHorizontalBarChart/render.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
// Copyright (c) 2021 Terminus, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package ownerHorizontalBarChart | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
|
||
"github.com/go-echarts/go-echarts/v2/opts" | ||
|
||
"github.com/erda-project/erda-infra/base/servicehub" | ||
"github.com/erda-project/erda-infra/providers/component-protocol/cptype" | ||
"github.com/erda-project/erda/apistructs" | ||
"github.com/erda-project/erda/modules/dop/component-protocol/components/issue-dashboard/common/chartbuilders" | ||
"github.com/erda-project/erda/modules/dop/component-protocol/components/issue-dashboard/common/gshelper" | ||
"github.com/erda-project/erda/modules/dop/component-protocol/components/issue-dashboard/common/stackhandlers" | ||
"github.com/erda-project/erda/modules/dop/dao" | ||
"github.com/erda-project/erda/modules/openapi/component-protocol/components/base" | ||
) | ||
|
||
func init() { | ||
base.InitProviderWithCreator("issue-dashboard", "ownerHorizontalBarChart", | ||
func() servicehub.Provider { return &ComponentAction{} }) | ||
} | ||
|
||
func (f *ComponentAction) getState(c *cptype.Component) error { | ||
d, err := json.Marshal(c.State) | ||
if err != nil { | ||
return err | ||
} | ||
return json.Unmarshal(d, &f.State) | ||
} | ||
|
||
func (f *ComponentAction) Render(ctx context.Context, c *cptype.Component, scenario cptype.Scenario, event cptype.ComponentEvent, gs *cptype.GlobalStateData) error { | ||
|
||
if err := f.getState(c); err != nil { | ||
return err | ||
} | ||
|
||
helper := gshelper.NewGSHelper(gs) | ||
|
||
members := helper.GetMembers() | ||
memberMap := make(map[string]*apistructs.Member) | ||
for i := range members { | ||
m := &members[i] | ||
memberMap[m.UserID] = m | ||
} | ||
|
||
issueList := helper.GetIssueList() | ||
var bugList []interface{} | ||
for i := range issueList { | ||
bugList = append(bugList, &issueList[i]) | ||
} | ||
|
||
handler := stackhandlers.NewStackRetriever( | ||
stackhandlers.WithIssueStateList(helper.GetIssueStateList()), | ||
stackhandlers.WithIssueStageList(helper.GetIssueStageList()), | ||
).GetRetriever(f.State.Values.Type) | ||
|
||
builder := &chartbuilders.BarBuilder{ | ||
Items: bugList, | ||
StackHandler: handler, | ||
FixedXAxisOrTop: chartbuilders.FixedXAxisOrTop{ | ||
Top: 500, | ||
XIndexer: getXIndexer(), | ||
XDisplayConverter: func(opt *chartbuilders.FixedXAxisOrTop) opts.XAxis { | ||
return opts.XAxis{ | ||
Type: "value", | ||
Max: opt.MaxValue, | ||
} | ||
}, | ||
}, | ||
YAxisOpt: chartbuilders.YAxisOpt{ | ||
YDisplayConverter: func(opt *chartbuilders.YAxisOpt) opts.YAxis { | ||
var names []string | ||
for _, userID := range opt.YAxis { | ||
var name string | ||
m, ok := memberMap[userID] | ||
if ok && m != nil { | ||
name = m.Nick | ||
} | ||
names = append(names, name) | ||
} | ||
return opts.YAxis{ | ||
Type: "category", | ||
Data: names, | ||
} | ||
}, | ||
}, | ||
StackOpt: chartbuilders.StackOpt{ | ||
SkipEmpty: true, | ||
}, | ||
DataHandleOpt: chartbuilders.DataHandleOpt{ | ||
SeriesConverter: chartbuilders.GetStackBarSingleSeriesConverter(), | ||
DataWhiteList: f.State.Values.Value, | ||
}, | ||
Result: chartbuilders.Result{ | ||
PostProcessor: chartbuilders.GetHorizontalPostProcessor(), | ||
}, | ||
} | ||
|
||
if err := builder.Generate(); err != nil { | ||
return err | ||
} | ||
|
||
props := make(map[string]interface{}) | ||
props["title"] = "缺陷 - 按责任者分布(Top 500)" | ||
props["chartType"] = "bar" | ||
props["option"] = builder.Result.Bb | ||
props["style"] = map[string]interface{}{"height": 400} | ||
|
||
c.Props = props | ||
c.State = nil | ||
return nil | ||
} | ||
|
||
func getXIndexer() func(interface{}) string { | ||
return func(item interface{}) string { | ||
return item.(*dao.IssueItem).Owner | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
.../component-protocol/components/issue-dashboard/bar/ownerHorizontalBarChartExtra/render.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright (c) 2021 Terminus, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package ownerHorizontalBarChartExtra | ||
|
||
import "github.com/erda-project/erda/modules/openapi/component-protocol/components/base" | ||
|
||
func init() { | ||
base.InitProvider("issue-dashboard", "ownerHorizontalBarChartExtra") | ||
} |
37 changes: 37 additions & 0 deletions
37
.../component-protocol/components/issue-dashboard/bar/ownerHorizontalBarChartFilter/model.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright (c) 2021 Terminus, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package ownerHorizontalBarChartFilter | ||
|
||
import ( | ||
"github.com/erda-project/erda-infra/providers/component-protocol/cptype" | ||
"github.com/erda-project/erda/modules/dop/component-protocol/components/issue-dashboard/common" | ||
"github.com/erda-project/erda/modules/openapi/component-protocol/components/base" | ||
"github.com/erda-project/erda/modules/openapi/component-protocol/components/filter" | ||
) | ||
|
||
type ComponentFilter struct { | ||
sdk *cptype.SDK | ||
filter.CommonFilter | ||
State State `json:"state,omitempty"` | ||
base.DefaultProvider | ||
} | ||
|
||
type State struct { | ||
Conditions []filter.PropCondition `json:"conditions,omitempty"` | ||
Values common.FilterConditions `json:"values,omitempty"` | ||
FrontendChangedKey string `json:"changedKey,omitempty"` | ||
} | ||
|
||
const OperationKeyFilter filter.OperationKey = "filter" |
141 changes: 141 additions & 0 deletions
141
...component-protocol/components/issue-dashboard/bar/ownerHorizontalBarChartFilter/render.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
// Copyright (c) 2021 Terminus, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package ownerHorizontalBarChartFilter | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
|
||
"github.com/erda-project/erda-infra/base/servicehub" | ||
"github.com/erda-project/erda-infra/providers/component-protocol/cptype" | ||
"github.com/erda-project/erda-infra/providers/component-protocol/utils/cputil" | ||
"github.com/erda-project/erda/modules/dop/component-protocol/components/issue-dashboard/common/gshelper" | ||
"github.com/erda-project/erda/modules/dop/component-protocol/components/issue-dashboard/common/stackhandlers" | ||
"github.com/erda-project/erda/modules/openapi/component-protocol/components/base" | ||
"github.com/erda-project/erda/modules/openapi/component-protocol/components/filter" | ||
) | ||
|
||
func init() { | ||
base.InitProviderWithCreator("issue-dashboard", "ownerHorizontalBarChartFilter", | ||
func() servicehub.Provider { return &ComponentFilter{} }) | ||
} | ||
|
||
func (f *ComponentFilter) InitFromProtocol(ctx context.Context, c *cptype.Component) error { | ||
// component 序列化 | ||
b, err := json.Marshal(c) | ||
if err != nil { | ||
return err | ||
} | ||
if err := json.Unmarshal(b, f); err != nil { | ||
return err | ||
} | ||
|
||
// sdk | ||
f.sdk = cputil.SDK(ctx) | ||
|
||
return nil | ||
} | ||
|
||
func (f *ComponentFilter) SetToProtocolComponent(c *cptype.Component) error { | ||
b, err := json.Marshal(f) | ||
if err != nil { | ||
return err | ||
} | ||
if err := json.Unmarshal(b, &c); err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func (f *ComponentFilter) Render(ctx context.Context, c *cptype.Component, scenario cptype.Scenario, event cptype.ComponentEvent, gs *cptype.GlobalStateData) error { | ||
if err := f.InitFromProtocol(ctx, c); err != nil { | ||
return err | ||
} | ||
|
||
if err := f.InitDefaultOperation(ctx, f.State, gs); err != nil { | ||
return err | ||
} | ||
|
||
return f.SetToProtocolComponent(c) | ||
} | ||
|
||
func (f *ComponentFilter) InitDefaultOperation(ctx context.Context, state State, gs *cptype.GlobalStateData) error { | ||
if f.State.Values.Type == "" { | ||
f.State.Values.Type = stackhandlers.Priority | ||
} | ||
if f.State.FrontendChangedKey == "type" { | ||
f.State.Values.Value = nil | ||
} | ||
helper := gshelper.NewGSHelper(gs) | ||
handler := stackhandlers.NewStackRetriever( | ||
stackhandlers.WithIssueStateList(helper.GetIssueStateList()), | ||
stackhandlers.WithIssueStageList(helper.GetIssueStageList()), | ||
).GetRetriever(f.State.Values.Type) | ||
f.State.Conditions = []filter.PropCondition{ | ||
{ | ||
EmptyText: "全部", | ||
Fixed: true, | ||
Key: "type", | ||
Label: "类型", | ||
Options: []filter.PropConditionOption{ | ||
{ | ||
Label: "优先级", | ||
Value: stackhandlers.Priority, | ||
}, | ||
{ | ||
Label: "复杂度", | ||
Value: stackhandlers.Complexity, | ||
}, | ||
{ | ||
Label: "严重程度", | ||
Value: stackhandlers.Severity, | ||
}, | ||
{ | ||
Label: "状态", | ||
Value: stackhandlers.State, | ||
}, | ||
{ | ||
Label: "引入源", | ||
Value: stackhandlers.Stage, | ||
}, | ||
}, | ||
Required: true, | ||
Type: filter.PropConditionTypeSelect, | ||
CustomProps: map[string]interface{}{ | ||
"mode": "single", | ||
}, | ||
}, | ||
{ | ||
EmptyText: "全部", | ||
Fixed: true, | ||
Key: "value", | ||
Label: "具体值", | ||
Options: handler.GetFilterOptions(), | ||
Type: filter.PropConditionTypeSelect, | ||
}, | ||
} | ||
|
||
f.Props = filter.Props{ | ||
Delay: 1000, | ||
} | ||
f.Operations = map[filter.OperationKey]filter.Operation{ | ||
OperationKeyFilter: { | ||
Key: OperationKeyFilter, | ||
Reload: true, | ||
}, | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.