github.com/kotovmak/go-admin@v1.1.1/template/types/display/icon.go (about)

     1  package display
     2  
     3  import (
     4  	"github.com/kotovmak/go-admin/template/icon"
     5  	"github.com/kotovmak/go-admin/template/types"
     6  )
     7  
     8  type Icon struct {
     9  	types.BaseDisplayFnGenerator
    10  }
    11  
    12  func init() {
    13  	types.RegisterDisplayFnGenerator("icon", new(Icon))
    14  }
    15  
    16  func (i *Icon) Get(args ...interface{}) types.FieldFilterFn {
    17  	return func(value types.FieldModel) interface{} {
    18  		icons := args[0].(map[string]string)
    19  		defaultIcon := ""
    20  		if len(args) > 1 {
    21  			defaultIcon = args[1].(string)
    22  		}
    23  		for k, iconClass := range icons {
    24  			if k == value.Value {
    25  				return icon.Icon(iconClass)
    26  			}
    27  		}
    28  		if defaultIcon != "" {
    29  			return icon.Icon(defaultIcon)
    30  		}
    31  		return value.Value
    32  	}
    33  }