index.go 14 KB

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