8 |
|
|
9 |
Display information about Strix sites |
Display information about Strix sites |
10 |
|
|
11 |
|
=head1 TEMPLATES |
12 |
|
|
13 |
=cut |
=cut |
14 |
|
|
15 |
use strict; |
use strict; |
18 |
use Jifty::View::Declare -base; |
use Jifty::View::Declare -base; |
19 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
20 |
|
|
21 |
|
=head2 / |
22 |
|
|
23 |
|
Display sites search and some stats |
24 |
|
|
25 |
|
=cut |
26 |
|
|
27 |
template 'index.html' => page { |
template 'index.html' => page { |
28 |
|
|
29 |
title is _('Strix sites'); |
title is _('Strix sites'); |
30 |
|
|
|
h1 { _('Statistics') } |
|
|
|
|
31 |
my $orgs = A3C::Model::StrixSiteCollection->new; |
my $orgs = A3C::Model::StrixSiteCollection->new; |
32 |
$orgs->unlimit; |
$orgs->unlimit; |
33 |
|
|
34 |
dt { _('Number of Strix sites') } |
div { _('Number of sites in Strix: %1', $orgs->count ) }; |
35 |
dd { $orgs->count } |
|
36 |
|
render_region( |
37 |
|
name => 'selected-sites', |
38 |
|
path => '/strix/selected-sites' |
39 |
|
); |
40 |
|
|
41 |
|
render_region( |
42 |
|
name => 'search-sites', |
43 |
|
path => '/strix/search-sites', |
44 |
|
); |
45 |
|
|
46 |
}; |
}; |
47 |
|
|
48 |
|
=head2 name_diff |
49 |
|
|
50 |
|
=cut |
51 |
|
|
52 |
template 'name_diff' => page { |
template 'name_diff' => page { |
53 |
|
|
54 |
title is _('Strix sites'); |
title is _('Strix name differences'); |
55 |
|
|
56 |
my $name_diff = A3C::SQL->new({ query => qq{ |
my $name_diff = A3C::SQL->new({ query => qq{ |
57 |
select |
select |
62 |
where o != _site_name |
where o != _site_name |
63 |
}}); |
}}); |
64 |
|
|
65 |
h1 { _('Name differences') } |
if ( $name_diff->count > 0 ) { |
66 |
dd { |
|
67 |
table { |
table { |
68 |
row { |
row { |
69 |
th { _('Site') } |
th { _('Site') } |
78 |
} |
} |
79 |
} |
} |
80 |
} |
} |
81 |
|
|
82 |
|
} else { |
83 |
|
div { _("Can't find any site in strix which has different name than data from LDAP") } |
84 |
|
} |
85 |
|
|
86 |
|
}; |
87 |
|
|
88 |
|
=head2 sql |
89 |
|
|
90 |
|
Execute SQL query on site |
91 |
|
|
92 |
|
=cut |
93 |
|
|
94 |
|
template 'sql' => page { |
95 |
|
|
96 |
|
title is _('Execute SQL'); |
97 |
|
|
98 |
|
render_region( |
99 |
|
name => 'selected-sites', |
100 |
|
path => '/strix/selected-sites' |
101 |
|
); |
102 |
|
|
103 |
|
render_region( |
104 |
|
name => 'execute-sql', |
105 |
|
path => '/strix/execute-sql', |
106 |
|
); |
107 |
|
|
108 |
|
}; |
109 |
|
|
110 |
|
=head1 REGIONS |
111 |
|
|
112 |
|
=head2 execute-sql |
113 |
|
|
114 |
|
Execute SQL query on site |
115 |
|
|
116 |
|
=cut |
117 |
|
|
118 |
|
template 'execute-sql' => sub { |
119 |
|
|
120 |
|
my $action = new_action( |
121 |
|
class => 'StrixSQL', |
122 |
|
moniker => 'strix-sql', |
123 |
|
sticky_on_success => 1, |
124 |
|
sticky_on_failure => 1, |
125 |
|
arguments => { |
126 |
|
strix => get('strix') |
127 |
|
} |
128 |
|
); |
129 |
|
|
130 |
|
form { |
131 |
|
render_action( $action => [ 'strix', 'sql' ] ); |
132 |
|
form_submit( label => _('Execute SQL') ); |
133 |
|
}; |
134 |
|
|
135 |
|
if ( my $sql = $action->result->content('sql') ) { |
136 |
|
div { _('Found %1 results', $sql->count ) } |
137 |
|
table { |
138 |
|
row { map { th { $_ } } $sql->_column_names }; |
139 |
|
while (my $row = $sql->next) { |
140 |
|
row { |
141 |
|
foreach my $col ( $sql->_column_names ) { |
142 |
|
cell { $row->$col } |
143 |
|
} |
144 |
|
} |
145 |
|
} |
146 |
|
} |
147 |
|
} |
148 |
|
}; |
149 |
|
|
150 |
|
=head2 search-sites |
151 |
|
|
152 |
|
=cut |
153 |
|
|
154 |
|
template 'search-sites' => sub { |
155 |
|
|
156 |
|
h1 { _('Find site') } |
157 |
|
|
158 |
|
my $action = new_action( |
159 |
|
class => 'SearchStrixSite', |
160 |
|
moniker => 'search-strix-site', |
161 |
|
sticky_on_success => 1, |
162 |
|
sticky_on_failure => 1, |
163 |
|
); |
164 |
|
|
165 |
|
|
166 |
|
form { |
167 |
|
render_action( $action => [ 'site_contains', '_site_name_contains' ] ); |
168 |
|
form_submit( label => _('Search') ); |
169 |
|
}; |
170 |
|
|
171 |
|
# warn dump( $action->result->content ); |
172 |
|
|
173 |
|
if ( my $search = $action->result->content('search') ) { |
174 |
|
div { _('Found %1 results', $search->count ) } |
175 |
|
table { |
176 |
|
while (my $strix = $search->next) { |
177 |
|
row { |
178 |
|
cell { tt { $strix->site } } |
179 |
|
cell { $strix->_site_name } |
180 |
|
cell { show( 'site-op', 'Create', '+', $strix->site ) } |
181 |
|
} |
182 |
|
} |
183 |
|
} |
184 |
} |
} |
185 |
|
|
186 |
}; |
}; |
187 |
|
|
188 |
|
=head2 selected-sites |
189 |
|
|
190 |
|
Show Selected sites for current user |
191 |
|
|
192 |
|
=cut |
193 |
|
|
194 |
|
template 'selected-sites' => sub { |
195 |
|
my $self = shift; |
196 |
|
|
197 |
|
warn "## IN selected-sites ",dump( @_ ); |
198 |
|
|
199 |
|
if ( my $op = get 'op' ) { |
200 |
|
my $site = get 'site' or die "no site?"; |
201 |
|
warn "# selected-sites $op on $site"; |
202 |
|
|
203 |
|
my $a; |
204 |
|
|
205 |
|
if ( $op eq 'Create' ) { |
206 |
|
|
207 |
|
$a = new_action( |
208 |
|
class => $op . 'StrixSiteSelection', |
209 |
|
moniker => $op, |
210 |
|
arguments => { |
211 |
|
strix => $site, |
212 |
|
by_user => $self->current_user->id, |
213 |
|
}, |
214 |
|
); |
215 |
|
|
216 |
|
} elsif ( $op eq 'Delete' ) { |
217 |
|
|
218 |
|
my $strix = A3C::Model::StrixSiteSelection->new; |
219 |
|
$strix->load_by_cols( strix => $site, by_user => $self->current_user->id ); |
220 |
|
die "can't find site $site" unless $strix->id; |
221 |
|
$a = $strix->as_delete_action; |
222 |
|
|
223 |
|
} |
224 |
|
warn "# argument_values = ",dump( $a->argument_values ); |
225 |
|
$a->run; |
226 |
|
warn "can't $op site $site" unless $a->result->success; |
227 |
|
} |
228 |
|
|
229 |
|
my $selected = A3C::Model::StrixSiteSelectionCollection->new; |
230 |
|
$selected->limit( column => 'by_user', value => Jifty->web->current_user->id ); |
231 |
|
|
232 |
|
if ( $selected->count > 0 ) { |
233 |
|
|
234 |
|
div { _('%1 sites selected', $selected->count ) } |
235 |
|
table { |
236 |
|
while (my $s = $selected->next) { |
237 |
|
row { |
238 |
|
cell { tt { $s->strix->site } } |
239 |
|
cell { $s->strix->_site_name } |
240 |
|
cell { show( 'site-op', 'Delete', '-', $s->strix->site ) } |
241 |
|
} |
242 |
|
} |
243 |
|
} |
244 |
|
} else { |
245 |
|
div { _('No sites selected') } |
246 |
|
} |
247 |
|
}; |
248 |
|
|
249 |
|
=head2 site-op |
250 |
|
|
251 |
|
Display button to add/remove site from selection |
252 |
|
|
253 |
|
show( 'site-op', 'Delete', '-', $strix->site ); |
254 |
|
|
255 |
|
=cut |
256 |
|
|
257 |
|
template 'site-op' => sub { |
258 |
|
my $self = shift; |
259 |
|
|
260 |
|
warn "# site-op = ",dump( @_ ); |
261 |
|
|
262 |
|
my ( $op, $label, $site ) = @_; |
263 |
|
|
264 |
|
form { |
265 |
|
hyperlink( |
266 |
|
label => $label, |
267 |
|
onclick => { |
268 |
|
refresh => 'selected-sites', |
269 |
|
path => '/strix/selected-sites', |
270 |
|
args => { |
271 |
|
site => $site, |
272 |
|
op => $op, |
273 |
|
} |
274 |
|
}, |
275 |
|
); |
276 |
|
} |
277 |
|
|
278 |
|
}; |
279 |
|
|
280 |
|
|
281 |
1; |
1; |