8000 AWS_REGION change to DB_RESET for show count down by zhangshanwen · Pull Request #663 · qor5/admin · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

AWS_REGION change to DB_RESET for show count down #663

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 19 additions & 23 deletions example/admin/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ var (
s3PublishBucket = osenv.Get("S3_Publish_Bucket", "s3-bucket for publish", "example-publish")
s3PublishRegion = osenv.Get("S3_Publish_Region", "s3-region for publish", "ap-northeast-1")
publishURL = osenv.Get("PUBLISH_URL", "publish url", "")
awsRegion = osenv.Get("AWS_REGION", "aws region for show count down", "")
dbReset = osenv.Get("DB_RESET", "db reset for show count down", "&q 8000 uot;)
resetAndImportInitialData = osenv.GetBool("RESET_AND_IMPORT_INITIAL_DATA",
"Will reset and import initial data if set to true", false)
)
Expand Down Expand Up @@ -320,7 +320,7 @@ func NewConfig(db *gorm.DB) Config {

b.Use(pageBuilder)

configListModel(b, ab)
configListModel(b, ab, publisher)

microb := microsite.New(db).Publisher(publisher)

Expand Down Expand Up @@ -368,12 +368,16 @@ func NewConfig(db *gorm.DB) Config {
}
}

func configListModel(b *presets.Builder, ab *activity.Builder) *presets.ModelBuilder {
l := b.Model(&models.ListModel{}).Use(ab)
func configListModel(b *presets.Builder, ab *activity.Builder, publisher *publish.Builder) *presets.ModelBuilder {
mb := b.Model(&models.ListModel{})
defer mb.Use(ab, publisher)
{
l.Listing("ID", "Title", "Status")
ed := l.Editing("StatusBar", "ScheduleBar", "Title", "DetailPath", "ListPath")
ed.Field("DetailPath").ComponentFunc(
mb.Listing("ID", "Title", "Status")
mb.Editing("Title")

detailing := mb.Detailing(publish.VersionsPublishBar, "Title", "DetailPath", "ListPath").Drawer(true)
detailing.Section("Title").Editing("Title")
detailing.Section("DetailPath").ComponentFunc(
func(obj interface{}, field *presets.FieldContext, ctx *web.EventContext) (r h.HTMLComponent) {
this := obj.(*models.ListModel)

Expand All @@ -384,8 +388,7 @@ func configListModel(b *presets.Builder, ab *activity.Builder) *presets.ModelBui
var content []h.HTMLComponent

content = append(content,
h.Label(i18n.PT(ctx.R, presets.ModelsI18nModuleKey, l.Info().Label(), field.Label)).Class("v-label v-label--active theme--light").Style("left: 0px; right: auto; position: absolute;"),
)
h.Label(i18n.PT(ctx.R, presets.ModelsI18nModuleKey, mb.Info().Label(), field.Label)))
domain := PublishStorage.GetEndpoint()
if this.OnlineUrl != "" {
p := this.OnlineUrl
Expand All @@ -394,17 +397,13 @@ func configListModel(b *presets.Builder, ab *activity.Builder) *presets.ModelBui

return h.Div(
h.Div(
h.Div(
content...,
).Class("v-text-field__slot").Style("padding: 8px 0;"),
h.Div(content...).Class("v-text-field__slot").Style("padding: 8px 0;"),
).Class("v-input__slot"),
).Class("v-input v-input--is-label-active v-input--is-dirty theme--light v-text-field v-text-field--is-booted")
},
).SetterFunc(func(obj interface{}, field *presets.FieldContext, ctx *web.EventContext) (err error) {
return nil
})
)

ed.Field("ListPath").ComponentFunc(
detailing.Section("ListPath").ComponentFunc(
func(obj interface{}, field *presets.FieldContext, ctx *web.EventContext) (r h.HTMLComponent) {
this := obj.(*models.ListModel)

Expand All @@ -415,8 +414,7 @@ func configListModel(b *presets.Builder, ab *activity.Builder) *presets.ModelBui
var content []h.HTMLComponent

content = append(content,
h.Label(i18n.PT(ctx.R, presets.ModelsI18nModuleKey, l.Info().Label(), field.Label)).Class("v-label v-label--active theme--light").Style("left: 0px; right: auto; position: absolute;"),
)
h.Label(i18n.PT(ctx.R, presets.ModelsI18nModuleKey, mb.Info().Label(), field.Label)))
domain := PublishStorage.GetEndpoint()
if this.OnlineUrl != "" {
p := this.GetListUrl(strconv.Itoa(this.PageNumber))
Expand All @@ -431,11 +429,9 @@ func configListModel(b *presets.Builder, ab *activity.Builder) *presets.ModelBui
).Class("v-input__slot"),
).Class("v-input v-input--is-label-active v-input--is-dirty theme--light v-text-field v-text-field--is-booted")
},
).SetterFunc(func(obj interface{}, field *presets.FieldContext, ctx *web.EventContext) (err error) {
return nil
})
)
}
return l
return mb
}

