MCPcopy
hub / github.com/g3n/engine / buildTable

Function buildTable

gui/builder_panel.go:738–802  ·  view source on GitHub ↗

buildTable builds a gui object of type: Table

(b *Builder, am map[string]interface{})

Source from the content-addressed store, hash-verified

736
737// buildTable builds a gui object of type: Table
738func buildTable(b *Builder, am map[string]interface{}) (IPanel, error) {
739
740 // Internal function to build a TableColumn from its attribute map
741 buildTableCol := func(b *Builder, am map[string]interface{}) (*TableColumn, error) {
742 tc := &TableColumn{}
743 if iv := am[AttribId]; iv != nil {
744 tc.Id = iv.(string)
745 }
746 if iv := am[AttribHeader]; iv != nil {
747 tc.Header = iv.(string)
748 }
749 if iv := am[AttribWidth]; iv != nil {
750 tc.Width = iv.(float32)
751 }
752 if iv := am[AttribMinwidth]; iv != nil {
753 tc.Minwidth = iv.(float32)
754 }
755 if iv := am[AttribHidden]; iv != nil {
756 tc.Hidden = iv.(bool)
757 }
758 if iv := am[AttribFormat]; iv != nil {
759 tc.Format = iv.(string)
760 }
761 if iv := am[AttribExpand]; iv != nil {
762 tc.Expand = iv.(float32)
763 }
764 if iv := am[AttribResize]; iv != nil {
765 tc.Resize = iv.(bool)
766 }
767 if iv := am[AttribSortType]; iv != nil {
768 tc.Sort = iv.(TableSortType)
769 }
770 return tc, nil
771 }
772
773 // Builds table columns array
774 tableCols := []TableColumn{}
775 if iv := am[AttribColumns]; iv != nil {
776 cols := iv.([]map[string]interface{})
777 for _, c := range cols {
778 tc, err := buildTableCol(b, c)
779 if err != nil {
780 return nil, err
781 }
782 tableCols = append(tableCols, *tc)
783 }
784 }
785
786 // Creates table and set common attributes
787 table, err := NewTable(0, 0, tableCols)
788 if err != nil {
789 return nil, err
790 }
791 err = b.SetAttribs(am, table)
792 if err != nil {
793 return nil, err
794 }
795

Callers

nothing calls this directly

Calls 3

ShowHeaderMethod · 0.95
NewTableFunction · 0.85
SetAttribsMethod · 0.80

Tested by

no test coverage detected