File Coverage

blib/lib/Catalyst/Plugin/RapidApp/TabGui.pm
Criterion Covered Total %
statement 13 13 100.0
branch 3 4 75.0
condition 3 6 50.0
subroutine 5 5 100.0
pod n/a
total 24 28 85.7


line stmt bran cond sub pod time code
1             package Catalyst::Plugin::RapidApp::TabGui;
2 4     4   2598 use Moose::Role;
  4         8  
  4         31  
3 4     4   17928 use namespace::autoclean;
  4         10  
  4         26  
4              
5             with 'Catalyst::Plugin::RapidApp';
6              
7 4     4   295 use RapidApp::Util qw(:all);
  4         9  
  4         3374  
8             require Module::Runtime;
9             require Catalyst::Utils;
10              
11             sub _navcore_enabled {
12 20     20   47 my $c = shift;
13             return (
14 20 50 33     105 $c->does('Catalyst::Plugin::RapidApp::NavCore') ||
15             $c->registered_plugins('RapidApp::NavCore') #<-- this one doesn't seem to apply
16             ) ? 1 : 0;
17             }
18              
19             sub _authcore_enabled {
20 8     8   15 my $c = shift;
21             return (
22 8 100 66     60 $c->does('Catalyst::Plugin::RapidApp::AuthCore') ||
23             $c->registered_plugins('RapidApp::NavCore') #<-- this one doesn't seem to apply
24             ) ? 1 : 0;
25             }
26              
27             before 'setup_components' => sub {
28             my $c = shift;
29            
30             my $config = $c->config->{'Plugin::RapidApp::TabGui'} or die
31             "No 'Plugin::RapidApp::TabGui' config specified!";
32            
33             $config->{title} ||= $c->config->{name};
34             $config->{nav_title} ||= $config->{title};
35            
36             # --- We're aware of the AuthCore plugin, and if it is running we automatically
37             # set a banner with a logout link if no banner is specified:
38             if($c->_authcore_enabled) {
39             $config->{banner_template} ||= 'templates/rapidapp/simple_auth_banner.tt';
40             }
41             # ---
42            
43             my @navtrees = ();
44            
45             if($config->{template_navtree_regex}) {
46             push @navtrees, ({
47             module => 'tpl_navtree',
48             class => 'RapidApp::Module::TemplateTree',
49             params => {
50             template_regex => $config->{template_navtree_regex},
51             default_expanded => $config->{template_navtree_expanded} || 0
52             }
53             });
54             }
55            
56             # New: add custom navtrees by config:
57             push @navtrees, @{$config->{navtrees}} if (exists $config->{navtrees});
58            
59             # --- We're also aware of the NavCore plugin. If it is running we stick its items
60             # at the **top** of the navigation tree:
61             unshift @navtrees, (
62             {
63             module => 'navtree',
64             class => 'Catalyst::Plugin::RapidApp::NavCore::NavTree',
65             params => {
66             title => 'Foo'
67             }
68             },
69             { xtype => 'spacer', height => '5px' }
70             ) if ($c->_navcore_enabled);
71             # ---
72            
73             # Turn off the navtree if it has no items:
74             $config->{navtree_disabled} = 1 unless (@navtrees > 0);
75            
76             my $main_module_params = {
77             title => $config->{nav_title},
78             right_footer => $config->{right_footer} || $config->{title},
79             iconCls => $config->{nav_title_iconcls} || 'ra-icon-catalyst-transparent',
80             init_width => $config->{navtree_init_width} || 230,
81             navtrees => \@navtrees
82             };
83            
84             if($config->{dashboard_template}) {
85             $main_module_params->{dashboard_class} = 'RapidApp::Module::HtmlContent';
86             $main_module_params->{dashboard_params} = {
87             get_html => sub {
88             my $self = shift;
89             my $vars = { c => $self->c };
90             return $self->c->template_render($config->{dashboard_template},$vars);
91             }
92             };
93             }
94            
95             # remap banner_template -> header_template
96             $main_module_params->{header_template} = $config->{banner_template}
97             if($config->{banner_template});
98            
99             my @copy_params = qw(
100             dashboard_url
101             navtree_footer_template
102             navtree_load_collapsed
103             navtree_disabled
104             tab_title_max_width
105             );
106             $config->{$_} and $main_module_params->{$_} = $config->{$_} for (@copy_params);
107            
108             # -- New: enable passthrough to exclude navtrees that define
109             # a 'require_role' property (See new API in RapidApp::Module::Explorer)
110             $main_module_params->{role_checker} =
111             $c->config->{'Plugin::RapidApp::AuthCore'}{role_checker}
112             if ($c->_authcore_enabled);
113             # --
114            
115             # New: allow the user to modify the main module class/params:
116             my $main_module_class = $config->{main_module_class} || 'RapidApp::Module::Explorer';
117             %$main_module_params = (
118             %$main_module_params,
119             %{ $config->{main_module_params} || {} }
120             );
121            
122             my $cnf = {
123             rootModuleClass => 'RapidApp::RootModule',
124             rootModuleConfig => {
125             app_title => $config->{title},
126             main_module_class => $main_module_class,
127             main_module_params => $main_module_params
128             }
129             };
130            
131             # Apply base/default configs to 'Model::RapidApp':
132             $c->config( 'Model::RapidApp' =>
133             Catalyst::Utils::merge_hashes($cnf, $c->config->{'Model::RapidApp'} || {} )
134             );
135             };
136              
137             1;
138              
139              
140             __END__
141              
142             =head1 NAME
143              
144             Catalyst::Plugin::RapidApp::TabGui - Instant tabbed Ajax admin navigation interface
145              
146             =head1 SYNOPSIS
147              
148             package MyApp;
149            
150             use Catalyst qw/ RapidApp::TabGui /;
151              
152             =head1 DESCRIPTION
153              
154             The TabGui plugin is the primary high-level turn-key interface paradigm provided by the
155             RapidApp distribution for top-most level GUIs (i.e. to be loaded in a full-browser, not within
156             another interface). It provides a standard admin-style interface, based on ExtJS, with an (optional)
157             navigation tree on the left-hand side and a tabbed content panel on the right, with an optional
158             banner section at the top.
159              
160             The content area hooks into a RESTful URL navigation scheme to load various kinds of content
161             at public paths in the application, including both RapidApp-specific Module views as well as
162             ordinary HTML content returned by ordinary controllers.
163              
164             The interface is pure Ajax with no browser page loads whatsoever, with simulated client-side
165             URLs triggered via the I<hash> section/mechanism of the URL. These are fully-valid, RESTful
166             URLs are called "hashnav paths" which start with C<#!/> such as:
167              
168             /#!/some/url/path
169              
170             The above URL loads the content of C</some/url/path> with a new tab (or existing tab if already
171             open) and works just as well if the TabGui is already loaded as accessing the url from a
172             fresh browser window.
173              
174             The TabGui is loaded at the root module, which defaults to root of the Catalyst app C</> for
175             a dedicated application, but can also be changed to provide an admin section for an existing
176             app by setting the C<module_root_namespace> RapidApp config:
177              
178             # in the main catalyst app class:
179             __PACKAGE__->config(
180             # ...
181             'RapidApp' => {
182             module_root_namespace => 'adm',
183             # ...
184             }
185             );
186              
187             In this case, the interface would be accessible via C</adm>, and in turn, the previous hashnav
188             URL example would be:
189              
190             /adm/#!/some/url/path
191              
192             The TabGui is automatically loaded and configured by other high-level plugins, most notably,
193             L<RapidDbic|Catalyst::Plugin::RapidApp::RapidDbic>.
194              
195             Thus, the following are exactly equivalent:
196              
197             use Catalyst qw/
198             RapidApp::TabGui
199             RapidApp::RapidDbic
200             /
201              
202             use Catalyst qw/
203             RapidApp::RapidDbic
204             /
205              
206             Additionally, there are multiple extra plugins with provide high-level functionality which
207             assume, build upon and/or otherwise interact with the TabGui as the primary navigation interface,
208             such as L<NavCore|Catalyst::Plugin::RapidApp::NavCore> and
209             L<CoreSchemaAdmin|Catalyst::Plugin::RapidApp::CoreSchemaAdmin>.
210              
211             The TabGui plugin itself is just a configuration layer. Internally, it assembles and automatically
212             configures a number of RapidApp modules which provide the actual functionality, including
213             L<RapidApp::Module::Explorer>, L<RapidApp::Module::Tree> and others.
214              
215             =head1 SEE ALSO
216              
217             =over
218              
219             =item *
220              
221             L<RapidApp::Manual::Plugins>
222              
223             =item *
224              
225             L<Catalyst::Plugin::RapidApp>
226              
227             =item *
228              
229             L<Catalyst::Plugin::RapidApp::RapidDbic>
230              
231             =item *
232              
233             L<Catalyst::Plugin::RapidApp::NavCore>
234              
235             =item *
236              
237             L<Catalyst>
238              
239             =back
240              
241             =head1 AUTHOR
242              
243             Henry Van Styn <vanstyn@cpan.org>
244              
245             =head1 COPYRIGHT AND LICENSE
246              
247             This software is copyright (c) 2013 by IntelliTree Solutions llc.
248              
249             This is free software; you can redistribute it and/or modify it under
250             the same terms as the Perl 5 programming language system itself.
251              
252             =cut
253              
254              
255             1;