Add setting for default format
authorr <r@freesoftwareextremist.com>
Mon, 19 Oct 2020 06:51:23 +0000 (06:51 +0000)
committerr <r@freesoftwareextremist.com>
Mon, 19 Oct 2020 06:51:23 +0000 (06:51 +0000)
model/post.go
model/settings.go
renderer/model.go
service/service.go
service/transport.go
templates/postform.tmpl
templates/settings.tmpl

index 7cfead79d15c8ff4d4b9cd1c1eae5bb37275cd99..831f74fd344d4c97439dd8efe34ecb7d5e34d2e8 100644 (file)
@@ -7,6 +7,7 @@ type PostFormat struct {
 
 type PostContext struct {
        DefaultVisibility string
+       DefaultFormat     string
        ReplyContext      *ReplyContext
        Formats           []PostFormat
        DarkMode          bool
index 03e95819c093a0fd2633a72e97b06961e75cfe3a..337a6a345a66ff0830b0925d4220145adb8151ff 100644 (file)
@@ -2,6 +2,7 @@ package model
 
 type Settings struct {
        DefaultVisibility        string `json:"default_visibility"`
+       DefaultFormat            string `json:"default_format"`
        CopyScope                bool   `json:"copy_scope"`
        ThreadInNewTab           bool   `json:"thread_in_new_tab"`
        HideAttachments          bool   `json:"hide_attachments"`
@@ -15,6 +16,7 @@ type Settings struct {
 func NewSettings() *Settings {
        return &Settings{
                DefaultVisibility:        "public",
+               DefaultFormat:            "",
                CopyScope:                true,
                ThreadInNewTab:           false,
                HideAttachments:          false,
index 4b177dbcac945780407d85acbe856a0c3eb28bc0..0e5204a9753e4798241eeed3611e0565ea6458f7 100644 (file)
@@ -121,5 +121,6 @@ type SearchData struct {
 
 type SettingsData struct {
        *CommonData
-       Settings *model.Settings
+       Settings    *model.Settings
+       PostFormats []model.PostFormat
 }
index 447f1862beebad80de82f13ba23a9b0fe5a008b2..23685c49897cf8c487bbfbe156db17980091f46f 100644 (file)
@@ -4,8 +4,8 @@ import (
        "context"
        "errors"
        "fmt"
-       "mime/multipart"
        "html/template"
+       "mime/multipart"
        "net/url"
        "strings"
 
@@ -198,6 +198,7 @@ func (svc *service) ServeNavPage(c *model.Client) (err error) {
 
        postContext := model.PostContext{
                DefaultVisibility: c.Session.Settings.DefaultVisibility,
+               DefaultFormat:     c.Session.Settings.DefaultFormat,
                Formats:           svc.postFormats,
        }
 
@@ -326,6 +327,7 @@ func (svc *service) ServeThreadPage(c *model.Client, id string, reply bool) (err
 
                postContext = model.PostContext{
                        DefaultVisibility: visibility,
+                       DefaultFormat:     c.Session.Settings.DefaultFormat,
                        Formats:           svc.postFormats,
                        ReplyContext: &model.ReplyContext{
                                InReplyToID:     id,
@@ -686,8 +688,9 @@ func (svc *service) ServeSearchPage(c *model.Client,
 func (svc *service) ServeSettingsPage(c *model.Client) (err error) {
        commonData := svc.getCommonData(c, "settings")
        data := &renderer.SettingsData{
-               CommonData: commonData,
-               Settings:   &c.Session.Settings,
+               CommonData:  commonData,
+               Settings:    &c.Session.Settings,
+               PostFormats: svc.postFormats,
        }
 
        rCtx := getRendererContext(c)
index 4f73c5ea9edfcd25748bec6e1485c528a10b796f..6c0975dba865a67b665b0acefacb9c8b0ea71593 100644 (file)
@@ -584,6 +584,7 @@ func NewHandler(s Service, staticDir string) http.Handler {
        settings := func(w http.ResponseWriter, req *http.Request) {
                c := newClient(w, req, req.FormValue("csrf_token"))
                visibility := req.FormValue("visibility")
+               format := req.FormValue("format")
                copyScope := req.FormValue("copy_scope") == "true"
                threadInNewTab := req.FormValue("thread_in_new_tab") == "true"
                hideAttachments := req.FormValue("hide_attachments") == "true"
@@ -595,6 +596,7 @@ func NewHandler(s Service, staticDir string) http.Handler {
 
                settings := &model.Settings{
                        DefaultVisibility:        visibility,
+                       DefaultFormat:            format,
                        CopyScope:                copyScope,
                        ThreadInNewTab:           threadInNewTab,
                        HideAttachments:          hideAttachments,
index ac774860391ee1c945f44ca36a7a3674ba673632..b38cb9d03c2a9578295365de9976215de707bf39 100644 (file)
        <div>
                {{if gt (len .Formats) 0}}
                <span class="post-form-field">
+                       {{$defFormat := .DefaultFormat}}
                        <select id="post-format" name="format" accesskey="F" title="Format (F)">
-                               {{range .Formats}} <option value="{{.Type}}">{{.Name}}</option> {{end}}
+                               {{range .Formats}} 
+                                       <option value="{{.Type}}" {{if eq $defFormat .Type}}selected{{end}}>{{.Name}}</option> 
+                               {{end}}
                        </select>
                </span>
                {{end}}
index 67386a4b47094c55563ab1108d7b549f04ea72f8..972e1a2eff9b6e38bc0aa6f721eaf0c14adacbeb 100644 (file)
@@ -4,6 +4,15 @@
 
 <form id="settings-form" action="/settings" method="POST">
        <input type="hidden" name="csrf_token" value="{{$.Ctx.CSRFToken}}">
+       <div class="settings-form-field">
+               <label for="visibility"> Default format </label>
+               {{$defFormat := .Settings.DefaultFormat}}
+               <select id="post-format" name="format">
+                       {{range .PostFormats}} 
+                               <option value="{{.Type}}" {{if eq $defFormat .Type}}selected{{end}}>{{.Name}}</option> 
+                       {{end}}
+               </select>
+       </div>
        <div class="settings-form-field">
                <label for="visibility"> Default scope </label>
                <select id="visibility" name="visibility">