From: Marius Gavrilescu Date: Thu, 13 Aug 2015 10:28:21 +0000 (+0300) Subject: Use a single table on /pb/ and /ct/ X-Git-Url: http://git.ieval.ro/?a=commitdiff_plain;h=2d39838c2a02e453a7c9c4d0d2633a250004aec8;p=plack-app-gruntmaster.git Use a single table on /pb/ and /ct/ --- diff --git a/Makefile.PL b/Makefile.PL index 0d62f05..7455a41 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -42,6 +42,7 @@ WriteMakefile( Plack::Middleware::Auth::Complex 0 Plack::Util 0 Scope::Upper 0 + Sort::ByExample 0 Web::Simple 0.019/, }, META_MERGE => { diff --git a/lib/Plack/App/Gruntmaster/HTML.pm b/lib/Plack/App/Gruntmaster/HTML.pm index 5c108d1..ea2e99e 100644 --- a/lib/Plack/App/Gruntmaster/HTML.pm +++ b/lib/Plack/App/Gruntmaster/HTML.pm @@ -8,6 +8,9 @@ use HTML::Element::Library; 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}; @@ -161,11 +164,8 @@ sub process_ct { $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 { @@ -211,22 +211,17 @@ sub process_sol { 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}; } diff --git a/tmpl/ct.en b/tmpl/ct.en index 52cf518..9169ce0 100644 --- a/tmpl/ct.en +++ b/tmpl/ct.en @@ -1,35 +1,8 @@ -
-

Running contests

- -
NameStart dateStop dateOwner +
NameStart dateStop dateOwnerStatus
Contest name......Owner name +
Contest name......Owner nameRunning
-
- -
-

Pending contests

- - - - - -
NameStart dateStop dateOwner -
Contest name......Owner name -
-
- -
-

Finished contests

- - - - - -
NameStart dateStop dateOwner -
Contest name......Owner name -
-
diff --git a/tmpl/pb.en b/tmpl/pb.en index 45e50ea..b86aca6 100644 --- a/tmpl/pb.en +++ b/tmpl/pb.en @@ -3,12 +3,9 @@ The timer for a problem starts when you open the problem. You will lose points if you open all problems at the same time. -
-

Beginner

- + -
NameAuthorOwner
NameAuthorOwnerLevel
NameauthorOwner name +
NameauthorOwner nameBeginner
-