| 1 | package Strehler::Dancer2::Plugin::Admin; | ||||||||||||||||||||||||||||
| 2 | 12 | $Strehler::Dancer2::Plugin::Admin::VERSION = '1.6.8'; | |||||||||||||||||||||||||||
| 3 | 12 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 12 | ▶ | use Dancer2::Plugin; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 12 | ▶ | use Strehler; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 12 | ▶ | use Strehler::Helpers; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 12 | ▶ | on_plugin_import { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=4.3
| |||||||||||||||||||||||||||||
| 9 | 12 | my $dsl = shift; | |||||||||||||||||||||||||||
| 10 | 12 | $dsl->prefix('/admin'); | |||||||||||||||||||||||||||
| 11 | $dsl->app->add_hook( | ||||||||||||||||||||||||||||
| 12 | 79 | ▶ | Dancer2::Core::Hook->new(name => 'before', code => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=22.9
| |||||||||||||||||||||||||||||
| 13 | 79 | $dsl->set(layout => 'admin'); | |||||||||||||||||||||||||||
| 14 | 79 | my $context = shift; | |||||||||||||||||||||||||||
| 15 | 79 | ▶ | return if(! $dsl->config->{Strehler}->{admin_secured}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 16 | 0 | ▶ | if((! $context->session->read('user')) && $context->request->path_info ne $dsl->dancer_app->prefix . '/login') | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $context->session->read("user") and $context->request->path_info ne $dsl->dancer_app->prefix . '/login'
MC/DC0%0/2
not $context->session->read("user") and $context->request->path_info ne $dsl->dancer_app->prefix . '/login'
not $context->session->read("user")
$context->request->path_info ne $dsl->dancer_app->prefix . '/login'
Truth table0%0/3
not(A) and B
A= not $context->session->read("user")B= $context->request->path_info ne $dsl->dancer_app->prefix . '/login'
| |||||||||||||||||||||||||||||
| 17 | { | ||||||||||||||||||||||||||||
| 18 | 0 | $context->session->{'redir_url'} = $context->request->path_info; | |||||||||||||||||||||||||||
| 19 | 0 | my $redir = $dsl->redirect($dsl->dancer_app->prefix . '/login'); | |||||||||||||||||||||||||||
| 20 | 0 | return $redir; | |||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||
| 22 | 12 | })); | |||||||||||||||||||||||||||
| 23 | $dsl->app->add_hook( | ||||||||||||||||||||||||||||
| 24 | 30 | ▶ | Dancer2::Core::Hook->new(name => 'before_template_render', code => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=35.9
| |||||||||||||||||||||||||||||
| 25 | 30 | my $tokens = shift; | |||||||||||||||||||||||||||
| 26 | 30 | my $match_string = "^" . $dsl->dancer_app->prefix . "\/(.*?)\/"; | |||||||||||||||||||||||||||
| 27 | 0 | my $match_regexp = qr/$match_string/; | |||||||||||||||||||||||||||
| 28 | 0 | my $path = $dsl->request->path_info(); | |||||||||||||||||||||||||||
| 29 | 0 | my $tab; | |||||||||||||||||||||||||||
| 30 | 0 | ▶ | if($path =~ $match_regexp) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | { | ||||||||||||||||||||||||||||
| 32 | 0 | $tab = $1; | |||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | else | ||||||||||||||||||||||||||||
| 35 | { | ||||||||||||||||||||||||||||
| 36 | 0 | $tab = 'home'; | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | 0 | my %navbar; | |||||||||||||||||||||||||||
| 39 | 0 | $navbar{$tab} = 'active'; | |||||||||||||||||||||||||||
| 40 | 0 | $tokens->{'navbar'} = \%navbar; | |||||||||||||||||||||||||||
| 41 | 0 | $tokens->{'extramenu'} = $dsl->config->{Strehler}->{'extra_menu'}; | |||||||||||||||||||||||||||
| 42 | 0 | ▶ | if(! $dsl->config->{Strehler}->{admin_secured}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | { | ||||||||||||||||||||||||||||
| 44 | 0 | $tokens->{'role'} = 'admin'; | |||||||||||||||||||||||||||
| 45 | 0 | $tokens->{'user'} = 'admin'; | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | else | ||||||||||||||||||||||||||||
| 48 | { | ||||||||||||||||||||||||||||
| 49 | 0 | $tokens->{'role'} = $dsl->app->session->read('role'); | |||||||||||||||||||||||||||
| 50 | 0 | $tokens->{'user'} = $dsl->app->session->read('user'); | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | 0 | my ($editor_menu, $admin_menu) = Strehler::Helpers::top_bars(); | |||||||||||||||||||||||||||
| 53 | 0 | $tokens->{'editor_menu'} = $editor_menu; | |||||||||||||||||||||||||||
| 54 | 0 | $tokens->{'admin_menu'} = $admin_menu; | |||||||||||||||||||||||||||
| 55 | 0 | ▶ | if($dsl->config->{'Strehler'}->{'dashboard_active'} && $dsl->config->{'Strehler'}->{'dashboard_active'} == 1) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$dsl->config->{"Strehler"}{"dashboard_active"} and $dsl->config->{"Strehler"}{"dashboard_active"} == 1
MC/DC0%0/2
$dsl->config->{"Strehler"}{"dashboard_active"} and $dsl->config->{"Strehler"}{"dashboard_active"} == 1
$dsl->config->{"Strehler"}{"dashboard_active"}
$dsl->config->{"Strehler"}{"dashboard_active"} == 1
Truth table0%0/3
A and B
A= $dsl->config->{"Strehler"}{"dashboard_active"}B= $dsl->config->{"Strehler"}{"dashboard_active"} == 1
| |||||||||||||||||||||||||||||
| 56 | { | ||||||||||||||||||||||||||||
| 57 | 0 | $tokens->{'dashboard_active'} = 1; | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | else | ||||||||||||||||||||||||||||
| 60 | { | ||||||||||||||||||||||||||||
| 61 | 0 | $tokens->{'dashboard_active'} = 0; | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | 0 | ▶ | $tokens->{'warnings'} = 1 if(! Strehler::Helpers::check_statics()); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | 0 | $tokens->{'strehler_version'} = $Strehler::VERSION; | |||||||||||||||||||||||||||
| 65 | 12 | })); | |||||||||||||||||||||||||||
| 66 | 12 | }; | |||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 12 | register_plugin for_versions => [ 2 ]; | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | =encoding utf8 | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | =head1 NAME | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | Strehler::Dancer2::Plugin::Admin - Dancer2 Plugin to write new routes in the Strehler Backend | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | Dancer2 Strehler Admin plugin allows you to write an app with new routes to be used in Strehler Backend, protected with Strehler login, and rendered with the Strehler context. | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | This element hasn't the standard Dancer2::Plugin namespace because it makes sense only in a Strehler system. | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | package MyBackend; | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | use Dancer2; | ||||||||||||||||||||||||||||
| 88 | use Strehler::Dancer2::Plugin::Admin; | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | If you want to write a module like this, you have to launch the command | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | strehler layout | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | under your Dancer2 App, to copy Strehler Layout in it, making it available for your developements. | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | =head1 HOW TO CUSTOMIZE STREHLER BACKEND HOMEPAGE | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | Strehler homepage is empty and really dumb. Probably there're informations you want to display on it or shortcut for your navigation. | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | To do this you can: | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | =over 4 | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | =item 1. | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | Launch strehler layout command in your Dancer2 App. | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | strehler layout | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | =item 2. | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | Write a view for the homepage like this: | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | B<views/strelher-home.tt> | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | <div class="span10"> | ||||||||||||||||||||||||||||
| 117 | <h1>My wonderful homepage</h1> | ||||||||||||||||||||||||||||
| 118 | <div>Lorem ipsum...</div> | ||||||||||||||||||||||||||||
| 119 | </div> | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | =item 3. | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | Write a module with Strehler::Dancer2::Plugin::Admin overriding '/' route, calling the new template. | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | B<lib/MyBackend.pm> | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | package MyBackend; | ||||||||||||||||||||||||||||
| 128 | use Dancer2; | ||||||||||||||||||||||||||||
| 129 | use Strehler::Dancer2::Plugin::Admin; | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | get '/' => sub { | ||||||||||||||||||||||||||||
| 132 | template 'strehler-home'; | ||||||||||||||||||||||||||||
| 133 | }; | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | true; | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | =item 4. | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | Include the module above Strehler::Admin in your application file. | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | B<bin/app.pl> | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | #!/usr/bin/env perl | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | use FindBin; | ||||||||||||||||||||||||||||
| 146 | use lib "$FindBin::Bin/../lib"; | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | use MyBackend; | ||||||||||||||||||||||||||||
| 149 | use Strehler::Admin; | ||||||||||||||||||||||||||||
| 150 | MyBackend->dance; | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | =back | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | =cut | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | 12 | 1; | |||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||