From 6720de0f88bab39594a6f0dea52c331cf04514db Mon Sep 17 00:00:00 2001 From: Lei Xu Date: Sat, 23 Dec 2017 19:53:48 -0800 Subject: [PATCH] Be able to sort subResource. --- controller.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/controller.go b/controller.go index ca43879..8c8cd19 100644 --- a/controller.go +++ b/controller.go @@ -6,6 +6,7 @@ import ( "net/http" "path" "strconv" + "strings" "github.com/qor/admin" "github.com/qor/qor" @@ -106,6 +107,17 @@ func (s *Sorting) ConfigureQorResource(res resource.Resourcer) { }) router := Admin.GetRouter() - router.Post(fmt.Sprintf("/%v/%v/sorting/update_position", res.ToParam(), res.ParamIDName()), updatePosition) + var paths []string + parent := res + for parent != nil { + paths = append(paths, parent.ParamIDName(), parent.ToParam()) + parent = parent.ParentResource + } + for i, j := 0, len(paths) - 1; i < j; i, j = i + 1, j - 1 { + paths[i], paths[j] = paths[j], paths[i] + } + router.Post(fmt.Sprintf("/%v/sorting/update_position", + strings.Join(paths, "/")), updatePosition, + &admin.RouteConfig{Resource: res}) } }