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

Advanced search in Teambuilder #1133

Merged
merged 7 commits into from
Jun 25, 2019
Merged
Changes from 5 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
23 changes: 22 additions & 1 deletion js/client-teambuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
'keyup .chartinput': 'chartKeyup',
'focus .chartinput': 'chartFocus',
'blur .chartinput': 'chartChange',
'keyup .searchinput': 'searchChange',

// drag/drop
'click .team': 'edit',
Expand Down Expand Up @@ -120,6 +121,7 @@
// '/' - show teams with no folder
curFolder: '',
curFolderKeep: '',
curSearchVal: '',

exportMode: false,
update: function () {
Expand Down Expand Up @@ -342,7 +344,8 @@
if (filterFormat && filterFormat !== 'gen7') {
newButtonText = "New " + Tools.escapeFormat(filterFormat) + " Team";
}
buf += '<p><button name="newTop" class="button big"><i class="fa fa-plus-circle"></i> ' + newButtonText + '</button></p>';
buf += '<p><button name="newTop" class="button big"><i class="fa fa-plus-circle"></i> ' + newButtonText + '</button> ' +
'<input type="text" id="teamSearchBar" name="search" class="textbox searchinput" value="' + this.curSearchVal + '" placeholder="search teams"/></p>';

buf += '<ul class="teamlist">';
var atLeastOne = false;
Expand Down Expand Up @@ -383,6 +386,10 @@
if (filterFormat && filterFormat !== (team.format || 'gen7')) continue;
if (filterFolder !== undefined && filterFolder !== team.folder) continue;

if (this.curSearchVal !== '' && team.team.indexOf(this.curSearchVal) == -1) {
continue;
}

if (!atLeastOne) atLeastOne = true;
var formatText = '';
if (team.format) {
Expand All @@ -395,6 +402,7 @@
buf += '<li><div name="edit" data-value="' + i + '" class="team" draggable="true">' + formatText + '<strong>' + Tools.escapeHTML(team.name) + '</strong><br /><small>';
buf += Storage.getTeamIcons(team);
buf += '</small></div><button name="edit" value="' + i + '"><i class="fa fa-pencil" aria-label="Edit" title="Edit (you can also just click on the team)"></i></button><button name="newTop" value="' + i + '" title="Duplicate" aria-label="Duplicate"><i class="fa fa-clone"></i></button><button name="delete" value="' + i + '"><i class="fa fa-trash"></i> Delete</button></li>';

}
if (!atLeastOne) {
if (filterFolder) {
Expand Down Expand Up @@ -436,6 +444,12 @@
$pane.scrollTop(this.teamScrollPos);
this.teamScrollPos = 0;
}

//reset focus to searchbar
var teamSearchBar = this.$("#teamSearchBar");
var strLength = teamSearchBar.val().length;
teamSearchBar.focus();
teamSearchBar[0].setSelectionRange(strLength, strLength);
},
updatePersistence: function (state) {
if (state) {
Expand Down Expand Up @@ -2570,6 +2584,13 @@
}
this.chartSet(val, selectNext);
},
searchChange: function (e) {
//91 for right CMD / 93 for left / CMD 17 for CTL
if (e.keyCode != 91 && e.keyCode != 93 && e.keyCode != 17) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can use !== here as (iirc) the type will always be number

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback! I'll update the PR when I'm home

this.curSearchVal = e.currentTarget.value;
this.updateTeamList();
}
},
chartSetCustom: function (val) {
val = toId(val);
if (val === 'cathy') {
Expand Down