8000 add change drawer data can`t close direct by zhangshanwen · Pull Request #497 · qor5/admin · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

add change drawer data can`t close direct #497

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 3 commits into from
Aug 20, 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
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func flowDuplicate_Step00_Event_presets_DetailingDrawer(t *testing.T, f *FlowDup
assert.Len(t, resp.UpdatePortals, 1)
assert.Equal(t, "presets_RightDrawerPortalName", resp.UpdatePortals[0].Name)
assert.Nil(t, resp.Data)
assert.Equal(t, testflow.RemoveTime(`setTimeout(function(){ vars.presetsRightDrawer = true }, 100)`), testflow.RemoveTime(resp.RunScript))
assert.Equal(t, testflow.RemoveTime(`setTimeout(function(){ vars.presetsRightDrawer = true,vars.conformLeave=false,vars.presetsDataChanged = {} }, 100)`), testflow.RemoveTime(resp.RunScript))

testflow.Validate(t, w, r,
testflow.OpenRightDrawer("WithPublishProduct "+f.ID),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func flowNew_Step00_Event_presets_New(t *testing.T, f *FlowNew) *testflow.Then {
assert.Len(t, resp.UpdatePortals, 1)
assert.Equal(t, "presets_RightDrawerPortalName", resp.UpdatePortals[0].Name)
assert.Nil(t, resp.Data)
assert.Equal(t, testflow.RemoveTime(`setTimeout(function(){ vars.presetsRightDrawer = true }, 100)`), testflow.RemoveTime(resp.RunScript))
assert.Equal(t, testflow.RemoveTime(`setTimeout(function(){ vars.presetsRightDrawer = true,vars.conformLeave=false,vars.presetsDataChanged = {} }, 100)`), testflow.RemoveTime(resp.RunScript))

testflow.Validate(t, w, r,
testflow.OpenRightDrawer("New WithPublishProduct"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func flowPerm_Step00_Event_presets_DetailingDrawer(t *testing.T, f *FlowPerm) *t
assert.Len(t, resp.UpdatePortals, 1)
assert.Equal(t, "presets_RightDrawerPortalName", resp.UpdatePortals[0].Name)
assert.Nil(t, resp.Data)
assert.Equal(t, testflow.RemoveTime(`setTimeout(function(){ vars.presetsRightDrawer = true }, 100)`), testflow.RemoveTime(resp.RunScript))
assert.Equal(t, testflow.RemoveTime(`setTimeout(function(){ vars.presetsRightDrawer = true,vars.conformLeave=false,vars.presetsDataChanged = {} }, 100)`), testflow.RemoveTime(resp.RunScript))

testflow.Validate(t, w, r,
testflow.OpenRightDrawer("WithPublishProduct "+f.ID),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func flowPublish_Step00_Event_presets_DetailingDrawer(t *testing.T, f *FlowPubli
assert.Len(t, resp.UpdatePortals, 1)
assert.Equal(t, "presets_RightDrawerPortalName", resp.UpdatePortals[0].Name)
assert.Nil(t, resp.Data)
assert.Equal(t, testflow.RemoveTime(`setTimeout(function(){ vars.presetsRightDrawer = true }, 100)`), testflow.RemoveTime(resp.RunScript))
assert.Equal(t, testflow.RemoveTime(`setTimeout(function(){ vars.presetsRightDrawer = true,vars.conformLeave=false,vars.presetsDataChanged = {} }, 100)`), testflow.RemoveTime(resp.RunScript))

testflow.Validate(t, w, r,
testflow.OpenRightDrawer("WithPublishProduct "+f.ID),
Expand Down Expand Up @@ -177,7 +177,7 @@ func flowPublish_Step02_Event_presets_DetailingDrawer(t *testing.T, f *FlowPubli
assert.Len(t, resp.UpdatePortals, 1)
assert.Equal(t, "presets_RightDrawerPortalName", resp.UpdatePortals[0].Name)
assert.Nil(t, resp.Data)
assert.Equal(t, testflow.RemoveTime(`setTimeout(function(){ vars.presetsRightDrawer = true }, 100)`), testflow.RemoveTime(resp.RunScript))
assert.Equal(t, testflow.RemoveTime(`setTimeout(function(){ vars.presetsRightDrawer = true,vars.conformLeave=false,vars.presetsDataChanged = {} }, 100)`), testflow.RemoveTime(resp.RunScript))

testflow.Validate(t, w, r,
testflow.OpenRightDrawer("WithPublishProduct "+f.ID),
Expand Down Expand Up @@ -230,7 +230,7 @@ func flowPublish_Step04_Event_presets_DetailingDrawer(t *testing.T, f *FlowPubli
assert.Len(t, resp.UpdatePortals, 1)
assert.Equal(t, "presets_RightDrawerPortalName", resp.UpdatePortals[0].Name)
assert.Nil(t, resp.Data)
assert.Equal(t, testflow.RemoveTime(`setTimeout(function(){ vars.presetsRightDrawer = true }, 100)`), testflow.RemoveTime(resp.RunScript))
assert.Equal(t, testflow.RemoveTime(`setTimeout(function(){ vars.presetsRightDrawer = true,vars.conformLeave=false,vars.presetsDataChanged = {} }, 100)`), testflow.RemoveTime(resp.RunScript))

testflow.Validate(t, w, r,
testflow.OpenRightDrawer("WithPublishProduct "+f.ID),
Expand Down Expand Up @@ -283,7 +283,7 @@ func flowPublish_Step06_Event_presets_DetailingDrawer(t *testing.T, f *FlowPubli
assert.Len(t, resp.UpdatePortals, 1)
assert.Equal(t, "presets_RightDrawerPortalName", resp.UpdatePortals[0].Name)
assert.Nil(t, resp.Data)
assert.Equal(t, testflow.RemoveTime(`setTimeout(function(){ vars.presetsRightDrawer = true }, 100)`), testflow.RemoveTime(resp.RunScript))
assert.Equal(t, testflow.RemoveTime(`setTimeout(function(){ vars.presetsRightDrawer = true,vars.conformLeave=false,vars.presetsDataChanged = {} }, 100)`), testflow.RemoveTime(resp.RunScript))

testflow.Validate(t, w, r,
testflow.OpenRightDrawer("WithPublishProduct "+f.ID),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func flowSchedule_Step00_Event_presets_DetailingDrawer(t *testing.T, f *FlowSche
assert.Len(t, resp.UpdatePortals, 1)
assert.Equal(t, "presets_RightDrawerPortalName", resp.UpdatePortals[0].Name)
assert.Nil(t, resp.Data)
assert.Equal(t, testflow.RemoveTime(`setTimeout(function(){ vars.presetsRightDrawer = true }, 100)`), testflow.RemoveTime(resp.RunScript))
assert.Equal(t, testflow.RemoveTime(`setTimeout(function(){ vars.presetsRightDrawer = true,vars.conformLeave=false,vars.presetsDataChanged = {} }, 100)`), testflow.RemoveTime(resp.RunScript))

testflow.Validate(t, w, r,
testflow.OpenRightDrawer("WithPublishProduct "+f.ID),
Expand Down
2 changes: 1 addition & 1 deletion pagebuilder/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func overview(m *ModelBuilder) presets.FieldComponentFunc {
onlineHint,
versionComponent,
web.Listen(m.mb.NotifModelsUpdated(),
web.Plaid().PushState(true).URL(m.mb.Info().DetailingHref(ps)).Go()),
web.Plaid().URL(m.mb.Info().DetailingHref(ps)).Go()),
h.Div(
h.Div(
h.If(containerCount == 0,
Expand Down
2 changes: 2 additions & 0 deletions presets/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ const (
ParamAfterDeleteEvent = "presets_after_delete_event"
ParamPortalName = "portal_name"

presetsDataChanged = "presetsDataChanged"

// list editor
ParamAddRowFormKey = "listEditor_AddRowFormKey"
ParamRemoveRowFormKey = "listEditor_RemoveRowFormKey"
Expand Down
3 changes: 2 additions & 1 deletion presets/detailing.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ func (b *DetailingBuilder) showInDrawer(ctx *web.EventContext) (r web.EventRespo
ShowMessage(&r, perm.PermissionDenied.Error(), "warning")
return
}
onChangeEvent := fmt.Sprintf("if (vars.%s) { vars.%s.detailing=true };", presetsDataChanged, presetsDataChanged)

overlayType := ctx.R.FormValue(ParamOverlay)
closeBtnVarScript := CloseRightDrawerVarScript
Expand Down Expand Up @@ -317,7 +318,7 @@ func (b *DetailingBuilder) showInDrawer(ctx *web.EventContext) (r web.EventRespo
).Class("pa-2"),
),
),
).VSlot("{ form }")
).VSlot("{ form }").OnChange(onChangeEvent).UseDebounce(150)

if b.idCurrentActiveProcessor != nil {
ctx.WithContextValue(ctxKeyIdCurrentActiveProcessor{}, b.idCurrentActiveProcessor)
Expand Down
10 changes: 6 additions & 4 deletions presets/editing.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func (b *EditingBuilder) editFormFor(obj interface{}, ctx *web.EventContext) h.H
id := ctx.R.FormValue(ParamID)
overlayType := ctx.R.FormValue(ParamOverlay)
isAutoSave := b.onChangeAction != nil && overlayType == actions.Content

onChangeEvent := fmt.Sprintf(`if (vars.%s) { vars.%s.editing=true };`, presetsDataChanged, presetsDataChanged)
if b.mb.singleton {
id = vx.ObjectID(obj)
}
Expand Down Expand Up @@ -384,11 +384,13 @@ func (b *EditingBuilder) editFormFor(obj interface{}, ctx *web.EventContext) h.H
VCard(asideContent).Variant(VariantFlat),
).Class("pa-2"),
),
)).VSlot("{ form }")
),
).VSlot("{ form }")
if isAutoSave {
scope.OnChange(b.onChangeAction(id, ctx))
return scope.OnChange(onChangeEvent + b.onChangeAction(id, ctx))
}
return scope
return scope.OnChange(onChangeEvent).UseDebounce(150)

}

func (b *EditingBuilder) doDelete(ctx *web.EventContext) (r web.EventResponse, err1 error) {
Expand Down
26 changes: 26 additions & 0 deletions presets/integration/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,32 @@ func TestExample(t *testing.T) {
return
},
},

{
Name: "Create Products Observe Change",
ReqFunc: func() *http.Request {
productData.TruncatePut(dbr)
return NewMultipartBuilder().
PageURL("/admin/products").
EventFunc(actions.New).
BuildEventFuncRequest()
},
ExpectPortalUpdate0ContainsInOrder: []string{"Object.values(vars.presetsDataChanged)",
"v-dialog", "If you leave before submitting the form, you will lose all the unsaved input."},
},
{
Name: "Edit Products Observe Change",
ReqFunc: func() *http.Request {
productData.TruncatePut(dbr)
return NewMultipartBuilder().
PageURL("/admin/products").
EventFunc(actions.Edit).
Query("id", "12").
BuildEventFuncRequest()
},
ExpectPortalUpdate0ContainsInOrder: []string{"Object.values(vars.presetsDataChanged)",
"v-dialog", "If you leave before submitting the form, you will lose all the unsaved input."},
},
}

for _, c := range cases {
Expand Down
17 changes: 13 additions & 4 deletions 10000 presets/presets.go
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ const (
)

const (
CloseRightDrawerVarScript = "vars.presetsRightDrawer = false"
CloseRightDrawerVarScript = "if(Object.values(vars.presetsDataChanged).some(value => value === true)){vars.conformLeave=true;}else{vars.presetsRightDrawer = false;};"
CloseDialogVarScript = "vars.presetsDialog = false"
CloseListingDialogVarScript = "vars.presetsListingDialog = false"
)
Expand Down Expand Up @@ -878,6 +878,8 @@ func (b *Builder) rightDrawer(ctx *web.EventContext, r *web.EventResponse, comp
if width == "" {
width = b.rightDrawerWidth
}
msgr := MustGetMessages(ctx.R)
listenChangeEvent := fmt.Sprintf("if(!$event && Object.values(vars.%s).some(value => value === true)) {vars.presetsRightDrawer=true};", presetsDataChanged)

activeWatcher, err := newActiveWatcher(ctx, "vars.presetsRightDrawer")
if err != nil {
Expand All @@ -886,16 +888,23 @@ func (b *Builder) rightDrawer(ctx *web.EventContext, r *web.EventResponse, comp
r.UpdatePortals = append(r.UpdatePortals, &web.PortalUpdate{
Name: RightDrawerPortalName,
Body: VNavigationDrawer(
VDialog(
VCard(
VCardActions(
VBtn(msgr.Cancel).Color(ColorSecondary).Attr("@click", "vars.conformLeave=false"),
VBtn(msgr.OK).Color(ColorPrimary).Attr("@click", "vars.conformLeave=false;vars.presetsRightDrawer = false")),
).PrependIcon("mdi-alert").Title(msgr.LeaveBeforeUnsubmit),
).Persistent(true).Width("auto").Attr("v-model", "vars.conformLeave"),
activeWatcher,
web.GlobalEvents().Attr("@keyup.esc", "vars.presetsRightDrawer = false"),
web.GlobalEvents().Attr("@keyup.esc", fmt.Sprintf(" if (!Object.values(vars.%s).some(value => value === true)) { vars.presetsRightDrawer = false} else {vars.conformLeave=true};", presetsDataChanged)),
web.Portal(comp).Name(RightDrawerContentPortalName),
).
// Attr("@input", "plaidForm.dirty && vars.presetsRightDrawer == false && !confirm('You have unsaved changes on this form. If you close it, you will lose all unsaved changes. Are you sure you want to close it?') ? vars.presetsRightDrawer = true: vars.presetsRightDrawer = $event"). // remove because drawer plaidForm has to be reset when UpdateOverlayContent
Class("v-navigation-drawer--temporary").
Attr("v-model", "vars.presetsRightDrawer").
Attr("@update:model-value", listenChangeEvent).
Location(LocationRight).
Temporary(true).
Persistent(true).
// Fixed(true).
Width(width).
Attr(":height", `"100%"`),
Expand All @@ -904,7 +913,7 @@ func (b *Builder) rightDrawer(ctx *web.EventContext, r *web.EventResponse, comp
// Floating(true).

})
r.RunScript = "setTimeout(function(){ vars.presetsRightDrawer = true }, 100)"
r.RunScript = fmt.Sprintf(`setTimeout(function(){ vars.presetsRightDrawer = true,vars.conformLeave=false,vars.%s = {} }, 100)`, presetsDataChanged)
}

func (b *Builder) contentDrawer(ctx *web.EventContext, r *web.EventResponse, comp h.HTMLComponent, width string) {
Expand Down
10 changes: 6 additions & 4 deletions presets/section.go
Original file line number D BEA9 iff line number Diff line change
Expand Up @@ -457,9 +457,12 @@ func (b *SectionBuilder) editComponent(obj interface{}, field *FieldContext, ctx
id = slugIf.PrimarySlug()
}
}
onChangeEvent := fmt.Sprintf("if (vars.%s ){ vars.%s.section_%s=true };", presetsDataChanged, presetsDataChanged, b.name)
cancelChangeEvent := fmt.Sprintf("if (vars.%s ){vars.%s.section_%s=false};", presetsDataChanged, presetsDataChanged, b.name)

cancelBtn := VBtn(i18n.T(ctx.R, CoreI18nModuleKey, "Cancel")).Size(SizeSmall).Variant(VariantFlat).Color(ColorGreyLighten3).
Attr("style", "text-transform: none;").
Attr("@click", web.Plaid().
Attr("@click", cancelChangeEvent+web.Plaid().
URL(ctx.R.URL.Path).
EventFunc(actions.DoSaveDetailingField).
Query(SectionFieldName, b.name).
Expand All @@ -470,7 +473,7 @@ func (b *SectionBuilder) editComponent(obj interface{}, field *FieldContext, ctx
disableEditBtn := b.father.mb.Info().Verifier().Do(PermUpdate).ObjectOn(obj).WithReq(ctx.R).IsAllowed() != nil
saveBtn := VBtn(i18n.T(ctx.R, CoreI18nModuleKey, "Save")).PrependIcon("mdi-check").Size(SizeSmall).Variant(VariantFlat).Color(ColorPrimary).Disabled(disableEditBtn).
Attr("style", "text-transform: none;").
Attr("@click", web.Plaid().
Attr("@click", cancelChangeEvent+web.Plaid().
URL(ctx.R.URL.Path).
EventFunc(actions.DoSaveDetailingField).
Query(SectionFieldName, b.name).
Expand Down Expand Up @@ -514,12 +517,11 @@ func (b *SectionBuilder) editComponent(obj interface{}, field *FieldContext, ctx
).Class("section-body"),
)
}

return h.Div(
web.Scope(
content,
hiddenComp,
).VSlot("{ form }"),
).VSlot("{ form }").OnChange(onChangeEvent).UseDebounce(150),
)
}

Expand Down
2 changes: 1 addition & 1 deletion utils/testflow/gentool/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/gobuffalo/flect v1.0.2
github.com/pkg/errors v0.9.1
github.com/qor5/admin/v3 v3.0.1-0.20240424102851-d75759576158
github.com/qor5/web/v3 v3.0.6
github.com/qor5/web/v3 v3.0.7-0.20240820073152-c8eaf32af2a1
github.com/sergi/go-diff v1.3.1
mvdan.cc/gofumpt v0.6.0
)
Expand Down
1 change: 1 addition & 0 deletions utils/testflow/gentool/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/qor5/web/v3 v3.0.6 h1:9OjFl/5czP2adC5b6YR/ybLJjHBJjaC1k0zJs0l31gc=
github.com/qor5/web/v3 v3.0.6/go.mod h1:32vdHHcZb2JimlcaclW9hLUyimdXjrllZDHTh3rl6d0=
github.com/qor5/web/v3 v3.0.7-0.20240820073152-c8eaf32af2a1/go.mod h1:32vdHHcZb2JimlcaclW9hLUyimdXjrllZDHTh3rl6d0=
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8=
Expand Down
Loading
0