Merge branch 'andy/table'
This commit is contained in:
@@ -6,8 +6,11 @@ import (
|
||||
"strconv"
|
||||
|
||||
"github.com/a-h/templ"
|
||||
"github.com/emarifer/go-templ-project-structure/models"
|
||||
"github.com/emarifer/go-templ-project-structure/services"
|
||||
"github.com/emarifer/go-templ-project-structure/views/component/customtextfieldautocomplete"
|
||||
"github.com/emarifer/go-templ-project-structure/views/component/pagination"
|
||||
tablecomponent "github.com/emarifer/go-templ-project-structure/views/component/table"
|
||||
mastermenuusergroup "github.com/emarifer/go-templ-project-structure/views/mastermenuusergroup"
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
@@ -15,6 +18,8 @@ import (
|
||||
type MasterMenuUserGroupService interface {
|
||||
GetMasterMenus() ([]services.MasterMenu, error)
|
||||
GetAutoComplete(param string, pageOf string, limit string) (string, string, string, []services.AutoComplete, error)
|
||||
GetUserGroup() ([]models.UserGroup, error)
|
||||
GetUserGroupByID(id string) (models.UserGroup, error)
|
||||
}
|
||||
|
||||
func NewMasterMenuUserGroupHandler(us MasterMenuUserGroupService) *MasterMenuUserGroupHandler {
|
||||
@@ -35,18 +40,28 @@ func (lh *MasterMenuUserGroupHandler) HandlerShowMasterMenuUserGroup(c echo.Cont
|
||||
fmt.Println(dataMenu)
|
||||
return err
|
||||
}
|
||||
// fmt.Printf("%+v\n", dataMenu)
|
||||
// si := mastermenu.ShowMasterMenu("Master Menu",
|
||||
// mastermenu.MainMasterMenu(dataMenu),
|
||||
// mastermenu.CssMasterMenu(),
|
||||
// mastermenu.JsMasterMenu(),
|
||||
// )
|
||||
dataUser, err := services.GetUser()
|
||||
fmt.Println(dataUser)
|
||||
fmt.Println(err)
|
||||
if err != nil {
|
||||
fmt.Println(dataUser)
|
||||
return err
|
||||
}
|
||||
dataUserGroup, err := lh.MasterMenuUserGroupService.GetUserGroup()
|
||||
fmt.Println(dataUserGroup)
|
||||
fmt.Println(err)
|
||||
if err != nil {
|
||||
fmt.Println(dataUserGroup)
|
||||
return err
|
||||
}
|
||||
|
||||
si := mastermenuusergroup.ShowMasterMenuUserGroup(
|
||||
"Master Menu",
|
||||
mastermenuusergroup.MainMasterMenuUserGroup(dataMenu),
|
||||
mastermenuusergroup.ContentMasterMenuUserGroup(dataUserGroup),
|
||||
mastermenuusergroup.CssMasterMenuUserGroup(),
|
||||
mastermenuusergroup.JsMasterMenuUserGroup(),
|
||||
dataMenu,
|
||||
dataUser,
|
||||
)
|
||||
|
||||
return lh.View(c, si)
|
||||
@@ -219,6 +234,42 @@ func (lh *MasterMenuUserGroupHandler) HandlerAutoCompleteExample(c echo.Context)
|
||||
|
||||
return lh.View(c, si)
|
||||
}
|
||||
func (lh *MasterMenuUserGroupHandler) ChangeFormEdit(c echo.Context) error {
|
||||
id := c.QueryParam("id")
|
||||
dataUserGroup, err := lh.MasterMenuUserGroupService.GetUserGroupByID(id)
|
||||
fmt.Println(dataUserGroup)
|
||||
fmt.Println(err)
|
||||
if err != nil {
|
||||
fmt.Println(dataUserGroup)
|
||||
return err
|
||||
}
|
||||
vw := mastermenuusergroup.DialogEditForm(dataUserGroup.UserGroupKode, dataUserGroup.UserGroupName)
|
||||
|
||||
return lh.View(c, vw)
|
||||
}
|
||||
func (lh *MasterMenuUserGroupHandler) HandleChangePage(c echo.Context) error {
|
||||
page := c.QueryParam("page")
|
||||
currPage := c.QueryParam("currentPage")
|
||||
dataUserGroup, err := lh.MasterMenuUserGroupService.GetUserGroup()
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(dataUserGroup)
|
||||
return err
|
||||
}
|
||||
pageInt, err := strconv.Atoi(page)
|
||||
if err != nil {
|
||||
fmt.Println("page err")
|
||||
return err
|
||||
}
|
||||
currPageInt, err := strconv.Atoi(currPage)
|
||||
if err != nil {
|
||||
fmt.Println("currpage err")
|
||||
return err
|
||||
}
|
||||
vw := tablecomponent.Table([]string{"KODE", "USERGROUP", "AKSI"}, []string{"40%", "40%", "20%"}, mastermenuusergroup.TableRow(dataUserGroup), pagination.Pagination(pageInt, currPageInt))
|
||||
|
||||
return lh.View(c, vw)
|
||||
}
|
||||
|
||||
func (uh *MasterMenuUserGroupHandler) View(c echo.Context, cmp templ.Component) error {
|
||||
c.Response().Header().Set(echo.HeaderContentType, echo.MIMETextHTML)
|
||||
|
||||
@@ -18,6 +18,9 @@ func SetupRoutesLogin(app *echo.Echo, h *LoginHandler) {
|
||||
func SetupRoutesXsample(app *echo.Echo, h *XsampleHandler) {
|
||||
xSample := app.Group("/xsample")
|
||||
xSample.GET("/xsample01", h.Hello)
|
||||
xSample.GET("/coba", h.ShowCoba)
|
||||
xSample.GET("/counter", h.ShowCounter)
|
||||
xSample.GET("/counterchange", h.ChangeCounter)
|
||||
}
|
||||
func SetupRoutesLandingPage(app *echo.Echo, h *LandingPageHandler, mastermenuusergroupHandler *MasterMenuUserGroupHandler) {
|
||||
Lp := app.Group("/landing_page")
|
||||
@@ -30,6 +33,8 @@ func SetupRoutesLandingPage(app *echo.Echo, h *LandingPageHandler, mastermenuuse
|
||||
autocomplete.GET("/autocomplete", mastermenuusergroupHandler.HandlerListAutoComplete)
|
||||
autocomplete.GET("/autoCompleteLoadMore/:pageOf/:searchParam/:limit", mastermenuusergroupHandler.HandlerListAutoCompleteLoadMore)
|
||||
autocomplete.GET("/autoCompleteSetValue/:setvalue", mastermenuusergroupHandler.HandlerListAutoCompleteAfterSelected)
|
||||
clientgroup.GET("/usergroup/edit", mastermenuusergroupHandler.ChangeFormEdit)
|
||||
clientgroup.GET("/usergroup/pagination", mastermenuusergroupHandler.HandleChangePage)
|
||||
|
||||
}
|
||||
func SetupRoutesPieChart(app *echo.Echo, h *PiechartHandler) {
|
||||
|
||||
@@ -1,13 +1,19 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/a-h/templ"
|
||||
"github.com/emarifer/go-templ-project-structure/services"
|
||||
"github.com/emarifer/go-templ-project-structure/utils"
|
||||
"github.com/emarifer/go-templ-project-structure/views/xsample"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
type XsampleService interface {
|
||||
GetListMenus() ([]services.MasterMenu, error)
|
||||
}
|
||||
|
||||
func NewXsampleHandler(us XsampleService) *XsampleHandler {
|
||||
@@ -24,6 +30,66 @@ func (uh *XsampleHandler) Hello(c echo.Context) error {
|
||||
helo := xsample.ShowHelo("Hello World", xsample.HelloWorld("Hello World"), xsample.CssHelo(), xsample.JsHelo())
|
||||
return uh.View(c, helo)
|
||||
}
|
||||
func (uh *XsampleHandler) ShowCoba(c echo.Context) error {
|
||||
dataMenu, err := uh.XsampleService.GetListMenus()
|
||||
fmt.Println(dataMenu)
|
||||
fmt.Println(err)
|
||||
if err != nil {
|
||||
fmt.Println(dataMenu)
|
||||
return err
|
||||
}
|
||||
randomID := utils.GenerateRandomID("coba")
|
||||
fmt.Println(randomID)
|
||||
dataUser, err := services.GetUser()
|
||||
fmt.Println(dataUser)
|
||||
fmt.Println(err)
|
||||
if err != nil {
|
||||
fmt.Println(dataUser)
|
||||
return err
|
||||
}
|
||||
helo := xsample.ShowCoba("Hello World", xsample.Coba("Hello World"), xsample.CssCoba(), xsample.JsCoba(), dataMenu, dataUser)
|
||||
return uh.View(c, helo)
|
||||
}
|
||||
func (uh *XsampleHandler) ShowCounter(c echo.Context) error {
|
||||
typectr := c.QueryParam("type")
|
||||
|
||||
counter := c.QueryParam("counter")
|
||||
if counter == "" {
|
||||
counter = "0"
|
||||
}
|
||||
ctr, err := strconv.Atoi(counter)
|
||||
if err != nil {
|
||||
fmt.Println("Error counter parse int")
|
||||
return err
|
||||
}
|
||||
|
||||
if typectr == "min" {
|
||||
ctr = ctr - 1
|
||||
} else if typectr == "plus" {
|
||||
ctr = ctr + 1
|
||||
}
|
||||
helo := xsample.Page(ctr)
|
||||
return uh.View(c, helo)
|
||||
}
|
||||
func (uh *XsampleHandler) ChangeCounter(c echo.Context) error {
|
||||
|
||||
typectr := c.QueryParam("type")
|
||||
|
||||
counter := c.QueryParam("counter")
|
||||
ctr, err := strconv.Atoi(counter)
|
||||
if err != nil {
|
||||
fmt.Println("Error counter parse int")
|
||||
return err
|
||||
}
|
||||
|
||||
if typectr == "min" {
|
||||
ctr = ctr - 1
|
||||
} else {
|
||||
ctr = ctr + 1
|
||||
}
|
||||
helo := xsample.Counts(ctr)
|
||||
return uh.View(c, helo)
|
||||
}
|
||||
|
||||
func (uh *XsampleHandler) View(c echo.Context, cmp templ.Component) error {
|
||||
c.Response().Header().Set(echo.HeaderContentType, echo.MIMETextHTML)
|
||||
|
||||
Reference in New Issue
Block a user