diff --git a/assets/asset-corporate-portal/css/sas.bundle.css b/assets/asset-corporate-portal/css/sas.bundle.css index a941405..dad9a39 100644 --- a/assets/asset-corporate-portal/css/sas.bundle.css +++ b/assets/asset-corporate-portal/css/sas.bundle.css @@ -219,6 +219,9 @@ a.text-white:focus { .bg-gray { background-color: var(--gray) !important; } +.bg-field { + background-color: var(--fieldbg) !important; +} /* ### BACKGROUND TRANSPARENT */ .bg-black-transparent { background-color: var(--dark) !important; diff --git a/assets/hanan/employee-medical-analytic.html b/assets/hanan/employee-medical-analytic.html new file mode 100644 index 0000000..6ee4077 --- /dev/null +++ b/assets/hanan/employee-medical-analytic.html @@ -0,0 +1,431 @@ + + + + + + + + + Westerindo + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
+
+ +
+ PT. Sadhana Abiyasa Sampoerna +
+ + + + + +
+ +
+ + + Filter + + +
+
+ + + +
+ +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/cmd/main.go b/cmd/main.go index c384dd8..37567fc 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -79,6 +79,14 @@ func main() { lphsx := handlers.NewPiechartHandler(lpchart) handlers.SetupRoutesPieChart(app, lphsx) + eStore, err := db.NewEmployeeStore(dbName) + if err != nil { + app.Logger.Fatalf("failed to create store: %s", err) + } + el := services.NewServicesEmployee(services.Employee{}, eStore) + ehs := handlers.NewEmployeeHandler(el) + handlers.SetupRoutesEmployee(app, ehs) + app.Logger.Fatal(app.Start(":5000")) } diff --git a/db/employee.store.go b/db/employee.store.go new file mode 100644 index 0000000..8c49eec --- /dev/null +++ b/db/employee.store.go @@ -0,0 +1,26 @@ +package db + +import ( + "database/sql" + + _ "github.com/glebarez/go-sqlite" +) + +type EmployeeStore struct { + Db *sql.DB +} + +func NewEmployeeStore(dbName string) (EmployeeStore, error) { + Db, err := getConnection(dbName) + if err != nil { + return EmployeeStore{}, err + } + + if err := createMigrations(dbName, Db); err != nil { + return EmployeeStore{}, err + } + + return EmployeeStore{ + Db, + }, nil +} diff --git a/handlers/employee.handler.go b/handlers/employee.handler.go new file mode 100644 index 0000000..971c31a --- /dev/null +++ b/handlers/employee.handler.go @@ -0,0 +1,42 @@ +package handlers + +import ( + "fmt" + + "github.com/a-h/templ" + "github.com/emarifer/go-templ-project-structure/services" + "github.com/emarifer/go-templ-project-structure/views/employee" + "github.com/labstack/echo/v4" +) + +type EmployeeService interface { + GetEmployeeService() ([]services.EmployeeService, error) +} + +func NewEmployeeHandler(us EmployeeService) *EmployeeHandler { + return &EmployeeHandler{ + EmployeeService: us, + } +} + +type EmployeeHandler struct { + EmployeeService EmployeeService +} + +func (eh *EmployeeHandler) ShowEmployee(c echo.Context) error { + udata, err := eh.EmployeeService.GetEmployeeService() + if err != nil { + // fmt.Println(err) + return err + } + + fmt.Printf("%+v\n", udata) + e := employee.ShowEmployee("Employee", employee.MainEmployee(employee.ListCardService(udata)), employee.CssEmployee(), employee.JsEmployee()) + return eh.View(c, e) +} + +func (eh *EmployeeHandler) View(c echo.Context, cmp templ.Component) error { + c.Response().Header().Set(echo.HeaderContentType, echo.MIMETextHTML) + + return cmp.Render(c.Request().Context(), c.Response().Writer) +} diff --git a/handlers/routes.go b/handlers/routes.go index e5cec8a..6f9a1b1 100644 --- a/handlers/routes.go +++ b/handlers/routes.go @@ -29,6 +29,10 @@ func SetupRoutesPieChart(app *echo.Echo, h *PiechartHandler) { Lp.GET("/peserta", h.ShowMcuPeserta) Lp.GET("/bar", h.ShowBarChart) } +func SetupRoutesEmployee(app *echo.Echo, e *EmployeeHandler) { + employee := app.Group("/employee") + employee.GET("/", e.ShowEmployee) +} func SetupRoutesProject(app *echo.Echo) { } diff --git a/services/employee.services.go b/services/employee.services.go new file mode 100644 index 0000000..63cec64 --- /dev/null +++ b/services/employee.services.go @@ -0,0 +1,71 @@ +package services + +import ( + "time" + + "github.com/emarifer/go-templ-project-structure/db" +) + +func NewServicesEmployee(u Employee, uStore db.EmployeeStore) *ServicesEmployee { + + return &ServicesEmployee{ + Employee: u, + EmployeeStore: uStore, + } +} + +type Employee struct { + ID int `json:"id"` + Employeename string `json:"Employeename"` + Email string `json:"email"` + CreatedAt time.Time `json:"created_at,omitempty"` +} + +type EmployeeService struct { + EmployeeID int `json:"EmployeeID"` + EmployeeTitle string `json:"EmployeeTitle"` + EmployeeDescription string `json:"EmployeeDescription"` + EmployeeStartDate string `json:"EmployeeStartDate"` + EmployeeEndDate string `json:"EmployeeEndDate"` +} + +type ServicesEmployee struct { + Employee Employee + EmployeeStore db.EmployeeStore +} + +func (se *ServicesEmployee) GetEmployeeService() ([]EmployeeService, error) { + + data := []EmployeeService{ + { + EmployeeID: 1, + EmployeeTitle: "MCU Calon Karyawan", + EmployeeDescription: "Tanggal Pelaksanaan", + EmployeeStartDate: "01/04/2024", + EmployeeEndDate: "06/04/2024", + }, + { + EmployeeID: 2, + EmployeeTitle: "MCU Karyawan", + EmployeeDescription: "Tanggal Pelaksanaan", + EmployeeStartDate: "01/04/2024", + EmployeeEndDate: "06/04/2024", + }, + { + EmployeeID: 1, + EmployeeTitle: "MCU Eselon 1", + EmployeeDescription: "Tanggal Pelaksanaan", + EmployeeStartDate: "01/04/2024", + EmployeeEndDate: "06/04/2024", + }, + { + EmployeeID: 1, + EmployeeTitle: "MCU Eselon 2", + EmployeeDescription: "Tanggal Pelaksanaan", + EmployeeStartDate: "01/04/2024", + EmployeeEndDate: "06/04/2024", + }, + } + + return data, nil +} diff --git a/views/employee/employee.templ b/views/employee/employee.templ new file mode 100644 index 0000000..80f81e8 --- /dev/null +++ b/views/employee/employee.templ @@ -0,0 +1,115 @@ +package employee + +import ( + "github.com/emarifer/go-templ-project-structure/views/layout" +) + +templ MainEmployee(cardServiceComponent templ.Component) { +
+ + + + + @HeadingEmployee("PT. Sadhana Abiyasa Sampoerna") + + +
+
+
+ + @cardServiceComponent + +
+
+
+ +
+} + +templ CssEmployee() { + +} + +templ JsEmployee() { +} + +templ ShowEmployee(title string, cmp templ.Component, css templ.Component, js templ.Component) { + @layout.PlaygroundLayout(title, css, js) { + @cmp + } +} diff --git a/views/employee/employee_templ.go b/views/employee/employee_templ.go new file mode 100644 index 0000000..f91b28c --- /dev/null +++ b/views/employee/employee_templ.go @@ -0,0 +1,138 @@ +// Code generated by templ - DO NOT EDIT. + +// templ: version: v0.2.663 +package employee + +//lint:file-ignore SA4006 This context is only used if a nested component is present. + +import "github.com/a-h/templ" +import "context" +import "io" +import "bytes" + +import ( + "github.com/emarifer/go-templ-project-structure/views/layout" +) + +func MainEmployee(cardServiceComponent 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) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var1 := templ.GetChildren(ctx) + if templ_7745c5c3_Var1 == nil { + templ_7745c5c3_Var1 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = HeadingEmployee("PT. Sadhana Abiyasa Sampoerna").Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = cardServiceComponent.Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + 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 + }) +} + +func CssEmployee() 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_Var2 := templ.GetChildren(ctx) + if templ_7745c5c3_Var2 == nil { + templ_7745c5c3_Var2 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + 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 + }) +} + +func JsEmployee() 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_Var3 := templ.GetChildren(ctx) + if templ_7745c5c3_Var3 == nil { + templ_7745c5c3_Var3 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) + } + return templ_7745c5c3_Err + }) +} + +func ShowEmployee(title string, cmp templ.Component, css templ.Component, js 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) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var4 := templ.GetChildren(ctx) + if templ_7745c5c3_Var4 == nil { + templ_7745c5c3_Var4 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + templ_7745c5c3_Var5 := 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) + } + templ_7745c5c3_Err = cmp.Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = io.Copy(templ_7745c5c3_W, templ_7745c5c3_Buffer) + } + return templ_7745c5c3_Err + }) + templ_7745c5c3_Err = layout.PlaygroundLayout(title, css, js).Render(templ.WithChildren(ctx, templ_7745c5c3_Var5), templ_7745c5c3_Buffer) + 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 + }) +} diff --git a/views/employee/employeecomponent.templ b/views/employee/employeecomponent.templ new file mode 100644 index 0000000..aa44900 --- /dev/null +++ b/views/employee/employeecomponent.templ @@ -0,0 +1,60 @@ +package employee + +import ( + "github.com/emarifer/go-templ-project-structure/services" +) + +templ CardService(title string, description string, startdate string, enddate string) { + +
+
+
+

{ title }

+
+
+ { description } +
+
+ { startdate } - { enddate } +
+
+
+
+} + +templ ListCardService(cardData []services.EmployeeService) { + for _, d := range cardData { + @CardService(d.EmployeeTitle, d.EmployeeDescription, d.EmployeeStartDate, d.EmployeeEndDate) + } +} + +templ HeadingEmployee(title string) { +
+
+ +
+ { title } +
+ + + + +
+
+ + + Filter + + +
+
+} diff --git a/views/employee/employeecomponent_templ.go b/views/employee/employeecomponent_templ.go new file mode 100644 index 0000000..ae708a5 --- /dev/null +++ b/views/employee/employeecomponent_templ.go @@ -0,0 +1,154 @@ +// Code generated by templ - DO NOT EDIT. + +// templ: version: v0.2.663 +package employee + +//lint:file-ignore SA4006 This context is only used if a nested component is present. + +import "github.com/a-h/templ" +import "context" +import "io" +import "bytes" + +import ( + "github.com/emarifer/go-templ-project-structure/services" +) + +func CardService(title string, description string, startdate string, enddate string) 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_Var1 := templ.GetChildren(ctx) + if templ_7745c5c3_Var1 == nil { + templ_7745c5c3_Var1 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var2 string + templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs(title) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\employee\employeecomponent.templ`, Line: 12, Col: 35} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var2)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var3 string + templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(description) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\employee\employeecomponent.templ`, Line: 15, Col: 61} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var4 string + templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(startdate) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\employee\employeecomponent.templ`, Line: 18, Col: 59} + } + _, 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(" - ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var5 string + templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(enddate) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\employee\employeecomponent.templ`, Line: 18, Col: 73} + } + _, 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("
") + 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 + }) +} + +func ListCardService(cardData []services.EmployeeService) 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_Var6 := templ.GetChildren(ctx) + if templ_7745c5c3_Var6 == nil { + templ_7745c5c3_Var6 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + for _, d := range cardData { + templ_7745c5c3_Err = CardService(d.EmployeeTitle, d.EmployeeDescription, d.EmployeeStartDate, d.EmployeeEndDate).Render(ctx, templ_7745c5c3_Buffer) + 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 + }) +} + +func HeadingEmployee(title string) 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("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var8 string + templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(title) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\employee\employeecomponent.templ`, Line: 36, Col: 11} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
Filter\r
") + 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 + }) +}