Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort study search results #12088

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 21 additions & 15 deletions app/controllers/Study.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,36 @@ final class Study(
prismicC: Prismic
) extends LilaController(env):

def search(text: String, page: Int) =
def search(text: String, order: String, page: Int) =
OpenBody { implicit ctx =>
Reasonable(page) {
if (text.trim.isEmpty)
env.study.pager.all(ctx.me, Order.default, page) flatMap { pag =>
preloadMembers(pag) >> negotiate(
html = Ok(html.study.list.all(pag, Order.default)).toFuccess,
api = _ => apiStudies(pag)
)
}
else
env.studySearch(ctx.me)(text, page) flatMap { pag =>
negotiate(
html = Ok(html.study.list.search(pag, text)).toFuccess,
api = _ => apiStudies(pag)
)
Order(order) match
case order if !Order.withoutSelector.contains(order) =>
Redirect(routes.Study.searchDefault(text, page)).toFuccess
case order => {
if (text.trim.isEmpty)
env.study.pager.all(ctx.me, order, page) flatMap { pag =>
preloadMembers(pag) >> negotiate(
html = Ok(html.study.list.all(pag, order)).toFuccess,
api = _ => apiStudies(pag)
)
}
else
env.studySearch(ctx.me)(text, page) flatMap { pag =>
negotiate(
html = Ok(html.study.list.search(pag, order, text)).toFuccess,
api = _ => apiStudies(pag)
)
}
}
}
}

def homeLang =
LangPage(routes.Study.allDefault())(allResults(Order.Hot.key, 1)(_))

def allDefault(page: Int) = all(Order.Hot.key, page)
def allDefault(page: Int) = all(Order.Hot.key, page)
def searchDefault(text: String, page: Int) = search(text, Order.Hot.key, page)

def all(o: String, page: Int) =
Open { implicit ctx =>
Expand Down
9 changes: 5 additions & 4 deletions app/views/study/list.scala
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ object list:
url = o => routes.Study.minePrivate(o)
)

def search(pag: Paginator[WithChaptersAndLiked], text: String)(implicit ctx: Context) =
def search(pag: Paginator[WithChaptersAndLiked], order: Order, text: String)(implicit ctx: Context) =
views.html.base.layout(
title = text,
moreCss = cssTag("study.index"),
Expand All @@ -107,9 +107,10 @@ object list:
main(cls := "page-menu__content study-index box")(
div(cls := "box__top")(
searchForm(trans.search.search.txt(), text),
bits.orderSelect(order, "", url = o => routes.Study.search(text, o, 1)),
bits.newForm()
),
paginate(pag, routes.Study.search(text))
paginate(pag, routes.Study.search(text, order.key))
)
)
}
Expand Down Expand Up @@ -163,8 +164,8 @@ object list:
)

private[study] def searchForm(placeholder: String, value: String) =
form(cls := "search", action := routes.Study.search(), method := "get")(
input(name := "q", st.placeholder := placeholder, st.value := value),
form(cls := "search", action := routes.Study.searchDefault(), method := "get")(
input(name := "q", st.placeholder := placeholder, st.value := value),
submitButton(cls := "button", dataIcon := "")
)

Expand Down
3 changes: 2 additions & 1 deletion conf/routes
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ GET /study/likes/:order controllers.Study.mineLikes(order, page:
GET /study/by/:username controllers.Study.byOwnerDefault(username, page: Int ?= 1)
GET /study/by/:username/export.pgn controllers.Study.exportPgn(username)
GET /study/by/:username/:order controllers.Study.byOwner(username, order, page: Int ?= 1)
GET /study/search controllers.Study.search(q ?= "", page: Int ?= 1)
GET /study/search controllers.Study.searchDefault(q ?= "", page: Int ?= 1)
GET /study/search/:order controllers.Study.search(q ?= "", order, page: Int ?= 1)
GET /study/$id<\w{8}> controllers.Study.show(id)
POST /study controllers.Study.create
POST /study/as controllers.Study.createAs
Expand Down