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