func configMenuOrder(b *presets.Builder) {
Expand Down Expand Up @@ -542,7 +538,7 @@ func configBrand(b *presets.Builder) {
v.VCol(h.H1(msgr.Demo)).Class("pt-4"),
),
// ).Density(DensityCompact),
h.If(awsRegion != "",
h.If(dbReset != "",
h.Div(
h.Span(msgr.DBResetTipLabel),
v.VIcon("schedule").Size(v.SizeXSmall),
Expand Down
65 changes: 65 additions & 0 deletions example/integration/activity_logs_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package integration_test

import (
"net/http"
"net/http/httptest"
"testing"

. "github.com/qor5/web/v3/multipartestutils"
"github.com/theplant/gofixtures"
"gorm.io/gorm"

"github.com/qor5/admin/v3/example/admin"
"github.com/qor5/admin/v3/example/models"
"github.com/qor5/admin/v3/role"
)

var activityLogsData = gofixtures.Data(gofixtures.Sql(`
INSERT INTO public.cms_activity_logs (id, created_at, updated_at, deleted_at, user_id, action, hidden, model_name, model_keys, model_label, model_link, detail, scope) VALUES (1, '2024-10-16 08:34:41.503174 +00:00', '2024-10-16 08:34:41.503543 +00:00', null, '888', 'login', false, 'User', '888', '', '', 'null', '');
`, []string{`cms_activity_logs`}))

var eCDashboardData = gofixtures.Data(gofixtures.Sql(`
INSERT INTO public.products (id, created_at, updated_at, deleted_at, code, name, price, image, status, online_url, scheduled_start_at, scheduled_end_at, actual_start_at, actual_end_at, version, version_name, parent_version) VALUES (1, '2024-10-18 09:11:31.659366 +00:00', '2024-10-18 09:11:31.659366 +00:00', null, '123', '123', 10, null, 'draft', '', null, null, null, null, '2024-10-18-v01', '2024-10-18-v01', '');
INSERT INTO public.orders (id, created_at, updated_at, deleted_at, source, status, delivery_method, payment_method, confirmed_at, order_items) VALUES (1, null, null, null, null, 'Pending', null, null, null, null);
`, []string{`products`, "orders"}))

func TestActivityLogs(t *testing.T) {
h := admin.TestHandler(TestDB, &models.User{
Model: gorm.Model{ID: 888},
Name: "viwer@theplant.jp",
Roles: []role.Role{
{
Name: models.RoleEditor,
},
},
})
dbr, _ := TestDB.DB()

cases := []TestCase{
{
Name: "Index Activity Logs",
Debug: true,
ReqFunc: func() *http.Request {
activityLogsData.TruncatePut(dbr)
return httptest.NewRequest("GET", "/activity-logs", nil)
},
ExpectPageBodyContainsInOrder: []string{"login"},
},

{
Name: "Index ECDashboard",
Debug: true,
ReqFunc: func() *http.Request {
eCDashboardData.TruncatePut(dbr)
return httptest.NewRequest("GET", "/ec-dashboard", nil)
},
ExpectPageBodyContainsInOrder: []string{"Statistics", "Order Status", "Pending"},
},
}

for _, c := range cases {
t.Run(c.Name, func(t *testing.T) {
RunCase(t, c, h)
})
}
}
69 changes: 69 additions & 0 deletions example/integration/list_model_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package integration_test

import (
"net/http"
"net/http/httptest"
"testing"

. "github.com/qor5/web/v3/multipartestutils"
"github.com/theplant/gofixtures"

"github.com/qor5/admin/v3/example/admin"
"github.com/qor5/admin/v3/presets"
"github.com/qor5/admin/v3/presets/actions"
)

var listModelData = gofixtures.Data(gofixtures.Sql(`
INSERT INTO public.list_models (id, created_at, updated_at, deleted_at, title, status, online_url, scheduled_start_at, scheduled_end_at, actual_start_at, actual_end_at, page_number, position, list_deleted, list_updated, version, version_name, parent_version) VALUES (1, '2024-10-18 07:23:43.969040 +00:00', '2024-10-18 07:23:43.969040 +00:00', null, '123', 'online', '/tmp/public', null, null, null, null, 1, 0, false, false, '2024-10-18-v01', '2024-10-18-v01', '');
INSERT INTO public.list_models (id, created_at, updated_at, deleted_at, title, status, online_url, scheduled_start_at, scheduled_end_at, actual_start_at, actual_end_at, page_number, position, list_deleted, list_updated, version, version_name, parent_version) VALUES (2, '2024-10-18 07:23:43.969040 +00:00', '2024-10-18 07:23:43.969040 +00:00', null, '456', 'draft', '', null, null, null, null, 0, 0, false, false, '2024-10-18-v01', '2024-10-18-v01', '');
`, []string{`list_models`}))

func TestListModel(t *testing.T) {
h := admin.TestHandler(TestDB, nil)
dbr, _ := TestDB.DB()

cases := []TestCase{
{
Name: "Index ListModel",
Debug: true,
ReqFunc: func() *http.Request {
listModelData.TruncatePut(dbr)
return httptest.NewRequest("GET", "/list-models", nil)
},
ExpectPageBodyContainsInOrder: []string{"123", "Online"},
},
{
Name: "Detail ListModel",
Debug: true,
ReqFunc: func() *http.Request {
listModelData.TruncatePut(dbr)
req := NewMultipartBuilder().PageURL("/list-models").
EventFunc(actions.DetailingDrawer).
Query(presets.ParamID, "1_2024-10-18-v01").
BuildEventFuncRequest()
return req
},
ExpectPortalUpdate0 5D32 ContainsInOrder: []string{"Online", "Unpublish", "123", "Detail Path", "List Path"},
},
{
Name: "Detail ListModel Draft",
Debug: true,
ReqFunc: func() *http.Request {
listModelData.TruncatePut(dbr)
req := NewMultipartBuilder().PageURL("/list-models").
EventFunc(actions.DetailingDrawer).
Query(presets.ParamID, "2_2024-10-18-v01").
BuildEventFuncRequest()
return req
},
ExpectPortalUpdate0ContainsInOrder: []string{"Draft", "Publish", "456"},
ExpectPortalUpdate0NotContains: []string{"Detail Path", "List Path"},
},
}

for _, c := range cases {
t.Run(c.Name, func(t *testing.T) {
RunCase(t, c, h)
})
}
}
12 changes: 12 additions & 0 deletions example/integration/post_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ func TestPost(t *testing.T) {
},
ExpectPortalUpdate0ContainsInOrder: []string{`Title`, `vx-field`, "Hero Image", "Choose File", "Body", "vx-tiptap-editor"},
},
{
Name: "Index Post View",
Debug: true,
ReqFunc: func() *http.Request {
admin.PostsExampleData.TruncatePut(dbr)
req := multipartestutils.NewMultipartBuilder().
PageURL("/posts").
BuildEventFuncRequest()
return req
},
ExpectPageBodyContainsInOrder: []string{`Demo`, `vx-filter`, "Create Time"},
},
}

for _, c := range cases {
Expand Down
Loading
Loading
0