github.com/kotovmak/go-admin@v1.1.1/plugins/example/controller.go (about) 1 package example 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 "github.com/kotovmak/go-admin/modules/auth" 14 "github.com/kotovmak/go-admin/modules/page" 15 template2 "github.com/kotovmak/go-admin/template" 16 "github.com/kotovmak/go-admin/template/chartjs" 17 "github.com/kotovmak/go-admin/template/types" 18 ) 19 20 func (e *Example) TestHandler(ctx *context.Context) { 21 page.SetPageContent(ctx, auth.Auth(ctx), func(ctx interface{}) (types.Panel, error) { 22 23 components := template2.Default() 24 colComp := components.Col() 25 26 /************************** 27 * Info Box 28 /**************************/ 29 30 infobox1 := infobox.New(). 31 SetText("CPU TRAFFIC"). 32 SetColor("#3583af"). 33 SetNumber("100"). 34 SetIcon(`<svg t="1568904058859" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2216" width="48" height="48"><path d="M864 64l-704 0C142.336 64 128 78.336 128 96l0 832C128 945.664 142.336 960 160 960l704 0c17.664 0 32-14.336 32-32l0-832C896 78.336 881.664 64 864 64zM832 896 192 896 192 128l640 0L832 896z" fill="#e6e6e6" p-id="2217"></path><path d="M353.92 320c17.6 0 32-14.336 32-32S371.584 256 353.92 256L353.28 256C335.616 256 321.6 270.336 321.6 288S336.256 320 353.92 320z" fill="#e6e6e6" p-id="2218"></path><path d="M353.92 512c17.6 0 32-14.336 32-32S371.584 448 353.92 448L353.28 448C335.616 448 321.6 462.336 321.6 480S336.256 512 353.92 512z" fill="#e6e6e6" p-id="2219"></path><path d="M353.92 704c17.6 0 32-14.336 32-32S371.584 640 353.92 640L353.28 640c-17.6 0-31.616 14.336-31.616 32S336.256 704 353.92 704z" fill="#e6e6e6" p-id="2220"></path><path d="M480 320l192 0C689.664 320 704 305.664 704 288S689.664 256 672 256l-192 0C462.336 256 448 270.336 448 288S462.336 320 480 320z" fill="#e6e6e6" p-id="2221"></path><path d="M480 512l192 0C689.664 512 704 497.664 704 480S689.664 448 672 448l-192 0C462.336 448 448 462.336 448 480S462.336 512 480 512z" fill="#e6e6e6" p-id="2222"></path><path d="M480 704l192 0c17.664 0 32-14.336 32-32S689.664 640 672 640l-192 0C462.336 640 448 654.336 448 672S462.336 704 480 704z" fill="#e6e6e6" p-id="2223"></path></svg>`). 35 GetContent() 36 37 infobox2 := infobox.New(). 38 SetText("Likes"). 39 SetColor("#6a7c86"). 40 SetNumber("1030.00<small>$</small>"). 41 SetIcon(`<svg t="1570468923385" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1124" width="48" height="48"><path d="M508.416 104.96c-225.28 0-408.064 182.784-408.064 408.064s182.784 408.064 408.064 408.064 408.064-182.784 408.064-408.064c0-108.032-43.008-211.968-119.808-288.768-76.288-76.288-180.224-119.296-288.256-119.296z m120.32 460.8c16.384 0 30.208 13.312 30.208 30.208 0 16.384-13.312 30.208-30.208 30.208h-90.624V716.8c0 16.384-13.312 30.208-30.208 30.208-16.384 0-30.208-13.312-30.208-30.208v-91.136H387.584c-16.384 0-30.208-13.312-30.208-30.208 0-16.384 13.312-30.208 30.208-30.208h90.624V495.104H387.584c-16.384 0-30.208-13.312-30.208-30.208 0-16.384 13.312-30.208 30.208-30.208h77.312L387.584 356.864c-9.216-11.776-8.192-28.672 2.56-39.424 10.752-10.752 27.648-11.776 39.424-2.56l78.848 78.848 77.312-77.312c11.264-11.264 29.696-11.264 41.472 0 11.264 11.264 11.264 29.696 0 41.472L548.864 435.2h79.36c16.384 0 30.208 13.312 30.208 30.208 0 16.384-13.312 30.208-30.208 30.208h-90.112v70.144h90.624z m0 0" fill="#ffffff" p-id="1125"></path></svg>`). 42 GetContent() 43 44 infobox3 := infobox.New(). 45 SetText("Sales"). 46 SetColor("#d8cd68"). 47 SetNumber("760"). 48 SetIcon(`<svg t="1570469111431" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="3801" width="48" height="48"><path d="M298.666667 128v768h426.666666V128H298.666667zM256 85.333333h512v853.333334H256V85.333333zM170.666667 128H85.333333V85.333333h128v853.333334H85.333333v-42.666667h85.333334V128z m768 768v42.666667h-128V85.333333h128v42.666667h-85.333334v768h85.333334z" p-id="3802" fill="#ffffff"></path></svg>`). 49 GetContent() 50 51 infobox4 := infobox.New(). 52 SetText("New Members"). 53 SetColor("#6cad6e"). 54 SetNumber("2,349"). 55 SetIcon(`<svg t="1570469079555" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2965" width="48" height="48"><path d="M702.9 293.4c26.6 48.9 41.8 105 41.8 164.6 0 190.7-155 345.3-346.2 345.3S52.3 648.7 52.3 458s155-345.3 346.2-345.3c127.4 0 238.7 68.7 298.8 170.9-0.5-1.8-0.7-3.6-0.7-5.5 0-12.1 9.8-21.8 21.8-21.8 4.6 0 9.1 0.1 13.6 0.3C663.8 144.1 539.9 69 398.5 69 183.2 69 8.6 243.1 8.6 458c0 188 133.7 344.8 311.3 381.1 25.2-5.8 51.6-8.9 78.6-8.9 27 0 53.4 3.1 78.6 8.9C654.8 802.8 788.4 646 788.4 458c0-55.1-11.5-107.5-32.2-155-12.3-2-24.9-3.1-37.7-3.1-6.1 0-11.6-2.5-15.6-6.5z" p-id="2966" fill="#ffffff"></path><path d="M319.9 839.1c-68.4 15.8-128.2 51.9-167.7 102.3-7.4 9.5-5.8 23.2 3.7 30.7 9.5 7.4 23.2 5.8 30.7-3.7 45.5-58.1 124.6-94.4 211.8-94.4 88.3 0 168.4 37.3 213.5 96.6 7.3 9.6 21 11.5 30.6 4.2 9.6-7.3 11.5-21 4.2-30.6-39.4-51.8-100-88.9-169.7-105-25.2-5.8-51.6-8.9-78.6-8.9-26.9-0.1-53.3 3-78.5 8.8z" p-id="2967" fill="#ffffff"></path><path d="M732.1 256.6c-4.5-0.2-9.1-0.3-13.6-0.3-12.1 0-21.8 9.8-21.8 21.8 0 1.9 0.2 3.7 0.7 5.5 1 3.8 2.9 7.1 5.6 9.8 4 4 9.5 6.5 15.6 6.5 12.8 0 25.4 1.1 37.7 3.1 132 21.6 229.6 153.8 215.3 290.1-15.7 149.4-146.3 258-291.4 242.7-12-1.3-22.8 7.4-24 19.4-0.1 0.5-0.1 1.1-0.1 1.6-0.1 0.5-0.2 1-0.2 1.6-1.3 12 7.4 22.8 19.4 24 66.7 7 124.1 42.3 153.3 91.9 6.1 10.4 19.5 13.9 29.9 7.7 10.4-6.1 13.9-19.5 7.7-29.9-19.5-33.1-48.6-60.8-83.8-80.7 122.3-31.5 218.3-138.3 232.6-273.8 17.8-169.3-112-332.7-282.9-341z" p-id="2968" fill="#ffffff"></path></svg>`). 56 GetContent() 57 58 var size = types.Size(6, 3, 0).XS(12) 59 infoboxCol1 := colComp.SetSize(size).SetContent(infobox1).GetContent() 60 infoboxCol2 := colComp.SetSize(size).SetContent(infobox2).GetContent() 61 infoboxCol3 := colComp.SetSize(size).SetContent(infobox3).GetContent() 62 infoboxCol4 := colComp.SetSize(size).SetContent(infobox4).GetContent() 63 row1 := components.Row().SetContent(infoboxCol1 + infoboxCol2 + infoboxCol3 + infoboxCol4).GetContent() 64 65 /************************** 66 * Box 67 /**************************/ 68 69 table := components.Table().SetInfoList([]map[string]types.InfoItem{ 70 { 71 "Order ID": {Content: "OR9842"}, 72 "Item": {Content: "Call of Duty IV"}, 73 "Status": {Content: "shipped"}, 74 "Popularity": {Content: "90%"}, 75 }, { 76 "Order ID": {Content: "OR9842"}, 77 "Item": {Content: "Call of Duty IV"}, 78 "Status": {Content: "shipped"}, 79 "Popularity": {Content: "90%"}, 80 }, { 81 "Order ID": {Content: "OR9842"}, 82 "Item": {Content: "Call of Duty IV"}, 83 "Status": {Content: "shipped"}, 84 "Popularity": {Content: "90%"}, 85 }, 86 }).SetThead(types.Thead{ 87 {Head: "Order ID"}, 88 {Head: "Item"}, 89 {Head: "Status"}, 90 {Head: "Popularity"}, 91 }).GetContent() 92 93 boxInfo := components.Box(). 94 WithHeadBorder(). 95 SetHeader("Latest Orders"). 96 SetHeadColor("#f7f7f7"). 97 SetBody(table). 98 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>`). 99 GetContent() 100 101 tableCol := colComp.SetSize(types.SizeMD(8)).SetContent(row1 + boxInfo).GetContent() 102 103 /************************** 104 * Product List 105 /**************************/ 106 107 productList := productlist.New().SetData([]map[string]string{ 108 { 109 "img": "http://adminlte.io/themes/AdminLTE/dist/img/default-50x50.gif", 110 "title": "GoAdmin", 111 "has_tabel": "true", 112 "labeltype": "warning", 113 "label": "free", 114 "description": `a framework help you build the dataviz system`, 115 }, { 116 "img": "http://adminlte.io/themes/AdminLTE/dist/img/default-50x50.gif", 117 "title": "GoAdmin", 118 "has_tabel": "true", 119 "labeltype": "warning", 120 "label": "free", 121 "description": `a framework help you build the dataviz system`, 122 }, { 123 "img": "http://adminlte.io/themes/AdminLTE/dist/img/default-50x50.gif", 124 "title": "GoAdmin", 125 "has_tabel": "true", 126 "labeltype": "warning", 127 "label": "free", 128 "description": `a framework help you build the dataviz system`, 129 }, 130 }).GetContent() 131 132 boxWarning := components.Box().SetTheme("warning").WithHeadBorder().SetHeader("Recently Added Products"). 133 SetBody(productList). 134 SetFooter(`<a href="javascript:void(0)" class="uppercase">View All Products</a>`). 135 GetContent() 136 137 newsCol := colComp.SetSize(types.SizeMD(4)).SetContent(boxWarning).GetContent() 138 139 row5 := components.Row().SetContent(tableCol + newsCol).GetContent() 140 141 /************************** 142 * Box 143 /**************************/ 144 145 lineChart := chartjs.Line(). 146 SetID("salechart"). 147 SetHeight(180). 148 SetTitle("Sales: 1 Jan, 2019 - 30 Jul, 2019"). 149 SetLabels([]string{"January", "February", "March", "April", "May", "June", "July"}). 150 AddDataSet("Electronics"). 151 DSData([]float64{65, 59, 80, 81, 56, 55, 40}). 152 DSFill(false). 153 DSBorderColor("rgb(210, 214, 222)"). 154 DSLineTension(0.1). 155 AddDataSet("Digital Goods"). 156 DSData([]float64{28, 48, 40, 19, 86, 27, 90}). 157 DSFill(false). 158 DSBorderColor("rgba(60,141,188,1)"). 159 DSLineTension(0.1). 160 GetContent() 161 162 title := `<p class="text-center"><strong>Goal Completion</strong></p>` 163 progressGroup := progress_group.New(). 164 SetTitle("Add Products to Cart"). 165 SetColor("#76b2d4"). 166 SetDenominator(200). 167 SetMolecular(160). 168 SetPercent(80). 169 GetContent() 170 171 progressGroup1 := progress_group.New(). 172 SetTitle("Complete Purchase"). 173 SetColor("#f17c6e"). 174 SetDenominator(400). 175 SetMolecular(310). 176 SetPercent(80). 177 GetContent() 178 179 progressGroup2 := progress_group.New(). 180 SetTitle("Visit Premium Page"). 181 SetColor("#ace0ae"). 182 SetDenominator(800). 183 SetMolecular(490). 184 SetPercent(80). 185 GetContent() 186 187 progressGroup3 := progress_group.New(). 188 SetTitle("Send Inquiries"). 189 SetColor("#fdd698"). 190 SetDenominator(500). 191 SetMolecular(250). 192 SetPercent(50). 193 GetContent() 194 195 boxInternalCol1 := colComp.SetContent(lineChart).SetSize(types.SizeMD(8)).GetContent() 196 boxInternalCol2 := colComp. 197 SetContent(template.HTML(title) + progressGroup + progressGroup1 + progressGroup2 + progressGroup3). 198 SetSize(types.SizeMD(4)). 199 GetContent() 200 201 boxInternalRow := components.Row().SetContent(boxInternalCol1 + boxInternalCol2).GetContent() 202 203 description1 := description.New(). 204 SetPercent("17"). 205 SetNumber("¥140,100"). 206 SetTitle("TOTAL REVENUE"). 207 SetArrow("up"). 208 SetColor("green"). 209 SetBorder("right"). 210 GetContent() 211 212 description2 := description.New(). 213 SetPercent("2"). 214 SetNumber("440,560"). 215 SetTitle("TOTAL REVENUE"). 216 SetArrow("down"). 217 SetColor("red"). 218 SetBorder("right"). 219 GetContent() 220 221 description3 := description.New(). 222 SetPercent("12"). 223 SetNumber("¥140,050"). 224 SetTitle("TOTAL REVENUE"). 225 SetArrow("up"). 226 SetColor("green"). 227 SetBorder("right"). 228 GetContent() 229 230 description4 := description.New(). 231 SetPercent("1"). 232 SetNumber("30943"). 233 SetTitle("TOTAL REVENUE"). 234 SetArrow("up"). 235 SetColor("green"). 236 GetContent() 237 238 size2 := types.SizeXS(6).SM(3) 239 boxInternalCol3 := colComp.SetContent(description1).SetSize(size2).GetContent() 240 boxInternalCol4 := colComp.SetContent(description2).SetSize(size2).GetContent() 241 boxInternalCol5 := colComp.SetContent(description3).SetSize(size2).GetContent() 242 boxInternalCol6 := colComp.SetContent(description4).SetSize(size2).GetContent() 243 244 boxInternalRow2 := components.Row().SetContent(boxInternalCol3 + boxInternalCol4 + boxInternalCol5 + boxInternalCol6).GetContent() 245 246 box := components.Box().WithHeadBorder().SetHeader("Monthly Recap Report"). 247 SetBody(boxInternalRow). 248 SetFooter(boxInternalRow2). 249 GetContent() 250 251 boxcol := colComp.SetContent(box).SetSize(types.SizeMD(12)).GetContent() 252 row2 := components.Row().SetContent(boxcol).GetContent() 253 254 /************************** 255 * Small Box 256 /**************************/ 257 258 smallbox1 := smallbox.New().SetColor("blue").SetIcon("ion-ios-gear-outline").SetUrl("/").SetTitle("new users").SetValue("345¥").GetContent() 259 smallbox2 := smallbox.New().SetColor("yellow").SetIcon("ion-ios-cart-outline").SetUrl("/").SetTitle("new users").SetValue("80%").GetContent() 260 smallbox3 := smallbox.New().SetColor("red").SetIcon("fa-user").SetUrl("/").SetTitle("new users").SetValue("645¥").GetContent() 261 smallbox4 := smallbox.New().SetColor("green").SetIcon("ion-ios-cart-outline").SetUrl("/").SetTitle("new users").SetValue("889¥").GetContent() 262 263 col1 := colComp.SetSize(size).SetContent(smallbox1).GetContent() 264 col2 := colComp.SetSize(size).SetContent(smallbox2).GetContent() 265 col3 := colComp.SetSize(size).SetContent(smallbox3).GetContent() 266 col4 := colComp.SetSize(size).SetContent(smallbox4).GetContent() 267 268 row3 := components.Row().SetContent(col1 + col2 + col3 + col4).GetContent() 269 270 /************************** 271 * Pie Chart 272 /**************************/ 273 274 pie := chartjs.Pie(). 275 SetHeight(170). 276 SetLabels([]string{"Navigator", "Opera", "Safari", "FireFox", "IE", "Chrome"}). 277 SetID("pieChart"). 278 AddDataSet("Chrome"). 279 DSData([]float64{100, 300, 600, 400, 500, 700}). 280 DSBackgroundColor([]chartjs.Color{ 281 "rgb(255, 205, 86)", "rgb(54, 162, 235)", "rgb(255, 99, 132)", "rgb(255, 205, 86)", "rgb(54, 162, 235)", "rgb(255, 99, 132)", 282 }). 283 GetContent() 284 285 legend := chart_legend.New().SetData([]map[string]string{ 286 { 287 "label": " Chrome", 288 "color": "red", 289 }, { 290 "label": " IE", 291 "color": "Green", 292 }, { 293 "label": " FireFox", 294 "color": "yellow", 295 }, { 296 "label": " Sarafri", 297 "color": "blue", 298 }, { 299 "label": " Opera", 300 "color": "light-blue", 301 }, { 302 "label": " Navigator", 303 "color": "gray", 304 }, 305 }).GetContent() 306 307 boxDanger := components.Box().SetTheme("danger").WithHeadBorder().SetHeader("Browser Usage"). 308 SetBody(components.Row(). 309 SetContent(colComp.SetSize(types.SizeMD(8)). 310 SetContent(pie). 311 GetContent() + colComp.SetSize(types.SizeMD(4)). 312 SetContent(legend). 313 GetContent()).GetContent()). 314 SetFooter(`<p class="text-center"><a href="javascript:void(0)" class="uppercase">View All Users</a></p>`). 315 GetContent() 316 317 tabs := components.Tabs().SetData([]map[string]template.HTML{ 318 { 319 "title": "tabs1", 320 "content": template.HTML(`<b>How to use:</b> 321 322 <p>Exactly like the original bootstrap tabs except you should use 323 the custom wrapper <code>.nav-tabs-custom</code> to achieve this style.</p> 324 A wonderful serenity has taken possession of my entire soul, 325 like these sweet mornings of spring which I enjoy with my whole heart. 326 I am alone, and feel the charm of existence in this spot, 327 which was created for the bliss of souls like mine. I am so happy, 328 my dear friend, so absorbed in the exquisite sense of mere tranquil existence, 329 that I neglect my talents. I should be incapable of drawing a single stroke 330 at the present moment; and yet I feel that I never was a greater artist than now.`), 331 }, { 332 "title": "tabs2", 333 "content": template.HTML(` 334 The European languages are members of the same family. Their separate existence is a myth. 335 For science, music, sport, etc, Europe uses the same vocabulary. The languages only differ 336 in their grammar, their pronunciation and their most common words. Everyone realizes why a 337 new common language would be desirable: one could refuse to pay expensive translators. To 338 achieve this, it would be necessary to have uniform grammar, pronunciation and more common 339 words. If several languages coalesce, the grammar of the resulting language is more simple 340 and regular than that of the individual languages. 341 `), 342 }, { 343 "title": "tabs3", 344 "content": template.HTML(` 345 Lorem Ipsum is simply dummy text of the printing and typesetting industry. 346 Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, 347 when an unknown printer took a galley of type and scrambled it to make a type specimen book. 348 It has survived not only five centuries, but also the leap into electronic typesetting, 349 remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset 350 sheets containing Lorem Ipsum passages, and more recently with desktop publishing software 351 like Aldus PageMaker including versions of Lorem Ipsum. 352 `), 353 }, 354 }).GetContent() 355 356 buttonTest := `<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal" data-whatever="@mdo">Open modal for @mdo</button>` 357 popupForm := `<form> 358 <div class="form-group"> 359 <label for="recipient-name" class="col-form-label">Recipient:</label> 360 <input type="text" class="form-control" id="recipient-name"> 361 </div> 362 <div class="form-group"> 363 <label for="message-text" class="col-form-label">Message:</label> 364 <textarea class="form-control" id="message-text"></textarea> 365 </div> 366 </form>` 367 popup := components.Popup().SetID("exampleModal"). 368 SetFooter("Save Change"). 369 SetTitle("this is a popup"). 370 SetBody(template.HTML(popupForm)). 371 GetContent() 372 373 col5 := colComp.SetSize(types.SizeMD(8)).SetContent(tabs + template.HTML(buttonTest)).GetContent() 374 col6 := colComp.SetSize(types.SizeMD(4)).SetContent(boxDanger + popup).GetContent() 375 376 row4 := components.Row().SetContent(col5 + col6).GetContent() 377 378 return types.Panel{ 379 Content: row5 + row2 + row3 + row4, 380 Title: "Dashboard", 381 Description: "dashboard example", 382 }, nil 383 }, e.Conn) 384 }