Skip to content

Commit

Permalink
Moving menu over to new template and stored proc model. THe menu expa…
Browse files Browse the repository at this point in the history
…nsion/contraction doesn't quite work yet and there needs to be some additional help on the CSS/Javascript side of this.

Also, this makes a few changes to the lower-level Perl API.  Classes calling LedgerSMB::call_procedure() directly may need some editing but I believe I got them all.  These changes were necessary to accomodate zero-argument stored procedures.

git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@1355 4979c152-3d1c-0410-bac9-87ea11338e46
  • Loading branch information
einhverfr committed Jul 9, 2007
1 parent ae39575 commit bdff086
Show file tree
Hide file tree
Showing 9 changed files with 982 additions and 71 deletions.
11 changes: 8 additions & 3 deletions LedgerSMB.pm
Expand Up @@ -536,11 +536,12 @@ sub call_procedure {
my $self = shift @_; my $self = shift @_;
my %args = @_; my %args = @_;
my $procname = $args{procname}; my $procname = $args{procname};
my @args = @{ $args{args} }; my @call_args;
@call_args = @{ $args{args} } if defined $args{args};
my $order_by = $args{order_by}; my $order_by = $args{order_by};
my $argstr = ""; my $argstr = "";
my @results; my @results;
for ( 1 .. scalar @args ) { for ( 1 .. scalar @call_args ) {
$argstr .= "?, "; $argstr .= "?, ";
} }
$argstr =~ s/\, $//; $argstr =~ s/\, $//;
Expand All @@ -550,7 +551,11 @@ sub call_procedure {
} }
$query =~ s/\(\)/($argstr)/; $query =~ s/\(\)/($argstr)/;
my $sth = $self->{dbh}->prepare($query); my $sth = $self->{dbh}->prepare($query);
$sth->execute(@args); if (scalar @call_args){
$sth->execute(@call_args);
} else {
$sth->execute();
}
my @types = @{$sth->{TYPE}}; my @types = @{$sth->{TYPE}};
my @names = @{$sth->{NAME_lc}}; my @names = @{$sth->{NAME_lc}};
while ( my $ref = $sth->fetchrow_hashref('NAME_lc') ) { while ( my $ref = $sth->fetchrow_hashref('NAME_lc') ) {
Expand Down
70 changes: 56 additions & 14 deletions LedgerSMB/DBObject.pm
Expand Up @@ -50,17 +50,24 @@ sub AUTOLOAD {
my $type = Scalar::Util::blessed $self; my $type = Scalar::Util::blessed $self;
$type =~ m/::(.*?)$/; $type =~ m/::(.*?)$/;
$type = lc $1; $type = lc $1;
print "Type: $type\n";
$self->exec_method( procname => "$type" . "_" . $AUTOLOAD, args => \@_); $self->exec_method( procname => "$type" . "_" . $AUTOLOAD, args => \@_);
} }


sub new { sub new {
my $class = shift @_; my $class = shift @_;
my %args = @_; my $args = shift @_;
my $base = $args{base}; my $base = $args->{base};
my $mode = $args{copy}; my $mode = $args->{copy};
my @mergelist = @{$args{merge}};
my $self = bless {}, $class; my $self = bless {}, $class;
my @mergelist;
if (defined $args->{merge}){
@mergelist = @{$args->{merge}};
} elsif (defined $mode && ( $mode eq 'list')) {
$self->error('Mergelist not set');
}
else {
@mergelist = [];
}
if ( !$base->isa('LedgerSMB') ) { if ( !$base->isa('LedgerSMB') ) {
$self->error("Constructor called without LedgerSMB object arg"); $self->error("Constructor called without LedgerSMB object arg");
} }
Expand Down Expand Up @@ -93,19 +100,23 @@ sub exec_method {
my $self = shift @_; my $self = shift @_;
my %args = @_; my %args = @_;
my $funcname = $args{funcname}; my $funcname = $args{funcname};
my @in_args = @{ $args{args} }; my @in_args;
@in_args = @{ $args{args}} if $args{args};
my @call_args; my @call_args;


my $query = "SELECT proname, proargnames FROM pg_proc WHERE proname = ?"; my $query = "SELECT proname, pronargs, proargnames FROM pg_proc WHERE proname = ?";
my $sth = $self->{dbh}->prepare($query); my $sth = $self->{dbh}->prepare($query);
$sth->execute($funcname); $sth->execute($funcname);
my $ref; my $ref;


$ref = $sth->fetchrow_hashref('NAME_lc'); $ref = $sth->fetchrow_hashref('NAME_lc');
my $args = $ref->{proargnames}; my $args = $ref->{proargnames};
$args =~ s/\{(.*)\}/$1/; my @proc_args;
my @proc_args = split /,/, $args; $ref->{pronargs} = 0 unless defined $ref->{pronargs};

if ($ref->{pronargs}){
$args =~ s/\{(.*)\}/$1/;
@proc_args = split /,/, $args if $args;
}
if ( !$ref ) { # no such function if ( !$ref ) { # no such function
$self->error( "No such function: ", $funcname ); $self->error( "No such function: ", $funcname );
die; die;
Expand All @@ -119,10 +130,10 @@ sub exec_method {
} }
} }
} }
else { for (@in_args) { push @call_args, $_ } ;
@call_args = @_; $self->{call_args} = \@call_args;
} $self->debug({file => '/tmp/dbobject'});
$self->call_procedure( procname => $funcname, args => \@call_args ); $self->call_procedure( procname => $funcname, args => @call_args );
} }


