From: Marius Gavrilescu Date: Fri, 17 Jan 2014 08:32:52 +0000 (+0200) Subject: Add user list and user pages X-Git-Url: http://git.ieval.ro/?a=commitdiff_plain;h=4aa8ba862bf3a79362df73c3d1e8707e8135af23;p=plack-app-gruntmaster.git Add user list and user pages --- diff --git a/gruntmaster-genallpages b/gruntmaster-genallpages index d26c02d..efa61fb 100755 --- a/gruntmaster-genallpages +++ b/gruntmaster-genallpages @@ -3,7 +3,7 @@ use v5.14; use Gruntmaster::Page; use Gruntmaster::Page::Log; -use Gruntmaster::Data qw/contests jobcard problems/; +use Gruntmaster::Data qw/contests jobcard problems users/; sub generate{ my $what = shift; @@ -13,10 +13,14 @@ sub generate{ generate "index.html"; generate "learn.html"; + generate "ct/index.html"; generate "ct/$_/index.thml" for contests; generate "ct/$_/log/st.html" for contests; +generate "us/index.html"; +generate "us/$_.html" for users; + for my $ct (undef, contests) { local $Gruntmaster::Data::contests = $ct; my $ctp = defined $ct ? "ct/$ct/" : ''; diff --git a/lib/Gruntmaster/Data.pm b/lib/Gruntmaster/Data.pm index 2f8a184..94eb507 100644 --- a/lib/Gruntmaster/Data.pm +++ b/lib/Gruntmaster/Data.pm @@ -33,6 +33,7 @@ sub rexec () { EXEC } sub problems () { SMEMBERS cp . 'problem' } sub contests () { SMEMBERS cp . 'contest' } +sub users () { SMEMBERS cp . 'user' } sub jobcard () { GET cp . 'job' } sub job_results (_) { decode_json HGET cp . "job.$_[0]", 'results' } @@ -71,7 +72,7 @@ sub defhash{ defhash problem => qw/name level statement/; defhash contest => qw/start end name owner/; defhash job => qw/date extension filesize private problem result result_text user/; -defhash user => qw/name email town university/; +defhash user => qw/name email town university level/; sub clean_job (_){ HDEL cp . "job.$_[0]", qw/result result_text results daemon/ diff --git a/lib/Gruntmaster/Page.pm b/lib/Gruntmaster/Page.pm index 953d8ae..d90d57c 100644 --- a/lib/Gruntmaster/Page.pm +++ b/lib/Gruntmaster/Page.pm @@ -37,6 +37,8 @@ sub declaregen{ declaregen Index => qr,^index$,; declaregen Learn => qr,^learn$,; declaregen Account => qr,^account$,; + declaregen Us => qr,^us/index$,; + declaregen 'Us::Entry' => qr,^us/$component$,; declaregen Ct => qr,^ct/index$,; declaregen 'Ct::Entry' => qr,^ct/$component/index$,; declaregen St => qr,^ct/$component/log/st$,; diff --git a/lib/Gruntmaster/Page/Ct.pm b/lib/Gruntmaster/Page/Ct.pm index 8ef3815..1c108fd 100644 --- a/lib/Gruntmaster/Page/Ct.pm +++ b/lib/Gruntmaster/Page/Ct.pm @@ -10,7 +10,7 @@ our $VERSION = '0.001'; use HTML::Template::Compiled; use POSIX qw/strftime/; use Gruntmaster::Page::Common qw/cook_templates reload_templates/; -use Gruntmaster::Data qw/contest_name contest_start contest_end contest_owner/; +use Gruntmaster::Data qw/contests contest_name contest_start contest_end contest_owner/; my %orig_templates = ( en => <<'HTML', @@ -61,7 +61,7 @@ HTML my %templates = cook_templates %orig_templates, ct => 'Contests'; sub generate{ - %templates = cook_templates %orig_templates, ct => 'Contests' if reload_template; + %templates = cook_templates %orig_templates, ct => 'Contests' if reload_templates; my $htc = HTML::Template::Compiled->new(scalarref => \$templates{$_[1]}); my (@running, @pending, @finished); diff --git a/lib/Gruntmaster/Page/Us.pm b/lib/Gruntmaster/Page/Us.pm new file mode 100644 index 0000000..2c87916 --- /dev/null +++ b/lib/Gruntmaster/Page/Us.pm @@ -0,0 +1,31 @@ +package Gruntmaster::Page::Us; + +use 5.014000; +use strict; +use warnings; +use parent qw/Exporter/; +our @EXPORT_OK = qw/generate/; +our $VERSION = '0.001'; + +use HTML::Template::Compiled; +use Gruntmaster::Data qw/users user_name/; +use Gruntmaster::Page::Common qw/cook_templates reload_templates/; + +my %orig_templates = ( + en => <<'HTML', + +HTML +); + +my %templates = cook_templates %orig_templates, us => 'Users'; + +sub generate{ + %templates = cook_templates %orig_templates, us => 'Users' if reload_templates; + my $htc = HTML::Template::Compiled->new(scalarref => \$templates{$_[1]}); + + $htc->param(users => [ map { {id => $_, name => user_name} } users ]); + $htc->output; +} + +1 diff --git a/lib/Gruntmaster/Page/Us/Entry.pm b/lib/Gruntmaster/Page/Us/Entry.pm new file mode 100644 index 0000000..5d493ba --- /dev/null +++ b/lib/Gruntmaster/Page/Us/Entry.pm @@ -0,0 +1,38 @@ +package Gruntmaster::Page::Us::Entry; + +use 5.014000; +use strict; +use warnings; +use parent qw/Exporter/; +our @EXPORT_OK = qw/generate/; +our $VERSION = '0.001'; + +use HTML::Template::Compiled; +use Gruntmaster::Data qw/users user_name user_town user_university user_level/; +use Gruntmaster::Page::Common qw/cook_templates reload_templates/; + +my %orig_templates = ( + en => <<'HTML', +

+Town:
+University:
+Level: +HTML +); + +my %templates = cook_templates %orig_templates, us_entry => ''; + +sub generate{ + %templates = cook_templates %orig_templates, us_entry => '' if reload_templates; + $_[0] =~ m,^us/([^/]+)\.html$,; + local $_ = $1; + my $htc = HTML::Template::Compiled->new(scalarref => \$templates{$_[1]}); + + $htc->param(name => user_name); + $htc->param(town => user_town); + $htc->param(university => user_university); + $htc->param(level => user_level); + $htc->output; +} + +1