index.go 14 KB

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