github.com/kotovmak/go-admin@v1.1.1/examples/datamodel/content.go (about) 1 package datamodel 2 3 import ( 4 "html/template" 5 6 "github.com/GoAdminGroup/themes/adminlte/components/chart_legend" 7 "github.com/GoAdminGroup/themes/adminlte/components/description" 8 "github.com/GoAdminGroup/themes/adminlte/components/infobox" 9 "github.com/GoAdminGroup/themes/adminlte/components/productlist" 10 "github.com/GoAdminGroup/themes/adminlte/components/progress_group" 11 "github.com/GoAdminGroup/themes/adminlte/components/smallbox" 12 "github.com/kotovmak/go-admin/context" 13 tmpl "github.com/kotovmak/go-admin/template" 14 "github.com/kotovmak/go-admin/template/chartjs" 15 "github.com/kotovmak/go-admin/template/icon" 16 "github.com/kotovmak/go-admin/template/types" 17 ) 18 19 // GetContent return the content of index page. 20 func GetContent(ctx *context.Context) (types.Panel, error) { 21 22 components := tmpl.Default() 23 colComp := components.Col() 24 25 /************************** 26 * Info Box 27 /**************************/ 28 29 infobox1 := infobox.New(). 30 SetText("CPU TRAFFIC"). 31 SetColor("aqua"). 32 SetNumber("100"). 33 SetIcon("ion-ios-gear-outline"). 34 GetContent() 35 36 infobox2 := infobox.New(). 37 SetText("Likes"). 38 SetColor("red"). 39 SetNumber("1030.00<small>$</small>"). 40 SetIcon(icon.GooglePlus). 41 GetContent() 42 43 infobox3 := infobox.New(). 44 SetText("Sales"). 45 SetColor("green"). 46 SetNumber("760"). 47 SetIcon("ion-ios-cart-outline"). 48 GetContent() 49 50 infobox4 := infobox.New(). 51 SetText("New Members"). 52 SetColor("yellow"). 53 SetNumber("2,349"). 54 SetIcon("ion-ios-people-outline"). // svg is ok 55 GetContent() 56 57 var size = types.Size(6, 3, 0).XS(12) 58 infoboxCol1 := colComp.SetSize(size).SetContent(infobox1).GetContent() 59 infoboxCol2 := colComp.SetSize(size).SetContent(infobox2).GetContent() 60 infoboxCol3 := colComp.SetSize(size).SetContent(infobox3).GetContent() 61 infoboxCol4 := colComp.SetSize(size).SetContent(infobox4).GetContent() 62 row1 := components.Row().SetContent(infoboxCol1 + infoboxCol2 + infoboxCol3 + infoboxCol4).GetContent() 63 64 /************************** 65 * Box 66 /**************************/ 67 68 table := components.Table().SetInfoList([]map[string]types.InfoItem{ 69 { 70 "Order ID": {Content: "OR9842"}, 71 "Item": {Content: "Call of Duty IV"}, 72 "Status": {Content: "shipped"}, 73 "Popularity": {Content: "90%"}, 74 }, { 75 "Order ID": {Content: "OR9842"}, 76 "Item": {Content: "Call of Duty IV"}, 77 "Status": {Content: "shipped"}, 78 "Popularity": {Content: "90%"}, 79 }, { 80 "Order ID": {Content: "OR9842"}, 81 "Item": {Content: "Call of Duty IV"}, 82 "Status": {Content: "shipped"}, 83 "Popularity": {Content: "90%"}, 84 }, { 85 "Order ID": {Content: "OR9842"}, 86 "Item": {Content: "Call of Duty IV"}, 87 "Status": {Content: "shipped"}, 88 "Popularity": {Content: "90%"}, 89 }, 90 }).SetThead(types.Thead{ 91 {Head: "Order ID"}, 92 {Head: "Item"}, 93 {Head: "Status"}, 94 {Head: "Popularity"}, 95 }).GetContent() 96 97 boxInfo := components.Box(). 98 WithHeadBorder(). 99 SetHeader("Latest Orders"). 100 SetHeadColor("#f7f7f7"). 101 SetBody(table). 102 SetFooter(`<div class="clearfix"><a href="javascript:void(0)" class="btn btn-sm btn-info btn-flat pull-left">处理订单</a><a href="javascript:void(0)" class="btn btn-sm btn-default btn-flat pull-right">查看所有新订单</a> </div>`). 103 GetContent() 104 105 tableCol := colComp.SetSize(types.SizeMD(8)).SetContent(row1 + boxInfo).GetContent() 106 107 /************************** 108 * Product List 109 /**************************/ 110 111 productList := productlist.New().SetData([]map[string]string{ 112 { 113 "img": "http://adminlte.io/themes/AdminLTE/dist/img/default-50x50.gif", 114 "title": "GoAdmin", 115 "has_tabel": "true", 116 "labeltype": "warning", 117 "label": "free", 118 "description": `a framework help you build the dataviz system`, 119 }, { 120 "img": "http://adminlte.io/themes/AdminLTE/dist/img/default-50x50.gif", 121 "title": "GoAdmin", 122 "has_tabel": "true", 123 "labeltype": "warning", 124 "label": "free", 125 "description": `a framework help you build the dataviz system`, 126 }, { 127 "img": "http://adminlte.io/themes/AdminLTE/dist/img/default-50x50.gif", 128 "title": "GoAdmin", 129 "has_tabel": "true", 130 "labeltype": "warning", 131 "label": "free", 132 "description": `a framework help you build the dataviz system`, 133 }, { 134 "img": "http://adminlte.io/themes/AdminLTE/dist/img/default-50x50.gif", 135 "title": "GoAdmin", 136 "has_tabel": "true", 137 "labeltype": "warning", 138 "label": "free", 139 "description": `a framework help you build the dataviz system`, 140 }, 141 }).GetContent() 142 143 boxWarning := components.Box().SetTheme("warning").WithHeadBorder().SetHeader("Recently Added Products"). 144 SetBody(productList). 145 SetFooter(`<a href="javascript:void(0)" class="uppercase">View All Products</a>`). 146 GetContent() 147 148 newsCol := colComp.SetSize(types.SizeMD(4)).SetContent(boxWarning).GetContent() 149 150 row5 := components.Row().SetContent(tableCol + newsCol).GetContent() 151 152 /************************** 153 * Box 154 /**************************/ 155 156 line := chartjs.Line() 157 158 lineChart := line. 159 SetID("salechart"). 160 SetHeight(180). 161 SetTitle("Sales: 1 Jan, 2019 - 30 Jul, 2019"). 162 SetLabels([]string{"January", "February", "March", "April", "May", "June", "July"}). 163 AddDataSet("Electronics"). 164 DSData([]float64{65, 59, 80, 81, 56, 55, 40}). 165 DSFill(false). 166 DSBorderColor("rgb(210, 214, 222)"). 167 DSLineTension(0.1). 168 AddDataSet("Digital Goods"). 169 DSData([]float64{28, 48, 40, 19, 86, 27, 90}). 170 DSFill(false). 171 DSBorderColor("rgba(60,141,188,1)"). 172 DSLineTension(0.1). 173 GetContent() 174 175 title := `<p class="text-center"><strong>Goal Completion</strong></p>` 176 progressGroup := progress_group.New(). 177 SetTitle("Add Products to Cart"). 178 SetColor("#76b2d4"). 179 SetDenominator(200). 180 SetMolecular(160). 181 SetPercent(80). 182 GetContent() 183 184 progressGroup1 := progress_group.New(). 185 SetTitle("Complete Purchase"). 186 SetColor("#f17c6e"). 187 SetDenominator(400). 188 SetMolecular(310). 189 SetPercent(80). 190 GetContent() 191 192 progressGroup2 := progress_group.New(). 193 SetTitle("Visit Premium Page"). 194 SetColor("#ace0ae"). 195 SetDenominator(800). 196 SetMolecular(490). 197 SetPercent(80). 198 GetContent() 199 200 progressGroup3 := progress_group.New(). 201 SetTitle("Send Inquiries"). 202 SetColor("#fdd698"). 203 SetDenominator(500). 204 SetMolecular(250). 205 SetPercent(50). 206 GetContent() 207 208 boxInternalCol1 := colComp.SetContent(lineChart).SetSize(types.SizeMD(8)).GetContent() 209 boxInternalCol2 := colComp. 210 SetContent(template.HTML(title) + progressGroup + progressGroup1 + progressGroup2 + progressGroup3). 211 SetSize(types.SizeMD(4)). 212 GetContent() 213 214 boxInternalRow := components.Row().SetContent(boxInternalCol1 + boxInternalCol2).GetContent() 215 216 description1 := description.New(). 217 SetPercent("17"). 218 SetNumber("¥140,100"). 219 SetTitle("TOTAL REVENUE"). 220 SetArrow("up"). 221 SetColor("green"). 222 SetBorder("right"). 223 GetContent() 224 225 description2 := description.New(). 226 SetPercent("2"). 227 SetNumber("440,560"). 228 SetTitle("TOTAL REVENUE"). 229 SetArrow("down"). 230 SetColor("red"). 231 SetBorder("right"). 232 GetContent() 233 234 description3 := description.New(). 235 SetPercent("12"). 236 SetNumber("¥140,050"). 237 SetTitle("TOTAL REVENUE"). 238 SetArrow("up"). 239 SetColor("green"). 240 SetBorder("right"). 241 GetContent() 242 243 description4 := description.New(). 244 SetPercent("1"). 245 SetNumber("30943"). 246 SetTitle("TOTAL REVENUE"). 247 SetArrow("up"). 248 SetColor("green"). 249 GetContent() 250 251 size2 := types.SizeXS(6).SM(3) 252 boxInternalCol3 := colComp.SetContent(description1).SetSize(size2).GetContent() 253 boxInternalCol4 := colComp.SetContent(description2).SetSize(size2).GetContent() 254 boxInternalCol5 := colComp.SetContent(description3).SetSize(size2).GetContent() 255 boxInternalCol6 := colComp.SetContent(description4).SetSize(size2).GetContent() 256 257 boxInternalRow2 := components.Row().SetContent(boxInternalCol3 + boxInternalCol4 + boxInternalCol5 + boxInternalCol6).GetContent() 258 259 box := components.Box().WithHeadBorder().SetHeader("Monthly Recap Report"). 260 SetBody(boxInternalRow). 261 SetFooter(boxInternalRow2). 262 GetContent() 263 264 boxcol := colComp.SetContent(box).SetSize(types.SizeMD(12)).GetContent() 265 row2 := components.Row().SetContent(boxcol).GetContent() 266 267 /************************** 268 * Small Box 269 /**************************/ 270 271 smallbox1 := smallbox.New().SetColor("blue").SetIcon("ion-ios-gear-outline").SetUrl("/").SetTitle("new users").SetValue("345¥").GetContent() 272 smallbox2 := smallbox.New().SetColor("yellow").SetIcon("ion-ios-cart-outline").SetUrl("/").SetTitle("new users").SetValue("80%").GetContent() 273 smallbox3 := smallbox.New().SetColor("red").SetIcon("fa-user").SetUrl("/").SetTitle("new users").SetValue("645¥").GetContent() 274 smallbox4 := smallbox.New().SetColor("green").SetIcon("ion-ios-cart-outline").SetUrl("/").SetTitle("new users").SetValue("889¥").GetContent() 275 276 col1 := colComp.SetSize(size).SetContent(smallbox1).GetContent() 277 col2 := colComp.SetSize(size).SetContent(smallbox2).GetContent() 278 col3 := colComp.SetSize(size).SetContent(smallbox3).GetContent() 279 col4 := colComp.SetSize(size).SetContent(smallbox4).GetContent() 280 281 row3 := components.Row().SetContent(col1 + col2 + col3 + col4).GetContent() 282 283 /************************** 284 * Pie Chart 285 /**************************/ 286 287 pie := chartjs.Pie(). 288 SetHeight(170). 289 SetLabels([]string{"Navigator", "Opera", "Safari", "FireFox", "IE", "Chrome"}). 290 SetID("pieChart"). 291 AddDataSet("Chrome"). 292 DSData([]float64{100, 300, 600, 400, 500, 700}). 293 DSBackgroundColor([]chartjs.Color{ 294 "rgb(255, 205, 86)", "rgb(54, 162, 235)", "rgb(255, 99, 132)", "rgb(255, 205, 86)", "rgb(54, 162, 235)", "rgb(255, 99, 132)", 295 }). 296 GetContent() 297 298 legend := chart_legend.New().SetData([]map[string]string{ 299 { 300 "label": " Chrome", 301 "color": "red", 302 }, { 303 "label": " IE", 304 "color": "Green", 305 }, { 306 "label": " FireFox", 307 "color": "yellow", 308 }, { 309 "label": " Sarafri", 310 "color": "blue", 311 }, { 312 "label": " Opera", 313 "color": "light-blue", 314 }, { 315 "label": " Navigator", 316 "color": "gray", 317 }, 318 }).GetContent() 319 320 boxDanger := components.Box().SetTheme("danger").WithHeadBorder().SetHeader("Browser Usage"). 321 SetBody(components.Row(). 322 SetContent(colComp.SetSize(types.SizeMD(8)). 323 SetContent(pie). 324 GetContent() + colComp.SetSize(types.SizeMD(4)). 325 SetContent(legend). 326 GetContent()).GetContent()). 327 SetFooter(`<p class="text-center"><a href="javascript:void(0)" class="uppercase">View All Users</a></p>`). 328 GetContent() 329 330 tabs := components.Tabs().SetData([]map[string]template.HTML{ 331 { 332 "title": "tabs1", 333 "content": template.HTML(`<b>How to use:</b> 334 335 <p>Exactly like the original bootstrap tabs except you should use 336 the custom wrapper <code>.nav-tabs-custom</code> to achieve this style.</p> 337 A wonderful serenity has taken possession of my entire soul, 338 like these sweet mornings of spring which I enjoy with my whole heart. 339 I am alone, and feel the charm of existence in this spot, 340 which was created for the bliss of souls like mine. I am so happy, 341 my dear friend, so absorbed in the exquisite sense of mere tranquil existence, 342 that I neglect my talents. I should be incapable of drawing a single stroke 343 at the present moment; and yet I feel that I never was a greater artist than now.`), 344 }, { 345 "title": "tabs2", 346 "content": template.HTML(` 347 The European languages are members of the same family. Their separate existence is a myth. 348 For science, music, sport, etc, Europe uses the same vocabulary. The languages only differ 349 in their grammar, their pronunciation and their most common words. Everyone realizes why a 350 new common language would be desirable: one could refuse to pay expensive translators. To 351 achieve this, it would be necessary to have uniform grammar, pronunciation and more common 352 words. If several languages coalesce, the grammar of the resulting language is more simple 353 and regular than that of the individual languages. 354 `), 355 }, { 356 "title": "tabs3", 357 "content": template.HTML(` 358 Lorem Ipsum is simply dummy text of the printing and typesetting industry. 359 Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, 360 when an unknown printer took a galley of type and scrambled it to make a type specimen book. 361 It has survived not only five centuries, but also the leap into electronic typesetting, 362 remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset 363 sheets containing Lorem Ipsum passages, and more recently with desktop publishing software 364 like Aldus PageMaker including versions of Lorem Ipsum. 365 `), 366 }, 367 }).GetContent() 368 369 buttonTest := `<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal" data-whatever="@mdo">Open modal for @mdo</button>` 370 popupForm := `<form> 371 <div class="form-group"> 372 <label for="recipient-name" class="col-form-label">Recipient:</label> 373 <input type="text" class="form-control" id="recipient-name"> 374 </div> 375 <div class="form-group"> 376 <label for="message-text" class="col-form-label">Message:</label> 377 <textarea class="form-control" id="message-text"></textarea> 378 </div> 379 </form>` 380 popup := components.Popup().SetID("exampleModal"). 381 SetFooter("Save Change"). 382 SetTitle("this is a popup"). 383 SetBody(template.HTML(popupForm)). 384 GetContent() 385 386 col5 := colComp.SetSize(types.SizeMD(8)).SetContent(tabs + template.HTML(buttonTest)).GetContent() 387 col6 := colComp.SetSize(types.SizeMD(4)).SetContent(boxDanger + popup).GetContent() 388 389 row4 := components.Row().SetContent(col5 + col6).GetContent() 390 391 return types.Panel{ 392 Content: row3 + row2 + row5 + row4, 393 Title: "Dashboard", 394 Description: "dashboard example", 395 }, nil 396 }