Skip to content

Commit

Permalink
Revert "advanced search on user profile"
Browse files Browse the repository at this point in the history
This reverts commit e04d9bc.
  • Loading branch information
ornicar committed Aug 31, 2015
1 parent f6559f8 commit c39a8a9
Show file tree
Hide file tree
Showing 18 changed files with 128 additions and 433 deletions.
22 changes: 9 additions & 13 deletions app/controllers/User.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package controllers
import play.api.libs.json.Json
import play.api.mvc._, Results._

import lila.api.{ Context, BodyContext }
import lila.api.Context
import lila.app._
import lila.app.mashup.GameFilterMenu
import lila.common.LilaCookie
Expand All @@ -22,7 +22,6 @@ object User extends LilaController {
private def gamePaginator = Env.game.paginator
private def forms = lila.user.DataForm
private def relationApi = Env.relation.api
private def userGameSearch = Env.gameSearch.userGameSearch

def tv(username: String) = Open { implicit ctx =>
OptionFuResult(UserRepo named username) { user =>
Expand All @@ -35,7 +34,7 @@ object User extends LilaController {
}
}

def show(username: String) = OpenBody { implicit ctx =>
def show(username: String) = Open { implicit ctx =>
filter(username, none, 1)
}

Expand All @@ -53,7 +52,7 @@ object User extends LilaController {
}
}

def showFilter(username: String, filterName: String, page: Int) = OpenBody { implicit ctx =>
def showFilter(username: String, filterName: String, page: Int) = Open { implicit ctx =>
filter(username, filterName.some, page)
}

Expand All @@ -72,7 +71,7 @@ object User extends LilaController {
username: String,
filterOption: Option[String],
page: Int,
status: Results.Status = Results.Ok)(implicit ctx: BodyContext) =
status: Results.Status = Results.Ok)(implicit ctx: Context) =
Reasonable(page) {
OptionFuResult(UserRepo named username) { u =>
if (u.enabled || isGranted(_.UserSpy)) negotiate(
Expand All @@ -91,38 +90,35 @@ object User extends LilaController {
}
}

private def userShow(u: UserModel, filterOption: Option[String], page: Int)(implicit ctx: BodyContext) = for {
private def userShow(u: UserModel, filterOption: Option[String], page: Int)(implicit ctx: Context) = for {
info Env.current.userInfo(u, ctx)
filters = GameFilterMenu(info, ctx.me, filterOption)
pag <- GameFilterMenu.paginatorOf(
userGameSearch = userGameSearch,
user = u,
info = info.some,
filter = filters.current,
me = ctx.me,
page = page)(ctx.body)
page = page)
relation <- ctx.userId ?? { relationApi.relation(_, u.id) }
notes <- ctx.me ?? { me =>
relationApi friends me.id flatMap { env.noteApi.get(u, me, _) }
}
followable <- ctx.isAuth ?? { Env.pref.api followable u.id }
blocked <- ctx.userId ?? { relationApi.blocks(u.id, _) }
searchForm = GameFilterMenu.searchForm(userGameSearch, filters.current)(ctx.body)
} yield html.user.show(u, info, pag, filters, searchForm, relation, notes, followable, blocked)
} yield html.user.show(u, info, pag, filters, relation, notes, followable, blocked)

private def userGames(u: UserModel, filterOption: Option[String], page: Int)(implicit ctx: BodyContext) = {
private def userGames(u: UserModel, filterOption: Option[String], page: Int)(implicit ctx: Context) = {
import lila.app.mashup.GameFilter.{ All, Playing }
filterOption.fold({
Env.simul isHosting u.id map (_.fold(Playing, All).name)
})(fuccess) flatMap { filterName =>
GameFilterMenu.paginatorOf(
userGameSearch = userGameSearch,
user = u,
info = none,
filter = GameFilterMenu.currentOf(GameFilterMenu.all, filterName),
me = ctx.me,
page = page
)(ctx.body) map { filterName -> _ }
) map { filterName -> _ }
}
}

Expand Down
23 changes: 5 additions & 18 deletions app/mashup/GameFilter.scala
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package lila.app
package mashup

import lila.common.paginator._
import lila.db.api.SortOrder
import lila.game.{ Game, Query }
import lila.user.User
import lila.db.api.SortOrder

import play.api.libs.json._
import play.api.mvc.Request
import scalaz.NonEmptyList

sealed abstract class GameFilter(val name: String)
Expand All @@ -22,7 +20,6 @@ object GameFilter {
case object Playing extends GameFilter("playing")
case object Bookmark extends GameFilter("bookmark")
case object Imported extends GameFilter("import")
case object Search extends GameFilter("search")
}

case class GameFilterMenu(
Expand All @@ -37,7 +34,7 @@ object GameFilterMenu {
import GameFilter._
import lila.db.Implicits.docId

val all = NonEmptyList.nel(All, List(Me, Rated, Win, Loss, Draw, Playing, Bookmark, Imported, Search))
val all = NonEmptyList.nel(All, List(Me, Rated, Win, Loss, Draw, Playing, Bookmark, Imported))

def apply(
info: UserInfo,
Expand All @@ -54,7 +51,7 @@ object GameFilterMenu {
(info.user.count.draw > 0) option Draw,
(info.nbPlaying > 0) option Playing,
(info.nbBookmark > 0) option Bookmark,
(info.user.count.game > 0) option Search
(info.nbImported > 0) option Imported
).flatten)

val currentName = currentNameOption | info.hasSimul.fold(
Expand All @@ -81,19 +78,17 @@ object GameFilterMenu {
case Win => user.count.win.some
case Loss => user.count.loss.some
case Draw => user.count.draw.some
case Search => user.count.game.some
case _ => None
}

import lila.common.paginator._
private def pag = Env.game.paginator

def paginatorOf(
userGameSearch: lila.gameSearch.UserGameSearch,
user: User,
info: Option[UserInfo],
filter: GameFilter,
me: Option[User],
page: Int)(implicit req: Request[_]): Fu[Paginator[Game]] = {
page: Int): Fu[Paginator[Game]] = {
val nb = cachedNbOf(user, info, filter)
def std(query: JsObject) = pag.recentlyCreated(query, nb)(page)
filter match {
Expand All @@ -112,14 +107,6 @@ object GameFilterMenu {
selector = Query nowPlaying user.id,
sort = Seq(),
nb = nb)(page)
case Search => userGameSearch(user, page)
}
}

def searchForm(
userGameSearch: lila.gameSearch.UserGameSearch,
filter: GameFilter)(implicit req: Request[_]): play.api.data.Form[_] = filter match {
case Search => userGameSearch.requestForm
case _ => userGameSearch.defaultForm
}
}
1 change: 0 additions & 1 deletion app/templating/UserHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,6 @@ trait UserHelper { self: I18nHelper with StringHelper with NumberHelper =>
case GameFilter.Playing => info.nbPlaying + " playing"
case GameFilter.Bookmark => trans.nbBookmarks(info.nbBookmark)
case GameFilter.Imported => trans.nbImportedGames(info.nbImported)
case GameFilter.Search => info.user.count.game + " " + trans.advancedSearch()
}).toString)

def describeUser(user: User) = {
Expand Down
12 changes: 2 additions & 10 deletions app/views/search/index.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,6 @@ <h1 class="title">@trans.advancedSearch()</h1>
<div class="half">To @base.select(form("aiLevelMax"), Query.aiLevels, "".some)</div>
</td>
</tr>
<tr>
<th>
<label for="@form("source").id">Source</label>
</th>
<td class="single">
@base.select(form("source"), Query.sources, "".some)
</td>
</tr>
<tr>
<th>
<label for="@form("variant").id">@trans.variant()</label>
Expand Down Expand Up @@ -165,7 +157,7 @@ <h1 class="title">@trans.advancedSearch()</h1>
</tr>
<tr>
<th>
<label for="analysed">Analysis <span class="help" title="Whether computer analysis is available or not">(?)</span></label>
<label>Analysis <span class="help" title="Whether computer analysis is available or not">(?)</span></label>
</th>
<td class="single">
@{ base.checkbox(form("analysed"), "", 1) }
Expand All @@ -177,7 +169,7 @@ <h1 class="title">@trans.advancedSearch()</h1>
@paginator.map { pager =>
@if(pager.nbResults > 0) {
<div class="search_status">
<strong>@pager.nbResults.localize games found</strong>
<strong>@pager.nbResults.localize games found</strong>
<a class="permalink" href="@routes.Search.index()">Permalink</a>
<a class="permalink" rel="nofollow" href="@routes.Search.export()">Download PGN</a>
</div>
Expand Down
162 changes: 0 additions & 162 deletions app/views/search/user.scala.html

This file was deleted.

Loading

0 comments on commit c39a8a9

Please sign in to comment.