autocomplete refactor
This commit is contained in:
@@ -2,7 +2,7 @@ package customtextfieldautocomplete;
|
||||
|
||||
import (
|
||||
"cpone/layout"
|
||||
services "cpone/services/dev"
|
||||
"cpone/models"
|
||||
)
|
||||
|
||||
templ MainCustomAutoComplete(value string) {
|
||||
@@ -32,7 +32,7 @@ templ ListCustomAutoCompleteHide() {
|
||||
<div id="hasilAutoComplete"></div>
|
||||
}
|
||||
|
||||
templ ListCustomAutoComplete(limit string, param string, totalDataInt int, foundCount int, pageOf string, textFound string, data []services.AutoComplete) {
|
||||
templ ListCustomAutoComplete(limit string, param string, totalDataInt int, foundCount int, pageOf string, textFound string, data []models.AutoComplete) {
|
||||
<div id="contentList" class="bootstrap-autocomplete dropdown-menu-custom bg-white show">
|
||||
if len(data) == 0 {
|
||||
<a class="dropdown-item" href="#" style="overflow: hidden; text-overflow: ellipsis;">Data Tidak Ditemukan</a>
|
||||
|
||||
@@ -12,7 +12,7 @@ import "bytes"
|
||||
|
||||
import (
|
||||
"cpone/layout"
|
||||
services "cpone/services/dev"
|
||||
"cpone/models"
|
||||
)
|
||||
|
||||
func MainCustomAutoComplete(value string) templ.Component {
|
||||
@@ -76,7 +76,7 @@ func ListCustomAutoCompleteHide() templ.Component {
|
||||
})
|
||||
}
|
||||
|
||||
func ListCustomAutoComplete(limit string, param string, totalDataInt int, foundCount int, pageOf string, textFound string, data []services.AutoComplete) templ.Component {
|
||||
func ListCustomAutoComplete(limit string, param string, totalDataInt int, foundCount int, pageOf string, textFound string, data []models.AutoComplete) 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 {
|
||||
|
||||
195
handlers/dev/autocomplete.handlers.go
Normal file
195
handlers/dev/autocomplete.handlers.go
Normal file
@@ -0,0 +1,195 @@
|
||||
package dev_handlers
|
||||
|
||||
import (
|
||||
"cpone/component/customtextfieldautocomplete"
|
||||
"cpone/models"
|
||||
"cpone/utils"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"github.com/a-h/templ"
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
type AutoCompleteService interface {
|
||||
GetAutoComplete(param string, pageOf string, limit string) (string, string, string, []models.AutoComplete, error)
|
||||
}
|
||||
|
||||
func NewAutoCompleteHandler(us AutoCompleteService) *AutoCompleteHandler {
|
||||
return &AutoCompleteHandler{
|
||||
AutoCompleteService: us,
|
||||
}
|
||||
}
|
||||
|
||||
type AutoCompleteHandler struct {
|
||||
AutoCompleteService AutoCompleteService
|
||||
}
|
||||
|
||||
// initial
|
||||
func (lh *AutoCompleteHandler) HandlerListAutoComplete(c echo.Context) error {
|
||||
// param := c.Param("p")
|
||||
param := c.QueryParam("searchAutocomplete")
|
||||
pageOf := "1"
|
||||
limit := "3"
|
||||
|
||||
pageOfBefore, _ := strconv.Atoi(c.Param("pageOf"))
|
||||
limitBefore, _ := strconv.Atoi(c.Param("limit"))
|
||||
|
||||
if pageOfBefore > 1 {
|
||||
pageCurrent := pageOfBefore + 1
|
||||
pageOf = strconv.Itoa(pageCurrent)
|
||||
|
||||
limitCurrent := limitBefore
|
||||
limit = strconv.Itoa(limitCurrent)
|
||||
}
|
||||
|
||||
// urlCustomAutoComplete := "/client/autoCompleteLoadMore/"+ strconv.Itoa(pageOf)
|
||||
var si templ.Component
|
||||
if param != "" {
|
||||
totalData, foundCount, textFound, dataAutoComplete, err := lh.AutoCompleteService.GetAutoComplete(param, pageOf, limit)
|
||||
fmt.Println(param)
|
||||
// fmt.Println(err)
|
||||
if err != nil {
|
||||
fmt.Println(dataAutoComplete)
|
||||
return err
|
||||
}
|
||||
|
||||
foundCountInt, err := strconv.Atoi(foundCount)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
totalDataInt, err := strconv.Atoi(totalData)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// si := customtextfieldautocomplete.ListCustomAutoComplete(dataAutoComplete)
|
||||
|
||||
si = customtextfieldautocomplete.ListCustomAutoComplete(limit, param, totalDataInt, foundCountInt, pageOf, textFound, dataAutoComplete)
|
||||
} else {
|
||||
si = customtextfieldautocomplete.ListCustomAutoCompleteHide()
|
||||
}
|
||||
|
||||
return utils.View(c, si)
|
||||
}
|
||||
|
||||
// after selected
|
||||
func (lh *AutoCompleteHandler) HandlerListAutoCompleteAfterSelected(c echo.Context) error {
|
||||
// param := c.QueryParam("searchAutocomplete")
|
||||
|
||||
setvalue := c.Param("setvalue")
|
||||
setvalue, err := url.PathUnescape(setvalue)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
si := customtextfieldautocomplete.MainCustomAutoComplete(setvalue)
|
||||
|
||||
return utils.View(c, si)
|
||||
}
|
||||
|
||||
// load more autocomplete
|
||||
func (lh *AutoCompleteHandler) HandlerListAutoCompleteLoadMore(c echo.Context) error {
|
||||
// param := c.QueryParam("searchAutocomplete")
|
||||
|
||||
var totalPerPage int = 3
|
||||
paramSearch := c.Param("searchParam")
|
||||
searchParam, err := url.PathUnescape(paramSearch)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
pageOfStr := c.Param("pageOf")
|
||||
pageOfInt, err := strconv.Atoi(pageOfStr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
pageOfInt++
|
||||
pageOf := strconv.Itoa(pageOfInt)
|
||||
|
||||
limitOfStr := c.Param("limit")
|
||||
limitOfInt, err := strconv.Atoi(limitOfStr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
limitOfX := limitOfInt + totalPerPage
|
||||
limitOf := strconv.Itoa(limitOfX)
|
||||
|
||||
var si templ.Component
|
||||
|
||||
totalData, foundCount, textFound, dataAutoComplete, err := lh.AutoCompleteService.GetAutoComplete(searchParam, pageOf, limitOf)
|
||||
|
||||
// fmt.Println(param)
|
||||
// fmt.Println(err)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(dataAutoComplete)
|
||||
return err
|
||||
}
|
||||
|
||||
foundCountInt, err := strconv.Atoi(foundCount)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
totalDataInt, err := strconv.Atoi(totalData)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// si := customtextfieldautocomplete.ListCustomAutoComplete(dataAutoComplete)
|
||||
si = customtextfieldautocomplete.ListCustomAutoComplete(limitOf, searchParam, totalDataInt, foundCountInt, pageOf, textFound, dataAutoComplete)
|
||||
|
||||
// if param != "" {
|
||||
// textFound, dataAutoComplete, err := lh.AutoCompleteService.GetAutoComplete(param, pageOf)
|
||||
// fmt.Println(param)
|
||||
// // fmt.Println(err)
|
||||
// if err != nil {
|
||||
// fmt.Println(dataAutoComplete)
|
||||
// return err
|
||||
// }
|
||||
|
||||
// // si := customtextfieldautocomplete.ListCustomAutoComplete(dataAutoComplete)
|
||||
// si = customtextfieldautocomplete.ListCustomAutoComplete(pageOf, textFound, dataAutoComplete)
|
||||
|
||||
// } else {
|
||||
// si = customtextfieldautocomplete.ListCustomAutoCompleteHide()
|
||||
// }
|
||||
|
||||
return utils.View(c, si)
|
||||
}
|
||||
|
||||
func (lh *AutoCompleteHandler) HandlerAutoCompleteExample(c echo.Context) error {
|
||||
// dataAutoComplete, err := lh.AutoCompleteService.GetAutoCompleteExample()
|
||||
// fmt.Println(dataAutoComplete)
|
||||
// fmt.Println(err)
|
||||
// if err != nil {
|
||||
// fmt.Println(dataAutoComplete)
|
||||
// return err
|
||||
// }
|
||||
// fmt.Printf("%+v\n", dataMenu)
|
||||
// si := mastermenu.ShowMasterMenu("Master Menu",
|
||||
// mastermenu.MainMasterMenu(dataMenu),
|
||||
// mastermenu.CssMasterMenu(),
|
||||
// mastermenu.JsMasterMenu(),
|
||||
// )
|
||||
|
||||
// si := mastermenuusergroup.ShowAutoComplete(
|
||||
// "Master Menu",
|
||||
// mastermenuusergroup.MainAutoComplete(dataMenu),
|
||||
// mastermenuusergroup.CssAutoComplete(),
|
||||
// mastermenuusergroup.JsAutoComplete(),
|
||||
// )
|
||||
|
||||
si := customtextfieldautocomplete.ShowCustomAutoComplete("",
|
||||
customtextfieldautocomplete.MainCustomAutoComplete(""),
|
||||
customtextfieldautocomplete.CssCustomAutoComplete(),
|
||||
customtextfieldautocomplete.JsCustomAutoComplete(),
|
||||
)
|
||||
|
||||
return utils.View(c, si)
|
||||
}
|
||||
@@ -1,15 +1,12 @@
|
||||
package dev_handlers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"cpone/component/customtextfieldautocomplete"
|
||||
"cpone/component/pagination"
|
||||
tablecomponent "cpone/component/table"
|
||||
"cpone/models"
|
||||
mastermenuusergroup "cpone/views/dev/mastermenuusergroup"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
services "cpone/services/dev"
|
||||
|
||||
@@ -69,173 +66,6 @@ func (lh *MasterMenuUserGroupHandler) HandlerShowMasterMenuUserGroup(c echo.Cont
|
||||
return lh.View(c, si)
|
||||
}
|
||||
|
||||
// initial
|
||||
func (lh *MasterMenuUserGroupHandler) HandlerListAutoComplete(c echo.Context) error {
|
||||
// param := c.Param("p")
|
||||
param := c.QueryParam("searchAutocomplete")
|
||||
pageOf := "1"
|
||||
limit := "3"
|
||||
|
||||
pageOfBefore, _ := strconv.Atoi(c.Param("pageOf"))
|
||||
limitBefore, _ := strconv.Atoi(c.Param("limit"))
|
||||
|
||||
if pageOfBefore > 1 {
|
||||
pageCurrent := pageOfBefore + 1
|
||||
pageOf = strconv.Itoa(pageCurrent)
|
||||
|
||||
limitCurrent := limitBefore
|
||||
limit = strconv.Itoa(limitCurrent)
|
||||
}
|
||||
|
||||
// urlCustomAutoComplete := "/client/autoCompleteLoadMore/"+ strconv.Itoa(pageOf)
|
||||
var si templ.Component
|
||||
if param != "" {
|
||||
totalData, foundCount, textFound, dataAutoComplete, err := lh.MasterMenuUserGroupService.GetAutoComplete(param, pageOf, limit)
|
||||
fmt.Println(param)
|
||||
// fmt.Println(err)
|
||||
if err != nil {
|
||||
fmt.Println(dataAutoComplete)
|
||||
return err
|
||||
}
|
||||
|
||||
foundCountInt, err := strconv.Atoi(foundCount)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
totalDataInt, err := strconv.Atoi(totalData)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// si := customtextfieldautocomplete.ListCustomAutoComplete(dataAutoComplete)
|
||||
|
||||
si = customtextfieldautocomplete.ListCustomAutoComplete(limit, param, totalDataInt, foundCountInt, pageOf, textFound, dataAutoComplete)
|
||||
} else {
|
||||
si = customtextfieldautocomplete.ListCustomAutoCompleteHide()
|
||||
}
|
||||
|
||||
return lh.View(c, si)
|
||||
}
|
||||
|
||||
// after selected
|
||||
func (lh *MasterMenuUserGroupHandler) HandlerListAutoCompleteAfterSelected(c echo.Context) error {
|
||||
// param := c.QueryParam("searchAutocomplete")
|
||||
|
||||
setvalue := c.Param("setvalue")
|
||||
setvalue, err := url.PathUnescape(setvalue)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
si := customtextfieldautocomplete.MainCustomAutoComplete(setvalue)
|
||||
|
||||
return lh.View(c, si)
|
||||
}
|
||||
|
||||
// load more autocomplete
|
||||
func (lh *MasterMenuUserGroupHandler) HandlerListAutoCompleteLoadMore(c echo.Context) error {
|
||||
// param := c.QueryParam("searchAutocomplete")
|
||||
|
||||
var totalPerPage int = 3
|
||||
paramSearch := c.Param("searchParam")
|
||||
searchParam, err := url.PathUnescape(paramSearch)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
pageOfStr := c.Param("pageOf")
|
||||
pageOfInt, err := strconv.Atoi(pageOfStr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
pageOfInt++
|
||||
pageOf := strconv.Itoa(pageOfInt)
|
||||
|
||||
limitOfStr := c.Param("limit")
|
||||
limitOfInt, err := strconv.Atoi(limitOfStr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
limitOfX := limitOfInt + totalPerPage
|
||||
limitOf := strconv.Itoa(limitOfX)
|
||||
|
||||
var si templ.Component
|
||||
|
||||
totalData, foundCount, textFound, dataAutoComplete, err := lh.MasterMenuUserGroupService.GetAutoComplete(searchParam, pageOf, limitOf)
|
||||
|
||||
// fmt.Println(param)
|
||||
// fmt.Println(err)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(dataAutoComplete)
|
||||
return err
|
||||
}
|
||||
|
||||
foundCountInt, err := strconv.Atoi(foundCount)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
totalDataInt, err := strconv.Atoi(totalData)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// si := customtextfieldautocomplete.ListCustomAutoComplete(dataAutoComplete)
|
||||
si = customtextfieldautocomplete.ListCustomAutoComplete(limitOf, searchParam, totalDataInt, foundCountInt, pageOf, textFound, dataAutoComplete)
|
||||
|
||||
// if param != "" {
|
||||
// textFound, dataAutoComplete, err := lh.MasterMenuUserGroupService.GetAutoComplete(param, pageOf)
|
||||
// fmt.Println(param)
|
||||
// // fmt.Println(err)
|
||||
// if err != nil {
|
||||
// fmt.Println(dataAutoComplete)
|
||||
// return err
|
||||
// }
|
||||
|
||||
// // si := customtextfieldautocomplete.ListCustomAutoComplete(dataAutoComplete)
|
||||
// si = customtextfieldautocomplete.ListCustomAutoComplete(pageOf, textFound, dataAutoComplete)
|
||||
|
||||
// } else {
|
||||
// si = customtextfieldautocomplete.ListCustomAutoCompleteHide()
|
||||
// }
|
||||
|
||||
return lh.View(c, si)
|
||||
}
|
||||
|
||||
func (lh *MasterMenuUserGroupHandler) HandlerAutoCompleteExample(c echo.Context) error {
|
||||
// dataAutoComplete, err := lh.MasterMenuUserGroupService.GetAutoCompleteExample()
|
||||
// fmt.Println(dataAutoComplete)
|
||||
// fmt.Println(err)
|
||||
// if err != nil {
|
||||
// fmt.Println(dataAutoComplete)
|
||||
// return err
|
||||
// }
|
||||
// fmt.Printf("%+v\n", dataMenu)
|
||||
// si := mastermenu.ShowMasterMenu("Master Menu",
|
||||
// mastermenu.MainMasterMenu(dataMenu),
|
||||
// mastermenu.CssMasterMenu(),
|
||||
// mastermenu.JsMasterMenu(),
|
||||
// )
|
||||
|
||||
// si := mastermenuusergroup.ShowMasterMenuUserGroup(
|
||||
// "Master Menu",
|
||||
// mastermenuusergroup.MainMasterMenuUserGroup(dataMenu),
|
||||
// mastermenuusergroup.CssMasterMenuUserGroup(),
|
||||
// mastermenuusergroup.JsMasterMenuUserGroup(),
|
||||
// )
|
||||
|
||||
si := customtextfieldautocomplete.ShowCustomAutoComplete("",
|
||||
customtextfieldautocomplete.MainCustomAutoComplete(""),
|
||||
customtextfieldautocomplete.CssCustomAutoComplete(),
|
||||
customtextfieldautocomplete.JsCustomAutoComplete(),
|
||||
)
|
||||
|
||||
return lh.View(c, si)
|
||||
}
|
||||
func (lh *MasterMenuUserGroupHandler) ChangeFormEdit(c echo.Context) error {
|
||||
id := c.QueryParam("id")
|
||||
dataUserGroup, err := lh.MasterMenuUserGroupService.GetUserGroupByID(id)
|
||||
|
||||
@@ -42,10 +42,10 @@ func SetupRoutesLandingPage(app *echo.Echo, h *dev_handlers.LandingPageHandler,
|
||||
// mdgroup := clientgroup.Group("/md")
|
||||
// clientusergroup.GET("/md", mastermenuusergroupHandler.HandlerShowMasterMenuUserGroup)
|
||||
clientgroup.GET("/usergroup", mastermenuusergroupHandler.HandlerShowMasterMenuUserGroup)
|
||||
autocomplete := app.Group("/client")
|
||||
autocomplete.GET("/autocomplete", mastermenuusergroupHandler.HandlerListAutoComplete)
|
||||
autocomplete.GET("/autoCompleteLoadMore/:pageOf/:searchParam/:limit", mastermenuusergroupHandler.HandlerListAutoCompleteLoadMore)
|
||||
autocomplete.GET("/autoCompleteSetValue/:setvalue", mastermenuusergroupHandler.HandlerListAutoCompleteAfterSelected)
|
||||
// autocomplete := app.Group("/client")
|
||||
// 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)
|
||||
|
||||
|
||||
5
models/autocomplete.models.go
Normal file
5
models/autocomplete.models.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package models
|
||||
|
||||
type AutoComplete struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
206
services/dev/autocomplete.services.go
Normal file
206
services/dev/autocomplete.services.go
Normal file
@@ -0,0 +1,206 @@
|
||||
package dev_services
|
||||
|
||||
import (
|
||||
"cpone/db"
|
||||
"cpone/utils"
|
||||
"fmt"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func NewServicesAutoComplete(uStore db.AppStore) *ServicesAutoComplete {
|
||||
|
||||
return &ServicesAutoComplete{
|
||||
AutoCompleteStore: uStore,
|
||||
}
|
||||
}
|
||||
|
||||
type ServicesAutoComplete struct {
|
||||
AutoCompleteStore db.AppStore
|
||||
}
|
||||
|
||||
// example autocomplete
|
||||
func (su *ServicesAutoComplete) GetAutoComplete(param string, pageOfParam string, limitOfStr string) (string, string, string, []AutoComplete, error) {
|
||||
// fmt.Println("ini param : ", param)
|
||||
|
||||
dummyAutoComplete := []AutoComplete{
|
||||
{
|
||||
Name: "Google",
|
||||
},
|
||||
{
|
||||
Name: "Google 1",
|
||||
},
|
||||
{
|
||||
Name: "Google 2",
|
||||
},
|
||||
{
|
||||
Name: "Google 3",
|
||||
},
|
||||
{
|
||||
Name: "Google 4",
|
||||
},
|
||||
{
|
||||
Name: "Google 5",
|
||||
},
|
||||
{
|
||||
Name: "Google 6",
|
||||
},
|
||||
{
|
||||
Name: "Gojek",
|
||||
},
|
||||
{
|
||||
Name: "Mozilla Firefox",
|
||||
},
|
||||
{
|
||||
Name: "Apple",
|
||||
},
|
||||
{
|
||||
Name: "Microsoft",
|
||||
},
|
||||
{
|
||||
Name: "Facebook",
|
||||
},
|
||||
{
|
||||
Name: "Amazon",
|
||||
},
|
||||
{
|
||||
Name: "Twitter",
|
||||
},
|
||||
{
|
||||
Name: "Instagram",
|
||||
},
|
||||
{
|
||||
Name: "Snapchat",
|
||||
},
|
||||
{
|
||||
Name: "LinkedIn",
|
||||
},
|
||||
{
|
||||
Name: "Netflix",
|
||||
},
|
||||
{
|
||||
Name: "YouTube",
|
||||
},
|
||||
{
|
||||
Name: "Reddit",
|
||||
},
|
||||
{
|
||||
Name: "WhatsApp",
|
||||
},
|
||||
{
|
||||
Name: "Pinterest",
|
||||
},
|
||||
{
|
||||
Name: "TikTok",
|
||||
},
|
||||
{
|
||||
Name: "Spotify",
|
||||
},
|
||||
{
|
||||
Name: "Zoom",
|
||||
},
|
||||
}
|
||||
|
||||
var textFound string
|
||||
var results []AutoComplete
|
||||
// var currentRes []AutoComplete
|
||||
// var oldResults []AutoComplete
|
||||
// var limit int = 3
|
||||
var count int = 0
|
||||
var foundCount int = 0
|
||||
var totalData int = 0
|
||||
var startIndex int = 0
|
||||
var endIndex int = 3
|
||||
|
||||
if len(dummyAutoComplete) > 0 {
|
||||
totalData = len(dummyAutoComplete)
|
||||
}
|
||||
|
||||
// pageOf, err := strconv.Atoi(pageOfParam)
|
||||
// if err != nil {
|
||||
// return "", "", "", nil, err
|
||||
// }
|
||||
|
||||
limit, err := strconv.Atoi(limitOfStr)
|
||||
if err != nil {
|
||||
return "", "", "", nil, err
|
||||
}
|
||||
|
||||
// find data search
|
||||
if pageOfParam == "1" {
|
||||
count = 0
|
||||
// for _, item := range dummyAutoComplete {
|
||||
// if utils.Contains(item.Name, param) {
|
||||
// results = append(results, item)
|
||||
// count++
|
||||
// if count == limit {
|
||||
// break
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
for _, item := range dummyAutoComplete {
|
||||
if utils.Contains(item.Name, param) {
|
||||
// Check if the item is already in results
|
||||
found := false
|
||||
for _, res := range results {
|
||||
if res.Name == item.Name {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
// If not found, append it
|
||||
if !found {
|
||||
results = append(results, item)
|
||||
count++
|
||||
if count == limit {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
// ketika klik load more
|
||||
// count = 0
|
||||
for _, item := range dummyAutoComplete {
|
||||
if utils.Contains(item.Name, param) {
|
||||
results = append(results, item)
|
||||
count++
|
||||
if count == limit {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
startIndex = 0
|
||||
endIndex = limit
|
||||
|
||||
if startIndex >= len(dummyAutoComplete) {
|
||||
return "", "max", "", nil, nil
|
||||
}
|
||||
|
||||
if endIndex > len(dummyAutoComplete) {
|
||||
endIndex = len(dummyAutoComplete)
|
||||
}
|
||||
|
||||
for _, item := range dummyAutoComplete[startIndex:endIndex] {
|
||||
found := false
|
||||
for _, res := range results {
|
||||
if res.Name == item.Name {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
// If not found, append it
|
||||
if !found {
|
||||
results = append(results, item)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foundCount = len(results)
|
||||
totalCount := len(dummyAutoComplete)
|
||||
textFound = fmt.Sprintf("Ditemukan %d dari %d", foundCount, totalCount)
|
||||
|
||||
return strconv.Itoa(totalData), strconv.Itoa(foundCount), textFound, results, nil
|
||||
}
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
|
||||
"cpone/db"
|
||||
"cpone/models"
|
||||
"cpone/utils"
|
||||
)
|
||||
|
||||
func NewServicesMasterMenuUserGroup(u MasterMenu, uStore db.AppStore) *ServicesMasterMenuUserGroup {
|
||||
@@ -552,192 +551,6 @@ func (su *ServicesMasterMenuUserGroup) GetMasterMenus() ([]MasterMenu, error) {
|
||||
return dummyMenu, nil
|
||||
}
|
||||
|
||||
// example autocomplete
|
||||
func (su *ServicesMasterMenuUserGroup) GetAutoComplete(param string, pageOfParam string, limitOfStr string) (string, string, string, []AutoComplete, error) {
|
||||
// fmt.Println("ini param : ", param)
|
||||
|
||||
dummyAutoComplete := []AutoComplete{
|
||||
{
|
||||
Name: "Google",
|
||||
},
|
||||
{
|
||||
Name: "Google 1",
|
||||
},
|
||||
{
|
||||
Name: "Google 2",
|
||||
},
|
||||
{
|
||||
Name: "Google 3",
|
||||
},
|
||||
{
|
||||
Name: "Google 4",
|
||||
},
|
||||
{
|
||||
Name: "Google 5",
|
||||
},
|
||||
{
|
||||
Name: "Google 6",
|
||||
},
|
||||
{
|
||||
Name: "Gojek",
|
||||
},
|
||||
{
|
||||
Name: "Mozilla Firefox",
|
||||
},
|
||||
{
|
||||
Name: "Apple",
|
||||
},
|
||||
{
|
||||
Name: "Microsoft",
|
||||
},
|
||||
{
|
||||
Name: "Facebook",
|
||||
},
|
||||
{
|
||||
Name: "Amazon",
|
||||
},
|
||||
{
|
||||
Name: "Twitter",
|
||||
},
|
||||
{
|
||||
Name: "Instagram",
|
||||
},
|
||||
{
|
||||
Name: "Snapchat",
|
||||
},
|
||||
{
|
||||
Name: "LinkedIn",
|
||||
},
|
||||
{
|
||||
Name: "Netflix",
|
||||
},
|
||||
{
|
||||
Name: "YouTube",
|
||||
},
|
||||
{
|
||||
Name: "Reddit",
|
||||
},
|
||||
{
|
||||
Name: "WhatsApp",
|
||||
},
|
||||
{
|
||||
Name: "Pinterest",
|
||||
},
|
||||
{
|
||||
Name: "TikTok",
|
||||
},
|
||||
{
|
||||
Name: "Spotify",
|
||||
},
|
||||
{
|
||||
Name: "Zoom",
|
||||
},
|
||||
}
|
||||
|
||||
var textFound string
|
||||
var results []AutoComplete
|
||||
// var currentRes []AutoComplete
|
||||
// var oldResults []AutoComplete
|
||||
// var limit int = 3
|
||||
var count int = 0
|
||||
var foundCount int = 0
|
||||
var totalData int = 0
|
||||
var startIndex int = 0
|
||||
var endIndex int = 3
|
||||
|
||||
if len(dummyAutoComplete) > 0 {
|
||||
totalData = len(dummyAutoComplete)
|
||||
}
|
||||
|
||||
// pageOf, err := strconv.Atoi(pageOfParam)
|
||||
// if err != nil {
|
||||
// return "", "", "", nil, err
|
||||
// }
|
||||
|
||||
limit, err := strconv.Atoi(limitOfStr)
|
||||
if err != nil {
|
||||
return "", "", "", nil, err
|
||||
}
|
||||
|
||||
// find data search
|
||||
if pageOfParam == "1" {
|
||||
count = 0
|
||||
// for _, item := range dummyAutoComplete {
|
||||
// if utils.Contains(item.Name, param) {
|
||||
// results = append(results, item)
|
||||
// count++
|
||||
// if count == limit {
|
||||
// break
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
for _, item := range dummyAutoComplete {
|
||||
if utils.Contains(item.Name, param) {
|
||||
// Check if the item is already in results
|
||||
found := false
|
||||
for _, res := range results {
|
||||
if res.Name == item.Name {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
// If not found, append it
|
||||
if !found {
|
||||
results = append(results, item)
|
||||
count++
|
||||
if count == limit {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
// ketika klik load more
|
||||
// count = 0
|
||||
for _, item := range dummyAutoComplete {
|
||||
if utils.Contains(item.Name, param) {
|
||||
results = append(results, item)
|
||||
count++
|
||||
if count == limit {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
startIndex = 0
|
||||
endIndex = limit
|
||||
|
||||
if startIndex >= len(dummyAutoComplete) {
|
||||
return "", "max", "", nil, nil
|
||||
}
|
||||
|
||||
if endIndex > len(dummyAutoComplete) {
|
||||
endIndex = len(dummyAutoComplete)
|
||||
}
|
||||
|
||||
for _, item := range dummyAutoComplete[startIndex:endIndex] {
|
||||
found := false
|
||||
for _, res := range results {
|
||||
if res.Name == item.Name {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
// If not found, append it
|
||||
if !found {
|
||||
results = append(results, item)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foundCount = len(results)
|
||||
totalCount := len(dummyAutoComplete)
|
||||
textFound = fmt.Sprintf("Ditemukan %d dari %d", foundCount, totalCount)
|
||||
|
||||
return strconv.Itoa(totalData), strconv.Itoa(foundCount), textFound, results, nil
|
||||
}
|
||||
func (ug *ServicesMasterMenuUserGroup) GetUserGroup() ([]models.UserGroup, error) {
|
||||
data := []models.UserGroup{
|
||||
{UserGroupID: 1, UserGroupKode: "A", UserGroupName: "UG1"},
|
||||
|
||||
Reference in New Issue
Block a user