@@ -27,6 +27,7 @@ import (
2727 "os/signal"
2828 "path/filepath"
2929 "reflect"
30+ "strconv"
3031 "strings"
3132 "sync"
3233 "time"
@@ -265,6 +266,8 @@ func (c *ServeCommand) Execute(args []string) error {
265266
266267 // News
267268 r .Handle ("/" , http .HandlerFunc (runTemplate ("mainPage.gohtml" ))).Methods ("GET" )
269+ r .Handle ("/tab" , http .HandlerFunc (runTemplate ("mainPage.gohtml" ))).Methods ("GET" )
270+ r .Handle ("/tab/{tab}" , http .HandlerFunc (runTemplate ("mainPage.gohtml" ))).Methods ("GET" )
268271 r .HandleFunc ("/" , runHandlerChain (TaskDoneAutoRefreshPage )).Methods ("POST" )
269272
270273 r .HandleFunc ("/edit" , runTemplate ("loginPage.gohtml" )).Methods ("GET" ).MatcherFunc (gorillamuxlogic .Not (RequiresAnAccount ()))
@@ -301,6 +304,12 @@ func (c *ServeCommand) Execute(args []string) error {
301304 r .HandleFunc ("/editTab" , runHandlerChain (TabEditSaveAction , TaskDoneAutoRefreshPage )).Methods ("POST" ).MatcherFunc (RequiresAnAccount ()).MatcherFunc (TaskMatcher (TaskSaveAndDone ))
302305 r .HandleFunc ("/editTab" , runHandlerChain (TabEditSaveAction , StopEditMode , redirectToHandlerBranchToRef ("/" ))).Methods ("POST" ).MatcherFunc (RequiresAnAccount ()).MatcherFunc (TaskMatcher (TaskSaveAndStopEditing ))
303306 r .HandleFunc ("/editTab" , runHandlerChain (TaskDoneAutoRefreshPage )).Methods ("POST" )
307+ r .HandleFunc ("/tab/{tab}/edit" , runTemplate ("loginPage.gohtml" )).Methods ("GET" ).MatcherFunc (gorillamuxlogic .Not (RequiresAnAccount ()))
308+ r .HandleFunc ("/tab/{tab}/edit" , runHandlerChain (EditTabPage )).Methods ("GET" ).MatcherFunc (RequiresAnAccount ())
309+ r .HandleFunc ("/tab/{tab}/edit" , runHandlerChain (TabEditSaveAction , redirectToHandlerBranchToRef ("/" ))).Methods ("POST" ).MatcherFunc (RequiresAnAccount ()).MatcherFunc (TaskMatcher (TaskSave ))
310+ r .HandleFunc ("/tab/{tab}/edit" , runHandlerChain (TabEditSaveAction , TaskDoneAutoRefreshPage )).Methods ("POST" ).MatcherFunc (RequiresAnAccount ()).MatcherFunc (TaskMatcher (TaskSaveAndDone ))
311+ r .HandleFunc ("/tab/{tab}/edit" , runHandlerChain (TabEditSaveAction , StopEditMode , redirectToHandlerBranchToRef ("/" ))).Methods ("POST" ).MatcherFunc (RequiresAnAccount ()).MatcherFunc (TaskMatcher (TaskSaveAndStopEditing ))
312+ r .HandleFunc ("/tab/{tab}/edit" , runHandlerChain (TaskDoneAutoRefreshPage )).Methods ("POST" )
304313
305314 r .HandleFunc ("/editPage" , runTemplate ("loginPage.gohtml" )).Methods ("GET" ).MatcherFunc (gorillamuxlogic .Not (RequiresAnAccount ()))
306315 r .HandleFunc ("/editPage" , runHandlerChain (EditPagePage )).Methods ("GET" ).MatcherFunc (RequiresAnAccount ())
@@ -311,7 +320,9 @@ func (c *ServeCommand) Execute(args []string) error {
311320
312321 r .HandleFunc ("/moveTab" , runHandlerChain (MoveTabAction )).Methods ("POST" ).MatcherFunc (RequiresAnAccount ())
313322 r .HandleFunc ("/movePage" , runHandlerChain (MovePageAction )).Methods ("POST" ).MatcherFunc (RequiresAnAccount ())
323+ r .HandleFunc ("/tab/{tab}/movePage" , runHandlerChain (MovePageAction )).Methods ("POST" ).MatcherFunc (RequiresAnAccount ())
314324 r .HandleFunc ("/moveEntry" , runHandlerChain (MoveEntryAction )).Methods ("POST" ).MatcherFunc (RequiresAnAccount ())
325+ r .HandleFunc ("/tab/{tab}/moveEntry" , runHandlerChain (MoveEntryAction )).Methods ("POST" ).MatcherFunc (RequiresAnAccount ())
315326
316327 r .HandleFunc ("/history" , runTemplate ("loginPage.gohtml" )).Methods ("GET" ).MatcherFunc (gorillamuxlogic .Not (RequiresAnAccount ()))
317328 r .HandleFunc ("/history" , runTemplate ("history.gohtml" )).Methods ("GET" ).MatcherFunc (RequiresAnAccount ())
@@ -623,19 +634,19 @@ func redirectToHandlerBranchToRef(toUrl string) func(http.ResponseWriter, *http.
623634 u , _ := url .Parse (toUrl )
624635 qs := u .Query ()
625636 qs .Set ("ref" , "refs/heads/" + r .PostFormValue ("branch" ))
626- tab := r . PostFormValue ( "tab" )
637+ tab := TabFromRequest ( r )
627638 if v , ok := r .Context ().Value (ContextValues ("redirectTab" )).(string ); ok {
628- tab = v
629- }
630- if tab != "" {
631- qs .Set ("tab" , tab )
639+ if parsed , err := strconv .Atoi (v ); err == nil {
640+ tab = parsed
641+ }
632642 }
643+ u .Path = TabPath (tab )
633644 page := r .PostFormValue ("page" )
634645 if v , ok := r .Context ().Value (ContextValues ("redirectPage" )).(string ); ok {
635646 page = v
636647 }
637- if page != "" {
638- u .Fragment = "page" + page
648+ if fragment := PageFragmentFromIndex ( page ); fragment != "" {
649+ u .Fragment = fragment
639650 }
640651 if edit := r .URL .Query ().Get ("edit" ); edit != "" {
641652 qs .Set ("edit" , edit )
@@ -649,11 +660,9 @@ func redirectToHandlerTabPage(toUrl string) func(http.ResponseWriter, *http.Requ
649660 return http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
650661 u , _ := url .Parse (toUrl )
651662 qs := u .Query ()
652- if tab := r .URL .Query ().Get ("tab" ); tab != "" {
653- qs .Set ("tab" , tab )
654- }
655- if page := r .URL .Query ().Get ("page" ); page != "" {
656- u .Fragment = "page" + page
663+ u .Path = TabPath (TabFromRequest (r ))
664+ if fragment := PageFragmentFromIndex (r .URL .Query ().Get ("page" )); fragment != "" {
665+ u .Fragment = fragment
657666 }
658667 if edit := r .URL .Query ().Get ("edit" ); edit != "" {
659668 qs .Set ("edit" , edit )
0 commit comments