Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/racke/refactor-te
Temporary repository for refactoring TableEditor.
https://github.com/racke/refactor-te
Last synced: 5 days ago
JSON representation
Temporary repository for refactoring TableEditor.
- Host: GitHub
- URL: https://github.com/racke/refactor-te
- Owner: racke
- Created: 2014-05-02T09:55:43.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2014-05-06T15:21:14.000Z (over 10 years ago)
- Last Synced: 2024-11-18T18:43:39.876Z (2 months ago)
- Language: Perl
- Size: 1.45 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.pod
Awesome Lists containing this project
README
=encoding utf8
=pod
=head1 NAME
Dancer - Table Edit
=head1 SYNOPSIS
Table Edit lets you edit database data. It uses L models for database metadata.
=head1 CONFIGURATION
You need a database and L models for this module to work. You can
write your own L models, or use schema loader.=head2 DBIx schema loader
You can use your existing DBIx schema or let schema loader make one for you.
=head2 Database config
You also have to set the DBIC connection details in the
Dancer configuration (usually in the environments/*.yml
files as this differs between systems).plugins:
DBIC:
default:
dsn: dbi:Pg:dbname=__DATABASE_NAME__;host=localhost;port=__PORT__
schema_class: TableEdit::Schema
user: __USERNAME__
pass: __PASSWORD__
options:
pg_enable_utf8: 1Make sure that you are using the appropriate UTF-8 flag for L, as
this plugin doesn't set it automatically.=head1 FRONTEND
Table Edit uses L and L for the frontend.
It is easy to change the Bootstrap theme to get a different look for Table Edit.=head1 USE
With basic configuration done you can start using Table Edit. You will probably want to fine tune it a bit though.
=head1 FINE TUNE
Make sure you set all additional info below # DO NOT MODIFY THIS OR ANYTHING ABOVE! line in L model.
For this example we will use following model.
use utf8;
package TableEdit::Schema::Result::User;
use strict;
use warnings;
use base 'DBIx::Class::Core';
__PACKAGE__->table("user");
__PACKAGE__->add_columns(
"id",
{ data_type => "integer", is_auto_increment => 1, is_nullable => 0 },
"username",
{ data_type => "varchar", is_nullable => 0, size => 45 },
"email",
{ data_type => "varchar", is_nullable => 1, size => 90 },
"birthday",
{ data_type => "timestamp with time zone", is_nullable => 1 },
"internal_code",
{ data_type => "integer", is_nullable => 1 },
"created_date",
{
data_type => "timestamp with time zone",
default_value => \"current_timestamp",
is_nullable => 0,
original => { default_value => \"now()" },
},
);
__PACKAGE__->set_primary_key("id");
__PACKAGE__->belongs_to(
"company",
"TableEdit::Schema::Result::Company",
{ id => "podjetje_id" },
{ is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" },
);
__PACKAGE__->has_many(
"user_items",
"TableEdit::Schema::Result::UserItem",
{ "foreign.approval_id" => "self.approval_id" },
{ cascade_copy => 0, cascade_delete => 0 },
);
__PACKAGE__->many_to_many("items", "user_items", "id", {class=>"Item",});
# Created by DBIx::Class::Schema::Loader v0.07033
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:g5NE5itWUoKXqfEKXj/8Rg
__PACKAGE__->resultset_attributes({
label => 'Employees',
grid_columns => ['id', 'username', 'email'],
form_columns => ['id', 'username', 'email', 'birthday', 'internal_code'],
many_to_many => {
items => {class => 'TableEdit::Schema::Result::Item', where => {inactive => 'false'}},
},
});
__PACKAGE__->columns_info->{created_date}->{readonly} = 1;
__PACKAGE__->columns_info->{internal_code}->{hidden} = 1;
__PACKAGE__->columns_info->{email}->{data_type} = 'text';
# You can replace this text with custom code or comments, and it will be preserved on regeneration
1;
=head2 Column label
You can override column label by specifying it
__PACKAGE__->columns_info->{fname}->{label} = 'Name';
=head2 Object / Row string representation
Row often has to be represented as string (titles, drop-down selectors, ...) so it is a good idea to
define a custom, human readable stringification method. For example users username, his id in parentheses
and company if he / she has one. It could be just username or something much complicated.use overload fallback => 1, '""' => \&to_string;
sub to_string {
my $self = shift;
my $company = $self->company || "";
return "$self->username ($self->id) $company";
}=head2 Hidden columns
Some columns are used only internally and you never want to see them in TableEdit. You can hide them.
__PACKAGE__->columns_info->{internal_code}->{hidden} = 1;
=head2 Readonly columns
You can set a column to be readonly
__PACKAGE__->columns_info->{created_date}->{readonly} = 1;
=head2 Many to many
"Has many" and "belongs_to" is automatically detected. However, many to many DBIx::Class information
doesn't provide enough information, so you have to specify it manually.
Only set resultset_attributes once, or it will be overwritten!__PACKAGE__->resultset_attributes({
many_to_many => {
items => {class => 'TableEdit::Schema::Result::Item', where => {inactive => 'false'}},
},
});
=head2 Grid / form visible columnsOften you don't care about all columns when you browse though rows or there are simply to many.
You can specify a list of columns that will appear on grid or form.
You have to be careful not to omit required columns and similar on form view.__PACKAGE__->resultset_attributes({
grid_columns => ['id', 'username', 'email'],
form_columns => ['id', 'username', 'email', 'birthday', 'internal_code'],
});
=head2 Model name / labelYou can set user friendly name of the table.
__PACKAGE__->resultset_attributes({
label => 'Employees',
});
=head2 Field data typeFields have basic data types based on types in db. You can override them to use different form element.
__PACKAGE__->columns_info->{email}->{data_type} = 'text';
You can also set them to use your custom widget. You create a HTML file with the matching name in /public/views/field directory.For example /public/views/field/email_widget.html
__PACKAGE__->columns_info->{email}->{data_type} = 'email_widget';
These field types are used on detail view and on list search.
=cut