Use a single table on /pb/ and /ct/
authorMarius Gavrilescu <marius@ieval.ro>
Thu, 13 Aug 2015 10:28:21 +0000 (13:28 +0300)
committerMarius Gavrilescu <marius@ieval.ro>
Thu, 13 Aug 2015 11:15:08 +0000 (14:15 +0300)
Makefile.PL
lib/Plack/App/Gruntmaster/HTML.pm
tmpl/ct.en
tmpl/pb.en

index 0d62f051a36ec7c488287160e5b42f48530bee42..7455a4116937a1365e8ad13feda7616b5d233e36 100644 (file)
@@ -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        => {
index 5c108d1a7a035618c3cafd23828f581276a215c6..ea2e99ea3c44d199ccd1460c859a5bd10d9db861 100644 (file)
@@ -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};
 }
 
index 52cf518929092d6a129306909519ce2e3f1c20dd..9169ce078b5e3df15cc309122558f0de9f256ab8 100644 (file)
@@ -1,35 +1,8 @@
-<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>
index 45e50ea629dbc2f87737efb94c8e4241796d8bd7..b86aca6601b757af52e80a6a3c40aa16b9443b3b 100644 (file)
@@ -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.
 </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>
This page took 0.014871 seconds and 4 git commands to generate.