github.com/benoitkugler/goacve@v0.0.0-20201217100549-151ce6e55dc8/server/core/rawdata/items.go (about) 1 package rawdata 2 3 // Data permet d'unifier toutes les données de sorties (listes, fichiers, etc...) 4 // Une valeur `nil` est tout à fait possible et doit être gérée par le 'consomateur' 5 type Data interface { 6 String() string 7 8 // Sortable renvoie une chaîne qui préserve l'ordre 9 Sortable() string 10 } 11 12 // Colors indique la couleur de chaque champ 13 type Colors interface { 14 byField(field Field) Color 15 } 16 17 type ConstantColor struct { 18 Color 19 } 20 21 func (c ConstantColor) byField(field Field) Color { 22 return c.Color 23 } 24 25 type MapColors map[Field]Color 26 27 func (m MapColors) byField(field Field) Color { 28 return m[field] 29 } 30 31 type Field uint8 32 33 type Header struct { 34 Field Field 35 Label string 36 } 37 38 type B = map[Field]bool 39 40 // Fields protège l'accès aux champs vides 41 type F map[Field]Data 42 43 // Data renvoie la donnée, qui est assurée de ne pas être `nil` 44 func (fs F) Data(field Field) Data { 45 d := fs[field] 46 if d == nil { 47 return String("") 48 } 49 return d 50 } 51 52 // IId permet de différencier des éléments de plusieurs table 53 type IId interface { 54 Int64() int64 55 } 56 57 // Id implémente IId, et suffit dans la plupart des cas. 58 type Id int64 59 60 func (i Id) Int64() int64 { return int64(i) } 61 62 // IdFacture représente un élement de la table Facture 63 type IdFacture int64 64 65 func (i IdFacture) Int64() int64 { return int64(i) } 66 67 // IdParticipant représente un élement de la table Participant 68 type IdParticipant int64 69 70 func (i IdParticipant) Int64() int64 { return int64(i) } 71 72 // IdParticipantsimple représente un élement de la table Participantsimple 73 type IdParticipantsimple int64 74 75 func (i IdParticipantsimple) Int64() int64 { return int64(i) } 76 77 // IdPersonne représente un élement de la table Personne 78 type IdPersonne int64 79 80 func (i IdPersonne) Int64() int64 { return int64(i) } 81 82 // IdOrganisme représente un élement de la table Organisme 83 type IdOrganisme int64 84 85 func (i IdOrganisme) Int64() int64 { return int64(i) } 86 87 // Item représente un élément générique, identifiable 88 // et statique, qui définit sa mise en forme 89 type Item struct { 90 Id IId 91 Fields F 92 Bolds B 93 TextColors Colors 94 BackgroundColors Colors 95 } 96 97 // TextColor renvoie la couleur du texte, qui est assurée de ne pas être `nil` 98 func (i Item) TextColor(field Field) Color { 99 var color Color 100 if i.TextColors != nil { 101 color = i.TextColors.byField(field) 102 } 103 return defaultC(color) 104 } 105 106 // BackgroundColor renvoie la couleur d'arrière plan, qui est assurée de ne pas être `nil` 107 func (i Item) BackgroundColor(field Field) Color { 108 var color Color 109 if i.BackgroundColors != nil { 110 color = i.BackgroundColors.byField(field) 111 } 112 return defaultC(color) 113 } 114 115 type Table = []Item 116 117 // ItemChilds est un arbre à un niveau 118 type ItemChilds struct { 119 Item 120 Childs []Item 121 }