-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
142 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
.twitter-typeahead, .tt-hint, .tt-input, .tt-menu | ||
width: 75% | ||
width: 100% | ||
|
||
.twitter-typeahead, .tt-hint, .tt-input | ||
.search, .tt-hint, .tt-input | ||
display: block !important | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import typeahead from "typeahead.js"; | ||
import Bloodhound from 'bloodhound-js' | ||
import Handlebars from 'handlebars' | ||
|
||
document.addEventListener('turbolinks:before-cache', function() { | ||
$('.game-select').typeahead('destroy') | ||
}) | ||
|
||
const loadGameSelector = function() { | ||
$('.game-select').typeahead({ | ||
minLength: 3, | ||
classNames: { | ||
hint: 'text-muted', | ||
menu: 'dropdown-menu', | ||
selectable: 'dropdown-item', | ||
cursor: 'active' | ||
} | ||
}, | ||
{ | ||
name: 'games', | ||
display: game => game.name, | ||
source: new Bloodhound({ | ||
datumTokenizer: Bloodhound.tokenizers.whitespace, | ||
queryTokenizer: Bloodhound.tokenizers.whitespace, | ||
remote: { | ||
url: '/api/v4/games', | ||
prepare: function(query, settings) { | ||
return Object.assign(settings, {url: encodeURI(`${settings.url}?search=${query.trim()}`)}) | ||
}, | ||
transform: response => response.games.map(game => Object.assign(game, {'_type': 'game'})), | ||
}, | ||
identify: game => game.id, | ||
}), | ||
templates: { | ||
notFound: '<div class="dropdown-header"><h5>Games</h5></div><div class="dropdown-item disabled"><i>No games found</i></div>', | ||
pending: '<div class="dropdown-header"><i>Searching games...</i></div>', | ||
suggestion: Handlebars.compile(` | ||
<div class="dropdown-item change-selected-game" data-id='{{id}}'> | ||
{{name}}<br /> | ||
<small>{{categories.length}} categories</small> | ||
</div> | ||
`) | ||
} | ||
}) | ||
} | ||
|
||
document.addEventListener('turbolinks:load', loadGameSelector) | ||
|
||
document.addEventListener('click', function(event) { | ||
if (!event.target.closest('.change-selected-game')) { | ||
return | ||
} | ||
|
||
document.getElementById('selected-game-id').value = event.target.dataset['id'] | ||
document.getElementById('category-selector').focus() | ||
|
||
const categorySelect = document.getElementById('category-selector') | ||
const saveButton = document.getElementById('game-category-submit') | ||
const loading = document.createElement('option') | ||
loading.text = 'Loading...' | ||
|
||
Array.from(categorySelect.children).forEach((option) => option.remove()) | ||
categorySelect.appendChild(loading) | ||
|
||
fetch(`/api/v4/games?search=${document.getElementById('selected-game-id').value}`).then(response => response.json()).then(response => { | ||
Array.from(categorySelect.children).forEach((option) => option.remove()) | ||
response.games[0].categories.forEach(category => { | ||
const option = document.createElement('option') | ||
option.value = category.id | ||
option.text = category.name | ||
categorySelect.appendChild(option) | ||
}) | ||
saveButton.disabled = false | ||
categorySelect.disabled = false | ||
}) | ||
}) | ||
|
||
export { loadGameSelector } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
- content_for(:title, 'Games') | ||
.row: .col-md-12 | ||
.alert.m-3 | ||
' Searching #{number_with_delimiter(@games.sum(&:count))} games with at least one run. | ||
' In total there are #{number_with_delimiter(Game.count)} games. | ||
input#search.form-control.mb-4 type='text' placeholder='Search games...' | ||
.card-columns.w-100 | ||
- @games.each do |label, srdc_games| | ||
- @games.each do |label, games| | ||
.card.game-section.w-100 | ||
.card-header = label | ||
.list-group.list-group-flush | ||
- srdc_games.each do |srdc_game| | ||
- games.each do |game| | ||
a.list-group-item.list-group-item-action.py-1.game.text-light( | ||
href=game_path(srdc_game.shortname) | ||
data={name: srdc_game.name} | ||
) = srdc_game.name | ||
href=game_path(game.srdc&.shortname) | ||
data={name: game.name} | ||
) = game.name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.