| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package RapidApp::Module::DbicNavTree; |
|
2
|
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
2276
|
use strict; |
|
|
4
|
|
|
|
|
10
|
|
|
|
4
|
|
|
|
|
134
|
|
|
4
|
4
|
|
|
4
|
|
22
|
use warnings; |
|
|
4
|
|
|
|
|
9
|
|
|
|
4
|
|
|
|
|
119
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# ABSTRACT: general purpose navtree for auto grid access to DBIC sources |
|
7
|
|
|
|
|
|
|
|
|
8
|
4
|
|
|
4
|
|
27
|
use Moose; |
|
|
4
|
|
|
|
|
8
|
|
|
|
4
|
|
|
|
|
36
|
|
|
9
|
|
|
|
|
|
|
extends 'RapidApp::Module::NavTree'; |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
4
|
|
|
4
|
|
24366
|
use RapidApp::Util qw(:all); |
|
|
4
|
|
|
|
|
9
|
|
|
|
4
|
|
|
|
|
7322
|
|
|
13
|
|
|
|
|
|
|
require Module::Runtime; |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has 'dbic_models', is => 'ro', isa => 'Maybe[ArrayRef[Str]]', default => undef; |
|
16
|
|
|
|
|
|
|
has 'table_class', is => 'ro', isa => 'Str', required => 1; |
|
17
|
|
|
|
|
|
|
has 'configs', is => 'ro', isa => 'HashRef', default => sub {{}}; |
|
18
|
|
|
|
|
|
|
has 'menu_require_role', is => 'ro', isa => 'Maybe[Str]', default => sub {undef}; |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
has 'dbic_model_tree', is => 'ro', isa => 'ArrayRef[HashRef]', lazy => 1, default => sub { |
|
21
|
|
|
|
|
|
|
my $self = shift; |
|
22
|
|
|
|
|
|
|
die "Must supply either 'dbic_models' or 'dbic_model_tree'" unless ($self->dbic_models); |
|
23
|
|
|
|
|
|
|
my $list = parse_dbic_model_list($self->app,@{$self->dbic_models}); |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# validate models: |
|
26
|
|
|
|
|
|
|
for my $itm (@$list) { |
|
27
|
|
|
|
|
|
|
my $Model = $self->app->model($itm->{model}); |
|
28
|
|
|
|
|
|
|
die "Error: model '$itm->{model}' is not a Catalyst::Model::DBIC::Schema" |
|
29
|
|
|
|
|
|
|
unless ($Model->isa('Catalyst::Model::DBIC::Schema')); |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
warn join("\n",'', |
|
32
|
|
|
|
|
|
|
" WARNING: using DBIC model '$itm->{model}' without 'quote_names' enabled.", |
|
33
|
|
|
|
|
|
|
" It is strongly reccomended that this setting be enabled...", |
|
34
|
|
|
|
|
|
|
" (Set env var RAPIDAPP_ISSUE99_IGNORE to supress this message)",'','' |
|
35
|
|
|
|
|
|
|
) unless ($Model->connect_info->{quote_names} || $ENV{RAPIDAPP_ISSUE99_IGNORE}); |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# strip excludes/limits: |
|
39
|
|
|
|
|
|
|
for my $itm (@$list) { |
|
40
|
|
|
|
|
|
|
my $mdl_cfg = $self->configs->{$itm->{model}} || {}; |
|
41
|
|
|
|
|
|
|
my $exclude_sources = $mdl_cfg->{exclude_sources} || []; |
|
42
|
|
|
|
|
|
|
my %excl_sources = map { $_ => 1 } @$exclude_sources; |
|
43
|
|
|
|
|
|
|
@{$itm->{sources}} = grep { ! $excl_sources{$_} } @{$itm->{sources}}; |
|
44
|
|
|
|
|
|
|
my $lim = $mdl_cfg->{limit_sources} ? {map{$_=>1} @{$mdl_cfg->{limit_sources}}} : undef; |
|
45
|
|
|
|
|
|
|
if($lim) { |
|
46
|
|
|
|
|
|
|
@{$itm->{sources}} = grep { $lim->{$_} } @{$itm->{sources}}; |
|
47
|
|
|
|
|
|
|
} |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
return $list; |
|
51
|
|
|
|
|
|
|
}; |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# return a flat list of all loaded source models: |
|
54
|
|
|
|
|
|
|
sub all_source_models { |
|
55
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
|
56
|
0
|
|
|
|
|
0
|
my @list = (); |
|
57
|
0
|
|
|
|
|
0
|
foreach my $hash (@{$self->dbic_model_tree}) { |
|
|
0
|
|
|
|
|
0
|
|
|
58
|
0
|
|
|
|
|
0
|
push @list, map { $hash->{model} . '::' . $_ } @{$hash->{sources}}; |
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
59
|
|
|
|
|
|
|
} |
|
60
|
0
|
|
|
|
|
0
|
return @list; |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# General func instead of class method for use in other packages (temporary): |
|
65
|
|
|
|
|
|
|
sub parse_dbic_model_list { |
|
66
|
4
|
|
|
4
|
0
|
11
|
my $c = shift; |
|
67
|
4
|
|
|
|
|
22
|
my @models = @_; |
|
68
|
|
|
|
|
|
|
|
|
69
|
4
|
|
|
|
|
12
|
my %schemas = (); |
|
70
|
4
|
|
|
|
|
10
|
my %sources = (); |
|
71
|
4
|
|
|
|
|
10
|
my @list = (); |
|
72
|
4
|
|
|
|
|
12
|
for my $model (@models) { |
|
73
|
5
|
50
|
|
|
|
18
|
die "Bad argument" if (ref $model); |
|
74
|
5
|
50
|
|
|
|
55
|
my $Model = $c->model($model) or die "No such model '$model'"; |
|
75
|
5
|
|
|
|
|
477
|
my ($schema, $result) = ($model); |
|
76
|
|
|
|
|
|
|
|
|
77
|
5
|
50
|
|
|
|
94
|
if($Model->isa('DBIx::Class::ResultSet')){ |
|
78
|
0
|
|
|
|
|
0
|
my @parts = split(/\:\:/,$model); |
|
79
|
0
|
|
|
|
|
0
|
$result = pop @parts; |
|
80
|
0
|
|
|
|
|
0
|
$schema = join('::',@parts); |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
|
|
83
|
5
|
50
|
|
|
|
21
|
my $M = $c->model($schema) or die "No such model '$schema'"; |
|
84
|
5
|
50
|
|
|
|
323
|
die "Model '$schema' does not appear to be a DBIC Schema Model." |
|
85
|
|
|
|
|
|
|
unless ($M->can('schema')); |
|
86
|
|
|
|
|
|
|
|
|
87
|
5
|
50
|
|
|
|
21
|
unless ($schemas{$schema}) { |
|
88
|
5
|
|
|
|
|
19
|
$schemas{$schema} = []; |
|
89
|
|
|
|
|
|
|
push @list, { |
|
90
|
|
|
|
|
|
|
model => $schema, |
|
91
|
5
|
|
|
|
|
24
|
sources => $schemas{$schema} |
|
92
|
|
|
|
|
|
|
}; |
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
# Either add specific/supplied result, or all results. Skip duplicates: |
|
96
|
5
|
50
|
|
|
|
176
|
my @results = $result ? ($result) : $M->schema->sources; |
|
97
|
5
|
|
50
|
|
|
503
|
$sources{$schema . '::' . $_}++ or push @{$schemas{$schema}}, $_ for (@results); |
|
|
54
|
|
|
|
|
163
|
|
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
|
|
100
|
4
|
|
|
|
|
23
|
return \@list; |
|
101
|
|
|
|
|
|
|
} |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub BUILD { |
|
105
|
4
|
|
|
4
|
0
|
12
|
my $self = shift; |
|
106
|
|
|
|
|
|
|
|
|
107
|
4
|
|
|
|
|
115
|
Module::Runtime::require_module($self->table_class); |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
# menu_require_role only applies to the top level/navtree nodes which |
|
110
|
|
|
|
|
|
|
# simply hides the links, but preserves access to the real pages/data |
|
111
|
4
|
50
|
33
|
|
|
162
|
$self->apply_extconfig( require_role => $self->menu_require_role ) if ( |
|
112
|
|
|
|
|
|
|
! $self->require_role && |
|
113
|
|
|
|
|
|
|
$self->menu_require_role |
|
114
|
|
|
|
|
|
|
); |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
# init |
|
117
|
4
|
|
|
|
|
109
|
$self->TreeConfig; |
|
118
|
|
|
|
|
|
|
} |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
has 'TreeConfig', is => 'ro', isa => 'ArrayRef[HashRef]', lazy => 1, default => sub { |
|
122
|
|
|
|
|
|
|
my $self = shift; |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
my @items = (); |
|
125
|
|
|
|
|
|
|
for my $s (@{$self->dbic_model_tree}) { |
|
126
|
|
|
|
|
|
|
my $model = $s->{model}; |
|
127
|
|
|
|
|
|
|
my $schema = $self->app->model($model)->schema; |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
my $require_role = $self->require_role || try{$self->configs->{$model}{require_role}}; |
|
130
|
|
|
|
|
|
|
my $menu_req_role = $require_role || $self->menu_require_role; |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
my @children = (); |
|
133
|
|
|
|
|
|
|
for my $source (sort @{$s->{sources}}) { |
|
134
|
|
|
|
|
|
|
my $Source = $schema->source($source) or die "Source $source not found!"; |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
my $cust_def_config = try{$self->configs->{$model}{grid_params}{'*defaults'}} || {}; |
|
137
|
|
|
|
|
|
|
my $cust_config = try{$self->configs->{$model}{grid_params}{$source}} || {}; |
|
138
|
|
|
|
|
|
|
# since we're using these params over and over we need to protect refs in deep params |
|
139
|
|
|
|
|
|
|
# since currently DataStore/TableSpec modules modify params like include_colspec in |
|
140
|
|
|
|
|
|
|
# place (note this probably needs to be fixed in there for exactly this reason) |
|
141
|
|
|
|
|
|
|
my $cust_merged = clone( Catalyst::Utils::merge_hashes($cust_def_config,$cust_config) ); |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
my $grid_class = $cust_merged->{grid_class} ? delete $cust_merged->{grid_class} : |
|
144
|
|
|
|
|
|
|
try{$self->configs->{$model}{grid_class}} || $self->table_class; |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
#my $table = $Source->schema->class($Source->source_name)->table; |
|
147
|
|
|
|
|
|
|
#$table = (split(/\./,$table,2))[1] || $table; #<-- get 'table' for both 'db.table' and 'table' format |
|
148
|
|
|
|
|
|
|
my $module_name = lc(join('_',$model,$source)); |
|
149
|
|
|
|
|
|
|
$module_name =~ s/\:\:/_/g; |
|
150
|
|
|
|
|
|
|
$self->apply_init_modules( $module_name => { |
|
151
|
|
|
|
|
|
|
class => $grid_class, |
|
152
|
|
|
|
|
|
|
params => { |
|
153
|
|
|
|
|
|
|
require_role => $require_role, |
|
154
|
|
|
|
|
|
|
%$cust_merged, |
|
155
|
|
|
|
|
|
|
ResultSource => $Source, |
|
156
|
|
|
|
|
|
|
source_model => $model . '::' . $source, |
|
157
|
|
|
|
|
|
|
} |
|
158
|
|
|
|
|
|
|
}); |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
my $class = $schema->class($source); |
|
161
|
|
|
|
|
|
|
my $text = $class->TableSpec_get_conf('title_multi') || $source; |
|
162
|
|
|
|
|
|
|
my $iconCls = $class->TableSpec_get_conf('multiIconCls') || 'ra-icon-application-view-detail'; |
|
163
|
|
|
|
|
|
|
push @children, { |
|
164
|
|
|
|
|
|
|
id => $module_name, |
|
165
|
|
|
|
|
|
|
text => $text, |
|
166
|
|
|
|
|
|
|
iconCls => $iconCls , |
|
167
|
|
|
|
|
|
|
module => $module_name, |
|
168
|
|
|
|
|
|
|
params => {}, |
|
169
|
|
|
|
|
|
|
expand => 1, |
|
170
|
|
|
|
|
|
|
children => [], |
|
171
|
|
|
|
|
|
|
require_role => $menu_req_role |
|
172
|
|
|
|
|
|
|
} |
|
173
|
|
|
|
|
|
|
} |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
my $exclude_sources = try{$self->configs->{$model}{exclude_sources}} || []; |
|
177
|
|
|
|
|
|
|
my $expand = (try{$self->configs->{$model}{expand}}) ? 1 : 0; |
|
178
|
|
|
|
|
|
|
my $text = (try{$self->configs->{$model}{text}}) || $model; |
|
179
|
|
|
|
|
|
|
my $template = try{$self->configs->{$model}{template}}; |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
my $dbd_driver = $schema->storage->dbh->{Driver}->{Name} || ''; |
|
183
|
|
|
|
|
|
|
my $iconcls = (try{$self->configs->{$model}{iconCls}}) || ( |
|
184
|
|
|
|
|
|
|
$dbd_driver eq 'SQLite' |
|
185
|
|
|
|
|
|
|
? 'ra-icon-page-white-database' |
|
186
|
|
|
|
|
|
|
: 'ra-icon-server-database' |
|
187
|
|
|
|
|
|
|
); |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
my $module_name = lc($model); |
|
190
|
|
|
|
|
|
|
$module_name =~ s/\:\:/_/g; |
|
191
|
|
|
|
|
|
|
$self->apply_init_modules( $module_name => { |
|
192
|
|
|
|
|
|
|
class => 'RapidApp::Module::DbicSchemaGrid', |
|
193
|
|
|
|
|
|
|
params => { |
|
194
|
|
|
|
|
|
|
Schema => $self->app->model($model)->schema, |
|
195
|
|
|
|
|
|
|
tabTitle => $text, |
|
196
|
|
|
|
|
|
|
tabIconCls => $iconcls, |
|
197
|
|
|
|
|
|
|
exclude_sources => $exclude_sources, |
|
198
|
|
|
|
|
|
|
header_template => $template, |
|
199
|
|
|
|
|
|
|
require_role => $require_role |
|
200
|
|
|
|
|
|
|
} |
|
201
|
|
|
|
|
|
|
}); |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
my $itm_id = lc($model) . '_tables'; |
|
204
|
|
|
|
|
|
|
$itm_id =~ s/\:\:/_/g; |
|
205
|
|
|
|
|
|
|
push @items, { |
|
206
|
|
|
|
|
|
|
id => $itm_id, |
|
207
|
|
|
|
|
|
|
text => $text, |
|
208
|
|
|
|
|
|
|
iconCls => $iconcls, |
|
209
|
|
|
|
|
|
|
module => $module_name, |
|
210
|
|
|
|
|
|
|
params => {}, |
|
211
|
|
|
|
|
|
|
expand => $expand, |
|
212
|
|
|
|
|
|
|
children => \@children, |
|
213
|
|
|
|
|
|
|
require_role => $menu_req_role |
|
214
|
|
|
|
|
|
|
}; |
|
215
|
|
|
|
|
|
|
} |
|
216
|
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
return \@items; |
|
218
|
|
|
|
|
|
|
}; |
|
219
|
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
#### --------------------- #### |
|
223
|
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
|
|
225
|
4
|
|
|
4
|
|
31
|
no Moose; |
|
|
4
|
|
|
|
|
9
|
|
|
|
4
|
|
|
|
|
23
|
|
|
226
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
|
227
|
|
|
|
|
|
|
1; |