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

     1  package display
     2  
     3  import (
     4  	"strings"
     5  
     6  	"github.com/GoAdminGroup/html"
     7  	"github.com/kotovmak/go-admin/template/icon"
     8  	"github.com/kotovmak/go-admin/template/types"
     9  )
    10  
    11  type Bool struct {
    12  	types.BaseDisplayFnGenerator
    13  }
    14  
    15  func init() {
    16  	types.RegisterDisplayFnGenerator("bool", new(Bool))
    17  }
    18  
    19  func (b *Bool) Get(args ...interface{}) types.FieldFilterFn {
    20  	return func(value types.FieldModel) interface{} {
    21  		params := args[0].([]string)
    22  		pass := icon.IconWithStyle(icon.Check, html.Style{
    23  			"color": "green",
    24  		})
    25  		fail := icon.IconWithStyle(icon.Remove, html.Style{
    26  			"color": "red",
    27  		})
    28  		if len(params) == 0 {
    29  			if value.Value == "0" || strings.ToLower(value.Value) == "false" {
    30  				return fail
    31  			}
    32  			return pass
    33  		} else if len(params) == 1 {
    34  			if value.Value == params[0] {
    35  				return pass
    36  			}
    37  			return fail
    38  		} else {
    39  			if value.Value == params[0] {
    40  				return pass
    41  			}
    42  			if value.Value == params[1] {
    43  				return fail
    44  			}
    45  		}
    46  		return ""
    47  	}
    48  }