-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from fykosak/nicer-results-filtering
Implement nicer results filtering
- Loading branch information
Showing
6 changed files
with
254 additions
and
55 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
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,61 +1,85 @@ | ||
{layout '../@layout.latte'} | ||
{varType string $lang} | ||
{block content} | ||
<div class="team-results-control"> | ||
{control filterForm} | ||
|
||
<div class="row"> | ||
<div class="col-12"> | ||
|
||
<!-- The button that triggers the collapsible content --> | ||
<button class="btn btn-primary-inverted button-collapse-header" type="button" data-bs-toggle="collapse" | ||
data-bs-target="#resultFilters" aria-expanded="false" aria-controls="resultFilters"> | ||
Toggle filters | ||
</button> | ||
|
||
|
||
<!-- The collapsible content --> | ||
<div class="collapse toggle-content px-3" id="resultFilters"> | ||
{control filterForm} | ||
</div> | ||
</div> | ||
</div> | ||
<div class="team-results-control"> | ||
{foreach $teams AS $category => $teamsForCategory} | ||
<h2 id="{$category}">{$category}</h2> | ||
<button class="btn btn-primary button-collapse-header" type="button" data-bs-toggle="collapse" | ||
data-bs-target="#collapse-category-{$category}" aria-expanded="false" aria-controls="collapse-category-{$category}"> | ||
Category {$category} | ||
</button> | ||
|
||
<div class="results-first-row results-header"> | ||
<div class="result-column" style="width: 5rem">#</div> | ||
<div class="result-column" style="flex-grow: 1">{_'Team'}</div> | ||
<div class="result-column" style="width: 5rem">{_'Points'}</div> | ||
<div class="result-column" style="width: 5rem">{_'Rank total'}</div> | ||
</div> | ||
{do usort($teamsForCategory, fn($a, $b) => ($a->rankCategory ? $a->rankCategory : PHP_INT_MAX) <=> ($b->rankCategory ? $b->rankCategory : PHP_INT_MAX))} | ||
{foreach $teamsForCategory AS $index => $team} | ||
<div class="results-row"> | ||
<div class="results-first-row"> | ||
{varType Fykosak\NetteFKSDBDownloader\ORM\Models\ModelTeam $team} | ||
<div class="result-column" | ||
style="width: 5rem">{if $team->status === "disqualified"}DNQ{else}{$team->rankCategory}.{/if}</div> | ||
<div class="result-column" style="flex-grow: 1"><strong>{$team->name}</strong></div> | ||
<div class="result-column" | ||
style="width: 5rem">{if $team->status === "disqualified"}{else}{$team->points}{/if}</div> | ||
<div class="result-column" | ||
style="width: 5rem">{if $team->status === "disqualified"}{else}{$team->rankTotal}.{/if}</div> | ||
</div> | ||
<div class="results-second-row"> | ||
<div class="result-column text-muted" style="flex-grow: 1; margin-left: 5rem; margin-right: 10rem"> | ||
{var $inSchool = 0} | ||
{if $team->members && count($team->members)} | ||
{do | ||
$participants = $team->members; | ||
usort($participants, fn($a, $b) => $a->schoolId <=> $b->schoolId) | ||
} | ||
{foreach $participants as $key => $participant} | ||
{varType Fykosak\NetteFKSDBDownloader\ORM\Models\ModelParticipant $participant} | ||
{$participant->name | ||
}{do $inSchool++ | ||
}{if $iterator->isLast() || (!is_null($participants[$key + 1]) && $participant->schoolId != $participants[$key + 1]->schoolId) | ||
} | ||
<span class="text-muted"> ({if $inSchool > 1}{$inSchool} × {/if}{$participant->schoolName}{if ($participant->countryIso != "ZZ")} <span | ||
class="flag-icon flag-icon-{$participant->countryIso|lower}"></span>{/if})</span> | ||
{do $inSchool = 0 | ||
}{/if | ||
}{if !$iterator->isLast() | ||
}, {/if} | ||
{/foreach} | ||
{else} | ||
{switch $lang} | ||
{case cs}informace o členech týmu nejsou dostupné | ||
{default}no info avaiable | ||
{/switch} | ||
{/if} | ||
<!-- The collapsible content --> | ||
<div class="collapse toggle-content" id="collapse-category-{$category}"> | ||
<!-- <h2 id="{$category}">{$category}</h2> --> | ||
|
||
<div class="results-first-row results-header"> | ||
<div class="result-column" style="width: 5rem">#</div> | ||
<div class="result-column" style="flex-grow: 1">{_'Team'}</div> | ||
<div class="result-column" style="width: 5rem">{_'Points'}</div> | ||
<div class="result-column" style="width: 5rem">{_'Rank total'}</div> | ||
</div> | ||
{do usort($teamsForCategory, fn($a, $b) => ($a->rankCategory ? $a->rankCategory : PHP_INT_MAX) <=> ($b->rankCategory ? $b->rankCategory : PHP_INT_MAX))} | ||
{foreach $teamsForCategory AS $index => $team} | ||
<div class="results-row"> | ||
<div class="results-first-row"> | ||
{varType Fykosak\NetteFKSDBDownloader\ORM\Models\ModelTeam $team} | ||
<div class="result-column" | ||
style="width: 5rem">{if $team->status === "disqualified"}DNQ{else}{$team->rankCategory}.{/if}</div> | ||
<div class="result-column" style="flex-grow: 1"><strong>{$team->name}</strong></div> | ||
<div class="result-column" | ||
style="width: 5rem">{if $team->status === "disqualified"}{else}{$team->points}{/if}</div> | ||
<div class="result-column" | ||
style="width: 5rem">{if $team->status === "disqualified"}{else}{$team->rankTotal}.{/if}</div> | ||
</div> | ||
<div class="results-second-row"> | ||
<div class="result-column text-muted" style="flex-grow: 1; margin-left: 5rem; margin-right: 10rem"> | ||
{var $inSchool = 0} | ||
{if $team->members && count($team->members)} | ||
{do | ||
$participants = $team->members; | ||
usort($participants, fn($a, $b) => $a->schoolId <=> $b->schoolId) | ||
} | ||
{foreach $participants as $key => $participant} | ||
{varType Fykosak\NetteFKSDBDownloader\ORM\Models\ModelParticipant $participant} | ||
{$participant->name | ||
}{do $inSchool++ | ||
}{if $iterator->isLast() || (!is_null($participants[$key + 1]) && $participant->schoolId != $participants[$key + 1]->schoolId) | ||
} | ||
<span class="text-muted"> ({if $inSchool > 1}{$inSchool} × {/if}{$participant->schoolName}{if ($participant->countryIso != "ZZ")} <span | ||
class="flag-icon flag-icon-{$participant->countryIso|lower}"></span>{/if})</span> | ||
{do $inSchool = 0 | ||
}{/if | ||
}{if !$iterator->isLast() | ||
}, {/if} | ||
{/foreach} | ||
{else} | ||
{switch $lang} | ||
{case cs}informace o členech týmu nejsou dostupné | ||
{default}no info avaiable | ||
{/switch} | ||
{/if} | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
{/foreach} | ||
{/foreach} | ||
</div> | ||
{/foreach} | ||
{/block} | ||
</div> |
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,56 @@ | ||
<?php | ||
|
||
namespace App\Renderers; | ||
|
||
use Nette\Forms\IFormRenderer; | ||
use Nette; | ||
use Nette\Forms\Form; | ||
use Nette\Utils\Html; | ||
use Latte\Engine; | ||
|
||
class CustomFormRenderer implements IFormRenderer | ||
{ | ||
private $latte; | ||
|
||
public function __construct() | ||
{ | ||
$this->latte = new Engine(); | ||
} | ||
|
||
public function render(Form $form, $mode = null): string | ||
{ | ||
$controls = [ | ||
'buttons' => [], | ||
'countries' => [], | ||
'special' => [] | ||
]; | ||
|
||
foreach ($form->getControls() as $control) { | ||
if ($control instanceof Nette\Forms\Controls\Button) { | ||
$controls['buttons'][] = [ | ||
'control' => $control, | ||
'html' => $control->getControl() | ||
]; | ||
} elseif ($control->getName() === 'OneMemberTeams') { | ||
$controls['special'][] = [ | ||
'control' => $control, | ||
'html' => $control->getControl() | ||
]; | ||
} elseif ($control instanceof Nette\Forms\Controls\Checkbox) { | ||
$controls['countries'][] = [ | ||
'control' => $control, | ||
'html' => $control->getControlPart()->addAttributes(['class' => 'checkbox-input']) | ||
]; | ||
} | ||
} | ||
|
||
|
||
// Pass controls to the template | ||
$params = ['controls' => $controls]; | ||
|
||
ob_start(); | ||
$this->latte->render(__DIR__ . '/templates/formRender.latte', $params); | ||
return ob_get_clean(); | ||
} | ||
|
||
} |
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,33 @@ | ||
|
||
<form> | ||
<div class="row"> | ||
{foreach $controls['special'] as $item} | ||
<div class="col-12 p-3"> | ||
<div class="country-container special"> | ||
{$item['html']} | ||
</div> | ||
</div> | ||
{/foreach} | ||
</div> | ||
<div class="row"> | ||
{foreach $controls['countries'] as $item} | ||
<div class="col-lg-3 col-md-4 p-3"> | ||
<div class="country-container"> | ||
{$item['html']} | ||
<div class="text-country-container"> | ||
<span class="flag-icon flag-icon-{strtolower($item['control']->getName())}"></span> | ||
{$item['control']->getCaption()}<br> | ||
{$item['control']->getOption('count')} participants | ||
</div> | ||
</div> | ||
</div> | ||
{/foreach} | ||
</div> | ||
<div class="row"> | ||
<div class="col-12 py-3"> | ||
{foreach $controls['buttons'] as $item} | ||
{$item['html']} | ||
{/foreach} | ||
</div> | ||
</div> | ||
</form> |