[WTF CVS] wtf/lib/WTF/Pages Admin.pm,1.3,1.4
Brought to you by:
gryphonshafer
|
From: Gryphon S. <gry...@us...> - 2006-11-20 02:53:10
|
Update of /cvsroot/wtf-tracker/wtf/lib/WTF/Pages In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv29218/lib/WTF/Pages Modified Files: Admin.pm Log Message: Added support for the Table Data administrator pages Index: Admin.pm =================================================================== RCS file: /cvsroot/wtf-tracker/wtf/lib/WTF/Pages/Admin.pm,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Admin.pm 7 Nov 2006 16:27:54 -0000 1.3 --- Admin.pm 20 Nov 2006 02:53:07 -0000 1.4 *************** *** 11,16 **** use constant { ! ROOT_URL => WTF::Config->get( 'links', 'root_url' ), ! UPDATE => WTF::Config->get( 'update' ), }; --- 11,54 ---- use constant { ! ROOT_URL => WTF::Config->get( 'links', 'root_url' ), ! UPDATE => WTF::Config->get( 'update' ), ! DATA_TABLES => [ ! { ! 'title' => 'Teams / Groups', ! 'table' => 'team', ! 'has_parent_id' => 1, ! 'has_description' => 0, ! 'has_active' => 0, ! 'has_project' => 0, ! 'has_groups' => 0, ! }, ! { ! 'title' => 'Functional Areas', ! 'table' => 'area', ! 'has_parent_id' => 0, ! 'has_description' => 1, ! 'has_active' => 1, ! 'has_project' => 0, ! 'has_groups' => 0, ! }, ! { ! 'title' => 'Tasks', ! 'table' => 'task', ! 'has_parent_id' => 1, ! 'has_description' => 1, ! 'has_active' => 1, ! 'has_project' => 1, ! 'has_groups' => 1, ! }, ! { ! 'title' => 'Summary Activities', ! 'table' => 'activity', ! 'has_parent_id' => 1, ! 'has_description' => 1, ! 'has_active' => 1, ! 'has_project' => 0, ! 'has_groups' => 1, ! }, ! ], }; *************** *** 287,290 **** --- 325,436 ---- } + sub screen_table_data { + my ( $self, $r ) = @_; + my $req = WTF::Utils::get_req($r); + my $tmpl_obj = $self->setup_tmpl('admin/table_data.tmpl'); + + my $table; + my @tables = map { + # set selected to true for the appropriate table requested by the user + # and save that name into $table for later + if ( defined $req->param('table') and $req->param('table') eq $_->{'table'} ) { + $_->{'selected'} = 1; + $table = $_; + } + else { + $_->{'selected'} = 0; + } + + $_; + } @{ (DATA_TABLES) }; + + # if user requested a table not in the above hard-coded data, then + # redirect them to the default Table Data view + if ( defined $req->param('table') and not defined $table ) { + $r->headers_out->set( 'Location' => ROOT_URL . '/view/admin/tables' ); + return $r->status( Apache2::Const::REDIRECT ); + } + + $table ||= DATA_TABLES->[0]; + my $sql_sth = 'table_data_' . $table->{'table'}; + $sth->{$sql_sth}->execute() or die $dbh->errstr(); + my $table_data = $sth->{$sql_sth}->fetchall_arrayref({}); + + if ( $table->{'has_parent_id'} ) { + my ( $indent, @rows, @last_ids ) = ( 0 ); + for ( @{$table_data} ) { + + # if there's no parent_id, then the item should have no intent + unless ( $_->{'parent_id'} ) { + $indent = 0; + @last_ids = (); + } + + # increment the items indent if the parent_id is not the same as the + # previous parent_id + elsif ( + @rows and + $_->{'parent_id'} != ( $last_ids[-1] || -1 ) + ) { + my $id = $_->{'parent_id'}; + + # this id seen before and in id stack, so decrement indent and + # pop ids off the stack until a match or at empty + if ( grep { $_ == $id } @last_ids ) { + do { + $indent--; + pop @last_ids; + } while ( $last_ids[-1] ne $id and @last_ids ); + } + + # this is an id that's not in the stack, so increment indent + # and push the id onto the stack + else { + $indent++; + push @last_ids, $_->{'parent_id'}; + } + } + $_->{'indent'} = $indent; + + # "group" denotes that the item is unselectable by the user, that the + # item is a group name, not a task name + $rows[-1]->{'group'} = 1 if ( + $table->{'has_groups'} and + @rows and defined $_->{'parent_id'} and + $_->{'parent_id'} == ( $rows[-1]->{'id'} || -1 ) + ); + + push @rows, $_; + } + $table_data = \@rows; + } + + $tmpl_obj->param( + 'title' => 'Administrate Table Data', + 'nav_bar' => WTF::Utils::nav_bar_data( $r, 'admin_tables' ), + 'tables' => \@tables, + 'table_data' => $table_data, + 'has_parent_id' => $table->{'has_parent_id'}, + 'has_description' => $table->{'has_description'}, + 'has_active' => $table->{'has_active'}, + 'has_project' => $table->{'has_project'}, + ); + + return $tmpl_obj->output(); + } + + sub action_save_table_data { + my ( $self, $r ) = @_; + my $req = WTF::Utils::get_req($r); + + + + + + + $r->headers_out->set( 'Location' => ROOT_URL . '/view/admin/tables' ); + return $r->status( Apache2::Const::REDIRECT ); + } + 1; __END__ |