Consolidated shared editor-related params

This commit is contained in:
Asaf Gartner 2022-09-15 00:44:27 +03:00
parent c9ee420dbb
commit c489d0ffa9
6 changed files with 35 additions and 22 deletions

View File

@ -1,7 +1,7 @@
{{ template "base.html" . }} {{ template "base.html" . }}
{{ define "extrahead" }} {{ define "extrahead" }}
{{ template "markdown_previews.html" . }} {{ template "markdown_previews.html" .TextEditor }}
<script src="{{ static "js/base64.js" }}"></script> <script src="{{ static "js/base64.js" }}"></script>
<script src="{{ static "js/markdown_upload.js" }}"></script> <script src="{{ static "js/markdown_upload.js" }}"></script>
@ -116,8 +116,8 @@
</div> </div>
<script> <script>
const maxFileSize = {{ .MaxFileSize }}; const maxFileSize = {{ .TextEditor.MaxFileSize }};
const uploadUrl = {{ .UploadUrl }}; const uploadUrl = {{ .TextEditor.UploadUrl }};
const form = document.querySelector('#form'); const form = document.querySelector('#form');
const titleField = document.querySelector('#title'); // may be undefined, be careful! const titleField = document.querySelector('#title'); // may be undefined, be careful!

View File

@ -1,7 +1,7 @@
{{ template "base.html" . }} {{ template "base.html" . }}
{{ define "extrahead" }} {{ define "extrahead" }}
{{ template "markdown_previews.html" . }} {{ template "markdown_previews.html" .TextEditor }}
<script src="{{ static "js/tabs.js" }}"></script> <script src="{{ static "js/tabs.js" }}"></script>
<script src="{{ static "js/image_selector.js" }}"></script> <script src="{{ static "js/image_selector.js" }}"></script>
<script src="{{ static "js/templates.js" }}"></script> <script src="{{ static "js/templates.js" }}"></script>
@ -407,8 +407,8 @@
document.querySelector('.upload_bar'), document.querySelector('.upload_bar'),
description, description,
doMarkdown, doMarkdown,
{{ .MaxFileSize }}, {{ .TextEditor.MaxFileSize }},
{{ .UploadUrl }} {{ .TextEditor.UploadUrl }}
); );
</script> </script>

View File

@ -389,6 +389,12 @@ type Tag struct {
Url string Url string
} }
type TextEditor struct {
ParserName string
MaxFileSize int
UploadUrl string
}
type EduArticle struct { type EduArticle struct {
Title string Title string
Slug string Slug string

View File

@ -317,12 +317,14 @@ func getEditorDataForEduArticle(
SubmitLabel: "Submit", SubmitLabel: "Submit",
CanEditPostTitle: true, CanEditPostTitle: true,
MaxFileSize: AssetMaxSize(currentUser),
UploadUrl: urlContext.BuildAssetUpload(),
ShowEduOptions: true, ShowEduOptions: true,
PreviewClass: "edu-article", PreviewClass: "edu-article",
ParserName: "parseMarkdownEdu", TextEditor: templates.TextEditor{
ParserName: "parseMarkdownEdu",
MaxFileSize: AssetMaxSize(currentUser),
UploadUrl: urlContext.BuildAssetUpload(),
},
} }
if article != nil { if article != nil {

View File

@ -51,9 +51,7 @@ type editorData struct {
ShowEduOptions bool ShowEduOptions bool
PreviewClass string PreviewClass string
ParserName string TextEditor templates.TextEditor
MaxFileSize int
UploadUrl string
} }
func getEditorDataForNew(urlContext *hmnurl.UrlContext, currentUser *models.User, baseData templates.BaseData, replyPost *templates.Post) editorData { func getEditorDataForNew(urlContext *hmnurl.UrlContext, currentUser *models.User, baseData templates.BaseData, replyPost *templates.Post) editorData {
@ -61,8 +59,10 @@ func getEditorDataForNew(urlContext *hmnurl.UrlContext, currentUser *models.User
BaseData: baseData, BaseData: baseData,
CanEditPostTitle: replyPost == nil, CanEditPostTitle: replyPost == nil,
PostReplyingTo: replyPost, PostReplyingTo: replyPost,
MaxFileSize: AssetMaxSize(currentUser), TextEditor: templates.TextEditor{
UploadUrl: urlContext.BuildAssetUpload(), MaxFileSize: AssetMaxSize(currentUser),
UploadUrl: urlContext.BuildAssetUpload(),
},
} }
if replyPost != nil { if replyPost != nil {
@ -79,8 +79,10 @@ func getEditorDataForEdit(urlContext *hmnurl.UrlContext, currentUser *models.Use
CanEditPostTitle: p.Thread.FirstID == p.Post.ID, CanEditPostTitle: p.Thread.FirstID == p.Post.ID,
IsEditing: true, IsEditing: true,
EditInitialContents: p.CurrentVersion.TextRaw, EditInitialContents: p.CurrentVersion.TextRaw,
MaxFileSize: AssetMaxSize(currentUser), TextEditor: templates.TextEditor{
UploadUrl: urlContext.BuildAssetUpload(), MaxFileSize: AssetMaxSize(currentUser),
UploadUrl: urlContext.BuildAssetUpload(),
},
} }
} }

View File

@ -419,8 +419,7 @@ type ProjectEditData struct {
APICheckUsernameUrl string APICheckUsernameUrl string
LogoMaxFileSize int LogoMaxFileSize int
MaxFileSize int TextEditor templates.TextEditor
UploadUrl string
} }
func ProjectNew(c *RequestContext) ResponseData { func ProjectNew(c *RequestContext) ResponseData {
@ -463,8 +462,10 @@ func ProjectNew(c *RequestContext) ResponseData {
APICheckUsernameUrl: hmnurl.BuildAPICheckUsername(), APICheckUsernameUrl: hmnurl.BuildAPICheckUsername(),
LogoMaxFileSize: ProjectLogoMaxFileSize, LogoMaxFileSize: ProjectLogoMaxFileSize,
MaxFileSize: AssetMaxSize(c.CurrentUser), TextEditor: templates.TextEditor{
UploadUrl: c.UrlContext.BuildAssetUpload(), MaxFileSize: AssetMaxSize(c.CurrentUser),
UploadUrl: c.UrlContext.BuildAssetUpload(),
},
}, c.Perf) }, c.Perf)
return res return res
} }
@ -606,8 +607,10 @@ func ProjectEdit(c *RequestContext) ResponseData {
APICheckUsernameUrl: hmnurl.BuildAPICheckUsername(), APICheckUsernameUrl: hmnurl.BuildAPICheckUsername(),
LogoMaxFileSize: ProjectLogoMaxFileSize, LogoMaxFileSize: ProjectLogoMaxFileSize,
MaxFileSize: AssetMaxSize(c.CurrentUser), TextEditor: templates.TextEditor{
UploadUrl: c.UrlContext.BuildAssetUpload(), MaxFileSize: AssetMaxSize(c.CurrentUser),
UploadUrl: c.UrlContext.BuildAssetUpload(),
},
}, c.Perf) }, c.Perf)
return res return res
} }