-
Notifications
You must be signed in to change notification settings - Fork 12
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
Fix/campaign publish #275
Merged
Merged
Fix/campaign publish #275
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7e7d08b
fix campaign can`t publish
zhangshanwen 78037ac
suport defaultPublishActions and custom PublishActions
zhangshanwen 31e3818
Rename a few names
sunfmin 2d550c1
fix liveurl
zhangshanwen 592a353
add WrapPublishActions; remove LiveUrl
zhangshanwen a771947
Regenerate all docs
sunfmin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,80 +7,55 @@ | |
"path" | ||
"path/filepath" | ||
|
||
"github.com/qor/oss" | ||
"github.com/qor5/admin/v3/utils" | ||
|
||
"github.com/qor5/admin/v3/l10n" | ||
|
||
"github.com/qor/oss" | ||
"github.com/qor5/admin/v3/publish" | ||
"gorm.io/gorm" | ||
) | ||
|
||
type contextKeyType int | ||
|
||
const contextKey contextKeyType = iota | ||
|
||
func (b *ModelBuilder) ContextValueProvider(in context.Context) context.Context { | ||
return context.WithValue(in, contextKey, b) | ||
} | ||
|
||
func builderFromContext(c context.Context) (b *ModelBuilder, ok bool) { | ||
b, ok = c.Value(contextKey).(*ModelBuilder) | ||
return | ||
} | ||
func (p *Page) PublishUrl(db *gorm.DB, ctx context.Context, storage oss.StorageInterface) (s string) { | ||
var ( | ||
err error | ||
localePath string | ||
) | ||
builder := ctx.Value(utils.GetObjName(p)) | ||
|
||
func (p *Page) GetPublishActions(db *gorm.DB, ctx context.Context, storage oss.StorageInterface) (objs []*publish.PublishAction, err error) { | ||
var b *ModelBuilder | ||
var ok bool | ||
if b, ok = builderFromContext(ctx); !ok || b == nil { | ||
return | ||
} | ||
content, err := p.getPublishContent(b, ctx) | ||
if err != nil { | ||
b, ok := builder.(*ModelBuilder) | ||
if !ok { | ||
return | ||
} | ||
|
||
var localePath string | ||
if b.builder.l10n != nil { | ||
localePath = l10n.LocalePathFromContext(p, ctx) | ||
} | ||
|
||
var category Category | ||
category, err = p.GetCategory(db) | ||
if err != nil { | ||
if category, err = p.GetCategory(db); err != nil { | ||
return | ||
} | ||
objs = append(objs, &publish.PublishAction{ | ||
Url: p.getPublishUrl(localePath, category.Path), | ||
Content: content, | ||
IsDelete: false, | ||
}) | ||
p.OnlineUrl = p.getPublishUrl(localePath, category.Path) | ||
return p.getPublishUrl(localePath, category.Path) | ||
} | ||
|
||
func (p *Page) LiveUrl(db *gorm.DB, ctx context.Context, storage oss.StorageInterface) (s string) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个方法一直返回空字符串? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 忘记返回了 |
||
var liveRecord Page | ||
|
||
builder := ctx.Value(utils.GetObjName(p)) | ||
mb, ok := builder.(ModelBuilder) | ||
if !ok { | ||
return | ||
} | ||
{ | ||
lrdb := db.Where("id = ? AND status = ?", p.ID, publish.StatusOnline) | ||
if b.builder.l10n != nil { | ||
if mb.builder.l10n != nil { | ||
lrdb = lrdb.Where("locale_code = ?", p.LocaleCode) | ||
} | ||
lrdb.First(&liveRecord) | ||
} | ||
if liveRecord.ID == 0 { | ||
return | ||
} | ||
|
||
if liveRecord.OnlineUrl != p.OnlineUrl { | ||
objs = append(objs, &publish.PublishAction{ | ||
Url: liveRecord.OnlineUrl, | ||
IsDelete: true, | ||
}) | ||
} | ||
|
||
return | ||
} | ||
|
||
func (p *Page) GetUnPublishActions(db *gorm.DB, ctx context.Context, storage oss.StorageInterface) (objs []*publish.PublishAction, err error) { | ||
objs = append(objs, &publish.PublishAction{ | ||
Url: p.OnlineUrl, | ||
IsDelete: true, | ||
}) | ||
return | ||
} | ||
|
||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个链接像是个列表页面?实际上是吗?