sub run_custom_queries { sub run_custom_queries {
Expand Down Expand Up @@ -224,4 +235,35 @@ sub run_custom_queries {
@rc; @rc;
} }


sub _parse_array {
my ($self, $value) = @_;
my $next;
my $separator;
my @return_array;

while ($value ne '{}') {
my $next = "";
my $separator = "";
if ($value =~ /^\{"/){
while ($next eq "" or ($next =~ /\\".$/)){
$value =~ s/^\{("[^"]*".)/\{/;
$next .= $1;
$next =~ /(.)$/;
$separator = $1;
}
$next =~ s/"(.*)"$separator$/$1/;

} else {
$value =~ s/^\{([^,]*)(,|\})/\{/;
$next = $1;
$separator = $2;
}
$value .= '}' if $separator eq '}';
$next =~ s/\\\\/\\/g;
$next =~ s/\\"/"/g;
push @return_array, $next;
}
return @return_array;
}

1; 1;
65 changes: 31 additions & 34 deletions LedgerSMB/Menu.pm
Expand Up @@ -18,53 +18,50 @@ included COPYRIGHT and LICENSE files for more information.
package LedgerSMB::Menu; package LedgerSMB::Menu;


use Config::Std; use Config::Std;
use base(qw(LedgerSMB)); use base(qw(LedgerSMB::DBObject));


1; 1;


=head1 METHODS =head1 METHODS
=over =over
=item new({files => ['path/to/file/glob' ... ], user = $user_ref}) =item LedgerSMB::Menu->new()
Creates a new Menu data structure with the files listed and the files in the Inherited from LedgerSMB::DBObject. Please see that documnetation for details.
paths.
=item $menu->generate()
This function returns a list of menu items. Each list item is a hashref:
keys %menu_item would return the equivalent of qw(position id level label path
args). Returns the complete list and sets $menu->{menu_items} to a referene to
th result set, This function does not return an entry for the top-level menu.
=cut =cut


sub generate {
my ($self) = shift @_;
my @args;

@{$self->{menu_items}} = $self->exec_method(funcname => 'menu_generate');

$self->debug({file => '/tmp/menu'});


sub new { shift @{$self->{menu_items}};
my ($class, $args) = @_;
my $self = {}; for my $attribute (@{$self->{menu_items}}){
bless ($self, $class);
my $index = 1; @args = $self->_parse_array($attribute->{args});
for $file_glob (@{$args->{files}}){ delete $attribute->{args};
for $file (glob($file_glob)){ @{$attribute->{args}} = @args;
my %config; for (@{$attribute->{args}}){
read_config($file => %config ); if ($_ =~ /(module|menu|action)=/){
for $key (keys %config){ @elems = split(/=/, $_);
next if $args->{user}->{acs} =~ /$key/; print STDERR join(','. @elems) . "\n";
my $orig_key = $key; $attribute->{$elems[0]} = $elems[1];
my $ref = $self;
while ($key =~ s/^([^-]*)--//){
$ref->{subs} ||= {};
$ref->{subs}->{$1} ||= {};
$ref = $ref->{subs}->{$1};
}
$ref->{subs} ||= {};
$ref->{subs}->{key} ||= {};
$ref = $ref->{subs}->{$key};
for (keys %{$config{$orig_key}}){
$ref->{$_} = ${$config{$orig_key}}{$_};
}
$ref->{id} = $index;
$ref->{label} = $key;
++$index;
} }
} }
} }
return $self; return @{$self->{menu_items}};
} }
1;
=back
2 changes: 1 addition & 1 deletion LedgerSMB/Reconciliation.pm
Expand Up @@ -179,4 +179,4 @@ sub entry {
return $self->single_entry($self->{report_id},$self->{entry_id}); return $self->single_entry($self->{report_id},$self->{entry_id});
} }


1; 1;
2 changes: 1 addition & 1 deletion UI/frameset.html
Expand Up @@ -17,7 +17,7 @@




<frameset cols="155,*" border="1"> <frameset cols="155,*" border="1">
<frame name="acc_menu" src="menu.pl?login=<?lsmb login ?>&amp;action=acc_menu&amp;path=bin/mozilla&amp;js=1" /> <frame name="acc_menu" src="menu.pl?login=<?lsmb login ?>&amp;action=expanding_menu&amp;path=bin/mozilla&amp;js=1" />
<frame name="main_window" src="<?lsmb main ?>" /> <frame name="main_window" src="<?lsmb main ?>" />
</frameset> </frameset>
</html> </html>
21 changes: 9 additions & 12 deletions UI/menu_expand.html
Expand Up @@ -34,19 +34,12 @@


<body class="menu"> <body class="menu">
<img class="cornderlogo" src="images/ledgersmb_small.png" width="100" height="50" border="1" alt="ledger-smb" /> <img class="cornderlogo" src="images/ledgersmb_small.png" width="100" height="50" border="1" alt="ledger-smb" />
<?lsmb FOREACH item = subs ?> <?lsmb FOREACH item = menu_items ?>
<?lsmb old_id = id ?><?lsmb old_path = path ?> <?lsmb href = "" ?>
<?lsmb id = item.id ?><?lsmb path = item.path ?> <?lsmb WHILE item.level < old_level ?>
<?lsmb IF (id != old_id) AND id ?> </div><?lsmb old_level = old_level - 1 ?>
<?lsmb desc_ids = [id, ''] ?>
<?lsmb asc_ids = [old_id, ''] ?>
<?lsmb IF old_id.search(desc_ids.join('--')) ?>
<div id="sub_<?lsmb old_id ?>" class="Submenu">
<?lsmb ELSIF id.search(asc_ids.join('--')) ?>
</div>
<?lsmb END ?>
<?lsmb END ?> <?lsmb END ?>
<div class="Menu" id="menu_<?lsmb id ?>"> <div class="Menu" id="menu_<?lsmb item.id ?>">
<a href="<?lsmb IF item.module ?><?lsmb item.module <a href="<?lsmb IF item.module ?><?lsmb item.module
?><?lsmb ELSE ?>menu.pl<?lsmb END ?><?lsmb ELSE ?>menu.pl<?lsmb END
?>?login=<?lsmb login ?>?login=<?lsmb login
Expand All @@ -59,6 +52,10 @@
ELSE ?>Item<?lsmb END ?>" ELSE ?>Item<?lsmb END ?>"
><?lsmb text(item.label) ?></a> ><?lsmb text(item.label) ?></a>
</div> </div>
<?lsmb IF item.menu ?>
<div id="sub_<?lsmb item.id ?>" class=submenu>
<?lsmb END ?>
<?lsmb old_level = item.level ?>
<?lsmb END ?> <?lsmb END ?>




Expand Down
2 changes: 1 addition & 1 deletion menu.pl
@@ -1,3 +1,3 @@
#!/usr/bin/perl #!/usr/bin/perl


require "old-handler.pl"; require "lsmb-request.pl";
8 changes: 3 additions & 5 deletions scripts/menu.pl
Expand Up @@ -34,9 +34,8 @@ sub display {


sub expanding_menu { sub expanding_menu {
my ($request) = @_; my ($request) = @_;
my $menu = new LedgerSMB::Menu( my $menu = new LedgerSMB::Menu({base => $request});
{files => ['menu.ini'], user => $request->{_user}} $menu->generate();
);
my $template = LedgerSMB::Template->new( my $template = LedgerSMB::Template->new(
user => $request->{_user}, user => $request->{_user},
locale => $request->{_locale}, locale => $request->{_locale},
Expand All @@ -45,10 +44,9 @@ sub expanding_menu {
format => 'HTML', format => 'HTML',
); );
$request->{subs} = []; $request->{subs} = [];
_attach_references({source => $menu, dest => $request->{subs}, path => ""});
$menu->debug({file => '/tmp/debug-menu'}); $menu->debug({file => '/tmp/debug-menu'});
$request->debug({file => '/tmp/debug'}); $request->debug({file => '/tmp/debug'});
$template->render($request); $template->render($menu);
} }


sub _attach_references { sub _attach_references {
Expand Down

0 comments on commit bdff086

Please sign in to comment.