Can now convert csv to proto + open proto file + filter
This commit is contained in:
66
app.go
66
app.go
@@ -3,11 +3,16 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"git.cems.dev/cdricms/bdooc/proto"
|
||||
"github.com/wailsapp/wails/v2/pkg/runtime"
|
||||
)
|
||||
|
||||
// App struct
|
||||
type App struct {
|
||||
ctx context.Context
|
||||
ctx context.Context
|
||||
employees *proto.EmployeeList // Caching purposes
|
||||
}
|
||||
|
||||
// NewApp creates a new App application struct
|
||||
@@ -21,7 +26,60 @@ func (a *App) startup(ctx context.Context) {
|
||||
a.ctx = ctx
|
||||
}
|
||||
|
||||
// Greet returns a greeting for the given name
|
||||
func (a *App) Greet(name string) string {
|
||||
return fmt.Sprintf("Hello %s, It's show time!", name)
|
||||
func (a *App) GetEmployees(path string, limit, page uint, column, query *string) ([]*proto.Employee, error) {
|
||||
if a.employees == nil {
|
||||
e, err := proto.LoadFromFile(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
a.employees = e
|
||||
}
|
||||
|
||||
if column != nil && query != nil {
|
||||
e, err := a.employees.QueryEmployeesByColumn(proto.EmployeeField(proto.SnakeCaseToPascalCase(*column)), *query)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if uint(len(e)) < page*limit+limit {
|
||||
return e[page*limit:], nil
|
||||
}
|
||||
return e[page*limit : page*limit+limit], nil
|
||||
}
|
||||
|
||||
if uint(len(a.employees.Employees)) < page*limit+limit {
|
||||
return a.employees.Employees[page*limit:], nil
|
||||
}
|
||||
return a.employees.Employees[page*limit : page*limit+limit], nil
|
||||
}
|
||||
|
||||
func (a *App) SaveData(data []uint8, filename string) {
|
||||
err := proto.SaveToFile(data, filename)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (a *App) GetProtoPath() string {
|
||||
return a.OpenPath([]runtime.FileFilter{{
|
||||
DisplayName: "Proto binary file",
|
||||
Pattern: "*.bin",
|
||||
}})
|
||||
}
|
||||
|
||||
func (a *App) OpenPath(filters []runtime.FileFilter) string {
|
||||
path, err := runtime.OpenFileDialog(a.ctx, runtime.OpenDialogOptions{
|
||||
Filters: filters,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return path
|
||||
}
|
||||
|
||||
func (a *App) IsPathValid(path string) bool {
|
||||
_, err := os.Stat(path)
|
||||
fmt.Println(path)
|
||||
return !os.IsNotExist(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user