github.com/kotovmak/go-admin@v1.1.1/adm/project_template.go (about) 1 package main 2 3 var projectTemplate = map[string]string{ 4 "gin": `{{define "project"}} 5 package main 6 7 import ( 8 "context" 9 "errors" 10 "io/ioutil" 11 "log" 12 "net/http" 13 "os" 14 "os/signal" 15 "syscall" 16 "time" 17 18 _ "github.com/kotovmak/go-admin/adapter/gin" // web framework adapter 19 _ "github.com/kotovmak/go-admin/modules/db/drivers/{{.DriverModule}}" // sql driver 20 _ "github.com/GoAdminGroup/themes/{{.Theme}}" // ui theme 21 22 "github.com/kotovmak/go-admin/engine" 23 "github.com/kotovmak/go-admin/template" 24 "github.com/kotovmak/go-admin/template/chartjs" 25 "github.com/gin-gonic/gin" 26 27 "{{.Module}}/pages" 28 "{{.Module}}/tables" 29 {{if ne .Orm ""}}"{{.Module}}/models"{{end}} 30 ) 31 32 func main() { 33 startServer() 34 } 35 36 func startServer() { 37 gin.SetMode(gin.ReleaseMode) 38 gin.DefaultWriter = ioutil.Discard 39 40 r := gin.Default() 41 42 template.AddComp(chartjs.NewChart()) 43 44 eng := engine.Default() 45 46 if err := eng.AddConfigFromJSON("./config.json"). 47 AddGenerators(tables.Generators). 48 Use(r); err != nil { 49 panic(err) 50 } 51 52 r.Static("/uploads", "./uploads") 53 54 eng.HTML("GET", "/{{.Prefix}}", pages.GetDashBoard) 55 eng.HTMLFile("GET", "/{{.Prefix}}/hello", "./html/hello.tmpl", map[string]interface{}{ 56 "msg": "Hello world", 57 }) 58 59 {{if ne .Orm ""}}models.Init(eng.{{title .Driver}}Connection()){{end}} 60 61 srv := &http.Server{ 62 Addr: ":{{.Port}}", 63 Handler: r, 64 } 65 66 go func() { 67 if err := srv.ListenAndServe(); err != nil && errors.Is(err, http.ErrServerClosed) { 68 log.Printf("listen: %s\n", err) 69 } 70 }() 71 72 quit := make(chan os.Signal, 1) 73 signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM) 74 <-quit 75 log.Println("Shutting down server...") 76 77 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) 78 defer cancel() 79 80 if err := srv.Shutdown(ctx); err != nil { 81 log.Fatal("Server forced to shutdown:", err) 82 } 83 log.Print("closing database connection") 84 eng.{{title .Driver}}Connection().Close() 85 86 log.Println("Server exiting") 87 } 88 {{end}}`, 89 90 "beego": `{{define "project"}} 91 package main 92 93 import ( 94 "log" 95 "os" 96 "os/signal" 97 98 _ "github.com/kotovmak/go-admin/adapter/beego" // web framework adapter 99 _ "github.com/kotovmak/go-admin/modules/db/drivers/{{.DriverModule}}" // sql driver 100 _ "github.com/GoAdminGroup/themes/{{.Theme}}" // ui theme 101 102 "github.com/kotovmak/go-admin/engine" 103 "github.com/kotovmak/go-admin/template" 104 "github.com/kotovmak/go-admin/template/chartjs" 105 "github.com/astaxie/beego" 106 107 "{{.Module}}/pages" 108 "{{.Module}}/tables" 109 {{if ne .Orm ""}}"{{.Module}}/models"{{end}} 110 ) 111 112 func main() { 113 startServer() 114 } 115 116 func startServer() { 117 app := beego.NewApp() 118 119 template.AddComp(chartjs.NewChart()) 120 121 eng := engine.Default() 122 123 beego.SetStaticPath("/uploads", "uploads") 124 125 if err := eng.AddConfigFromJSON("./config.json"). 126 AddGenerators(tables.Generators). 127 Use(app); err != nil { 128 panic(err) 129 } 130 131 eng.HTML("GET", "/{{.Prefix}}", pages.GetDashBoard) 132 eng.HTMLFile("GET", "/{{.Prefix}}/hello", "./html/hello.tmpl", map[string]interface{}{ 133 "msg": "Hello world", 134 }) 135 136 {{if ne .Orm ""}}models.Init(eng.{{title .Driver}}Connection()){{end}} 137 138 beego.BConfig.Listen.HTTPAddr = "127.0.0.1" 139 beego.BConfig.Listen.HTTPPort = {{.Port}} 140 go app.Run() 141 142 quit := make(chan os.Signal, 1) 143 signal.Notify(quit, os.Interrupt) 144 <-quit 145 log.Print("closing database connection") 146 eng.{{title .Driver}}Connection().Close() 147 } 148 {{end}}`, 149 150 "buffalo": `{{define "project"}} 151 package main 152 153 import ( 154 "log" 155 "net/http" 156 "os" 157 "os/signal" 158 159 _ "github.com/kotovmak/go-admin/adapter/buffalo" // web framework adapter 160 _ "github.com/kotovmak/go-admin/modules/db/drivers/{{.DriverModule}}" // sql driver 161 _ "github.com/GoAdminGroup/themes/{{.Theme}}" // ui theme 162 163 "github.com/kotovmak/go-admin/engine" 164 "github.com/kotovmak/go-admin/template" 165 "github.com/kotovmak/go-admin/template/chartjs" 166 "github.com/gobuffalo/buffalo" 167 168 "{{.Module}}/pages" 169 "{{.Module}}/tables" 170 {{if ne .Orm ""}}"{{.Module}}/models"{{end}} 171 ) 172 173 func main() { 174 startServer() 175 } 176 177 func startServer() { 178 bu := buffalo.New(buffalo.Options{ 179 Env: "test", 180 Addr: "127.0.0.1:{{.Port}}", 181 }) 182 183 template.AddComp(chartjs.NewChart()) 184 185 eng := engine.Default() 186 187 if err := eng.AddConfigFromJSON("./config.json"). 188 AddGenerators(tables.Generators). 189 Use(bu); err != nil { 190 panic(err) 191 } 192 193 eng.HTML("GET", "/{{.Prefix}}", pages.GetDashBoard) 194 eng.HTMLFile("GET", "/{{.Prefix}}/hello", "./html/hello.tmpl", map[string]interface{}{ 195 "msg": "Hello world", 196 }) 197 198 {{if ne .Orm ""}}models.Init(eng.{{title .Driver}}Connection()){{end}} 199 200 bu.ServeFiles("/uploads", http.Dir("./uploads")) 201 202 go func() { 203 _ = bu.Serve() 204 }() 205 206 quit := make(chan os.Signal, 1) 207 signal.Notify(quit, os.Interrupt) 208 <-quit 209 log.Print("closing database connection") 210 eng.{{title .Driver}}Connection().Close() 211 } 212 {{end}}`, 213 214 "chi": `{{define "project"}} 215 package main 216 217 import ( 218 "log" 219 "net/http" 220 "os" 221 "os/signal" 222 "path/filepath" 223 "strings" 224 225 _ "github.com/kotovmak/go-admin/adapter/chi" // web framework adapter 226 _ "github.com/kotovmak/go-admin/modules/db/drivers/{{.DriverModule}}" // sql driver 227 _ "github.com/GoAdminGroup/themes/{{.Theme}}" // ui theme 228 229 "github.com/kotovmak/go-admin/engine" 230 "github.com/kotovmak/go-admin/template" 231 "github.com/kotovmak/go-admin/template/chartjs" 232 "github.com/go-chi/chi" 233 234 "{{.Module}}/pages" 235 "{{.Module}}/tables" 236 {{if ne .Orm ""}}"{{.Module}}/models"{{end}} 237 ) 238 239 func main() { 240 startServer() 241 } 242 243 func startServer() { 244 r := chi.NewRouter() 245 246 template.AddComp(chartjs.NewChart()) 247 248 eng := engine.Default() 249 250 if err := eng.AddConfigFromJSON("./config.json"). 251 AddGenerators(tables.Generators). 252 Use(r); err != nil { 253 panic(err) 254 } 255 256 eng.HTML("GET", "/{{.Prefix}}", pages.GetDashBoard) 257 eng.HTMLFile("GET", "/{{.Prefix}}/hello", "./html/hello.tmpl", map[string]interface{}{ 258 "msg": "Hello world", 259 }) 260 261 {{if ne .Orm ""}}models.Init(eng.{{title .Driver}}Connection()){{end}} 262 263 workDir, _ := os.Getwd() 264 filesDir := filepath.Join(workDir, "uploads") 265 fileServer(r, "/uploads", http.Dir(filesDir)) 266 267 go func() { 268 _ = http.ListenAndServe(":{{.Port}}", r) 269 }() 270 271 quit := make(chan os.Signal, 1) 272 signal.Notify(quit, os.Interrupt) 273 <-quit 274 log.Print("closing database connection") 275 eng.{{title .Driver}}Connection().Close() 276 } 277 278 279 // fileServer conveniently sets up a http.FileServer handler to serve 280 // static files from a http.FileSystem. 281 func fileServer(r chi.Router, path string, root http.FileSystem) { 282 if strings.ContainsAny(path, "{}*") { 283 panic("FileServer does not permit URL parameters.") 284 } 285 286 fs := http.StripPrefix(path, http.FileServer(root)) 287 288 if path != "/" && path[len(path)-1] != '/' { 289 r.Get(path, http.RedirectHandler(path+"/", 301).ServeHTTP) 290 path += "/" 291 } 292 path += "*" 293 294 r.Get(path, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 295 fs.ServeHTTP(w, r) 296 })) 297 } 298 {{end}}`, 299 300 "echo": `{{define "project"}} 301 package main 302 303 import ( 304 "log" 305 "os" 306 "os/signal" 307 308 _ "github.com/kotovmak/go-admin/adapter/echo" // web framework adapter 309 _ "github.com/kotovmak/go-admin/modules/db/drivers/{{.DriverModule}}" // sql driver 310 _ "github.com/GoAdminGroup/themes/{{.Theme}}" // ui theme 311 312 "github.com/kotovmak/go-admin/engine" 313 "github.com/kotovmak/go-admin/template" 314 "github.com/kotovmak/go-admin/template/chartjs" 315 "github.com/labstack/echo/v4" 316 317 "{{.Module}}/pages" 318 "{{.Module}}/tables" 319 {{if ne .Orm ""}}"{{.Module}}/models"{{end}} 320 ) 321 322 func main() { 323 startServer() 324 } 325 326 func startServer() { 327 e := echo.New() 328 329 template.AddComp(chartjs.NewChart()) 330 331 eng := engine.Default() 332 333 if err := eng.AddConfigFromJSON("./config.json"). 334 AddGenerators(tables.Generators). 335 Use(e); err != nil { 336 panic(err) 337 } 338 339 eng.HTML("GET", "/{{.Prefix}}", pages.GetDashBoard) 340 eng.HTMLFile("GET", "/{{.Prefix}}/hello", "./html/hello.tmpl", map[string]interface{}{ 341 "msg": "Hello world", 342 }) 343 344 {{if ne .Orm ""}}models.Init(eng.{{title .Driver}}Connection()){{end}} 345 346 e.Static("/uploads", "./uploads") 347 348 go e.Logger.Fatal(e.Start(":{{.Port}}")) 349 350 quit := make(chan os.Signal, 1) 351 signal.Notify(quit, os.Interrupt) 352 <-quit 353 log.Print("closing database connection") 354 eng.{{title .Driver}}Connection().Close() 355 } 356 {{end}}`, 357 358 "fasthttp": `{{define "project"}} 359 package main 360 361 import ( 362 "log" 363 "os" 364 "os/signal" 365 366 _ "github.com/kotovmak/go-admin/adapter/fasthttp" // web framework adapter 367 _ "github.com/kotovmak/go-admin/modules/db/drivers/{{.DriverModule}}" // sql driver 368 _ "github.com/GoAdminGroup/themes/{{.Theme}}" // ui theme 369 370 "github.com/kotovmak/go-admin/engine" 371 "github.com/kotovmak/go-admin/template" 372 "github.com/kotovmak/go-admin/template/chartjs" 373 "github.com/buaazp/fasthttprouter" 374 "github.com/valyala/fasthttp" 375 376 "{{.Module}}/pages" 377 "{{.Module}}/tables" 378 {{if ne .Orm ""}}"{{.Module}}/models"{{end}} 379 ) 380 381 func main() { 382 startServer() 383 } 384 385 func startServer() { 386 router := fasthttprouter.New() 387 388 template.AddComp(chartjs.NewChart()) 389 390 eng := engine.Default() 391 392 if err := eng.AddConfigFromJSON("./config.json"). 393 AddGenerators(tables.Generators). 394 Use(router); err != nil { 395 panic(err) 396 } 397 398 eng.HTML("GET", "/{{.Prefix}}", pages.GetDashBoard) 399 eng.HTMLFile("GET", "/{{.Prefix}}/hello", "./html/hello.tmpl", map[string]interface{}{ 400 "msg": "Hello world", 401 }) 402 403 {{if ne .Orm ""}}models.Init(eng.{{title .Driver}}Connection()){{end}} 404 405 router.ServeFiles("/uploads/*filepath", "./uploads") 406 407 go func() { 408 _ = fasthttp.ListenAndServe(":{{.Port}}", router.Handler) 409 }() 410 411 quit := make(chan os.Signal, 1) 412 signal.Notify(quit, os.Interrupt) 413 <-quit 414 log.Print("closing database connection") 415 eng.{{title .Driver}}Connection().Close() 416 } 417 {{end}}`, 418 419 "gf": `{{define "project"}} 420 package main 421 422 import ( 423 "log" 424 "os" 425 "os/signal" 426 427 _ "github.com/kotovmak/go-admin/adapter/gf" // web framework adapter 428 _ "github.com/kotovmak/go-admin/modules/db/drivers/{{.DriverModule}}" // sql driver 429 _ "github.com/GoAdminGroup/themes/{{.Theme}}" // ui theme 430 431 "github.com/kotovmak/go-admin/engine" 432 "github.com/kotovmak/go-admin/template" 433 "github.com/kotovmak/go-admin/template/chartjs" 434 "github.com/gogf/gf/frame/g" 435 436 "{{.Module}}/pages" 437 "{{.Module}}/tables" 438 {{if ne .Orm ""}}"{{.Module}}/models"{{end}} 439 ) 440 441 func main() { 442 startServer() 443 } 444 445 func startServer() { 446 s := g.Server() 447 448 template.AddComp(chartjs.NewChart()) 449 450 eng := engine.Default() 451 452 if err := eng.AddConfigFromJSON("./config.json"). 453 AddGenerators(tables.Generators). 454 Use(s); err != nil { 455 panic(err) 456 } 457 458 eng.HTML("GET", "/{{.Prefix}}", pages.GetDashBoard) 459 eng.HTMLFile("GET", "/{{.Prefix}}/hello", "./html/hello.tmpl", map[string]interface{}{ 460 "msg": "Hello world", 461 }) 462 463 {{if ne .Orm ""}}models.Init(eng.{{title .Driver}}Connection()){{end}} 464 465 s.AddStaticPath("/uploads", "./uploads") 466 467 s.SetPort({{.Port}}) 468 go s.Run() 469 470 quit := make(chan os.Signal, 1) 471 signal.Notify(quit, os.Interrupt) 472 <-quit 473 log.Print("closing database connection") 474 eng.{{title .Driver}}Connection().Close() 475 } 476 {{end}}`, 477 478 "gorilla": `{{define "project"}} 479 package main 480 481 import ( 482 "log" 483 "net/http" 484 "os" 485 "os/signal" 486 487 _ "github.com/kotovmak/go-admin/adapter/gorilla" // web framework adapter 488 _ "github.com/kotovmak/go-admin/modules/db/drivers/{{.DriverModule}}" // sql driver 489 _ "github.com/GoAdminGroup/themes/{{.Theme}}" // ui theme 490 491 "github.com/kotovmak/go-admin/engine" 492 "github.com/kotovmak/go-admin/template" 493 "github.com/kotovmak/go-admin/template/chartjs" 494 "github.com/gorilla/mux" 495 496 "{{.Module}}/pages" 497 "{{.Module}}/tables" 498 {{if ne .Orm ""}}"{{.Module}}/models"{{end}} 499 ) 500 501 func main() { 502 startServer() 503 } 504 505 func startServer() { 506 app := mux.NewRouter() 507 508 template.AddComp(chartjs.NewChart()) 509 510 eng := engine.Default() 511 512 if err := eng.AddConfigFromJSON("./config.json"). 513 AddGenerators(tables.Generators). 514 Use(app); err != nil { 515 panic(err) 516 } 517 518 eng.HTML("GET", "/{{.Prefix}}", pages.GetDashBoard) 519 eng.HTMLFile("GET", "/{{.Prefix}}/hello", "./html/hello.tmpl", map[string]interface{}{ 520 "msg": "Hello world", 521 }) 522 523 {{if ne .Orm ""}}models.Init(eng.{{title .Driver}}Connection()){{end}} 524 525 app.PathPrefix("/uploads/").Handler(http.StripPrefix("/uploads/", http.FileServer(http.Dir("./uploads")))) 526 527 go func() { 528 _ = http.ListenAndServe(":{{.Port}}", app) 529 }() 530 531 quit := make(chan os.Signal, 1) 532 signal.Notify(quit, os.Interrupt) 533 <-quit 534 log.Print("closing database connection") 535 eng.{{title .Driver}}Connection().Close() 536 } 537 {{end}}`, 538 539 "iris": `{{define "project"}} 540 package main 541 542 import ( 543 "log" 544 "os" 545 "os/signal" 546 547 _ "github.com/kotovmak/go-admin/adapter/iris" // web framework adapter 548 _ "github.com/kotovmak/go-admin/modules/db/drivers/{{.DriverModule}}" // sql driver 549 _ "github.com/GoAdminGroup/themes/{{.Theme}}" // ui theme 550 551 "github.com/kotovmak/go-admin/engine" 552 "github.com/kotovmak/go-admin/template" 553 "github.com/kotovmak/go-admin/template/chartjs" 554 "github.com/kataras/iris/v12" 555 556 "{{.Module}}/pages" 557 "{{.Module}}/tables" 558 {{if ne .Orm ""}}"{{.Module}}/models"{{end}} 559 ) 560 561 func main() { 562 startServer() 563 } 564 565 func startServer() { 566 app := iris.Default() 567 568 template.AddComp(chartjs.NewChart()) 569 570 eng := engine.Default() 571 572 if err := eng.AddConfigFromJSON("./config.json"). 573 AddGenerators(tables.Generators). 574 Use(app); err != nil { 575 panic(err) 576 } 577 578 eng.HTML("GET", "/{{.Prefix}}", pages.GetDashBoard) 579 eng.HTMLFile("GET", "/{{.Prefix}}/hello", "./html/hello.tmpl", map[string]interface{}{ 580 "msg": "Hello world", 581 }) 582 583 {{if ne .Orm ""}}models.Init(eng.{{title .Driver}}Connection()){{end}} 584 585 app.HandleDir("/uploads", "./uploads", iris.DirOptions{ 586 IndexName: "/index.html", 587 Gzip: false, 588 ShowList: false, 589 }) 590 591 go func() { 592 _ = app.Run(iris.Addr(":{{.Port}}")) 593 }() 594 595 quit := make(chan os.Signal, 1) 596 signal.Notify(quit, os.Interrupt) 597 <-quit 598 log.Print("closing database connection") 599 eng.{{title .Driver}}Connection().Close() 600 } 601 {{end}}`, 602 } 603 604 var swordIndexPage = []byte(`package pages 605 606 import ( 607 "github.com/kotovmak/go-admin/context" 608 "github.com/kotovmak/go-admin/modules/config" 609 template2 "github.com/kotovmak/go-admin/template" 610 "github.com/kotovmak/go-admin/template/chartjs" 611 "github.com/kotovmak/go-admin/template/types" 612 "github.com/GoAdminGroup/themes/sword/components/card" 613 "github.com/GoAdminGroup/themes/sword/components/chart_legend" 614 "github.com/GoAdminGroup/themes/sword/components/description" 615 "github.com/GoAdminGroup/themes/sword/components/progress_group" 616 "html/template" 617 ) 618 619 func GetDashBoard(ctx *context.Context) (types.Panel, error) { 620 621 components := template2.Get(config.GetTheme()) 622 colComp := components.Col() 623 624 /************************** 625 * Info Box 626 /**************************/ 627 628 cardcard := card.New(). 629 SetTitle("TOTAL REVENUE"). 630 SetSubTitle("¥ 113,340"). 631 SetAction(template.HTML(` + "`" + `<i aria-label="图标: info-circle-o" class="anticon anticon-info-circle-o"><svg viewBox="64 64 896 896" focusable="false" class="" data-icon="info-circle" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm0 820c-205.4 0-372-166.6-372-372s166.6-372 372-372 372 166.6 372 372-166.6 372-372 372z"></path><path d="M464 336a48 48 0 1 0 96 0 48 48 0 1 0-96 0zm72 112h-48c-4.4 0-8 3.6-8 8v272c0 4.4 3.6 8 8 8h48c4.4 0 8-3.6 8-8V456c0-4.4-3.6-8-8-8z"></path></svg></i>` + "`" + `)). 632 SetContent(template.HTML(` + "`" + `<div><div title="" style="margin-right: 16px;"><span><span>Week Compare</span><span style="margin-left: 8px;">12%</span></span><span style="color: #f5222d;margin-left: 4px;top: 1px;"><i style="font-size: 12px;" aria-label="图标: caret-up" class="anticon anticon-caret-up"><svg viewBox="0 0 1024 1024" focusable="false" class="" data-icon="caret-up" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M858.9 689L530.5 308.2c-9.4-10.9-27.5-10.9-37 0L165.1 689c-12.2 14.2-1.2 35 18.5 35h656.8c19.7 0 30.7-20.8 18.5-35z"></path></svg></i></span></div><div class="antd-pro-pages-dashboard-analysis-components-trend-index-trendItem" title=""><span><span>Day Compare</span><span style="margin-left: 8px;">11%</span></span><span style="color: #52c41a;margin-left: 4px;top: 1px;"><i style="font-size: 12px;" aria-label="图标: caret-down" class="anticon anticon-caret-down"><svg viewBox="0 0 1024 1024" focusable="false" class="" data-icon="caret-down" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M840.4 300H183.6c-19.7 0-30.7 20.8-18.5 35l328.4 380.8c9.4 10.9 27.5 10.9 37 0L858.9 335c12.2-14.2 1.2-35-18.5-35z"></path></svg></i></span></div></div>` + "`" + `)). 633 SetFooter(template.HTML(` + "`" + `TOTAL DAY REVENUE <strong style="margin-left:8px;">$11,325</strong>` + "`" + `)) 634 infobox := cardcard.GetContent() 635 636 infobox2 := cardcard.GetContent() 637 638 infobox3 := cardcard.GetContent() 639 640 infobox4 := cardcard.GetContent() 641 642 var size = map[string]string{"md": "3", "sm": "6", "xs": "12"} 643 infoboxCol1 := colComp.SetSize(size).SetContent(infobox).GetContent() 644 infoboxCol2 := colComp.SetSize(size).SetContent(infobox2).GetContent() 645 infoboxCol3 := colComp.SetSize(size).SetContent(infobox3).GetContent() 646 infoboxCol4 := colComp.SetSize(size).SetContent(infobox4).GetContent() 647 row1 := components.Row().SetContent(infoboxCol1 + infoboxCol2 + infoboxCol3 + infoboxCol4).GetContent() 648 649 /************************** 650 * Box 651 /**************************/ 652 653 lineChart := chartjs.Line(). 654 SetID("salechart"). 655 SetHeight(180). 656 SetTitle("Sales: 1 Jan, 2019 - 30 Jul, 2019"). 657 SetLabels([]string{"January", "February", "March", "April", "May", "June", "July"}). 658 AddDataSet("Electronics"). 659 DSData([]float64{65, 59, 80, 81, 56, 55, 40}). 660 DSFill(false). 661 DSBorderColor("rgb(210, 214, 222)"). 662 DSLineTension(0.1). 663 AddDataSet("Digital Goods"). 664 DSData([]float64{28, 48, 40, 19, 86, 27, 90}). 665 DSFill(false). 666 DSBorderColor("rgba(60,141,188,1)"). 667 DSLineTension(0.1). 668 GetContent() 669 670 title := ` + "`" + `<p class="text-center"><strong>Goal Completion</strong></p>` + "`" + ` 671 progressGroup := progress_group.New(). 672 SetTitle("Add Products to Cart"). 673 SetColor("#76b2d4"). 674 SetDenominator(200). 675 SetMolecular(160). 676 SetPercent(80). 677 GetContent() 678 679 progressGroup1 := progress_group.New(). 680 SetTitle("Complete Purchase"). 681 SetColor("#f17c6e"). 682 SetDenominator(400). 683 SetMolecular(310). 684 SetPercent(80). 685 GetContent() 686 687 progressGroup2 := progress_group.New(). 688 SetTitle("Visit Premium Page"). 689 SetColor("#ace0ae"). 690 SetDenominator(800). 691 SetMolecular(490). 692 SetPercent(80). 693 GetContent() 694 695 progressGroup3 := progress_group.New(). 696 SetTitle("Send Inquiries"). 697 SetColor("#fdd698"). 698 SetDenominator(500). 699 SetMolecular(250). 700 SetPercent(50). 701 GetContent() 702 703 boxInternalCol1 := colComp.SetContent(lineChart).SetSize(types.SizeMD(8)).GetContent() 704 boxInternalCol2 := colComp. 705 SetContent(template.HTML(title) + progressGroup + progressGroup1 + progressGroup2 + progressGroup3). 706 SetSize(types.SizeMD(4)). 707 GetContent() 708 709 boxInternalRow := components.Row().SetContent(boxInternalCol1 + boxInternalCol2).GetContent() 710 711 description1 := description.New(). 712 SetPercent("17"). 713 SetNumber("¥140,100"). 714 SetTitle("TOTAL REVENUE"). 715 SetArrow("up"). 716 SetColor("green"). 717 SetBorder("right"). 718 GetContent() 719 720 description2 := description.New(). 721 SetPercent("2"). 722 SetNumber("440,560"). 723 SetTitle("TOTAL REVENUE"). 724 SetArrow("down"). 725 SetColor("red"). 726 SetBorder("right"). 727 GetContent() 728 729 description3 := description.New(). 730 SetPercent("12"). 731 SetNumber("¥140,050"). 732 SetTitle("TOTAL REVENUE"). 733 SetArrow("up"). 734 SetColor("green"). 735 SetBorder("right"). 736 GetContent() 737 738 description4 := description.New(). 739 SetPercent("1"). 740 SetNumber("30943"). 741 SetTitle("TOTAL REVENUE"). 742 SetArrow("up"). 743 SetColor("green"). 744 GetContent() 745 746 size2 := map[string]string{"sm": "3", "xs": "6"} 747 boxInternalCol3 := colComp.SetContent(description1).SetSize(size2).GetContent() 748 boxInternalCol4 := colComp.SetContent(description2).SetSize(size2).GetContent() 749 boxInternalCol5 := colComp.SetContent(description3).SetSize(size2).GetContent() 750 boxInternalCol6 := colComp.SetContent(description4).SetSize(size2).GetContent() 751 752 boxInternalRow2 := components.Row().SetContent(boxInternalCol3 + boxInternalCol4 + boxInternalCol5 + boxInternalCol6).GetContent() 753 754 box := components.Box().WithHeadBorder().SetHeader("Monthly Recap Report"). 755 SetBody(boxInternalRow). 756 SetFooter(boxInternalRow2). 757 GetContent() 758 759 boxcol := colComp.SetContent(box).SetSize(types.SizeMD(12)).GetContent() 760 row2 := components.Row().SetContent(boxcol).GetContent() 761 762 /************************** 763 * Pie Chart 764 /**************************/ 765 766 pie := chartjs.Pie(). 767 SetHeight(170). 768 SetLabels([]string{"Navigator", "Opera", "Safari", "FireFox", "IE", "Chrome"}). 769 SetID("pieChart"). 770 AddDataSet("Chrome"). 771 DSData([]float64{100, 300, 600, 400, 500, 700}). 772 DSBackgroundColor([]chartjs.Color{ 773 "rgb(255, 205, 86)", "rgb(54, 162, 235)", "rgb(255, 99, 132)", "rgb(255, 205, 86)", "rgb(54, 162, 235)", "rgb(255, 99, 132)", 774 }). 775 GetContent() 776 legend := chart_legend.New().SetData([]map[string]string{ 777 { 778 "label": " Chrome", 779 "color": "red", 780 }, { 781 "label": " IE", 782 "color": "Green", 783 }, { 784 "label": " FireFox", 785 "color": "yellow", 786 }, { 787 "label": " Sarafri", 788 "color": "blue", 789 }, { 790 "label": " Opera", 791 "color": "light-blue", 792 }, { 793 "label": " Navigator", 794 "color": "gray", 795 }, 796 }).GetContent() 797 798 boxDanger := components.Box().SetTheme("danger").WithHeadBorder().SetHeader("Browser Usage"). 799 SetBody(components.Row(). 800 SetContent(colComp.SetSize(types.SizeMD(8)). 801 SetContent(pie). 802 GetContent() + colComp.SetSize(types.SizeMD(4)). 803 SetContent(legend). 804 GetContent()).GetContent()). 805 SetFooter(` + "`" + `<p class="text-center"><a href="javascript:void(0)" class="uppercase">View All Users</a></p>` + "`" + `). 806 GetContent() 807 808 tabs := components.Tabs().SetData([]map[string]template.HTML{ 809 { 810 "title": "tabs1", 811 "content": template.HTML(` + "`" + `<b>How to use:</b> 812 813 <p>Exactly like the original bootstrap tabs except you should use 814 the custom wrapper <code>.nav-tabs-custom</code> to achieve this style.</p> 815 A wonderful serenity has taken possession of my entire soul, 816 like these sweet mornings of spring which I enjoy with my whole heart. 817 I am alone, and feel the charm of existence in this spot, 818 which was created for the bliss of souls like mine. I am so happy, 819 my dear friend, so absorbed in the exquisite sense of mere tranquil existence, 820 that I neglect my talents. I should be incapable of drawing a single stroke 821 at the present moment; and yet I feel that I never was a greater artist than now.` + "`" + `), 822 }, { 823 "title": "tabs2", 824 "content": template.HTML(` + "`" + ` 825 The European languages are members of the same family. Their separate existence is a myth. 826 For science, music, sport, etc, Europe uses the same vocabulary. The languages only differ 827 in their grammar, their pronunciation and their most common words. Everyone realizes why a 828 new common language would be desirable: one could refuse to pay expensive translators. To 829 achieve this, it would be necessary to have uniform grammar, pronunciation and more common 830 words. If several languages coalesce, the grammar of the resulting language is more simple 831 and regular than that of the individual languages. 832 ` + "`" + `), 833 }, { 834 "title": "tabs3", 835 "content": template.HTML(` + "`" + ` 836 Lorem Ipsum is simply dummy text of the printing and typesetting industry. 837 Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, 838 when an unknown printer took a galley of type and scrambled it to make a type specimen book. 839 It has survived not only five centuries, but also the leap into electronic typesetting, 840 remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset 841 sheets containing Lorem Ipsum passages, and more recently with desktop publishing software 842 like Aldus PageMaker including versions of Lorem Ipsum. 843 ` + "`" + `), 844 }, 845 }).GetContent() 846 847 buttonTest := ` + "`" + `<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal" data-whatever="@mdo">Open modal for @mdo</button>` + "`" + ` 848 popupForm := ` + "`" + `<form> 849 <div class="form-group"> 850 <label for="recipient-name" class="col-form-label">Recipient:</label> 851 <input type="text" class="form-control" id="recipient-name"> 852 </div> 853 <div class="form-group"> 854 <label for="message-text" class="col-form-label">Message:</label> 855 <textarea class="form-control" id="message-text"></textarea> 856 </div> 857 </form>` + "`" + ` 858 popup := components.Popup().SetID("exampleModal"). 859 SetFooter("Save Change"). 860 SetTitle("this is a popup"). 861 SetBody(template.HTML(popupForm)). 862 GetContent() 863 864 col5 := colComp.SetSize(types.SizeMD(8)).SetContent(tabs + template.HTML(buttonTest)).GetContent() 865 col6 := colComp.SetSize(types.SizeMD(4)).SetContent(boxDanger + popup).GetContent() 866 867 row4 := components.Row().SetContent(col5 + col6).GetContent() 868 869 return types.Panel{ 870 Content: row1 + row2 + row4, 871 Title: "Dashboard", 872 Description: "dashboard example", 873 }, nil 874 } 875 `) 876 877 var adminlteIndexPage = []byte(`package pages 878 879 import ( 880 "github.com/kotovmak/go-admin/context" 881 tmpl "github.com/kotovmak/go-admin/template" 882 "github.com/kotovmak/go-admin/template/chartjs" 883 "github.com/kotovmak/go-admin/template/icon" 884 "github.com/kotovmak/go-admin/template/types" 885 "github.com/GoAdminGroup/themes/adminlte/components/chart_legend" 886 "github.com/GoAdminGroup/themes/adminlte/components/description" 887 "github.com/GoAdminGroup/themes/adminlte/components/infobox" 888 "github.com/GoAdminGroup/themes/adminlte/components/productlist" 889 "github.com/GoAdminGroup/themes/adminlte/components/progress_group" 890 "github.com/GoAdminGroup/themes/adminlte/components/smallbox" 891 "html/template" 892 ) 893 894 func GetDashBoard(ctx *context.Context) (types.Panel, error) { 895 896 components := tmpl.Default() 897 colComp := components.Col() 898 899 /************************** 900 * Info Box 901 /**************************/ 902 903 infobox1 := infobox.New(). 904 SetText("CPU TRAFFIC"). 905 SetColor("aqua"). 906 SetNumber("100"). 907 SetIcon("ion-ios-gear-outline"). 908 GetContent() 909 910 infobox2 := infobox.New(). 911 SetText("Likes"). 912 SetColor("red"). 913 SetNumber("1030.00<small>$</small>"). 914 SetIcon(icon.GooglePlus). 915 GetContent() 916 917 infobox3 := infobox.New(). 918 SetText("Sales"). 919 SetColor("green"). 920 SetNumber("760"). 921 SetIcon("ion-ios-cart-outline"). 922 GetContent() 923 924 infobox4 := infobox.New(). 925 SetText("New Members"). 926 SetColor("yellow"). 927 SetNumber("2,349"). 928 SetIcon("ion-ios-people-outline"). // svg is ok 929 GetContent() 930 931 var size = types.SizeMD(3).SM(6).XS(12) 932 infoboxCol1 := colComp.SetSize(size).SetContent(infobox1).GetContent() 933 infoboxCol2 := colComp.SetSize(size).SetContent(infobox2).GetContent() 934 infoboxCol3 := colComp.SetSize(size).SetContent(infobox3).GetContent() 935 infoboxCol4 := colComp.SetSize(size).SetContent(infobox4).GetContent() 936 row1 := components.Row().SetContent(infoboxCol1 + infoboxCol2 + infoboxCol3 + infoboxCol4).GetContent() 937 938 /************************** 939 * Box 940 /**************************/ 941 942 table := components.Table().SetType("table").SetInfoList([]map[string]types.InfoItem{ 943 { 944 "Order ID": {Content: "OR9842"}, 945 "Item": {Content: "Call of Duty IV"}, 946 "Status": {Content: "shipped"}, 947 "Popularity": {Content: "90%"}, 948 }, { 949 "Order ID": {Content: "OR9842"}, 950 "Item": {Content: "Call of Duty IV"}, 951 "Status": {Content: "shipped"}, 952 "Popularity": {Content: "90%"}, 953 }, { 954 "Order ID": {Content: "OR9842"}, 955 "Item": {Content: "Call of Duty IV"}, 956 "Status": {Content: "shipped"}, 957 "Popularity": {Content: "90%"}, 958 }, { 959 "Order ID": {Content: "OR9842"}, 960 "Item": {Content: "Call of Duty IV"}, 961 "Status": {Content: "shipped"}, 962 "Popularity": {Content: "90%"}, 963 }, 964 }).SetThead(types.Thead{ 965 {Head: "Order ID"}, 966 {Head: "Item"}, 967 {Head: "Status"}, 968 {Head: "Popularity"}, 969 }).GetContent() 970 971 boxInfo := components.Box(). 972 WithHeadBorder(). 973 SetHeader("Latest Orders"). 974 SetHeadColor("#f7f7f7"). 975 SetBody(table). 976 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>` + "`" + `). 977 GetContent() 978 979 tableCol := colComp.SetSize(types.SizeMD(8)).SetContent(row1 + boxInfo).GetContent() 980 981 /************************** 982 * Product List 983 /**************************/ 984 985 productList := productlist.New().SetData([]map[string]string{ 986 { 987 "img": "//adminlte.io/themes/AdminLTE/dist/img/default-50x50.gif", 988 "title": "GoAdmin", 989 "has_tabel": "true", 990 "labeltype": "warning", 991 "label": "free", 992 "description": ` + "`" + `a framework help you build the dataviz system` + "`" + `, 993 }, { 994 "img": "//adminlte.io/themes/AdminLTE/dist/img/default-50x50.gif", 995 "title": "GoAdmin", 996 "has_tabel": "true", 997 "labeltype": "warning", 998 "label": "free", 999 "description": ` + "`" + `a framework help you build the dataviz system` + "`" + `, 1000 }, { 1001 "img": "//adminlte.io/themes/AdminLTE/dist/img/default-50x50.gif", 1002 "title": "GoAdmin", 1003 "has_tabel": "true", 1004 "labeltype": "warning", 1005 "label": "free", 1006 "description": ` + "`" + `a framework help you build the dataviz system` + "`" + `, 1007 }, { 1008 "img": "//adminlte.io/themes/AdminLTE/dist/img/default-50x50.gif", 1009 "title": "GoAdmin", 1010 "has_tabel": "true", 1011 "labeltype": "warning", 1012 "label": "free", 1013 "description": ` + "`" + `a framework help you build the dataviz system` + "`" + `, 1014 }, 1015 }).GetContent() 1016 1017 boxWarning := components.Box().SetTheme("warning").WithHeadBorder().SetHeader("Recently Added Products"). 1018 SetBody(productList). 1019 SetFooter(` + "`" + `<a href="javascript:void(0)" class="uppercase">View All Products</a>` + "`" + `). 1020 GetContent() 1021 1022 newsCol := colComp.SetSize(types.SizeMD(4)).SetContent(boxWarning).GetContent() 1023 1024 row5 := components.Row().SetContent(tableCol + newsCol).GetContent() 1025 1026 /************************** 1027 * Box 1028 /**************************/ 1029 1030 line := chartjs.Line() 1031 1032 lineChart := line. 1033 SetID("salechart"). 1034 SetHeight(180). 1035 SetTitle("Sales: 1 Jan, 2019 - 30 Jul, 2019"). 1036 SetLabels([]string{"January", "February", "March", "April", "May", "June", "July"}). 1037 AddDataSet("Electronics"). 1038 DSData([]float64{65, 59, 80, 81, 56, 55, 40}). 1039 DSFill(false). 1040 DSBorderColor("rgb(210, 214, 222)"). 1041 DSLineTension(0.1). 1042 AddDataSet("Digital Goods"). 1043 DSData([]float64{28, 48, 40, 19, 86, 27, 90}). 1044 DSFill(false). 1045 DSBorderColor("rgba(60,141,188,1)"). 1046 DSLineTension(0.1). 1047 GetContent() 1048 1049 title := ` + "`" + `<p class="text-center"><strong>Goal Completion</strong></p>` + "`" + ` 1050 progressGroup := progress_group.New(). 1051 SetTitle("Add Products to Cart"). 1052 SetColor("#76b2d4"). 1053 SetDenominator(200). 1054 SetMolecular(160). 1055 SetPercent(80). 1056 GetContent() 1057 1058 progressGroup1 := progress_group.New(). 1059 SetTitle("Complete Purchase"). 1060 SetColor("#f17c6e"). 1061 SetDenominator(400). 1062 SetMolecular(310). 1063 SetPercent(80). 1064 GetContent() 1065 1066 progressGroup2 := progress_group.New(). 1067 SetTitle("Visit Premium Page"). 1068 SetColor("#ace0ae"). 1069 SetDenominator(800). 1070 SetMolecular(490). 1071 SetPercent(80). 1072 GetContent() 1073 1074 progressGroup3 := progress_group.New(). 1075 SetTitle("Send Inquiries"). 1076 SetColor("#fdd698"). 1077 SetDenominator(500). 1078 SetMolecular(250). 1079 SetPercent(50). 1080 GetContent() 1081 1082 boxInternalCol1 := colComp.SetContent(lineChart).SetSize(types.SizeMD(8)).GetContent() 1083 boxInternalCol2 := colComp. 1084 SetContent(template.HTML(title) + progressGroup + progressGroup1 + progressGroup2 + progressGroup3). 1085 SetSize(types.SizeMD(4)). 1086 GetContent() 1087 1088 boxInternalRow := components.Row().SetContent(boxInternalCol1 + boxInternalCol2).GetContent() 1089 1090 description1 := description.New(). 1091 SetPercent("17"). 1092 SetNumber("¥140,100"). 1093 SetTitle("TOTAL REVENUE"). 1094 SetArrow("up"). 1095 SetColor("green"). 1096 SetBorder("right"). 1097 GetContent() 1098 1099 description2 := description.New(). 1100 SetPercent("2"). 1101 SetNumber("440,560"). 1102 SetTitle("TOTAL REVENUE"). 1103 SetArrow("down"). 1104 SetColor("red"). 1105 SetBorder("right"). 1106 GetContent() 1107 1108 description3 := description.New(). 1109 SetPercent("12"). 1110 SetNumber("¥140,050"). 1111 SetTitle("TOTAL REVENUE"). 1112 SetArrow("up"). 1113 SetColor("green"). 1114 SetBorder("right"). 1115 GetContent() 1116 1117 description4 := description.New(). 1118 SetPercent("1"). 1119 SetNumber("30943"). 1120 SetTitle("TOTAL REVENUE"). 1121 SetArrow("up"). 1122 SetColor("green"). 1123 GetContent() 1124 1125 size2 := types.SizeSM(3).XS(6) 1126 boxInternalCol3 := colComp.SetContent(description1).SetSize(size2).GetContent() 1127 boxInternalCol4 := colComp.SetContent(description2).SetSize(size2).GetContent() 1128 boxInternalCol5 := colComp.SetContent(description3).SetSize(size2).GetContent() 1129 boxInternalCol6 := colComp.SetContent(description4).SetSize(size2).GetContent() 1130 1131 boxInternalRow2 := components.Row().SetContent(boxInternalCol3 + boxInternalCol4 + boxInternalCol5 + boxInternalCol6).GetContent() 1132 1133 box := components.Box().WithHeadBorder().SetHeader("Monthly Recap Report"). 1134 SetBody(boxInternalRow). 1135 SetFooter(boxInternalRow2). 1136 GetContent() 1137 1138 boxcol := colComp.SetContent(box).SetSize(types.SizeMD(12)).GetContent() 1139 row2 := components.Row().SetContent(boxcol).GetContent() 1140 1141 /************************** 1142 * Small Box 1143 /**************************/ 1144 1145 smallbox1 := smallbox.New().SetColor("blue").SetIcon("ion-ios-gear-outline").SetUrl("/").SetTitle("new users").SetValue("345¥").GetContent() 1146 smallbox2 := smallbox.New().SetColor("yellow").SetIcon("ion-ios-cart-outline").SetUrl("/").SetTitle("new users").SetValue("80%").GetContent() 1147 smallbox3 := smallbox.New().SetColor("red").SetIcon("fa-user").SetUrl("/").SetTitle("new users").SetValue("645¥").GetContent() 1148 smallbox4 := smallbox.New().SetColor("green").SetIcon("ion-ios-cart-outline").SetUrl("/").SetTitle("new users").SetValue("889¥").GetContent() 1149 1150 col1 := colComp.SetSize(size).SetContent(smallbox1).GetContent() 1151 col2 := colComp.SetSize(size).SetContent(smallbox2).GetContent() 1152 col3 := colComp.SetSize(size).SetContent(smallbox3).GetContent() 1153 col4 := colComp.SetSize(size).SetContent(smallbox4).GetContent() 1154 1155 row3 := components.Row().SetContent(col1 + col2 + col3 + col4).GetContent() 1156 1157 /************************** 1158 * Pie Chart 1159 /**************************/ 1160 1161 pie := chartjs.Pie(). 1162 SetHeight(170). 1163 SetLabels([]string{"Navigator", "Opera", "Safari", "FireFox", "IE", "Chrome"}). 1164 SetID("pieChart"). 1165 AddDataSet("Chrome"). 1166 DSData([]float64{100, 300, 600, 400, 500, 700}). 1167 DSBackgroundColor([]chartjs.Color{ 1168 "rgb(255, 205, 86)", "rgb(54, 162, 235)", "rgb(255, 99, 132)", "rgb(255, 205, 86)", "rgb(54, 162, 235)", "rgb(255, 99, 132)", 1169 }). 1170 GetContent() 1171 1172 legend := chart_legend.New().SetData([]map[string]string{ 1173 { 1174 "label": " Chrome", 1175 "color": "red", 1176 }, { 1177 "label": " IE", 1178 "color": "Green", 1179 }, { 1180 "label": " FireFox", 1181 "color": "yellow", 1182 }, { 1183 "label": " Sarafri", 1184 "color": "blue", 1185 }, { 1186 "label": " Opera", 1187 "color": "light-blue", 1188 }, { 1189 "label": " Navigator", 1190 "color": "gray", 1191 }, 1192 }).GetContent() 1193 1194 boxDanger := components.Box().SetTheme("danger").WithHeadBorder().SetHeader("Browser Usage"). 1195 SetBody(components.Row(). 1196 SetContent(colComp.SetSize(types.SizeMD(8)). 1197 SetContent(pie). 1198 GetContent() + colComp.SetSize(types.SizeMD(4)). 1199 SetContent(legend). 1200 GetContent()).GetContent()). 1201 SetFooter(` + "`" + `<p class="text-center"><a href="javascript:void(0)" class="uppercase">View All Users</a></p>` + "`" + `). 1202 GetContent() 1203 1204 tabs := components.Tabs().SetData([]map[string]template.HTML{ 1205 { 1206 "title": "tabs1", 1207 "content": template.HTML(` + "`" + `<b>How to use:</b> 1208 1209 <p>Exactly like the original bootstrap tabs except you should use 1210 the custom wrapper <code>.nav-tabs-custom</code> to achieve this style.</p> 1211 A wonderful serenity has taken possession of my entire soul, 1212 like these sweet mornings of spring which I enjoy with my whole heart. 1213 I am alone, and feel the charm of existence in this spot, 1214 which was created for the bliss of souls like mine. I am so happy, 1215 my dear friend, so absorbed in the exquisite sense of mere tranquil existence, 1216 that I neglect my talents. I should be incapable of drawing a single stroke 1217 at the present moment; and yet I feel that I never was a greater artist than now.` + "`" + `), 1218 }, { 1219 "title": "tabs2", 1220 "content": template.HTML(` + "`" + ` 1221 The European languages are members of the same family. Their separate existence is a myth. 1222 For science, music, sport, etc, Europe uses the same vocabulary. The languages only differ 1223 in their grammar, their pronunciation and their most common words. Everyone realizes why a 1224 new common language would be desirable: one could refuse to pay expensive translators. To 1225 achieve this, it would be necessary to have uniform grammar, pronunciation and more common 1226 words. If several languages coalesce, the grammar of the resulting language is more simple 1227 and regular than that of the individual languages. 1228 ` + "`" + `), 1229 }, { 1230 "title": "tabs3", 1231 "content": template.HTML(` + "`" + ` 1232 Lorem Ipsum is simply dummy text of the printing and typesetting industry. 1233 Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, 1234 when an unknown printer took a galley of type and scrambled it to make a type specimen book. 1235 It has survived not only five centuries, but also the leap into electronic typesetting, 1236 remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset 1237 sheets containing Lorem Ipsum passages, and more recently with desktop publishing software 1238 like Aldus PageMaker including versions of Lorem Ipsum. 1239 ` + "`" + `), 1240 }, 1241 }).GetContent() 1242 1243 buttonTest := ` + "`" + `<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal" data-whatever="@mdo">Open modal for @mdo</button>` + "`" + ` 1244 popupForm := ` + "`" + `<form> 1245 <div class="form-group"> 1246 <label for="recipient-name" class="col-form-label">Recipient:</label> 1247 <input type="text" class="form-control" id="recipient-name"> 1248 </div> 1249 <div class="form-group"> 1250 <label for="message-text" class="col-form-label">Message:</label> 1251 <textarea class="form-control" id="message-text"></textarea> 1252 </div> 1253 </form>` + "`" + ` 1254 popup := components.Popup().SetID("exampleModal"). 1255 SetFooter("Save Change"). 1256 SetTitle("this is a popup"). 1257 SetBody(template.HTML(popupForm)). 1258 GetContent() 1259 1260 col5 := colComp.SetSize(types.SizeMD(8)).SetContent(tabs + template.HTML(buttonTest)).GetContent() 1261 col6 := colComp.SetSize(types.SizeMD(4)).SetContent(boxDanger + popup).GetContent() 1262 1263 row4 := components.Row().SetContent(col5 + col6).GetContent() 1264 1265 return types.Panel{ 1266 Content: row3 + row2 + row5 + row4, 1267 Title: "Dashboard", 1268 Description: "dashboard example", 1269 }, nil 1270 }`) 1271 1272 var mainTest = []byte(`package main 1273 1274 import ( 1275 "./tables" 1276 "github.com/kotovmak/go-admin/modules/config" 1277 "github.com/kotovmak/go-admin/tests" 1278 "github.com/kotovmak/go-admin/tests/common" 1279 "github.com/kotovmak/go-admin/tests/frameworks/gin" 1280 "github.com/kotovmak/go-admin/tests/web" 1281 "github.com/gavv/httpexpect" 1282 "log" 1283 "testing" 1284 ) 1285 1286 // Black box testing 1287 func TestMainBlackBox(t *testing.T) { 1288 cfg := config.ReadFromJson("./config.json") 1289 tests.BlackBoxTestSuit(t, gin.NewHandler, cfg.Databases, tables.Generators, func(cfg config.DatabaseList) { 1290 // Data cleaner of the framework 1291 tests.Cleaner(cfg) 1292 // Clean your own data: 1293 // ... 1294 }, func(e *httpexpect.Expect) { 1295 // Test cases of the framework 1296 common.Test(e) 1297 // Write your own API test, for example: 1298 // More usages: https://github.com/gavv/httpexpect 1299 // e.POST("/signin").Expect().Status(http.StatusOK) 1300 }) 1301 } 1302 1303 // User acceptance testing 1304 func TestMainUserAcceptance(t *testing.T) { 1305 web.UserAcceptanceTestSuit(t, func(t *testing.T, page *web.Page) { 1306 // Write test case base on chromedriver, for example: 1307 // More usages: https://github.com/sclevine/agouti 1308 page.NavigateTo("http://127.0.0.1:9033/admin") 1309 //page.Contain("username") 1310 //page.Click("") 1311 }, func(quit chan struct{}) { 1312 // start the server: 1313 // .... 1314 go startServer() 1315 <-quit 1316 log.Print("test quit") 1317 }, true) // if local parameter is true, it will not be headless, and window not close when finishing tests. 1318 }`) 1319 1320 var mainTestCN = []byte(`package main 1321 1322 import ( 1323 "./tables" 1324 "github.com/kotovmak/go-admin/modules/config" 1325 "github.com/kotovmak/go-admin/tests" 1326 "github.com/kotovmak/go-admin/tests/common" 1327 "github.com/kotovmak/go-admin/tests/frameworks/gin" 1328 "github.com/kotovmak/go-admin/tests/web" 1329 "github.com/gavv/httpexpect" 1330 "log" 1331 "testing" 1332 ) 1333 1334 // 黑盒测试 1335 func TestMainBlackBox(t *testing.T) { 1336 cfg := config.ReadFromJson("./config.json") 1337 tests.BlackBoxTestSuit(t, gin.NewHandler, cfg.Databases, tables.Generators, func(cfg config.DatabaseList) { 1338 // 框架自带数据清理 1339 tests.Cleaner(cfg) 1340 // 以下清理自己的数据: 1341 // ... 1342 }, func(e *httpexpect.Expect) { 1343 // 框架自带内置表测试 1344 common.Test(e) 1345 // 以下写API测试: 1346 // 更多用法:https://github.com/gavv/httpexpect 1347 // ... 1348 // e.POST("/signin").Expect().Status(http.StatusOK) 1349 }) 1350 } 1351 1352 // 浏览器验收测试 1353 func TestMainUserAcceptance(t *testing.T) { 1354 web.UserAcceptanceTestSuit(t, func(t *testing.T, page *web.Page) { 1355 // 写浏览器测试,基于chromedriver 1356 // 更多用法:https://github.com/sclevine/agouti 1357 // page.NavigateTo("http://127.0.0.1:9033/admin") 1358 // page.Contain("username") 1359 // page.Click("") 1360 }, func(quit chan struct{}) { 1361 // 启动服务器 1362 go startServer() 1363 <-quit 1364 log.Print("test quit") 1365 }, true) 1366 }`) 1367 1368 var makefile = []byte(`GOCMD = go 1369 GOBUILD = $(GOCMD) build 1370 GOMOD = $(GOCMD) mod 1371 GOTEST = $(GOCMD) test 1372 BINARY_NAME = goadmin 1373 CLI = adm 1374 1375 all: serve 1376 1377 init: 1378 $(GOMOD) init $(module) 1379 1380 install: 1381 $(GOMOD) tidy 1382 1383 serve: 1384 $(GOCMD) run . 1385 1386 build: 1387 CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOBUILD) -o ./build/$(BINARY_NAME) -v ./ 1388 1389 generate: 1390 $(CLI) generate -c adm.ini 1391 1392 test: black-box-test user-acceptance-test 1393 1394 black-box-test: ready-for-data 1395 $(GOTEST) -v -test.run=TestMainBlackBox 1396 make clean 1397 1398 user-acceptance-test: ready-for-data 1399 $(GOTEST) -v -test.run=TestMainUserAcceptance 1400 make clean 1401 1402 ready-for-data: 1403 cp admin.db admin_test.db 1404 1405 clean: 1406 rm admin_test.db 1407 1408 .PHONY: all serve build generate test black-box-test user-acceptance-test ready-for-data clean`) 1409 1410 var admINI = `{{define "ini"}} 1411 ; default database config 默认数据库配置 1412 [database]{{if eq .DriverName "sqlite"}} 1413 driver = sqlite 1414 file = {{.File}} 1415 {{else}} 1416 driver = {{.DriverName}} 1417 host = {{.Host}} 1418 username = {{.User}} 1419 port = {{.Port}} 1420 password = {{.Password}} 1421 database = {{.Database}} 1422 {{end}} 1423 ; Here are new tables to generate. 新的待转换的表格 1424 ; tables = new_table1,new_table2 1425 1426 ; specified connection database config 指定数据库配置 1427 ; for example, database config which connection name is mydb. 1428 ;[database.mydb] 1429 1430 ; table model config 数据模型设置 1431 [model] 1432 package = tables 1433 connection = default 1434 output = ./tables 1435 {{end}}` 1436 1437 var readme = `# GoAdmin Instruction 1438 1439 GoAdmin is a golang framework help gopher quickly build a data visualization platform. 1440 1441 - [github](https://github.com/GoAdminGroup/go-admin) 1442 - [forum](http://discuss.go-admin.com) 1443 - [document](https://book.go-admin.cn) 1444 1445 ## Directories Introduction 1446 1447 ` + "```" + ` 1448 . 1449 ├── Dockerfile Dockerfile 1450 ├── Makefile Makefile 1451 ├── adm.ini adm config 1452 ├── admin.db sqlite database 1453 ├── build binary build target folder 1454 ├── config.json config file 1455 ├── go.mod go.mod 1456 ├── go.sum go.sum 1457 ├── html frontend html files 1458 ├── logs logs 1459 ├── main.go main.go 1460 ├── main_test.go ci test 1461 ├── pages page controllers 1462 ├── tables table models 1463 └── uploads upload files 1464 ` + "```" + ` 1465 1466 ## Generate Table Model 1467 1468 ### online tool 1469 1470 visit: http://127.0.0.1:%s/info/generate/new 1471 1472 ### use adm 1473 1474 ` + "```" + ` 1475 adm generate 1476 ` + "```" + ` 1477 1478 ` 1479 1480 var readmeCN = `# GoAdmin 介绍 1481 1482 GoAdmin 是一个帮你快速搭建数据可视化管理应用平台的框架。 1483 1484 - [github](https://github.com/GoAdminGroup/go-admin) 1485 - [论坛](http://discuss.go-admin.com) 1486 - [文档](https://book.go-admin.cn) 1487 1488 ## 目录介绍 1489 1490 ` + "```" + ` 1491 . 1492 ├── Dockerfile Dockerfile 1493 ├── Makefile Makefile 1494 ├── adm.ini adm配置文件 1495 ├── admin.db sqlite数据库 1496 ├── build 二进制构建目标文件夹 1497 ├── config.json 配置文件 1498 ├── go.mod go.mod 1499 ├── go.sum go.sum 1500 ├── html 前端html文件 1501 ├── logs 日志 1502 ├── main.go main.go 1503 ├── main_test.go CI测试 1504 ├── pages 页面控制器 1505 ├── tables 数据模型 1506 └── uploads 上传文件夹 1507 ` + "```" + ` 1508 1509 ## 生成CRUD数据模型 1510 1511 ### 在线工具 1512 1513 管理员身份运行后,访问:http://127.0.0.1:%s/info/generate/new 1514 1515 ### 使用命令行工具 1516 1517 ` + "```" + ` 1518 adm generate -l cn -c adm.ini 1519 ` + "```" + ` 1520 1521 `