| 1 | # ABSTRACT: Web interface for DBIx::Class Schema/ResultSource/ResultSet | ||||||||||||||||||||
| 2 | 3 | ▶ | use v5.14; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | 3 | ▶ | use utf8; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 3 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | package Mojolicious::Plugin::DBICAdmin; | ||||||||||||||||||||
| 7 | { | ||||||||||||||||||||
| 8 | 3 | $Mojolicious::Plugin::DBICAdmin::VERSION = '0.0006'; | |||||||||||||||||||
| 9 | } | ||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | 3 | ▶ | use Mojo::Base 'Mojolicious::Plugin'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | 3 | ▶ | use Web::Util::DBIC::Paging; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 3 | my $config = { page_size => 25, }; | |||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | 1 | ▶ | sub register { | ||||||||||||||||||
|
Subroutine
register: called CC=4 SCAR=28.1
Pod
documented
| |||||||||||||||||||||
| 18 | 1 | my ( $self, $app, $conf ) = @_; | |||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | # our base route | ||||||||||||||||||||
| 21 | 1 | my $r = $app->routes->route('/admin/dbic'); | |||||||||||||||||||
| 22 | 0 | ▶ | if ( my $cond = $conf->{condition} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 23 | 0 | $r->over($cond); | |||||||||||||||||||
| 24 | } | ||||||||||||||||||||
| 25 | else { | ||||||||||||||||||||
| 26 | # only localhost can view by default | ||||||||||||||||||||
| 27 | $app->routes->add_condition( | ||||||||||||||||||||
| 28 | 0 | ▶ | localhost => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 29 | 0 | my ( $route, $c, $captures, $pattern ) = @_; | |||||||||||||||||||
| 30 | 0 | $c->tx->remote_address eq '127.0.0.1'; | |||||||||||||||||||
| 31 | } | ||||||||||||||||||||
| 32 | 0 | ); | |||||||||||||||||||
| 33 | 0 | $r->over('localhost'); | |||||||||||||||||||
| 34 | } | ||||||||||||||||||||
| 35 | 0 | ▶ | $config->{page_size} = $conf->{page_size} if $conf->{page_size} // 0 > 0; | ||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$conf->{"page_size"} //
MC/DC0%0/1
$conf->{"page_size"} //
$conf->{"page_size"}
Truth table0%0/2
A
A= $conf->{"page_size"}
| |||||||||||||||||||||
| 36 | 0 | $config = +{ %$conf, %$config }; | |||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | # setup route and template | ||||||||||||||||||||
| 39 | 0 | push @{ $app->renderer->classes }, __PACKAGE__; | |||||||||||||||||||
| 40 | 0 | $r->any( '/' => \&_dbic_list )->name('dbic-admin-index'); | |||||||||||||||||||
| 41 | 0 | $r->any( '/list' => \&_dbic_list )->name('dbic-admin-list'); | |||||||||||||||||||
| 42 | 0 | $r->any( '/info' => \&_dbic_select_source ) | |||||||||||||||||||
| 43 | ->name('dbic-admin-info-select-source'); | ||||||||||||||||||||
| 44 | 0 | $r->any( '/info/:source' => \&_dbic_info )->name('dbic-admin-info'); | |||||||||||||||||||
| 45 | 0 | $r->any( '/search' => \&_dbic_select_source ) | |||||||||||||||||||
| 46 | ->name('dbic-admin-search-select-source'); | ||||||||||||||||||||
| 47 | 0 | $r->any( '/search/:source' => \&_dbic_search )->name('dbic-admin-search'); | |||||||||||||||||||
| 48 | 0 | $r->any( '/delete/:source' => \&_dbic_delete )->name('dbic-admin-delete'); | |||||||||||||||||||
| 49 | 0 | return 1; | |||||||||||||||||||
| 50 | } | ||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | 0 | ▶ | sub _dbic_list { | ||||||||||||||||||
|
Subroutine
_dbic_list: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 53 | 0 | my $c = shift; | |||||||||||||||||||
| 54 | 0 | my @sources = sort grep !/::/, $c->app->schema->sources; | |||||||||||||||||||
| 55 | 0 | $c->render( sources => \@sources, config => $config, ); | |||||||||||||||||||
| 56 | } | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | 0 | ▶ | sub _dbic_delete { | ||||||||||||||||||
|
Subroutine
_dbic_delete: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 59 | 0 | my $c = shift; | |||||||||||||||||||
| 60 | 0 | my $source = $c->stash('source'); | |||||||||||||||||||
| 61 | 0 | $c->render( text => "search" ); | |||||||||||||||||||
| 62 | } | ||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | 0 | ▶ | sub _dbic_info { | ||||||||||||||||||
|
Subroutine
_dbic_info: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 65 | 0 | my $c = shift; | |||||||||||||||||||
| 66 | 0 | my $source = $c->stash('source'); | |||||||||||||||||||
| 67 | 0 | my $src_obj = $c->app->schema->source($source); | |||||||||||||||||||
| 68 | 0 | $c->render( src_obj => $src_obj, config => $config ); | |||||||||||||||||||
| 69 | } | ||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | 0 | ▶ | sub _dbic_search { | ||||||||||||||||||
|
Subroutine
_dbic_search: not called CC=6 SCAR=37.4
| |||||||||||||||||||||
| 72 | 0 | my $c = shift; | |||||||||||||||||||
| 73 | 0 | my $source = $c->stash('source'); | |||||||||||||||||||
| 74 | 0 | ▶ | my $rs = $c->app->schema->resultset($source) | ||||||||||||||||||
|
Condition0%0/2
$c->app->schema->resultset($source) || (return $c->render_exception('ResultSource unexist !'))
MC/DC0%0/1
$c->app->schema->resultset($source) || (return $c->render_exception('ResultSource unexist !'))
$c->app->schema->resultset($source)
Truth table0%0/2
A
A= $c->app->schema->resultset($source)
| |||||||||||||||||||||
| 75 | || return $c->render_exception("ResultSource unexist !"); | ||||||||||||||||||||
| 76 | 0 | my $param = $c->req->params->to_hash; | |||||||||||||||||||
| 77 | 0 | $rs = search( 'raw', $param, $rs, $config ); | |||||||||||||||||||
| 78 | 0 | my $count = $rs->count; | |||||||||||||||||||
| 79 | 0 | ▶ | my $start = $param->{start} // 0; | ||||||||||||||||||
|
Condition0%0/2
$param->{"start"} // 0
MC/DC0%0/1
$param->{"start"} // 0
$param->{"start"}
Truth table0%0/2
A
A= $param->{"start"}
| |||||||||||||||||||||
| 80 | 0 | ▶ | my $next = $count < $config->{page_size} ? undef : $start + $count; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 81 | my $prev = | ||||||||||||||||||||
| 82 | $start <= 0 ? -1 | ||||||||||||||||||||
| 83 | : $start > $config->{page_size} ? $start - $config->{page_size} | ||||||||||||||||||||
| 84 | 0 | ▶ | : 0; | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 85 | 0 | $c->render( | |||||||||||||||||||
| 86 | rs => $rs, | ||||||||||||||||||||
| 87 | next => $next, | ||||||||||||||||||||
| 88 | prev => $prev, | ||||||||||||||||||||
| 89 | config => $config, | ||||||||||||||||||||
| 90 | ); | ||||||||||||||||||||
| 91 | } | ||||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | 0 | ▶ | sub _dbic_select_source { | ||||||||||||||||||
|
Subroutine
_dbic_select_source: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 94 | 0 | my $c = shift; | |||||||||||||||||||
| 95 | 0 | $c->render( config => $config, template => 'dbic-admin-select-source' ); | |||||||||||||||||||
| 96 | } | ||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | 0 | ▶ | sub _dbic_index { | ||||||||||||||||||
|
Subroutine
_dbic_index: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 99 | 0 | my $c = shift; | |||||||||||||||||||
| 100 | 0 | $c->render( config => $config ); | |||||||||||||||||||
| 101 | } | ||||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | 3 | 1; | |||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | =pod | ||||||||||||||||||||
| 106 | |||||||||||||||||||||
| 107 | =head1 NAME | ||||||||||||||||||||
| 108 | |||||||||||||||||||||
| 109 | Mojolicious::Plugin::DBICAdmin - Web interface for DBIx::Class Schema/ResultSource/ResultSet | ||||||||||||||||||||
| 110 | |||||||||||||||||||||
| 111 | =head1 VERSION | ||||||||||||||||||||
| 112 | |||||||||||||||||||||
| 113 | version 0.0006 | ||||||||||||||||||||
| 114 | |||||||||||||||||||||
| 115 | =head1 SYNOPSIS | ||||||||||||||||||||
| 116 | |||||||||||||||||||||
| 117 | This Plugin just for Web master view/search their data in DB | ||||||||||||||||||||
| 118 | |||||||||||||||||||||
| 119 | =head2 Configure | ||||||||||||||||||||
| 120 | |||||||||||||||||||||
| 121 | In Mojolicious App's C<startup> method: | ||||||||||||||||||||
| 122 | |||||||||||||||||||||
| 123 | $self->plugin('DBICAdmin' => { | ||||||||||||||||||||
| 124 | condition => 'login', # optional | ||||||||||||||||||||
| 125 | stylesheet => '/dbic-admin-pure.css', #optional | ||||||||||||||||||||
| 126 | # ... other configurations | ||||||||||||||||||||
| 127 | }); | ||||||||||||||||||||
| 128 | |||||||||||||||||||||
| 129 | =head2 Use | ||||||||||||||||||||
| 130 | |||||||||||||||||||||
| 131 | #start app and view the URI : | ||||||||||||||||||||
| 132 | http://yourapp.domain/admin/dbic/ | ||||||||||||||||||||
| 133 | |||||||||||||||||||||
| 134 | =head1 DESCRIPTION | ||||||||||||||||||||
| 135 | |||||||||||||||||||||
| 136 | You will see it, when you open URI : L</admin/dbic/> | ||||||||||||||||||||
| 137 | |||||||||||||||||||||
| 138 | =head2 routes | ||||||||||||||||||||
| 139 | |||||||||||||||||||||
| 140 | the Plugin set following routes : | ||||||||||||||||||||
| 141 | |||||||||||||||||||||
| 142 | =over | ||||||||||||||||||||
| 143 | |||||||||||||||||||||
| 144 | =item C</admin/dbic/> | ||||||||||||||||||||
| 145 | |||||||||||||||||||||
| 146 | Index of the module's function | ||||||||||||||||||||
| 147 | |||||||||||||||||||||
| 148 | =item C</admin/dbic/search> and C</admin/dbic/search/:source> | ||||||||||||||||||||
| 149 | |||||||||||||||||||||
| 150 | Search DBIx::Class drivered database | ||||||||||||||||||||
| 151 | |||||||||||||||||||||
| 152 | =item C</admin/dbic/info> and C</admin/dbic/info/:source> | ||||||||||||||||||||
| 153 | |||||||||||||||||||||
| 154 | List Result Source Class's columns info | ||||||||||||||||||||
| 155 | |||||||||||||||||||||
| 156 | =item C</admin/dbic/list> | ||||||||||||||||||||
| 157 | |||||||||||||||||||||
| 158 | List Result source loaded by DBIx::Class | ||||||||||||||||||||
| 159 | |||||||||||||||||||||
| 160 | =back | ||||||||||||||||||||
| 161 | |||||||||||||||||||||
| 162 | =head2 display style | ||||||||||||||||||||
| 163 | |||||||||||||||||||||
| 164 | Plugin use L<purecss|http://purecss.io/> | ||||||||||||||||||||
| 165 | |||||||||||||||||||||
| 166 | you can use customed theme of purecss by pass config directive : C<stylesheet="/dbic-admin-pure.css"> | ||||||||||||||||||||
| 167 | |||||||||||||||||||||
| 168 | customlized theme of purecss must use name : C<.pure-skin-dbic> | ||||||||||||||||||||
| 169 | |||||||||||||||||||||
| 170 | where to coustom the theme ? | ||||||||||||||||||||
| 171 | |||||||||||||||||||||
| 172 | L<Here|http://yui.github.io/skinbuilder/?mode=pure> | ||||||||||||||||||||
| 173 | |||||||||||||||||||||
| 174 | =head2 config | ||||||||||||||||||||
| 175 | |||||||||||||||||||||
| 176 | =over | ||||||||||||||||||||
| 177 | |||||||||||||||||||||
| 178 | =item page_size | ||||||||||||||||||||
| 179 | |||||||||||||||||||||
| 180 | rows displayed per page | ||||||||||||||||||||
| 181 | |||||||||||||||||||||
| 182 | =item stylesheet | ||||||||||||||||||||
| 183 | |||||||||||||||||||||
| 184 | theme of the web page, should be the url of css file create by L<YUI Skin Builder|http://yui.github.io/skinbuilder/?mode=pure> | ||||||||||||||||||||
| 185 | |||||||||||||||||||||
| 186 | =item condition | ||||||||||||||||||||
| 187 | |||||||||||||||||||||
| 188 | array or scalar if single of Mojolicious route condition used for access control | ||||||||||||||||||||
| 189 | |||||||||||||||||||||
| 190 | =back | ||||||||||||||||||||
| 191 | |||||||||||||||||||||
| 192 | =encoding utf8 | ||||||||||||||||||||
| 193 | |||||||||||||||||||||
| 194 | =head1 NAME | ||||||||||||||||||||
| 195 | |||||||||||||||||||||
| 196 | DBICAdmin - Web interface for DBIx::Class Schema/ResultSource/ResultSet | ||||||||||||||||||||
| 197 | |||||||||||||||||||||
| 198 | =head1 AUTHOR | ||||||||||||||||||||
| 199 | |||||||||||||||||||||
| 200 | ChinaXing(陈云星) <chen.yack@gmail.com> | ||||||||||||||||||||
| 201 | |||||||||||||||||||||
| 202 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||
| 203 | |||||||||||||||||||||
| 204 | This software is Copyright (c) 2013 by ChinaXing(陈云星). | ||||||||||||||||||||
| 205 | |||||||||||||||||||||
| 206 | This is free software, licensed under: | ||||||||||||||||||||
| 207 | |||||||||||||||||||||
| 208 | The (three-clause) BSD License | ||||||||||||||||||||
| 209 | |||||||||||||||||||||
| 210 | =cut | ||||||||||||||||||||
| 211 | |||||||||||||||||||||
| 212 | __DATA__ | ||||||||||||||||||||