autocomplete with team members only - for #9556
parent
50690d95d9
commit
ae270ce986
|
@ -546,9 +546,11 @@ final class User(
|
|||
}
|
||||
case Some(term) =>
|
||||
{
|
||||
(get("tour"), get("swiss")) match {
|
||||
case (Some(tourId), _) => env.tournament.playerRepo.searchPlayers(tourId, term, 10)
|
||||
case (_, Some(swissId)) => env.swiss.api.searchPlayers(lila.swiss.Swiss.Id(swissId), term, 10)
|
||||
(get("tour"), get("swiss"), get("team")) match {
|
||||
case (Some(tourId), _, _) => env.tournament.playerRepo.searchPlayers(tourId, term, 10)
|
||||
case (_, Some(swissId), _) =>
|
||||
env.swiss.api.searchPlayers(lila.swiss.Swiss.Id(swissId), term, 10)
|
||||
case (_, _, Some(teamId)) => env.team.api.searchMembers(teamId, term, 10)
|
||||
case _ =>
|
||||
ctx.me.ifTrue(getBool("friend")) match {
|
||||
case Some(follower) =>
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package views.html.team
|
||||
|
||||
import controllers.routes
|
||||
import play.api.data.Field
|
||||
import play.api.data.Form
|
||||
|
||||
import lila.api.Context
|
||||
|
@ -26,9 +27,7 @@ object admin {
|
|||
"Only invite leaders that you fully trust. Team leaders can kick members and other leaders out of the team."
|
||||
),
|
||||
postForm(cls := "leaders", action := routes.Team.leaders(t.id))(
|
||||
form3.group(form("leaders"), frag(usersWhoCanManageThisTeam()))(
|
||||
form3.textarea(_)(rows := 2)
|
||||
),
|
||||
form3.group(form("leaders"), frag(usersWhoCanManageThisTeam()))(teamMembersAutoComplete(t)),
|
||||
form3.actions(
|
||||
a(href := routes.Team.show(t.id))(trans.cancel()),
|
||||
form3.submit(trans.save())
|
||||
|
@ -53,9 +52,7 @@ object admin {
|
|||
div(cls := "page-menu__content box box-pad")(
|
||||
h1(title),
|
||||
postForm(action := routes.Team.kick(t.id))(
|
||||
form3.group(form("members"), frag(whoToKick()))(
|
||||
form3.textarea(_)(rows := 2)
|
||||
),
|
||||
form3.group(form("members"), frag(whoToKick()))(teamMembersAutoComplete(t)),
|
||||
form3.actions(
|
||||
a(href := routes.Team.show(t.id))(trans.cancel()),
|
||||
form3.submit(trans.save())
|
||||
|
@ -66,6 +63,9 @@ object admin {
|
|||
}
|
||||
}
|
||||
|
||||
private def teamMembersAutoComplete(team: lila.team.Team)(field: Field) =
|
||||
form3.textarea(field)(rows := 2, dataRel := team.id)
|
||||
|
||||
def pmAll(t: lila.team.Team, form: Form[_], tours: List[lila.tournament.Tournament])(implicit
|
||||
ctx: Context
|
||||
) = {
|
||||
|
|
|
@ -225,6 +225,16 @@ final class TeamApi(
|
|||
cached.invalidateTeamIds(userId) inject teamIds
|
||||
}
|
||||
|
||||
def searchMembers(teamId: Team.ID, term: String, nb: Int): Fu[List[User.ID]] =
|
||||
User.validateId(term) ?? { valid =>
|
||||
memberRepo.coll.primitive[User.ID](
|
||||
selector = memberRepo.teamQuery(teamId) ++ $doc("user" $startsWith valid),
|
||||
sort = $sort desc "user",
|
||||
nb = nb,
|
||||
field = "user"
|
||||
)
|
||||
}
|
||||
|
||||
def kick(team: Team, userId: User.ID, me: User): Funit =
|
||||
doQuit(team, userId) >>
|
||||
(!team.leaders(me.id)).?? {
|
||||
|
|
|
@ -12,6 +12,7 @@ lichess.load.then(() => {
|
|||
});
|
||||
|
||||
function initTagify(input: HTMLInputElement, maxTags: number) {
|
||||
const team = input.dataset['rel'];
|
||||
const tagify = new Tagify(input, {
|
||||
pattern: /.{3,}/,
|
||||
maxTags,
|
||||
|
@ -19,7 +20,7 @@ function initTagify(input: HTMLInputElement, maxTags: number) {
|
|||
whitelist: input.value.trim().split(/\s*,\s*/),
|
||||
});
|
||||
const doFetch: (term: string) => Promise<string[]> = debounce(
|
||||
(term: string) => xhr.json(xhr.url('/player/autocomplete', { term, names: 1 })),
|
||||
(term: string) => xhr.json(xhr.url('/player/autocomplete', { term, names: 1, team })),
|
||||
300
|
||||
);
|
||||
tagify.on('input', e => {
|
||||
|
|
Loading…
Reference in New Issue