Skip to content

Commit

Permalink
feat✨:
Browse files Browse the repository at this point in the history
  • Loading branch information
wcz0 committed Oct 1, 2024
1 parent a8f3d94 commit 00bebfe
Show file tree
Hide file tree
Showing 5 changed files with 392 additions and 212 deletions.
220 changes: 190 additions & 30 deletions app/http/controllers/admin/home_controller.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package admin

import (
"goravel/app/tools"

"github.com/goravel/framework/contracts/http"
"github.com/goravel/framework/facades"
"github.com/wcz0/gamis"
"github.com/wcz0/gamis/renderers"
)

type HomeController struct {
Expand All @@ -19,14 +23,169 @@ func NewHomeController() *HomeController {
func (h *HomeController) Index(ctx http.Context) http.Response {
page := h.Controller.BasePage().Css(h.css(ctx)).Body([]any{
gamis.Grid().ClassName("mb-1").Columns([]any{
// h.frameworkInfo(ctx).Set("md", 5),
// gamis.Flex().Items([]any{
// )
h.frameworkInfo().Set("md", 5),
gamis.Flex().Items([]any{
h.pieChart(),
h.cube(),
}),
}),
gamis.Grid().Columns([]any{
h.lineChart().Set("md", 8),
gamis.Flex().ClassName("h-full").Items([]any{
h.clock(),
h.codeView(),
}).Direction("column"),
}),
})
return h.SuccessData(ctx, page)
}

func (h *HomeController) codeView() *renderers.Card {
return gamis.Card().ClassName("h-full clear-card-mb rounded-md").Body([]any{
gamis.Markdown().Options(map[string]any{"html": true, "breaks": true}).Value(`
### __The beginning of everything__
<br>
`),
})
}

func (h *HomeController) clock() *renderers.Card {
return gamis.Card().ClassName("h-full bg-blingbling mb-4").Header(map[string]string{"title": "Clock"}).Body([]any{
gamis.Custom().Name("clock").Html(`
<div id="clock" class="text-4xl"></div><div id="clock-date" class="mt-5"></div>
`).OnMount(`
const clock = document.getElementById('clock');
const tick = () => {
clock.innerHTML = (new Date()).toLocaleTimeString();
requestAnimationFrame(tick);
};
tick();
const clockDate = document.getElementById('clock-date');
clockDate.innerHTML = (new Date()).toLocaleDateString();
`),
})

}

func (h *HomeController) pieChart() *renderers.Card {
return gamis.Card().ClassName("h-96").Body([]any{
gamis.Chart().Height(350).Config(map[string]any{
"backgroundColor": "",
"tooltip": map[string]string{
"trigger": "item",
},
"legend": map[string]string{
"bottom": "0",
"left": "center",
},
"series": []map[string]any{
{
"name": "Access From",
"type": "pie",
"radius": []string{"40%", "70%"},
"avoidLabelOverlap": false,
"itemStyle": map[string]any{
"borderRadius": 10,
"borderColor": "#fff",
"borderWidth": 2,
},
"label": map[string]any{"show": false, "position": "center"},
"emphasis": map[string]any{
"label": map[string]any{
"show": true,
"fontSize": "40",
"fontWeight": "bold",
},
},
"labelLine": map[string]any{"show": false},
"data": []map[string]any{
{"value": 1048, "name": "Search Engine"},
{"value": 735, "name": "Direct"},
{"value": 580, "name": "Email"},
{"value": 484, "name": "Union Ads"},
{"value": 300, "name": "Video Ads"},
},
},
},
}),
})
}

func (h *HomeController) cube() *renderers.Card {
return gamis.Card().ClassName("h-96 ml-4 w-8/12").Body([]any{
gamis.Html().Html(`
<style>
.cube-box{ height: 300px; display: flex; align-items: center; justify-content: center; }
.cube { width: 100px; height: 100px; position: relative; transform-style: preserve-3d; animation: rotate 10s linear infinite; }
.cube:after {
content: '';
width: 100%;
height: 100%;
box-shadow: 0 0 50px rgba(0, 0, 0, 0.2);
position: absolute;
transform-origin: bottom;
transform-style: preserve-3d;
transform: rotateX(90deg) translateY(50px) translateZ(-50px);
background-color: rgba(0, 0, 0, 0.1);
}
.cube div {
background-color: rgba(64, 158, 255, 0.7);
position: absolute;
width: 100%;
height: 100%;
border: 1px solid rgb(27, 99, 170);
box-shadow: 0 0 60px rgba(64, 158, 255, 0.7);
}
.cube div:nth-child(1) { transform: translateZ(-50px); animation: shade 10s -5s linear infinite; }
.cube div:nth-child(2) { transform: translateZ(50px) rotateY(180deg); animation: shade 10s linear infinite; }
.cube div:nth-child(3) { transform-origin: right; transform: translateZ(50px) rotateY(270deg); animation: shade 10s -2.5s linear infinite; }
.cube div:nth-child(4) { transform-origin: left; transform: translateZ(50px) rotateY(90deg); animation: shade 10s -7.5s linear infinite; }
.cube div:nth-child(5) { transform-origin: bottom; transform: translateZ(50px) rotateX(90deg); background-color: rgba(0, 0, 0, 0.7); }
.cube div:nth-child(6) { transform-origin: top; transform: translateZ(50px) rotateX(270deg); }
@keyframes rotate {
0% { transform: rotateX(-15deg) rotateY(0deg); }
100% { transform: rotateX(-15deg) rotateY(360deg); }
}
@keyframes shade { 50% { background-color: rgba(0, 0, 0, 0.7); } }
</style>
<div class="cube-box">
<div class="cube">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
</div>
`),
})
}

func (h *HomeController) lineChart() *renderers.Card {
random1 := []int{50, 200, 100, 150, 180, 130, 160}
random2 := []int{150, 100, 180, 130, 160, 50, 200}
chart := gamis.Chart().Height(380).ClassName("h-96").Config(map[string]any{
"backgroundColor": "",
"title": map[string]string{"text": "Users Behavior"},
"tooltip": map[string]string{"trigger": "axis"},
"xAxis": []map[string]any{
{"type": "category", "boundaryGap": false, "data": []string{"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"}},
},
"yAxis": []map[string]string{{"type": "value"}},
"grid": map[string]string{"left": "7%", "right": "3%", "top": "60", "bottom": "30"},
"legend": map[string][]string{"data": {"Visits", "Bounce Rate"}},
"series": []map[string]any{
{"name": "Visits", "data": random1, "type": "line", "areaStyle": []string{}, "smooth": true, "symbol": "none"},
{"name": "Bounce Rate", "data": random2, "type": "line", "areaStyle": []string{}, "smooth": true, "symbol": "none"},
},
})
return gamis.Card().ClassName("clear-card-mb").Body(chart)
}

// GET /resource/{id}
func (h *HomeController) Show(ctx http.Context) http.Response {
return h.Success(ctx)
Expand All @@ -47,33 +206,34 @@ func (h *HomeController) Destroy(ctx http.Context) http.Response {
return h.Success(ctx)
}

// func (h *HomeController) frameworkInfo(ctx http.Context) renderers.Card {
// link = func(label any, link string) renderers.Action {
// return *gamis.Action().
// Level("link").
// ClassName("text-lg font-semibold").
// Label(label).
// Set("blank", true).
// ActionType("url").
// Link(link)
// }
// config := facades.Config()
// return gamis.Card().ClassName("h-96").Body(
// gamis.Wrapper().ClassName("h-full").Body(
// gamis.Flex().ClassName("h-full").Direction("column").
// Justify("center").
// AlignItems("center").
// Items([]any{
// gamis.Image().Src(tools.Url(config.GetString("app.logo"))),
// gamis.Wrapper().ClassName("text-3xl mt-9 font-bold").Body(config.GetString("admin.name")),
// gamis.Flex().ClassName("w-full mt-5").Justify("center").Items([]any{
// link("Github", "https://github.com/wcz0/goravel-admin"),
// // link("Amis")
// }),
// }),
// ),
// )
// }
func (h *HomeController) frameworkInfo() *renderers.Card {
link := func(label any, link string) renderers.Action {
return *gamis.Action().
Level("link").
ClassName("text-lg font-semibold").
Label(label).
Set("blank", true).
ActionType("url").
Link(link)
}
config := facades.Config()
return gamis.Card().ClassName("h-96").Body(
gamis.Wrapper().ClassName("h-full").Body(
gamis.Flex().
ClassName("h-full").
Direction("column").
Justify("center").
AlignItems("center").
Items([]any{
gamis.Image().Src(tools.Url(config.GetString("app.logo"))),
gamis.Wrapper().ClassName("text-3xl mt-9 font-bold").Body(config.GetString("admin.name")),
gamis.Flex().ClassName("w-full mt-5").Justify("center").Items([]any{
link("Github", "https://github.com/wcz0/goravel-admin"),
}),
}),
),
)
}

func (h *HomeController) css(ctx http.Context) map[string]any {
return map[string]any{
Expand Down
19 changes: 19 additions & 0 deletions config/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import (
"github.com/goravel/framework/contracts/route"
"github.com/goravel/framework/facades"
ginfacades "github.com/goravel/gin/facades"
// fiberfacades "github.com/goravel/fiber/facades"
// "github.com/gofiber/template/html/v2"
// "github.com/gofiber/fiber/v2"
)

func init() {
Expand All @@ -17,7 +20,23 @@ func init() {
"route": func() (route.Route, error) {
return ginfacades.Route("gin"), nil
},
"body_limit": 4096,
"header_limit": 4096,
},
// "fiber": map[string]any{
// // prefork mode, see https://docs.gofiber.io/api/fiber/#config
// "prefork": false,
// // Optional, default is 4096 KB
// "body_limit": 4096,
// "header_limit": 4096,
// "route": func() (route.Route, error) {
// return fiberfacades.Route("fiber"), nil
// },
// // Optional, default is "html/template"
// "template": func() (fiber.Views, error) {
// return html.New("./resources/views", ".tmpl"), nil
// },
// },
},
// HTTP URL
"url": config.Env("APP_URL", "http://localhost"),
Expand Down
Loading

0 comments on commit 00bebfe

Please sign in to comment.