github.com/erda-project/erda-infra@v1.0.9/providers/component-protocol/components/table/impl/default.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 impl 16 17 import ( 18 "github.com/erda-project/erda-infra/providers/component-protocol/components/defaults" 19 "github.com/erda-project/erda-infra/providers/component-protocol/components/table" 20 "github.com/erda-project/erda-infra/providers/component-protocol/cptype" 21 "github.com/erda-project/erda-infra/providers/component-protocol/utils/cputil" 22 ) 23 24 // DefaultTable . 25 type DefaultTable struct { 26 defaults.DefaultImpl 27 Impl table.ITable 28 29 *StdStructuredPtr 30 } 31 32 // StdStructuredPtr . 33 type StdStructuredPtr struct { 34 StdInParamsPtr *cptype.ExtraMap 35 StdDataPtr *table.Data 36 StdStatePtr *cptype.ExtraMap 37 } 38 39 // DataPtr . 40 func (s *StdStructuredPtr) DataPtr() interface{} { return s.StdDataPtr } 41 42 // StatePtr . 43 func (s *StdStructuredPtr) StatePtr() interface{} { return s.StdStatePtr } 44 45 // InParamsPtr . 46 func (s *StdStructuredPtr) InParamsPtr() interface{} { return s.StdInParamsPtr } 47 48 // RegisterCompStdOps . 49 func (d *DefaultTable) RegisterCompStdOps() (opFuncs map[cptype.OperationKey]cptype.OperationFunc) { 50 return map[cptype.OperationKey]cptype.OperationFunc{ 51 // table-level 52 table.OpTableChangePage{}.OpKey(): func(sdk *cptype.SDK) cptype.IStdStructuredPtr { 53 return d.Impl.RegisterTableChangePageOp(*cputil.MustObjJSONTransfer(sdk.Event.OperationData, &table.OpTableChangePage{}).(*table.OpTableChangePage))(sdk) 54 }, 55 table.OpTableChangeSort{}.OpKey(): func(sdk *cptype.SDK) cptype.IStdStructuredPtr { 56 return d.Impl.RegisterTableSortOp(*cputil.MustObjJSONTransfer(sdk.Event.OperationData, &table.OpTableChangeSort{}).(*table.OpTableChangeSort))(sdk) 57 }, 58 table.OpBatchRowsHandle{}.OpKey(): func(sdk *cptype.SDK) cptype.IStdStructuredPtr { 59 return d.Impl.RegisterBatchRowsHandleOp(*cputil.MustObjJSONTransfer(sdk.Event.OperationData, &table.OpBatchRowsHandle{}).(*table.OpBatchRowsHandle))(sdk) 60 }, 61 // row-level 62 table.OpRowSelect{}.OpKey(): func(sdk *cptype.SDK) cptype.IStdStructuredPtr { 63 return d.Impl.RegisterRowSelectOp(*cputil.MustObjJSONTransfer(sdk.Event.OperationData, &table.OpRowSelect{}).(*table.OpRowSelect))(sdk) 64 }, 65 table.OpRowAdd{}.OpKey(): func(sdk *cptype.SDK) cptype.IStdStructuredPtr { 66 return d.Impl.RegisterRowAddOp(*cputil.MustObjJSONTransfer(sdk.Event.OperationData, &table.OpRowAdd{}).(*table.OpRowAdd))(sdk) 67 }, 68 table.OpRowEdit{}.OpKey(): func(sdk *cptype.SDK) cptype.IStdStructuredPtr { 69 return d.Impl.RegisterRowEditOp(*cputil.MustObjJSONTransfer(sdk.Event.OperationData, &table.OpRowEdit{}).(*table.OpRowEdit))(sdk) 70 }, 71 table.OpRowDelete{}.OpKey(): func(sdk *cptype.SDK) cptype.IStdStructuredPtr { 72 return d.Impl.RegisterRowDeleteOp(*cputil.MustObjJSONTransfer(sdk.Event.OperationData, &table.OpRowDelete{}).(*table.OpRowDelete))(sdk) 73 }, 74 // cell-level 75 } 76 } 77 78 // RegisterCompNonStdOps . 79 func (d *DefaultTable) RegisterCompNonStdOps() (opFuncs map[cptype.OperationKey]cptype.OperationFunc) { 80 return nil 81 } 82 83 // Initialize . 84 func (d *DefaultTable) Initialize(sdk *cptype.SDK) {} 85 86 // Finalize . 87 func (d *DefaultTable) Finalize(sdk *cptype.SDK) {} 88 89 // SkipOp providers default impl for user. 90 func (d *DefaultTable) SkipOp(sdk *cptype.SDK) bool { return !d.Impl.Visible(sdk) } 91 92 // Visible . 93 func (d *DefaultTable) Visible(sdk *cptype.SDK) bool { return true } 94 95 // BeforeHandleOp providers default impl for user. 96 func (d *DefaultTable) BeforeHandleOp(sdk *cptype.SDK) {} 97 98 // AfterHandleOp providers default impl for user. 99 func (d *DefaultTable) AfterHandleOp(sdk *cptype.SDK) {} 100 101 // StdStructuredPtrCreator . 102 func (d *DefaultTable) StdStructuredPtrCreator() func() cptype.IStdStructuredPtr { 103 return func() cptype.IStdStructuredPtr { 104 return &StdStructuredPtr{ 105 StdInParamsPtr: &cptype.ExtraMap{}, 106 StdStatePtr: &cptype.ExtraMap{}, 107 StdDataPtr: &table.Data{}, 108 } 109 } 110 }