<%init>

# Set up application-specific parts
my $ApplicationClass = Jifty->config->framework('ApplicationClass');

my @models;   

# This creates a sub "jifty_app_models" which when called, finds packages under
# $ApplicationClass::Model, requires them, and returns a list of their
# names.
Module::Pluggable->import(
    require     => 1,
    except      => qr/\.#/,
    search_path => [  $ApplicationClass . "::Model" ],
    sub_name    => 'jifty_app_models',
);

for my $model ( __PACKAGE__->jifty_app_models ) {

    # We don't want to get the Collections, or models that have a
    # 'since' that is after the current application version.

    # TODO XXX FIXME:
    #   This *will* try to generate SQL for abstract base classes you might
    #   stick in $AC::Model::.
    next unless $model->isa( 'Jifty::Record' );
    next if $model =~ /::SUPER$/;
    push @models, $model;
}

</%init>
<&|/_elements/wrapper, title => 'Jifty Administrative Console' &>

<h1><%_('Database Administration')%></h1>

<p><%_('This console lets you manage the records in your Jifty database. Below, you should see a list of all your database tables. Feel free to go through and add, delete or modify records.')%></p>

<p><%_(q{To disable this administrative console, add "framework: AdminMode: 0" to your application's configuration file.})%></p>
    
<h2><%_('Models')%></h2>
<ul>
% foreach my $model (@models) {
% next unless ($model =~ /^(?:.*)::(.*?)$/);
% my $type = $1;
<li><% Jifty->web->link( url => '/__jifty/admin/model/'.$type, label => $type)%>
%}
</ul>

<h2><%_('Actions')%></h2>
<ul>
% foreach my $action (Jifty->api->actions) {
% Jifty::Util->require($action);
% next if ( $action->autogenerated);
<li><% Jifty->web->link( url => '/__jifty/admin/action/'.$action, label => $action) %>
% }
</ul>

<h2>Done?</h2>
<% Jifty->web->return( to => "/", label => 'Back to the application') %>

</&>
