Skip to content
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

publish: add DisableDataChangeTracking for pagebuilder editor #544

Merged
merged 2 commits into from
Sep 3, 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
2 changes: 1 addition & 1 deletion activity/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type User struct {
Avatar string
}

const DefaultMaxCountShowInTimeline = 5
const DefaultMaxCountShowInTimeline = 10

// @snippet_begin(ActivityBuilder)
type Builder struct {
Expand Down
4 changes: 2 additions & 2 deletions docs/docsrc/examples/examples_admin/activity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ func TestActivity(t *testing.T) {
activityExample(pb, TestDB, func(mb *presets.ModelBuilder, ab *activity.Builder) {
defer pb.Use(ab)
ab.FindLogsForTimelineFunc(func(ctx context.Context, db *gorm.DB, modelName, modelKeys string) ([]*activity.ActivityLog, bool, error) {
maxCount := 11
maxCount := 10
var logs []*activity.ActivityLog
err := db.Where("hidden = FALSE AND model_name = ? AND model_keys = ? AND action = ?", modelName, modelKeys, activity.ActionNote).
Order("created_at DESC").Limit(maxCount).Find(&logs).Error
Order("created_at DESC").Limit(maxCount + 1).Find(&logs).Error
if err != nil {
return nil, false, err
}
Expand Down
2 changes: 1 addition & 1 deletion pagebuilder/editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (b *Builder) Editor(m *ModelBuilder) web.PageFunc {
Attr("ref", "overlay").
Attr("@after-leave", afterLeaveEvent).
Attr("v-model", "vars.overlay")
versionComponent = publish.DefaultVersionComponentFunc(m.editor, publish.VersionComponentConfig{Top: true, DisableListeners: true})(obj, &presets.FieldContext{ModelInfo: m.editor.Info()}, ctx)
versionComponent = publish.DefaultVersionComponentFunc(m.editor, publish.VersionComponentConfig{Top: true, DisableListeners: true, DisableDataChangeTracking: true})(obj, &presets.FieldContext{ModelInfo: m.editor.Info()}, ctx)
pageAppbarContent = h.Components(
h.Div(
h.Div().Style("transform:rotateY(180deg)").Class("mr-4").Children(
Expand Down
31 changes: 19 additions & 12 deletions publish/version_compo.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,23 @@ const VersionListDialogURISuffix = "-version-list-dialog"

type VersionComponentConfig struct {
// If you want to use custom publish dialog, you can update the portal named PublishCustomDialogPortalName
PublishEvent func(obj interface{}, field *presets.FieldContext, ctx *web.EventContext) string
UnPublishEvent func(obj interface{}, field *presets.FieldContext, ctx *web.EventContext) string
RePublishEvent func(obj interface{}, field *presets.FieldContext, ctx *web.EventContext) string
Top bool
DisableListeners bool
PublishEvent func(obj interface{}, field *presets.FieldContext, ctx *web.EventContext) string
UnPublishEvent func(obj interface{}, field *presets.FieldContext, ctx *web.EventContext) string
RePublishEvent func(obj interface{}, field *presets.FieldContext, ctx *web.EventContext) string
Top bool
DisableListeners bool
DisableDataChangeTracking bool
}

func DefaultVersionComponentFunc(mb *presets.ModelBuilder, cfg ...VersionComponentConfig) presets.FieldComponentFunc {
var config VersionComponentConfig
if len(cfg) > 0 {
config = cfg[0]
}
phraseHasPresetsDataChanged := presets.PhraseHasPresetsDataChanged
if config.DisableDataChangeTracking {
phraseHasPresetsDataChanged = "false"
}
return func(obj interface{}, field *presets.FieldContext, ctx *web.EventContext) h.HTMLComponent {
var (
version VersionInterface
Expand Down Expand Up @@ -85,7 +90,7 @@ func DefaultVersionComponentFunc(mb *presets.ModelBuilder, cfg ...VersionCompone
h.Text(`{{ xlocals.versionName }}`),
).Label(true).Variant(v.VariantOutlined).
Attr("style", "height:36px;").
Attr(":disabled", presets.PhraseHasPresetsDataChanged).
Attr(":disabled", phraseHasPresetsDataChanged).
On("click", web.Plaid().EventFunc(actions.OpenListingDialog).
URL(mb.Info().PresetsPrefix()+"/"+urlSuffix).
Query(filterKeySelected, slug).
Expand All @@ -105,7 +110,7 @@ func DefaultVersionComponentFunc(mb *presets.ModelBuilder, cfg ...VersionCompone
if !DeniedDo(verifier, obj, ctx.R, presets.PermUpdate, PermDuplicate) {
div.AppendChildren(v.VBtn(msgr.Duplicate).
Height(36).Class("ml-2").Variant(v.VariantOutlined).
Attr(":disabled", presets.PhraseHasPresetsDataChanged).
Attr(":disabled", phraseHasPresetsDataChanged).
Attr("@click", fmt.Sprintf(`locals.action="%s";locals.commonConfirmDialog = true`, EventDuplicateVersion)))
}
}
Expand All @@ -122,7 +127,7 @@ func DefaultVersionComponentFunc(mb *presets.ModelBuilder, cfg ...VersionCompone
}
publishBtn = h.Div(
v.VBtn(msgr.Publish).
Attr(":disabled", presets.PhraseHasPresetsDataChanged).
Attr(":disabled", phraseHasPresetsDataChanged).
Attr("@click", publishEvent).Class("ml-2").
ClassIf("rounded", config.Top).ClassIf("rounded-0 rounded-s", !config.Top).
Variant(v.VariantElevated).Color(v.ColorPrimary).Height(36),
Expand All @@ -146,13 +151,13 @@ func DefaultVersionComponentFunc(mb *presets.ModelBuilder, cfg ...VersionCompone
publishBtn = h.Div(
h.Iff(unPublishEvent != "", func() h.HTMLComponent {
return v.VBtn(msgr.Unpublish).
Attr(":disabled", presets.PhraseHasPresetsDataChanged).
Attr(":disabled", phraseHasPresetsDataChanged).
Attr("@click", unPublishEvent).
Class("ml-2").Variant(v.VariantElevated).Color(v.ColorError).Height(36)
}),
h.Iff(rePublishEvent != "", func() h.HTMLComponent {
return v.VBtn(msgr.Republish).
Attr(":disabled", presets.PhraseHasPresetsDataChanged).
Attr(":disabled", phraseHasPresetsDataChanged).
Attr("@click", rePublishEvent).Class("ml-2").
ClassIf("rounded", config.Top).ClassIf("rounded-0 rounded-s", !config.Top).
Variant(v.VariantElevated).Color(v.ColorPrimary).Height(36)
Expand Down Expand Up @@ -182,11 +187,13 @@ func DefaultVersionComponentFunc(mb *presets.ModelBuilder, cfg ...VersionCompone
scheduleBtn = v.VAutocomplete().PrependInnerIcon("mdi-alarm").Density(v.DensityCompact).
Variant(v.FieldVariantSoloFilled).ModelValue(msgr.SchedulePublishTime).
BgColor(v.ColorPrimaryLighten2).Readonly(true).
Width(500).HideDetails(true).Attr("@click", clickEvent).Class("ml-2 text-caption page-builder-autoCmp")
Width(500).HideDetails(true).
Attr(":disabled", phraseHasPresetsDataChanged).
Attr("@click", clickEvent).Class("ml-2 text-caption page-builder-autoCmp")
} else {
scheduleBtn = v.VBtn("").Size(v.SizeSmall).Children(v.VIcon("mdi-alarm").Size(v.SizeXLarge)).Rounded("0").Class("rounded-e ml-abs-1").
Variant(v.VariantElevated).Color(v.ColorPrimary).Width(36).Height(36).
Attr(":disabled", presets.PhraseHasPresetsDataChanged).
Attr(":disabled", phraseHasPresetsDataChanged).
Attr("@click", clickEvent)
}
div.AppendChildren(scheduleBtn)
Expand Down
Loading