From 67e4581f118b399856091028d49e416c2536315b Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 17 Nov 2022 10:02:50 +0800 Subject: [PATCH 1/3] [change] importer --- importer/importer.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/importer/importer.go b/importer/importer.go index 6f09f3c5..bd77157b 100644 --- a/importer/importer.go +++ b/importer/importer.go @@ -59,10 +59,11 @@ func Open(name string) from.Source { ext := strings.ToLower(strings.TrimPrefix(filepath.Ext(name), ".")) switch ext { case "xlsx": - fullpath := name - if !strings.HasPrefix(fullpath, "/") { - fullpath = filepath.Join(xfs.Stor.Root, name) - } + // fullpath := name + fullpath := filepath.Join(xfs.Stor.Root, name) + // if !strings.HasPrefix(fullpath, "/") { + // fullpath = filepath.Join(xfs.Stor.Root, name) + // } return xlsx.Open(fullpath) } exception.New("暂不支持: %s 文件导入", 400, ext).Throw() From 515cbe68bc77990b2468fdba10df03b21489c2c1 Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 17 Nov 2022 10:19:52 +0800 Subject: [PATCH 2/3] [_] --- .gitignore | 1 + importer/importer_test.go | 16 ++++++++-------- importer/process_test.go | 9 ++++----- .../assets/multiple-columns.xlsx | Bin tests/{imports => data}/assets/multiple.xlsx | Bin tests/{imports => data}/assets/simple.csv | 0 tests/{imports => data}/assets/simple.xlsx | Bin 7 files changed, 13 insertions(+), 13 deletions(-) rename tests/{imports => data}/assets/multiple-columns.xlsx (100%) rename tests/{imports => data}/assets/multiple.xlsx (100%) rename tests/{imports => data}/assets/simple.csv (100%) rename tests/{imports => data}/assets/simple.xlsx (100%) diff --git a/.gitignore b/.gitignore index eea5ce1c..162dd4f1 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,7 @@ dist ui ^ui/index.html tests/data/* +!tests/data/assets debug.log yao-test dev.sh diff --git a/importer/importer_test.go b/importer/importer_test.go index d9d13184..8452e7bd 100644 --- a/importer/importer_test.go +++ b/importer/importer_test.go @@ -15,7 +15,7 @@ func TestLoad(t *testing.T) { assert.IsType(t, &Importer{}, Select("order")) } func TestFingerprintSimple(t *testing.T) { - simple := filepath.Join(config.Conf.Root, "imports", "assets", "simple.xlsx") + simple := filepath.Join(config.Conf.Root, "data", "assets", "simple.xlsx") file := xlsx.Open(simple) defer file.Close() imp := Select("order") @@ -24,7 +24,7 @@ func TestFingerprintSimple(t *testing.T) { } func TestAutoMappingSimple(t *testing.T) { - simple := filepath.Join(config.Conf.Root, "imports", "assets", "simple.xlsx") + simple := filepath.Join(config.Conf.Root, "data", "assets", "simple.xlsx") file := xlsx.Open(simple) defer file.Close() @@ -48,7 +48,7 @@ func TestAutoMappingSimple(t *testing.T) { } func TestDataGetSimple(t *testing.T) { - simple := filepath.Join(config.Conf.Root, "imports", "assets", "simple.xlsx") + simple := filepath.Join(config.Conf.Root, "data", "assets", "simple.xlsx") file := xlsx.Open(simple) defer file.Close() @@ -69,7 +69,7 @@ func TestDataGetSimple(t *testing.T) { } func TestDataChunkSimple(t *testing.T) { - simple := filepath.Join(config.Conf.Root, "imports", "assets", "simple.xlsx") + simple := filepath.Join(config.Conf.Root, "data", "assets", "simple.xlsx") file := xlsx.Open(simple) defer file.Close() @@ -83,7 +83,7 @@ func TestDataChunkSimple(t *testing.T) { } func TestRunSimple(t *testing.T) { - simple := filepath.Join(config.Conf.Root, "imports", "assets", "simple.xlsx") + simple := filepath.Join(config.Conf.Root, "data", "assets", "simple.xlsx") file := xlsx.Open(simple) defer file.Close() @@ -97,7 +97,7 @@ func TestRunSimple(t *testing.T) { } func TestDataPreviewSimple(t *testing.T) { - simple := filepath.Join(config.Conf.Root, "imports", "assets", "simple.xlsx") + simple := filepath.Join(config.Conf.Root, "data", "assets", "simple.xlsx") file := xlsx.Open(simple) defer file.Close() imp := Select("order") @@ -116,7 +116,7 @@ func TestDataPreviewSimple(t *testing.T) { } func TestMappingPreviewSimple(t *testing.T) { - simple := filepath.Join(config.Conf.Root, "imports", "assets", "simple.xlsx") + simple := filepath.Join(config.Conf.Root, "data", "assets", "simple.xlsx") file := xlsx.Open(simple) defer file.Close() @@ -140,7 +140,7 @@ func TestMappingPreviewSimple(t *testing.T) { } func TestMappingSetting(t *testing.T) { - simple := filepath.Join(config.Conf.Root, "imports", "assets", "simple.xlsx") + simple := filepath.Join(config.Conf.Root, "data", "assets", "simple.xlsx") file := xlsx.Open(simple) defer file.Close() diff --git a/importer/process_test.go b/importer/process_test.go index ba8f870d..d385e034 100644 --- a/importer/process_test.go +++ b/importer/process_test.go @@ -6,11 +6,10 @@ import ( "github.com/stretchr/testify/assert" "github.com/yaoapp/gou" - "github.com/yaoapp/yao/config" ) func TestProcessMapping(t *testing.T) { - simple := filepath.Join(config.Conf.Root, "imports", "assets", "simple.xlsx") + simple := filepath.Join("assets", "simple.xlsx") args := []interface{}{"order", simple} response := gou.NewProcess("xiang.import.Mapping", args...).Run() _, ok := response.(*Mapping) @@ -18,7 +17,7 @@ func TestProcessMapping(t *testing.T) { } func TestProcessMappingSetting(t *testing.T) { - simple := filepath.Join(config.Conf.Root, "imports", "assets", "simple.xlsx") + simple := filepath.Join("assets", "simple.xlsx") args := []interface{}{"order", simple} response := gou.NewProcess("xiang.import.MappingSetting", args...).Run() _, ok := response.(map[string]interface{}) @@ -26,7 +25,7 @@ func TestProcessMappingSetting(t *testing.T) { } func TestProcessData(t *testing.T) { - simple := filepath.Join(config.Conf.Root, "imports", "assets", "simple.xlsx") + simple := filepath.Join("assets", "simple.xlsx") mapping := gou.NewProcess("xiang.import.Mapping", "order", simple).Run() args := []interface{}{"order", simple, 1, 2, mapping} response := gou.NewProcess("xiang.import.Data", args...).Run() @@ -49,7 +48,7 @@ func TestProcessSetting(t *testing.T) { } func TestProcessRun(t *testing.T) { - simple := filepath.Join(config.Conf.Root, "imports", "assets", "simple.xlsx") + simple := filepath.Join("assets", "simple.xlsx") mapping := gou.NewProcess("xiang.import.Mapping", "order", simple).Run() args := []interface{}{"order", simple, mapping} response := gou.NewProcess("xiang.import.Run", args...).Run() diff --git a/tests/imports/assets/multiple-columns.xlsx b/tests/data/assets/multiple-columns.xlsx similarity index 100% rename from tests/imports/assets/multiple-columns.xlsx rename to tests/data/assets/multiple-columns.xlsx diff --git a/tests/imports/assets/multiple.xlsx b/tests/data/assets/multiple.xlsx similarity index 100% rename from tests/imports/assets/multiple.xlsx rename to tests/data/assets/multiple.xlsx diff --git a/tests/imports/assets/simple.csv b/tests/data/assets/simple.csv similarity index 100% rename from tests/imports/assets/simple.csv rename to tests/data/assets/simple.csv diff --git a/tests/imports/assets/simple.xlsx b/tests/data/assets/simple.xlsx similarity index 100% rename from tests/imports/assets/simple.xlsx rename to tests/data/assets/simple.xlsx From 467eb24539fc188899276bf7a958ccb33a9157a7 Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 17 Nov 2022 10:35:15 +0800 Subject: [PATCH 3/3] [fix] form bind table --- widgets/form/layout.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/widgets/form/layout.go b/widgets/form/layout.go index da0528df..cc489a3e 100644 --- a/widgets/form/layout.go +++ b/widgets/form/layout.go @@ -24,7 +24,7 @@ func (layout *LayoutDSL) BindModel(m *gou.Model, formID string, fields *FieldsDS Icon: "icon-trash-2", Style: "danger", Action: map[string]component.ParamsDSL{ - "Table.delete": {"model": formID}, + "Form.delete": {"model": formID}, }, Confirm: &component.ConfirmActionDSL{ Title: "::Confirm", @@ -108,7 +108,7 @@ func (layout *LayoutDSL) BindTable(tab *table.DSL, formID string, fields *Fields Icon: "icon-trash-2", Style: "danger", Action: map[string]component.ParamsDSL{ - "Table.delete": {"model": formID}, + "Form.delete": {"model": formID}, }, Confirm: &component.ConfirmActionDSL{ Title: "::Confirm", @@ -135,7 +135,7 @@ func (layout *LayoutDSL) BindTable(tab *table.DSL, formID string, fields *Fields } name := column.Key - if col, has := fields.Form[name]; has { + if col, has := fields.Form[name]; has && column.Bind != "deleted_at" { width := 12 columns = append(columns, Column{InstanceDSL: component.InstanceDSL{Name: col.Key, Width: width}}) }