App-Widget
view release on metacpan or search on metacpan
lib/App/Widget/RepositoryEditor.pm view on Meta::CPAN
## o TODO (edit): for selected rows screen, show all fields, allow editing on selected fields
## o TODO (edit): when no rows selected, use the selection criteria to get the new rows
## o TODO (export): allow exporting of data
## o TODO (import): allow importing of data
## o TODO (import): allow export/import of data
## o TODO (edit): include some column for modifying the size, maxlength of edit field
## o TODO (edit): include some column for validation rules
## o TODO (edit): include some column for drop-down selections
## o TODO: add report-saving feature
## x TODO: transform into a standard HTML::Widget::Base constructor interface
## o TODO: get context logic out of this class
## o TODO: can't edit "summary" data (what should I do when they try?)
## o TODO: add show/hide detail of report criteria screen
## x TODO: if sort column is chosen which is not in the list of selected columns
## 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") {
}
lib/App/Widget/RepositoryEditor.pm view on Meta::CPAN
$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;
$self->{context}->dbgprint("RepositoryEditor->set_mode(): params=[", join(",", @$ref), "]") if ($ref);
$ref = $param_contains;
$self->{context}->dbgprint("RepositoryEditor->set_mode(): param_contains=[", join(",", @$ref), "]") if ($ref);
$self->{context}->dbgprint("RepositoryEditor->set_mode(): params=[", join(",", @params), "]");
$self->{context}->dbgprint("RepositoryEditor->set_mode(): paramvalues=[", join(",", %paramvalues), "]");
}
}
######################################################################
# OUTPUT METHODS
######################################################################
sub html {
my $self = shift;
my ($context, $name, $mode);
$context = $self->{context};
$name = $self->{name};
$mode = $self->get("mode","");
if ($mode eq "edit" || $mode eq "view") {
return $context->widget("${name}_datatable")->html();
}
else {
return $self->mk_criteria_html();
}
}
sub mk_criteria_html {
my $self = shift;
my ($name, $context, $repname, $rep, $table, $table_names, $table_label_hashref, $table_label);
$context = $self->{context};
$name = $self->{name};
$repname = $self->{repository};
$rep = $context->repository($repname);
$self->{rep} = $rep;
$rep = $self->{rep};
$table_names = $rep->get_table_names();
$table_label_hashref = $rep->get_table_labels();
$table = $self->get("table");
$table_label = $table_label_hashref->{$table};
$table_label = $table if (!$table_label);
$self->set("saveas_view","");
$self->set("new_table",$table);
my ($html);
my ($view, $saveas_view, $new_table, $maxrows);
my ($open_button, $save_button, $delete_button, $saveas_button);
my ($view_button, $edit_button, $select_button);
my ($columns, $params);
$view = $context->widget("$name-view",
class => "App::Widget::TextField",
size => 20,
maxwidth => 99,
)->html();
$saveas_view = $context->widget("$name-saveas_view",
class => "App::Widget::TextField",
size => 20,
maxwidth => 99,
)->html();
$new_table = $context->widget("$name-new_table",
class => "App::Widget::Select",
values => $table_names,
( run in 0.411 second using v1.01-cache-2.11-cpan-39bf76dae61 )