package DTA::Controller::Milestone;
use Moose;
use namespace::autoclean;

BEGIN {extends 'Catalyst::Controller'; }

use YAML qw(LoadFile);

=head1 NAME

DTA::Controller::Milestone - Catalyst Controller

=head1 DESCRIPTION

Catalyst Controller. DEPRECATED!

=head1 METHODS

=head2 index

=cut

sub auto : Private {
    my ( $self, $c ) = @_;
    $c->detach('/error_404');
    # $c->stash(
    #     yml      => LoadFile( $c->path_to('milestone_2011-11.yml')."" ),
    #     dirnames => { reverse map { $_->dirname ? ($_->id_book => $_->dirname) : () } $c->model('DTADB::Metadaten')->search->all },
    # );
    # return 1;
}

# sub index :Path :Args(0) {
#     my ( $self, $c ) = @_;

#     my @genres = ('Fraktur/Wissenschaft', 'Antiqua/Wissenschaft', 'Fraktur/Belletristik', 'Fraktur/Gebrauchsliteratur');
#     my @decades = map { sprintf "%d-%d", $_*10, ($_+2)*10-1 } (178, 180, 182, 184, 186, 188);

#     my %result;
#     my @dump;
#     while ( my ($genre, $decades) = each %{$c->stash->{yml}} ) {
#         while ( my ($decade, $books) = each %$decades ) {
#             while ( my ($dirname, $startpage) = each %$books ) {
#                 for my $page ( $startpage .. $startpage+29 ) {
#                     my $rv = $c->model('DTADB::Review')->search({
#                         book => $c->stash->{dirnames}->{ $dirname },
#                         page => $page,
#                         type => [ -or => [ 'text', 'transcription' ] ],
#                     });
#                     $result{ $genre }{ $decade }++ if $rv->count;
#                     while( my $row = $rv->next ) {
#                         push @dump, [ $row->account->id, $row->book, $row->page ];
#                     }
#                 }
#             }
#         }  
#     }

# #    use Data::Dumper;
# #    open FH, '>/tmp/task-teimm3.dd' or die $!;
# #    print FH Dumper(\@dump);
# #    close FH;

#     $c->stash(
#         genres   => \@genres,
#         decades  => \@decades,
#         result   => \%result,
#         template => 'milestone/2011-11/index.tt',
#     );
# }

# sub todo : Local {
#     my ( $self, $c ) = @_;
#     my $genre  = $c->req->params->{genre};
#     my $decade = $c->req->params->{decade};

#     my @books = keys %{$c->stash->{yml}{$genre}{$decade}};

#     my @todo;
#     foreach my $book ( @books ) {
#         my $startpage = $c->stash->{yml}{$genre}{$decade}{$book};
#         foreach my $page ( $startpage .. $startpage+29 ) {
#             my $rv = $c->model('DTADB::Review')->search({
#                 book => $c->stash->{dirnames}->{ $book },
#                 page => $page,
#                 type => [ -or => [ 'text', 'transcription' ] ],
#             })->count;
#             push @todo, [ $book, $page ] unless $rv;
#         }
#     }
#     $c->stash(
#         template => 'milestone/2011-11/todo.tt',
#         todo     => \@todo,
#     );
# }

# sub done : Local {
#     my ( $self, $c ) = @_;
#     my $genre  = $c->req->params->{genre};
#     my $decade = $c->req->params->{decade};

#     my @books = keys %{$c->stash->{yml}{$genre}{$decade}};

#     my @done;
#     foreach my $book ( @books ) {
#         my $startpage = $c->stash->{yml}{$genre}{$decade}{$book};
#         foreach my $page ( $startpage .. $startpage+29 ) {
#             my $rv = $c->model('DTADB::Review')->search({                                      
#                 book => $c->stash->{dirnames}->{ $book },
#                 page => $page,                                                                                      
#                 type => [ -or => [ 'text', 'transcription' ] ],                                                                                                          
#             })->count;
#             push @done, [ $book, $page ] if $rv;
#         }
#     }
#     $c->stash(
#         template => 'milestone/2011-11/done.tt',
#         done     => \@done,
#     );
# }

__PACKAGE__->meta->make_immutable;

1;

=head1 AUTHOR

Frank Wiegand

=head1 LICENSE

This library is free software. You can redistribute it and/or modify
it under the same terms as Perl itself.

=cut
