App-Widget
view release on metacpan or search on metacpan
lib/App/Widget/RepositoryEditor.pm view on Meta::CPAN
## we add it to the list and use its alias
## x TODO: add primary key to the group-by clause whenever non-summary group-by is required
## (or editing is required)
## x TODO: autogenerate missing aliases (i.e. col001) for use in group by, order by
## x TODO: only display the columns in the selected columns list (more will be returned)
## x TODO: add default {summary} formula as count(distinct COL) (for non-numbers)
## x TODO: add default {summary} formula as sum(COL) (for numbers)
package App::Widget::RepositoryEditor;
$VERSION = (q$Revision: 3668 $ =~ /(\d[\d\.]*)/)[0]; # VERSION numbers generated by svn
use App;
use App::Widget;
@ISA = ( "App::Widget" );
use App::Repository;
use strict;
=head1 NAME
App::Widget::RepositoryEditor - A widget allowing the user to browse and edit a repository
=head1 SYNOPSIS
$name = "repedit";
# official way
use App;
$context = App->context();
$w = $context->widget($name);
# internal way
use App::Widget::RepositoryEditor;
$w = App::Widget::RepositoryEditor->new($name);
=cut
######################################################################
# CONSTANTS
######################################################################
######################################################################
# ATTRIBUTES
######################################################################
# INPUTS FROM THE ENVIRONMENT
=head1 DESCRIPTION
This class implements a widget.
=cut
######################################################################
# INITIALIZATION
######################################################################
sub _init {
my $self = shift;
$self->SUPER::_init(@_);
my ($context, $name, $rep, $repname, $table, $table_names);
$context = $self->{context};
$name = $self->{name};
$repname = $self->get("repository");
$rep = $context->repository($repname);
$table = $self->get("table");
if (! $table) {
$table_names = $rep->get_table_names();
$table = $table_names->[0];
$self->set("table",$table);
}
$self->{columns} = [] if (!defined $self->{columns});
$context->widget("${name}_datatable",
class => "App::Widget::DataTable",
scrollable => 1,
sortable => 1,
filterable => 1,
repository => $repname,
);
}
######################################################################
# EVENTS
######################################################################
# Usage: $widget->handle_event($wname, $event, @args);
sub handle_event {
my ($self, $wname, $event, @args) = @_;
my ($name, $table);
$name = $self->{name};
$self->{context}->dbgprint("RepositoryEditor($name)->handle_event($wname,$event,@args)")
if ($App::DEBUG && $self->{context}->dbg(1));
if ($wname eq "$name-open_button") {
}
elsif ($wname eq "$name-save_button") {
}
elsif ($wname eq "$name-delete_button") {
}
elsif ($wname eq "$name-saveas_button") {
}
elsif ($wname eq "$name-view_button") {
$self->set_mode("view", 0);
}
elsif ($wname eq "$name-edit_button") {
$self->set_mode("edit", 1);
}
elsif ($wname eq "$name-select_button") {
$table = $self->get("new_table");
$self->set("table", $table);
$self->set("columns", []);
$self->set("ordercols", []);
$self->set("directions", []);
$self->set("param",[]);
$self->set("param_min",[]);
$self->set("param_max",[]);
$self->set("param_contains",[]);
}
else {
return $self->SUPER::handle_event($wname, $event, @args);
}
return 1;
}
sub set_mode {
my ($self, $mode, $editable) = @_;
my ($context, $name, $w);
$self->set("mode", $mode);
$context = $self->{context};
$name = $self->{name};
$w = $context->widget("${name}_datatable");
$w->set("table", $self->get("table"));
$w->set("columns", $self->get("columns"));
$w->set("ordercols", $self->get("ordercols"));
$w->set("directions", $self->get("directions"));
$w->set("paramvalues", $self->get("paramvalues"));
$w->set("maxrows", $self->get("maxrows"));
$w->set("editable", $editable);
my ($i, @params, %paramvalues, $param, $params, $param_min, $param_max, $param_contains);
$params = $self->get("param");
$param_min = $self->get("param_min",[]);
$param_max = $self->get("param_max",[]);
$param_contains = $self->get("param_contains",[]);
$paramvalues{"_conjunction"} = $self->get("conjunction");
if ($params && ref($params) eq "ARRAY") {
for ($i = 0; $i <= $#$params; $i++) {
$param = $params->[$i];
next if (!defined $param || $param eq "");
if (defined $param_min->[$i] && $param_min->[$i] ne "") {
push(@params, "${param}.ge");
$paramvalues{"${param}.ge"} = $param_min->[$i];
}
if (defined $param_max->[$i] && $param_max->[$i] ne "") {
push(@params, "${param}.le");
$paramvalues{"${param}.le"} = $param_max->[$i];
}
if (defined $param_contains->[$i] && $param_contains->[$i] ne "") {
push(@params, "${param}.contains");
$paramvalues{"${param}.contains"} = $param_contains->[$i];
}
}
}
$w->set("params", \@params);
$w->set("paramvalues", \%paramvalues);
if ($App::DEBUG && $self->{context}->dbg(2)) {
my ($ref);
$ref = $self->get("columns");
$self->{context}->dbgprint("RepositoryEditor->set_mode(): columns=[", join(",", @$ref), "]") if ($ref);
$ref = $self->get("ordercols");
$self->{context}->dbgprint("RepositoryEditor->set_mode(): ordercols=[", join(",", @$ref), "]") if ($ref);
$ref = $self->get("directions");
$self->{context}->dbgprint("RepositoryEditor->set_mode(): directions=[", join(",", @$ref), "]") if ($ref);
$ref = $params;
( run in 0.850 second using v1.01-cache-2.11-cpan-98e64b0badf )