listing data minus pagination + bug dislpay group name
This commit is contained in:
@@ -3,18 +3,23 @@ package dev_handlers
|
||||
import (
|
||||
breadcrumbadmin "cpone/component/breadcrumbadmin"
|
||||
navbarmenu "cpone/component/navbar"
|
||||
"cpone/component/pagination"
|
||||
sidebaruserprofile "cpone/component/sidebar_user_profile"
|
||||
"cpone/models"
|
||||
"cpone/services"
|
||||
"cpone/utils"
|
||||
dev_mdsamplestationview "cpone/views/dev/mdsamplestation"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/a-h/templ"
|
||||
"github.com/labstack/echo/v4"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type MDSampleStationServices interface {
|
||||
GetMDSampleStationBreadcrumb() (models.BreadCrumbV1, error)
|
||||
GetListSampleStation(search string, currentPage int, rowPerPage int) ([]models.MDSampleStation, int, error)
|
||||
}
|
||||
|
||||
func NewMDSampleStationHandler(ss MDSampleStationServices) *MDSampleStationHandler {
|
||||
@@ -31,7 +36,13 @@ func (mdss *MDSampleStationHandler) HandleShowMDSampleStationScreen(c echo.Conte
|
||||
logger, _ := zap.NewProduction()
|
||||
title := "Master Sample Station"
|
||||
|
||||
dialogAddID := utils.GenerateRandomID("dialogaddID")
|
||||
tableID := utils.GenerateRandomID("tableID")
|
||||
paginationID := utils.GenerateRandomID("paginationID")
|
||||
dialogAddID := utils.GenerateRandomID("dialogAddID")
|
||||
// dialogEditID := utils.GenerateRandomID("dialogEditID")
|
||||
// dialogEditBodyID := utils.GenerateRandomID("dialogEditBodyID")
|
||||
// dialogDeleteID := utils.GenerateRandomID("dialogDeleteID")
|
||||
// dialogDeleteBodyID := utils.GenerateRandomID("dialogDeleteBodyID")
|
||||
|
||||
dataMenu, err := services.GetMenu()
|
||||
if err != nil {
|
||||
@@ -56,9 +67,35 @@ func (mdss *MDSampleStationHandler) HandleShowMDSampleStationScreen(c echo.Conte
|
||||
breadcrumbComp := breadcrumbadmin.MainBreadcrumbAdminV1(dataBreadcrumb)
|
||||
sidebaruserprofilceComp := sidebaruserprofile.Navbaruserprofile(dataUser)
|
||||
|
||||
// table content
|
||||
dataTable, totalPage, err := mdss.MDSampleStationServices.GetListSampleStation("", 1, 5)
|
||||
if err != nil {
|
||||
defer logger.Sync()
|
||||
logger.Info("ERROR GET LIST SAMPLE STATION", zap.Any("error", err))
|
||||
return err
|
||||
}
|
||||
fmt.Println("data sample station", dataTable)
|
||||
|
||||
tableComponent := dev_mdsamplestationview.TableSampleStation(dataTable, tableID)
|
||||
|
||||
// pagination table
|
||||
paginationTable := pagination.PaginationV2(
|
||||
totalPage,
|
||||
1,
|
||||
"/dev/md/samplestation/changepage",
|
||||
paginationID,
|
||||
"#tableID, #paginationID",
|
||||
"#"+paginationID,
|
||||
"outerHTML", "", "",
|
||||
)
|
||||
|
||||
content := dev_mdsamplestationview.ContentMDSampleStation(
|
||||
tableID,
|
||||
dialogAddID,
|
||||
paginationID,
|
||||
breadcrumbComp,
|
||||
tableComponent,
|
||||
paginationTable,
|
||||
)
|
||||
css := dev_mdsamplestationview.CSSMDSampleStation()
|
||||
js := dev_mdsamplestationview.JSMDSampleStation()
|
||||
@@ -66,3 +103,39 @@ func (mdss *MDSampleStationHandler) HandleShowMDSampleStationScreen(c echo.Conte
|
||||
view := dev_mdsamplestationview.ShowMDSampleStation(title, content, css, js, navbarmenuComp, navbaruserComp, sidebaruserprofilceComp)
|
||||
return utils.View(c, view)
|
||||
}
|
||||
|
||||
func (mdss *MDSampleStationHandler) HandleChangePageSampleStation(c echo.Context) error {
|
||||
pageparam := c.QueryParam("page")
|
||||
tableID := c.QueryParam("tableID")
|
||||
paginationID := c.QueryParam("paginationID")
|
||||
|
||||
var retval []templ.Component
|
||||
logger, _ := zap.NewProduction()
|
||||
page, err := strconv.Atoi(pageparam)
|
||||
if err != nil {
|
||||
defer logger.Sync()
|
||||
logger.Info("ERROR CONVERT PAGE PARAM", zap.Any("page", page), zap.Any("error", err))
|
||||
return err
|
||||
}
|
||||
|
||||
dataSS, totalPage, err := mdss.MDSampleStationServices.GetListSampleStation("", page, 5)
|
||||
if err != nil {
|
||||
defer logger.Sync()
|
||||
logger.Info("ERROR GET DATA", zap.Any("error", err))
|
||||
return err
|
||||
}
|
||||
|
||||
tableComp := dev_mdsamplestationview.TableSampleStation(dataSS, tableID)
|
||||
paginationComp := pagination.PaginationV2(
|
||||
totalPage,
|
||||
page,
|
||||
"/dev/md/samplestation/changepage",
|
||||
paginationID,
|
||||
"#tableID, #paginationID",
|
||||
"#"+paginationID,
|
||||
"outerHTML", "", "")
|
||||
|
||||
retval = append(retval, tableComp)
|
||||
retval = append(retval, paginationComp)
|
||||
return utils.ViewMulti(c, retval)
|
||||
}
|
||||
|
||||
@@ -265,7 +265,8 @@ func SetupRoutesDev(app *echo.Echo, appStore db.AppStore) {
|
||||
// md sample station
|
||||
devMDSampleStationServices := dev_services.NewMDSampleStationServices(appStore)
|
||||
devMDSampleStationHandlers := dev_handlers.NewMDSampleStationHandler(devMDSampleStationServices)
|
||||
dev.GET("/samplestation", devMDSampleStationHandlers.HandleShowMDSampleStationScreen)
|
||||
dev.GET("/md/samplestation", devMDSampleStationHandlers.HandleShowMDSampleStationScreen)
|
||||
dev.GET("/md/samplestation/changepage", devMDSampleStationHandlers.HandleChangePageSampleStation)
|
||||
// masterdata nat unit
|
||||
devMdNatUnitServices := dev_services.NewMdNatUnitServices(appStore)
|
||||
devMdNatUnitHandlers := dev_handlers.NeWMdNatUnitHandler(devMdNatUnitServices)
|
||||
|
||||
@@ -3,6 +3,10 @@ package dev_services
|
||||
import (
|
||||
"cpone/db"
|
||||
"cpone/models"
|
||||
dbx "cpone/package/database"
|
||||
"fmt"
|
||||
"math"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func NewMDSampleStationServices(uStore db.AppStore) *MDSampleStationServices {
|
||||
@@ -39,3 +43,46 @@ func (ss *MDSampleStationServices) GetMDSampleStationBreadcrumb() (models.BreadC
|
||||
ret = Breadcrumb
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (ss *MDSampleStationServices) GetListSampleStation(search string, currentPage int, rowPerPage int) ([]models.MDSampleStation, int, error) {
|
||||
var sampleStationList []models.MDSampleStation
|
||||
var totalData int
|
||||
|
||||
offset := (currentPage - 1) * rowPerPage
|
||||
prm := "%" + strings.TrimSpace(search) + "%"
|
||||
querytotal := `
|
||||
SELECT COUNT(*)
|
||||
FROM t_samplestation
|
||||
WHERE T_SampleStationIsActive = 'Y' AND (T_SampleStationCode LIKE ? OR T_SampleStationName LIKE ?)
|
||||
`
|
||||
if err := dbx.Handlex.Get(&totalData, querytotal, prm, prm); err != nil {
|
||||
return nil, 0, fmt.Errorf("error query get total data: %v", err)
|
||||
}
|
||||
|
||||
query := `
|
||||
SELECT
|
||||
T_SampleStationID,
|
||||
T_SampleStationCode,
|
||||
T_SampleStationName,
|
||||
T_SampleStationNat_GroupID,
|
||||
T_SampleStationIsNonLab,
|
||||
T_SampleStationIsActive
|
||||
FROM t_samplestation
|
||||
WHERE T_SampleStationIsActive = 'Y'
|
||||
AND (T_SampleStationCode LIKE ? OR T_SampleStationName LIKE ?)
|
||||
ORDER BY T_SampleStationID ASC
|
||||
LIMIT ? OFFSET ?
|
||||
`
|
||||
if err := dbx.Handlex.Select(&sampleStationList, query, prm, prm, rowPerPage, offset); err != nil {
|
||||
return nil, 0, fmt.Errorf("error query database: %v", err)
|
||||
}
|
||||
totalPage := int(math.Ceil(float64(totalData) / float64(rowPerPage)))
|
||||
|
||||
for _, d := range sampleStationList {
|
||||
if len(d.T_SampleStationIsNonLab) == 0 {
|
||||
d.T_SampleStationIsNonLab = "Lab"
|
||||
}
|
||||
}
|
||||
|
||||
return sampleStationList, totalPage, nil
|
||||
}
|
||||
|
||||
@@ -9,14 +9,20 @@ import (
|
||||
templ ContentMDSampleStation(
|
||||
tableID string,
|
||||
dialogAddID string,
|
||||
paginationID string,
|
||||
breadcrumb templ.Component,
|
||||
tablecontent templ.Component,
|
||||
paginationtable templ.Component,
|
||||
) {
|
||||
<div class="container-fluid">
|
||||
@customtextfield.CustomTextFieldv2(models.CustomTextFieldv2Prm{ID: "tableID",
|
||||
Name: "tableID",
|
||||
Type: "hidden",
|
||||
Value: tableID})
|
||||
@customtextfield.CustomTextFieldv2(models.CustomTextFieldv2Prm{ID: "paginationID",
|
||||
Name: "paginationID",
|
||||
Type: "hidden",
|
||||
Value: paginationID})
|
||||
@customtextfield.CustomTextFieldv2(models.CustomTextFieldv2Prm{ID: "dialogAddID",
|
||||
Name: "dialogAddID",
|
||||
Type: "hidden",
|
||||
@@ -43,6 +49,7 @@ templ ContentMDSampleStation(
|
||||
</div>
|
||||
</div>
|
||||
@tablecontent
|
||||
@paginationtable
|
||||
</div>
|
||||
}
|
||||
|
||||
|
||||
@@ -19,8 +19,10 @@ import (
|
||||
func ContentMDSampleStation(
|
||||
tableID string,
|
||||
dialogAddID string,
|
||||
paginationID string,
|
||||
breadcrumb templ.Component,
|
||||
tablecontent templ.Component,
|
||||
paginationtable templ.Component,
|
||||
) templ.Component {
|
||||
return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) {
|
||||
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer)
|
||||
@@ -45,6 +47,13 @@ func ContentMDSampleStation(
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = customtextfield.CustomTextFieldv2(models.CustomTextFieldv2Prm{ID: "paginationID",
|
||||
Name: "paginationID",
|
||||
Type: "hidden",
|
||||
Value: paginationID}).Render(ctx, templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = customtextfield.CustomTextFieldv2(models.CustomTextFieldv2Prm{ID: "dialogAddID",
|
||||
Name: "dialogAddID",
|
||||
Type: "hidden",
|
||||
@@ -67,7 +76,7 @@ func ContentMDSampleStation(
|
||||
var templ_7745c5c3_Var2 string
|
||||
templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs("#" + dialogAddID)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdsamplestation\mdsamplestation.templ`, Line: 34, Col: 55}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdsamplestation\mdsamplestation.templ`, Line: 40, Col: 55}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var2))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -80,7 +89,7 @@ func ContentMDSampleStation(
|
||||
var templ_7745c5c3_Var3 string
|
||||
templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs("#" + dialogAddID)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdsamplestation\mdsamplestation.templ`, Line: 42, Col: 51}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdsamplestation\mdsamplestation.templ`, Line: 48, Col: 51}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -94,6 +103,10 @@ func ContentMDSampleStation(
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = paginationtable.Render(ctx, templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</div>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
|
||||
@@ -21,7 +21,31 @@ templ ItemRow(data []models.MDSampleStation) {
|
||||
<tr>
|
||||
<td>{ v.T_SampleStationCode }</td>
|
||||
<td>{ v.T_SampleStationName }</td>
|
||||
<td>{ v.T_SampleStationNat_GroupID }</td>
|
||||
<td>{ v.T_SampleStationIsNonLab }</td>
|
||||
<td>
|
||||
@ItemAction()
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
}
|
||||
|
||||
templ ItemAction() {
|
||||
<div class="row px-5 d-flex justify-content-around">
|
||||
<a
|
||||
id="btneditss"
|
||||
type="button"
|
||||
class="btneditss col-12 col-sm-12 col-md-12 col-lg-5 col-xl-5 col-xxl-5 btn btn-light-tosca mb-2"
|
||||
hx-get=""
|
||||
hx-target=""
|
||||
hx-swap=""
|
||||
hx-include="">Edit</a>
|
||||
<a
|
||||
id="btndeletess"
|
||||
type="button"
|
||||
class="btndeletess col-12 col-sm-12 col-md-12 col-lg-5 col-xl-5 col-xxl-5 btn btn-light-danger mb-2"
|
||||
hx-get=""
|
||||
hx-target=""
|
||||
hx-swap=""
|
||||
hx-include="">Hapus</a>
|
||||
</div>
|
||||
}
|
||||
@@ -80,7 +80,54 @@ func ItemRow(data []models.MDSampleStation) templ.Component {
|
||||
}
|
||||
}
|
||||
for _, v := range data {
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<tr><td></td></tr>")
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<tr><td>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var4 string
|
||||
templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(v.T_SampleStationCode)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdsamplestation\mdsamplestationtable.templ`, Line: 22, Col: 39}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</td><td>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var5 string
|
||||
templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(v.T_SampleStationName)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdsamplestation\mdsamplestationtable.templ`, Line: 23, Col: 39}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</td><td>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var6 string
|
||||
templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(v.T_SampleStationIsNonLab)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdsamplestation\mdsamplestationtable.templ`, Line: 24, Col: 43}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</td><td>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = ItemAction().Render(ctx, templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</td></tr>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
@@ -91,3 +138,27 @@ func ItemRow(data []models.MDSampleStation) templ.Component {
|
||||
return templ_7745c5c3_Err
|
||||
})
|
||||
}
|
||||
|
||||
func ItemAction() templ.Component {
|
||||
return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) {
|
||||
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer)
|
||||
if !templ_7745c5c3_IsBuffer {
|
||||
templ_7745c5c3_Buffer = templ.GetBuffer()
|
||||
defer templ.ReleaseBuffer(templ_7745c5c3_Buffer)
|
||||
}
|
||||
ctx = templ.InitializeContext(ctx)
|
||||
templ_7745c5c3_Var7 := templ.GetChildren(ctx)
|
||||
if templ_7745c5c3_Var7 == nil {
|
||||
templ_7745c5c3_Var7 = templ.NopComponent
|
||||
}
|
||||
ctx = templ.ClearChildren(ctx)
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<div class=\"row px-5 d-flex justify-content-around\"><a id=\"btneditss\" type=\"button\" class=\"btneditss col-12 col-sm-12 col-md-12 col-lg-5 col-xl-5 col-xxl-5 btn btn-light-tosca mb-2\" hx-get=\"\" hx-target=\"\" hx-swap=\"\" hx-include=\"\">Edit</a> <a id=\"btndeletess\" type=\"button\" class=\"btndeletess col-12 col-sm-12 col-md-12 col-lg-5 col-xl-5 col-xxl-5 btn btn-light-danger mb-2\" hx-get=\"\" hx-target=\"\" hx-swap=\"\" hx-include=\"\">Hapus</a></div>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
if !templ_7745c5c3_IsBuffer {
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W)
|
||||
}
|
||||
return templ_7745c5c3_Err
|
||||
})
|
||||
}
|
||||
|
||||
@@ -127,11 +127,7 @@ func MdUserGroupScreen(
|
||||
var templ_7745c5c3_Var2 string
|
||||
templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs("#" + dialogAddID)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
<<<<<<< HEAD
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdusergroup\mdusergroup.templ`, Line: 74, Col: 37}
|
||||
=======
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdusergroup\mdusergroup.templ`, Line: 52, Col: 37}
|
||||
>>>>>>> 3afd212 (add sample station handler, services, model)
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var2))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -144,11 +140,7 @@ func MdUserGroupScreen(
|
||||
var templ_7745c5c3_Var3 string
|
||||
templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs("#" + dialogAddID)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
<<<<<<< HEAD
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdusergroup\mdusergroup.templ`, Line: 83, Col: 36}
|
||||
=======
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdusergroup\mdusergroup.templ`, Line: 61, Col: 36}
|
||||
>>>>>>> 3afd212 (add sample station handler, services, model)
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
|
||||
Reference in New Issue
Block a user