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