use HTML::TreeBuilder;
use POSIX qw//;
use Data::Dumper qw/Dumper/;
+use Sort::ByExample
+ sorter => {-as => 'pb_sort', example => [qw/beginner easy medium hard/], xform => sub {$_->{level}}},
+ sorter => {-as => 'ct_sort', example => [qw/Running Pending Finished/], xform => sub {$_->{status}}};
my $optional_end_tags = {%HTML::Tagset::optionalEndTag, tr => 1, td => 1, th => 1};
$tr->fclass('name')->namedlink($data->{id}, $data->{name});
$tr->fclass('owner')->namedlink($data->{owner}, $data->{owner_name});
};
- for (@{$args{ct}}) {
- my $state = $_->{finished} ? 'finished' : $_->{started} ? 'running' : 'pending';
- push @{$args{$state} //= []}, $_;
- }
- $args{$_} ? $tree->fid($_)->find('tbody')->find('tr')->iter3($args{$_}, $iter) : $tree->fid($_)->detach for qw/running pending finished/;
+ $_->{status} = $_->{finished} ? 'Finished' : $_->{started} ? 'Running' : 'Pending' for @{$args{ct}};
+ $tree->find('tbody')->find('tr')->iter3([ct_sort @{$args{ct}}], $iter);
}
sub process_pb_entry {
sub process_pb {
my ($tree, %args) = @_;
- my $titer = sub {
+ my $iter = sub {
my ($data, $tr) = @_;
$tr->set_child_content(class => 'author', $data->{author});
+ $tr->set_child_content(class => 'level', ucfirst $data->{level});
$tr->fclass('name')->namedlink($data->{id}, $data->{name});
$tr->fclass('name')->find('a')->edit_href(sub {$_ .= "?contest=$args{contest}"}) if $args{contest};
$tr->fclass('owner')->namedlink($data->{owner}, $data->{owner_name});
$tr->find('td')->attr(class => $tr->find('td')->attr('class').' warning') if $data->{private} && !$args{contest};
};
- my $iter = sub {
- my ($data, $div) = @_;
- $div->attr(id => $data);
- $div->find('h2')->replace_content(ucfirst $data);
- $div->find('tbody')->find('tr')->iter3($args{$data}, $titer);
- };
- push @{$args{$_->{level}} //= []}, $_ for @{$args{pb}};
- $tree->fid('beginner')->iter3([grep {$args{$_}} qw/beginner easy medium hard/], $iter);
+
+ $tree->find('tbody')->find('tr')->iter3([pb_sort @{$args{pb}}], $iter);
$tree->fid('open-alert')->detach unless $args{contest};
}
-<div id="running">
-<h1>Running contests</h1>
<table class="table table-striped">
<thead>
-<tr><th>Name<th>Start date<th>Stop date<th>Owner
+<tr><th>Name<th>Start date<th>Stop date<th>Owner<th>Status
</thead>
<tbody>
-<tr><td class="name"><a href="/ct/id">Contest name</a><td class="start">...<td class="stop">...<td class="owner"><a href="/us/id">Owner name</a>
+<tr><td class="name"><a href="/ct/id">Contest name</a><td class="start">...<td class="stop">...<td class="owner"><a href="/us/id">Owner name</a><td class="status">Running
</table>
-</div>
-
-<div id="pending">
-<h1>Pending contests</h1>
-<table class="table table-striped">
-<thead>
-<tr><th>Name<th>Start date<th>Stop date<th>Owner
-</thead>
-
-<tbody>
-<tr><td class="name"><a href="/ct/id">Contest name</a><td class="start">...<td class="stop">...<td class="owner"><a href="/us/id">Owner name</a>
-</table>
-</div>
-
-<div id="finished">
-<h1>Finished contests</h1>
-<table class="table table-striped">
-<thead>
-<tr><th>Name<th>Start date<th>Stop date<th>Owner
-</thead>
-
-<tbody>
-<tr><td class="name"><a href="/ct/id">Contest name</a><td class="start">...<td class="stop">...<td class="owner"><a href="/us/id">Owner name</a>
-</table>
-</div>
The timer for a problem starts when you open the problem. You will lose points if you open all problems at the same time.
</div>
-<div id="beginner">
-<h2>Beginner</h2>
<table class="table table-striped table-fixed">
-<thead><tr><th>Name<th>Author<th>Owner</thead>
+<thead><tr><th>Name<th>Author<th>Owner<th>Level</thead>
<tbody>
-<tr><td class="name"><a href="id">Name</a><td class="author">author<td class="owner"><a href="/us/id">Owner name</a>
+<tr><td class="name"><a href="id">Name</a><td class="author">author<td class="owner"><a href="/us/id">Owner name</a><td class="level">Beginner
</table>
-</div>