github.com/erda-project/erda-infra@v1.0.9/providers/component-protocol/examples/components/table_demo/table/provider.go (about)

     1  // Copyright (c) 2021 Terminus, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package table
    16  
    17  import (
    18  	"github.com/erda-project/erda-infra/providers/component-protocol/components/commodel"
    19  	"github.com/erda-project/erda-infra/providers/component-protocol/components/table"
    20  	"github.com/erda-project/erda-infra/providers/component-protocol/components/table/impl"
    21  	"github.com/erda-project/erda-infra/providers/component-protocol/cptype"
    22  	"github.com/erda-project/erda-infra/providers/component-protocol/utils/cputil"
    23  )
    24  
    25  type provider struct {
    26  	impl.DefaultTable
    27  }
    28  
    29  const (
    30  	columnMergedTitle    table.ColumnKey = "mergedTitle"
    31  	columnIcon           table.ColumnKey = "icon"
    32  	columnTitle          table.ColumnKey = "title"
    33  	columnLabels         table.ColumnKey = "labels"
    34  	columnPriority       table.ColumnKey = "priority"
    35  	columnState          table.ColumnKey = "state"
    36  	columnAssignee       table.ColumnKey = "assignee"
    37  	columnFinishedAt     table.ColumnKey = "finishedAt"
    38  	columnMoreOperations table.ColumnKey = "moreOperations"
    39  	columnProgress       table.ColumnKey = "progress"
    40  )
    41  
    42  func (p *provider) RegisterInitializeOp() (opFunc cptype.OperationFunc) {
    43  	return func(sdk *cptype.SDK) cptype.IStdStructuredPtr {
    44  		p.StdDataPtr = &table.Data{
    45  			Table: table.Table{
    46  				Columns: table.ColumnsInfo{
    47  					Merges: map[table.ColumnKey]table.MergedColumn{
    48  						columnMergedTitle: {Orders: []table.ColumnKey{columnIcon, columnTitle, columnLabels}},
    49  					},
    50  					Orders: []table.ColumnKey{columnTitle, columnPriority, columnState, columnAssignee, columnFinishedAt, columnProgress, columnMoreOperations},
    51  					ColumnsMap: map[table.ColumnKey]table.Column{
    52  						columnTitle:      {Title: "标题"},
    53  						columnPriority:   {Title: "优先级"},
    54  						columnState:      {Title: "状态"},
    55  						columnAssignee:   {Title: "处理人"},
    56  						columnFinishedAt: {Title: "截止日期"},
    57  						columnProgress:   {Title: "进度条"},
    58  					},
    59  				},
    60  				Rows: []table.Row{
    61  					{
    62  						ID:         "issue-id-1",
    63  						Selectable: true,
    64  						Selected:   false,
    65  						CellsMap: map[table.ColumnKey]table.Cell{
    66  							columnIcon:  table.NewIconCell(*commodel.NewTypedIcon("ISSUE_ICON.issue.TASK")).Build(),
    67  							columnTitle: table.NewTextCell("【服务监控】增加链路查询页面").Build(),
    68  							columnLabels: table.NewLabelsCell(
    69  								commodel.Labels{
    70  									Labels: []commodel.Label{
    71  										{
    72  											ID:    "label-id-1",
    73  											Title: "area/监控",
    74  											Color: commodel.ColorRed,
    75  										},
    76  										{
    77  											ID:    "label-id-2",
    78  											Title: "team/前端",
    79  											Color: commodel.ColorPurple,
    80  										},
    81  									},
    82  								},
    83  							).Build(),
    84  							columnPriority: table.NewDropDownMenuCell(commodel.DropDownMenu{
    85  								Menus: []commodel.DropDownMenuItem{
    86  									{
    87  										ID:       "urgent",
    88  										Text:     "紧急",
    89  										Icon:     commodel.NewTypedIcon("ISSUE_ICON.priority.URGENT"),
    90  										Selected: false,
    91  										Disabled: false,
    92  										Hidden:   false,
    93  									},
    94  									{
    95  										ID:       "high",
    96  										Text:     "高",
    97  										Icon:     commodel.NewTypedIcon("ISSUE_ICON.priority.HIGH"),
    98  										Selected: false,
    99  										Disabled: false,
   100  										Hidden:   false,
   101  									},
   102  									{
   103  										ID:       "normal",
   104  										Text:     "中",
   105  										Icon:     commodel.NewTypedIcon("ISSUE_ICON.priority.NORMAL"),
   106  										Selected: true,
   107  										Disabled: false,
   108  										Hidden:   false,
   109  									},
   110  									{
   111  										ID:       "low",
   112  										Text:     "低",
   113  										Icon:     commodel.NewTypedIcon("ISSUE_ICON.priority.LOW"),
   114  										Selected: false,
   115  										Disabled: false,
   116  										Hidden:   false,
   117  									},
   118  								},
   119  								Operations: map[cptype.OperationKey]cptype.Operation{
   120  									commodel.OpDropDownMenuChange{}.OpKey(): cputil.NewOpBuilder().Build(),
   121  								},
   122  							}).Build(),
   123  							columnState: table.NewDropDownMenuCell(commodel.DropDownMenu{
   124  								Menus: []commodel.DropDownMenuItem{
   125  									{
   126  										ID:       "state-id-for-open",
   127  										Text:     "待处理",
   128  										Selected: false,
   129  										Disabled: true,
   130  										Hidden:   true,
   131  										Tip:      "无法转移",
   132  									},
   133  									{
   134  										ID:       "state-id-for-working",
   135  										Text:     "进行中",
   136  										Selected: true,
   137  										Disabled: false,
   138  										Hidden:   false,
   139  									},
   140  									{
   141  										ID:       "state-id-for-done",
   142  										Text:     "已完成",
   143  										Selected: false,
   144  										Disabled: false,
   145  										Hidden:   false,
   146  									},
   147  									{
   148  										ID:       "state-id-for-abandoned",
   149  										Text:     "已作废",
   150  										Selected: false,
   151  										Disabled: false,
   152  										Hidden:   false,
   153  									},
   154  								},
   155  								Operations: map[cptype.OperationKey]cptype.Operation{
   156  									commodel.OpDropDownMenuChange{}.OpKey(): cputil.NewOpBuilder().Build(),
   157  								},
   158  							}).Build(),
   159  							columnAssignee: table.NewUserSelectorCell(commodel.UserSelector{
   160  								Scope:           "project",
   161  								ScopeID:         "1000300",
   162  								SelectedUserIDs: []string{"92"},
   163  								Operations: map[cptype.OperationKey]cptype.Operation{
   164  									commodel.OpUserSelectorChange{}.OpKey(): cputil.NewOpBuilder().Build(),
   165  								},
   166  							}).Build(),
   167  							columnFinishedAt: table.NewTextCell("2021-12-29").Build(),
   168  							columnProgress: table.NewProgressBarCell(commodel.ProgressBar{
   169  								BarPercent: 70,
   170  								Text:       "7/10",
   171  								Tip:        "7 executed of total 10",
   172  								Status:     commodel.ProcessingStatus,
   173  							}).Build(),
   174  						},
   175  						Operations: map[cptype.OperationKey]cptype.Operation{
   176  							table.OpRowSelect{}.OpKey(): cputil.NewOpBuilder().Build(),
   177  							table.OpRowAdd{}.OpKey():    cputil.NewOpBuilder().Build(),
   178  							table.OpRowEdit{}.OpKey():   cputil.NewOpBuilder().Build(),
   179  							table.OpRowDelete{}.OpKey(): cputil.NewOpBuilder().Build(),
   180  						},
   181  					},
   182  					{
   183  						ID: "issue-id-2",
   184  						CellsMap: map[table.ColumnKey]table.Cell{
   185  							columnProgress: table.NewProgressBarCell(commodel.ProgressBar{
   186  								BarCompletedNum: 0,
   187  								BarTotalNum:     10,
   188  								Status:          commodel.ProcessingStatus,
   189  							}).Build(),
   190  						},
   191  					},
   192  					{
   193  						ID: "issue-id-3",
   194  					},
   195  					{
   196  						ID: "pipeline-definition-1",
   197  						CellsMap: map[table.ColumnKey]table.Cell{
   198  							columnMoreOperations: table.NewMoreOperationsCell(commodel.MoreOperations{
   199  								Ops: []commodel.MoreOpItem{
   200  									{
   201  										ID:   "star",
   202  										Text: "标星",
   203  										Operations: map[cptype.OperationKey]cptype.Operation{
   204  											commodel.OpMoreOperationsItemClick{}.OpKey(): cputil.NewOpBuilder().
   205  												WithServerDataPtr(&commodel.OpMoreOperationsItemClickServerData{}).
   206  												Build(),
   207  										},
   208  									},
   209  									{
   210  										ID:   "goto-detail-page",
   211  										Text: "查看详情",
   212  										Operations: map[cptype.OperationKey]cptype.Operation{
   213  											commodel.OpMoreOperationsItemClickGoto{}.OpKey(): cputil.NewOpBuilder().
   214  												WithServerDataPtr(&commodel.OpMoreOperationsItemClickGotoServerData{
   215  													OpClickGotoServerData: commodel.OpClickGotoServerData{
   216  														JumpOut: false,
   217  														Target:  "projectPipelineDetail",
   218  														Params: map[string]interface{}{
   219  															"pipelineDefinitionID": "1",
   220  														},
   221  														Query: nil,
   222  													}}).
   223  												Build(),
   224  										},
   225  									},
   226  								},
   227  							}).Build(),
   228  						},
   229  					},
   230  				},
   231  				PageNo:   1,
   232  				PageSize: 10,
   233  				Total:    1,
   234  			},
   235  			Operations: map[cptype.OperationKey]cptype.Operation{
   236  				table.OpTableChangePage{}.OpKey(): cputil.NewOpBuilder().WithServerDataPtr(&table.OpTableChangePageServerData{}).Build(),
   237  				table.OpTableChangeSort{}.OpKey(): cputil.NewOpBuilder().Build(),
   238  				table.OpBatchRowsHandle{}.OpKey(): cputil.NewOpBuilder().WithText("批量操作").WithServerDataPtr(&table.OpBatchRowsHandleServerData{
   239  					Options: []table.OpBatchRowsHandleOption{
   240  						{
   241  							ID:            "delete",
   242  							Text:          "删除",
   243  							AllowedRowIDs: []string{"row1", "row2"},
   244  						},
   245  						{
   246  							ID:              "start",
   247  							Text:            "启动",
   248  							ForbiddenRowIDs: []string{"row2"},
   249  						},
   250  					},
   251  				}).Build(),
   252  			},
   253  		}
   254  		return nil
   255  	}
   256  }
   257  
   258  func (p *provider) RegisterRenderingOp() (opFunc cptype.OperationFunc) {
   259  	return p.RegisterInitializeOp()
   260  }
   261  
   262  func (p *provider) RegisterTablePagingOp(opData table.OpTableChangePage) (opFunc cptype.OperationFunc) {
   263  	return nil
   264  }
   265  
   266  func (p *provider) RegisterTableChangePageOp(opData table.OpTableChangePage) (opFunc cptype.OperationFunc) {
   267  	return nil
   268  }
   269  
   270  func (p *provider) RegisterTableSortOp(opData table.OpTableChangeSort) (opFunc cptype.OperationFunc) {
   271  	return nil
   272  }
   273  
   274  func (p *provider) RegisterBatchRowsHandleOp(opData table.OpBatchRowsHandle) (opFunc cptype.OperationFunc) {
   275  	return nil
   276  }
   277  
   278  func (p *provider) RegisterRowSelectOp(opData table.OpRowSelect) (opFunc cptype.OperationFunc) {
   279  	return nil
   280  }
   281  
   282  func (p *provider) RegisterRowAddOp(opData table.OpRowAdd) (opFunc cptype.OperationFunc) {
   283  	return nil
   284  }
   285  
   286  func (p *provider) RegisterRowEditOp(opData table.OpRowEdit) (opFunc cptype.OperationFunc) {
   287  	return nil
   288  }
   289  
   290  func (p *provider) RegisterRowDeleteOp(opData table.OpRowDelete) (opFunc cptype.OperationFunc) {
   291  	return nil
   292  }