github.com/erda-project/erda-infra@v1.0.9/providers/component-protocol/components/table/model.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/cptype"
    19  )
    20  
    21  type (
    22  	// Data .
    23  	Data struct {
    24  		Table      Table                                    `json:"table,omitempty"`
    25  		Operations map[cptype.OperationKey]cptype.Operation `json:"operations,omitempty"`
    26  	}
    27  
    28  	// Table .
    29  	Table struct {
    30  		Columns ColumnsInfo `json:"columns,omitempty"`
    31  		Rows    []Row       `json:"rows,omitempty"`
    32  
    33  		PageNo   uint64 `json:"pageNo,omitempty"`
    34  		PageSize uint64 `json:"pageSize,omitempty"`
    35  		Total    uint64 `json:"total,omitempty"`
    36  	}
    37  )
    38  
    39  type (
    40  	// ColumnsInfo .
    41  	ColumnsInfo struct {
    42  		// Merges merge some columns into one.
    43  		// +optional
    44  		Merges map[ColumnKey]MergedColumn `json:"merges,omitempty"`
    45  
    46  		// Orders is the order of columns.
    47  		// If some columns is merged, just put the columnKey for exhibition.
    48  		Orders []ColumnKey `json:"orders,omitempty"`
    49  
    50  		// ColumnsMap contains all columns.
    51  		ColumnsMap map[ColumnKey]Column `json:"columnsMap,omitempty"`
    52  	}
    53  
    54  	// MergedColumn .
    55  	MergedColumn struct {
    56  		Orders []ColumnKey `json:"orders,omitempty"`
    57  	}
    58  
    59  	// Column .
    60  	Column struct {
    61  		Title string `json:"title,omitempty"`
    62  		Tip   string `json:"tip,omitempty"`
    63  
    64  		FieldBindToOrder string `json:"fieldBindToOrder,omitempty"` // bind which field to order
    65  		AscOrder         *bool  `json:"ascOrder,omitempty"`         // true for asc, false for desc, nil for no sort
    66  		EnableSort       bool   `json:"enableSort"`                 // true can sort
    67  		Hidden           bool   `json:"hidden,omitempty"`           // true can hidden
    68  		cptype.Extra
    69  	}
    70  
    71  	// ColumnKey .
    72  	ColumnKey string
    73  )
    74  
    75  type (
    76  	// Row .
    77  	Row struct {
    78  		ID         RowID              `json:"id,omitempty"` // row id, used for row-level operations
    79  		Selectable bool               `json:"selectable,omitempty"`
    80  		Selected   bool               `json:"selected,omitempty"`
    81  		CellsMap   map[ColumnKey]Cell `json:"cellsMap,omitempty"`
    82  
    83  		Operations map[cptype.OperationKey]cptype.Operation `json:"operations,omitempty"`
    84  	}
    85  
    86  	// RowID .
    87  	RowID string
    88  )
    89  
    90  type (
    91  	// Cell .
    92  	Cell struct {
    93  		ID   string          `json:"id,omitempty"`
    94  		Tip  string          `json:"tip,omitempty"`
    95  		Type CellType        `json:"type,omitempty"`
    96  		Data cptype.ExtraMap `json:"data,omitempty"`
    97  
    98  		Operations map[cptype.OperationKey]cptype.Operation `json:"operations,omitempty"`
    99  		cptype.Extra
   100  	}
   101  
   102  	// CellType .
   103  	CellType string
   104  )