content.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. package pagebuilder
  2. import (
  3. "fmt"
  4. "net/url"
  5. "github.com/qor5/admin/publish"
  6. . "github.com/qor5/ui/vuetify"
  7. "github.com/qor5/web"
  8. h "github.com/theplant/htmlgo"
  9. )
  10. func (b *Builder) PageContent(ctx *web.EventContext) (r web.PageResponse, err error) {
  11. isTpl := ctx.R.FormValue("tpl") != ""
  12. id := ctx.R.FormValue("id")
  13. version := ctx.R.FormValue("version")
  14. locale := ctx.R.Form.Get("locale")
  15. isLocalizable := ctx.R.Form.Has("locale")
  16. var body h.HTMLComponent
  17. var containerList h.HTMLComponent
  18. var device string
  19. var p *Page
  20. var previewHref string
  21. deviceQueries := url.Values{}
  22. deviceQueries.Add("tab", "content")
  23. if isTpl {
  24. previewHref = fmt.Sprintf("/preview?id=%s&tpl=1", id)
  25. // deviceQueries.Add("tpl", "1")
  26. if isLocalizable && l10nON {
  27. previewHref = fmt.Sprintf("/preview?id=%s&tpl=1&locale=%s", id, locale)
  28. // deviceQueries.Add("locale", locale)
  29. }
  30. } else {
  31. previewHref = fmt.Sprintf("/preview?id=%s&version=%s", id, version)
  32. // deviceQueries.Add("version", version)
  33. if isLocalizable && l10nON {
  34. previewHref = fmt.Sprintf("/preview?id=%s&version=%s&locale=%s", id, version, locale)
  35. // deviceQueries.Add("locale", locale)
  36. }
  37. }
  38. body, p, err = b.renderPageOrTemplate(ctx, isTpl, id, version, locale, true)
  39. if err != nil {
  40. return
  41. }
  42. r.PageTitle = fmt.Sprintf("Editor for %s: %s", id, p.Title)
  43. device, _ = b.getDevice(ctx)
  44. activeDevice := 0
  45. switch device {
  46. case DeviceTablet:
  47. activeDevice = 1
  48. case DevicePhone:
  49. activeDevice = 2
  50. }
  51. containerList, err = b.renderContainersList(ctx, p.ID, p.GetVersion(), p.GetLocale(), p.GetStatus() != publish.StatusDraft)
  52. if err != nil {
  53. return
  54. }
  55. // msgr := i18n.MustGetModuleMessages(ctx.R, I18nPageBuilderKey, Messages_en_US).(*Messages)
  56. r.Body = h.Components(
  57. VContainer(web.Portal(body).Name(editorPreviewContentPortal)).
  58. Class("mt-6").
  59. Fluid(true),
  60. VNavigationDrawer(
  61. VContainer(
  62. VRow(
  63. VCol(
  64. VBtnToggle(
  65. VBtn("").Icon(true).Children(
  66. VIcon("laptop_mac").Small(true),
  67. ).Attr("@click", web.Plaid().Queries(deviceQueries).Query("device", DeviceComputer).PushState(true).Go()),
  68. VBtn("").Icon(true).Children(
  69. VIcon("tablet_mac").Small(true),
  70. ).Attr("@click", web.Plaid().Queries(deviceQueries).Query("device", DeviceTablet).PushState(true).Go()),
  71. VBtn("").Icon(true).Children(
  72. VIcon("phone_iphone").Small(true),
  73. ).Attr("@click", web.Plaid().Queries(deviceQueries).Query("device", DevicePhone).PushState(true).Go()),
  74. ).Class("pa-2 rounded-lg").Attr("v-model", "locals.activeDevice").
  75. Attr(web.InitContextLocals, fmt.Sprintf(`{activeDevice: %d}`, activeDevice)).Dense(true),
  76. ).Cols(9).Class("pa-2"),
  77. VCol(
  78. VBtn("").Icon(true).Children(
  79. VIcon("visibility"),
  80. ).Class("pa-6").Href(b.prefix+previewHref).Target("_blank"),
  81. ).Cols(3).Class("pa-2 d-flex justify-center"),
  82. ),
  83. ),
  84. containerList,
  85. ).
  86. App(true).
  87. Right(true).
  88. Clipped(true).
  89. Fixed(true).
  90. Value(true).
  91. Width(420).
  92. Attr("v-model", "vars.pbEditorDrawer").
  93. Attr(web.InitContextVars, `{pbEditorDrawer: null}`),
  94. )
  95. return
  96. }