wip: conn list
This commit is contained in:
parent
b2c13508f4
commit
bea30130f1
@ -48,3 +48,14 @@ div.body-connections-search-dismiss{
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
div.body-connections-list-item {
|
||||
height: 36px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
font-size: 14px;
|
||||
margin: 1px 0;
|
||||
}
|
||||
div.body-connections-list-item:first-child {
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
@ -26,6 +26,18 @@ function Home() {
|
||||
})
|
||||
}, []);
|
||||
|
||||
async function handleConnect(item: Connection) {
|
||||
console.log('[DEBUG] double clicked item =', item)
|
||||
let res = await Dial<unknown>("/api/connection/connect", {id: item.id})
|
||||
if (res.status === 200) {
|
||||
connectionList.forEach((conn) => {
|
||||
if (conn.id === item.id) {
|
||||
conn.active = true
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="container">
|
||||
<div className="header">
|
||||
@ -47,7 +59,18 @@ function Home() {
|
||||
<DismissRegular/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="body-connections-list"></div>
|
||||
<div className="body-connections-list">
|
||||
{connectionList.map(item => {
|
||||
return <div className="body-connections-list-item" key={item.id}>
|
||||
<Button
|
||||
onDoubleClick={() => {
|
||||
handleConnect(item)
|
||||
}}
|
||||
appearance='transparent' style={{textIndent: '0px', justifyContent: 'left'}}
|
||||
>{item.name}</Button>
|
||||
</div>
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
<div className="body-content"></div>
|
||||
</div>
|
||||
|
3
frontend/wailsjs/go/controller/App.d.ts
vendored
3
frontend/wailsjs/go/controller/App.d.ts
vendored
@ -1,4 +1,7 @@
|
||||
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
|
||||
// This file is automatically generated. DO NOT EDIT
|
||||
import {context} from '../models';
|
||||
|
||||
export function Init(arg1:context.Context):Promise<void>;
|
||||
|
||||
export function Invoke(arg1:string,arg2:string):Promise<string>;
|
||||
|
@ -2,6 +2,10 @@
|
||||
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
|
||||
// This file is automatically generated. DO NOT EDIT
|
||||
|
||||
export function Init(arg1) {
|
||||
return window['go']['controller']['App']['Init'](arg1);
|
||||
}
|
||||
|
||||
export function Invoke(arg1, arg2) {
|
||||
return window['go']['controller']['App']['Invoke'](arg1, arg2);
|
||||
}
|
||||
|
2
go.mod
2
go.mod
@ -13,6 +13,7 @@ require (
|
||||
github.com/loveuer/go-sqlite3 v1.0.2
|
||||
github.com/loveuer/nf v0.2.11
|
||||
github.com/ncruces/go-sqlite3/gormlite v0.18.4
|
||||
github.com/pkg/errors v0.9.1
|
||||
github.com/psanford/httpreadat v0.1.0
|
||||
github.com/wailsapp/wails/v2 v2.9.2
|
||||
gorm.io/driver/mysql v1.5.7
|
||||
@ -58,7 +59,6 @@ require (
|
||||
github.com/ncruces/go-sqlite3 v0.18.4 // indirect
|
||||
github.com/ncruces/julianday v1.0.0 // indirect
|
||||
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // indirect
|
||||
github.com/pkg/errors v0.9.1 // indirect
|
||||
github.com/rivo/uniseg v0.4.4 // indirect
|
||||
github.com/samber/lo v1.38.1 // indirect
|
||||
github.com/tetratelabs/wazero v1.8.0 // indirect
|
||||
|
@ -27,6 +27,8 @@ func Init(ctx context.Context) error {
|
||||
register("/api/connection/test", handler.ConnectionTest)
|
||||
register("/api/connection/create", handler.ConnectionCreate)
|
||||
register("/api/connection/list", handler.ConnectionList)
|
||||
register("/api/connection/connect", handler.ConnectionConnect)
|
||||
register("/api/connection/buckets", handler.ConnectionBuckets)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -21,12 +21,14 @@ func NewApp() *App {
|
||||
}
|
||||
}
|
||||
|
||||
func (a *App) Startup(ctx context.Context) {
|
||||
log.Info("app startup!!!")
|
||||
|
||||
func (a *App) Init(ctx context.Context) {
|
||||
log.Info("app init!!!")
|
||||
a.ctx = ctx
|
||||
|
||||
tool.Must(db.Init(ctx, "sqlite::memory", db.OptSqliteByMem(nil)))
|
||||
tool.Must(model.Init(db.Default.Session()))
|
||||
tool.Must(api.Init(ctx))
|
||||
}
|
||||
|
||||
func (a *App) Startup(ctx context.Context) {
|
||||
log.Info("app startup!!!")
|
||||
}
|
||||
|
@ -6,6 +6,8 @@ import (
|
||||
"github.com/loveuer/nf-disk/internal/model"
|
||||
"github.com/loveuer/nf-disk/internal/s3"
|
||||
"github.com/loveuer/nf-disk/ndh"
|
||||
"github.com/pkg/errors"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func ConnectionTest(c *ndh.Ctx) error {
|
||||
@ -86,11 +88,20 @@ func ConnectionCreate(c *ndh.Ctx) error {
|
||||
}
|
||||
|
||||
func ConnectionList(c *ndh.Ctx) error {
|
||||
type Req struct {
|
||||
Keyword string `json:"keyword"`
|
||||
}
|
||||
|
||||
var (
|
||||
err error
|
||||
list = make([]*model.Connection, 0)
|
||||
req = new(Req)
|
||||
)
|
||||
|
||||
if err = c.ReqParse(req); err != nil {
|
||||
return c.Send400(nil, "参数错误")
|
||||
}
|
||||
|
||||
if err = db.Default.Session().Model(&model.Connection{}).
|
||||
Find(&list).
|
||||
Error; err != nil {
|
||||
@ -99,3 +110,56 @@ func ConnectionList(c *ndh.Ctx) error {
|
||||
|
||||
return c.Send200(map[string]any{"list": list})
|
||||
}
|
||||
|
||||
func ConnectionConnect(c *ndh.Ctx) error {
|
||||
type Req struct {
|
||||
Id uint64 `json:"id"`
|
||||
}
|
||||
|
||||
var (
|
||||
err error
|
||||
req = new(Req)
|
||||
conn = new(model.Connection)
|
||||
client *s3.Client
|
||||
)
|
||||
|
||||
if err = c.ReqParse(req); err != nil {
|
||||
return c.Send400(nil, "参数错误")
|
||||
}
|
||||
|
||||
if err = db.Default.Session().Take(conn, req.Id).Error; err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return c.Send400(c, "不存在的连接")
|
||||
}
|
||||
|
||||
return c.Send500(nil)
|
||||
}
|
||||
|
||||
if client, err = s3.New(c.Context(), conn.Endpoint, conn.Access, conn.Key); err != nil {
|
||||
return c.Send500(err.Error())
|
||||
}
|
||||
|
||||
if err = manager.Register(conn, client); err != nil {
|
||||
return c.Send500(err.Error())
|
||||
}
|
||||
|
||||
return c.Send200(conn)
|
||||
}
|
||||
|
||||
func ConnectionBuckets(c *ndh.Ctx) error {
|
||||
type Req struct {
|
||||
Id uint64 `json:"id"`
|
||||
Keyword string `json:"keyword"`
|
||||
}
|
||||
|
||||
var (
|
||||
err error
|
||||
req = new(Req)
|
||||
)
|
||||
|
||||
if err = c.ReqParse(req); err != nil {
|
||||
return c.Send400(nil, "参数错误")
|
||||
}
|
||||
|
||||
panic("implement me: ConnectionBuckets")
|
||||
}
|
||||
|
@ -1,9 +1,34 @@
|
||||
package model
|
||||
|
||||
import "gorm.io/gorm"
|
||||
import (
|
||||
"github.com/loveuer/nf-disk/internal/opt"
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
)
|
||||
|
||||
func Init(tx *gorm.DB) error {
|
||||
return tx.AutoMigrate(
|
||||
func Init(tx *gorm.DB) (err error) {
|
||||
err = tx.AutoMigrate(
|
||||
&Connection{},
|
||||
)
|
||||
|
||||
if opt.Debug {
|
||||
err = tx.Create([]*Connection{
|
||||
{
|
||||
Name: "dev-minio",
|
||||
Endpoint: "http://10.220.10.15:9000",
|
||||
Access: "8ALV3DUZI31YG4BDRJ0Z",
|
||||
Key: "CRqwS1MsiUj27TbRK+3T2n+LpKWd07VvaDKuzU0H",
|
||||
},
|
||||
{
|
||||
Name: "test",
|
||||
Endpoint: "http://10.220.10.14:19000",
|
||||
Access: "5VCR05L4BSGNCTCD8DXP",
|
||||
Key: "FPTMYBEiHhWLJ05C3aGXW8bjFXXNmghc8Za3Fo2u",
|
||||
},
|
||||
}).Clauses(clause.OnConflict{
|
||||
DoNothing: true,
|
||||
}).Error
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
@ -7,5 +7,5 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
Debug bool
|
||||
Debug bool = false
|
||||
)
|
||||
|
16
main.go
16
main.go
@ -1,10 +1,13 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"embed"
|
||||
"flag"
|
||||
"github.com/loveuer/nf-disk/internal/controller"
|
||||
"github.com/loveuer/nf/nft/nfctl/opt"
|
||||
"github.com/loveuer/nf-disk/internal/opt"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"github.com/loveuer/nf/nft/log"
|
||||
"github.com/wailsapp/wails/v2"
|
||||
@ -15,18 +18,21 @@ import (
|
||||
//go:embed all:frontend/dist
|
||||
var assets embed.FS
|
||||
|
||||
func init() {
|
||||
flag.BoolVar(&opt.Debug, "debug", false, "debug mode")
|
||||
func main() {
|
||||
ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
|
||||
defer cancel()
|
||||
|
||||
flag.BoolVar(&opt.Debug, "debug", true, "debug mode")
|
||||
flag.Parse()
|
||||
|
||||
if opt.Debug {
|
||||
log.SetLogLevel(log.LogLevelDebug)
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
app := controller.NewApp()
|
||||
|
||||
app.Init(ctx)
|
||||
|
||||
if err := wails.Run(&options.App{
|
||||
Title: "nf-disk",
|
||||
Width: 1024,
|
||||
|
Loading…
x
Reference in New Issue
Block a user