-sub make_generate {
- my %thing = @_;
- sub {
- my ($self, $htc, $lang, $env, $ct) = @_;
- undef $ct unless $thing{contest};
- debug $env => "Contest is $ct";
- local $Gruntmaster::Data::contest = $ct if $ct;
- my @thing = hgetall $thing{hash};
- @thing = map { $thing{mangle}->(); $_ } @thing if exists $thing{mangle};
- @thing = grep { $thing{choose}->() } @thing if exists $thing{choose};
- @thing = sort { $thing{sortby}->() } @thing if exists $thing{sortby};
- my %params;
- $thing{group} //= sub { $thing{id} };
- for (@thing) {
- my $group = $thing{group}->();
- $params{$group} //= [];
- push $params{$group}, $_
- }
- $htc->param(%params);
+sub list {
+ my ($thing, $lang, $env) = @_;
+ my %thing = %$thing;
+ my %params;
+ #debug $env => "Contest is $ct";
+ $thing{makers} //= sub { db(shift)->resultset($thing{rsname}) };
+ my $rs = $thing{makers}->($env);
+ $rs = $rs->search(undef, {order_by => 'me.id'}) unless $rs->is_ordered;
+ if (my $page = $env->{'gruntmaster.page'}) {
+ my $pages = int ($rs->count / PAGE_SIZE);
+ $params{default_page} = $page == -1;
+ $pages = 1 if $pages < 1;
+ $page = $pages if $page == -1;
+ @params{'page', 'pages'} = ($page, $pages);
+ $rs = $rs->search(undef, {offset => ($page - 1) * PAGE_SIZE, ($page == $pages ? () : (rows => PAGE_SIZE))});
+ }
+ $rs = $rs->search(undef, {
+ exists $thing{prefetch} ? (prefetch => $thing{prefetch}) : (),
+ exists $thing{columns} ? (columns => $thing{columns}) : (),
+ });
+ my @thing = map +{rs => $_, $_->get_columns}, $rs->all;
+ @thing = map { $thing{mangle}->($env); $_ } @thing if exists $thing{mangle};
+ @thing = grep { $thing{choose}->() } @thing if exists $thing{choose};
+ @thing = sort { $thing{sortby}->() } @thing if exists $thing{sortby};
+ $thing{group} //= sub { $thing{id} };
+ for (@thing) {
+ my $group = $thing{group}->();
+ $params{$group} //= [];
+ push $params{$group}, $_