1 |
package A3C::View::Strix; |
2 |
|
3 |
=head1 NAME |
4 |
|
5 |
A3C::View::Strix |
6 |
|
7 |
=head1 DESCRIPTION |
8 |
|
9 |
Display information about Strix instances |
10 |
|
11 |
=head1 TEMPLATES |
12 |
|
13 |
=cut |
14 |
|
15 |
use strict; |
16 |
use warnings; |
17 |
|
18 |
use Jifty::View::Declare -base; |
19 |
use Data::Dump qw/dump/; |
20 |
|
21 |
=head2 / |
22 |
|
23 |
Display instaces search and some stats |
24 |
|
25 |
=cut |
26 |
|
27 |
template 'index.html' => page { |
28 |
|
29 |
title is _('Strix instances'); |
30 |
|
31 |
my $orgs = A3C::Model::StrixInstanceCollection->new; |
32 |
$orgs->unlimit; |
33 |
|
34 |
div { _('Number of instances in Strix: %1', $orgs->count ) }; |
35 |
|
36 |
render_region( |
37 |
name => 'selected-instances', |
38 |
path => '/strix/selected-instances' |
39 |
); |
40 |
|
41 |
render_region( |
42 |
name => 'search-instances', |
43 |
path => '/strix/search-instances', |
44 |
); |
45 |
|
46 |
}; |
47 |
|
48 |
=head2 name_diff |
49 |
|
50 |
=cut |
51 |
|
52 |
template 'name_diff' => page { |
53 |
|
54 |
title is _('Strix name differences'); |
55 |
|
56 |
render_region( |
57 |
name => 'selected-instances', |
58 |
path => '/strix/selected-instances' |
59 |
); |
60 |
|
61 |
my $name_diff = A3C::SQL->new({ query => qq{ |
62 |
select |
63 |
instance,hreduorgurl, |
64 |
_site_name,o |
65 |
from strix_instances |
66 |
join hr_edu_orgs on cn = instance |
67 |
where o != _site_name |
68 |
}}); |
69 |
|
70 |
if ( $name_diff->count > 0 ) { |
71 |
|
72 |
table { |
73 |
row { |
74 |
th {} |
75 |
th { _('Instance') } |
76 |
th { _('Strix instance name') } |
77 |
th { _('hrEduOrg.o') } |
78 |
}; |
79 |
while ( my $row = $name_diff->next ) { |
80 |
row { |
81 |
cell { show( 'instance-op', 'Create', '+', $row->instance ) } |
82 |
cell { $row->instance } |
83 |
cell { $row->_site_name } |
84 |
cell { $row->o } |
85 |
} |
86 |
} |
87 |
} |
88 |
|
89 |
} else { |
90 |
div { _("Can't find any instance of strix which has different name than data from LDAP") } |
91 |
} |
92 |
|
93 |
}; |
94 |
|
95 |
=head2 sql |
96 |
|
97 |
Execute SQL query on instance |
98 |
|
99 |
=cut |
100 |
|
101 |
template 'sql' => page { |
102 |
|
103 |
title is _('Execute SQL'); |
104 |
|
105 |
render_region( |
106 |
name => 'selected-instances', |
107 |
path => '/strix/selected-instances' |
108 |
); |
109 |
|
110 |
render_region( |
111 |
name => 'execute-sql', |
112 |
path => '/strix/execute-sql', |
113 |
); |
114 |
|
115 |
}; |
116 |
|
117 |
sub strix { |
118 |
my $instance = get('instance'); |
119 |
return Strix->new({ instance => $instance }); |
120 |
} |
121 |
|
122 |
=head2 sitemap |
123 |
|
124 |
=cut |
125 |
|
126 |
template 'sitemap' => page { |
127 |
|
128 |
title is _('Sitemap %1', get('instance')); |
129 |
|
130 |
render_region( |
131 |
name => 'selected-instances', |
132 |
path => '/strix/selected-instances' |
133 |
); |
134 |
|
135 |
my $site_id = get('site_id') || 1; |
136 |
|
137 |
my $sitemap = strix->site_navigation( $site_id ); |
138 |
|
139 |
sub full_url { |
140 |
my $p = shift; |
141 |
hyperlink( |
142 |
url => 'http://new.cms-qa.skole.hr' . $p->{url}, |
143 |
label => $p->{naziv}, |
144 |
); |
145 |
if ( $p->{type} eq 'category' ) { |
146 |
outs_raw(' '); |
147 |
hyperlink( |
148 |
url => '/strix/layout?url=' . $p->{url}, |
149 |
label => _('layout'), |
150 |
class => 'layout', |
151 |
); |
152 |
} |
153 |
} |
154 |
|
155 |
sub children { |
156 |
my $c = shift; |
157 |
return unless defined $c->{children}; |
158 |
ul { |
159 |
foreach my $p ( @{ $c->{children} } ) { |
160 |
li { |
161 |
{ class is $p->{class} }; |
162 |
full_url( $p ); |
163 |
children( $p ); |
164 |
} |
165 |
} |
166 |
} |
167 |
} |
168 |
|
169 |
ul { |
170 |
foreach my $p ( @$sitemap ) { |
171 |
li { |
172 |
full_url( $p ); |
173 |
children( $p ); |
174 |
} |
175 |
} |
176 |
} |
177 |
|
178 |
}; |
179 |
|
180 |
=head2 layout |
181 |
|
182 |
=cut |
183 |
|
184 |
template 'layout' => page { |
185 |
|
186 |
my $url = get('url') || '/'; |
187 |
|
188 |
my $category = strix->category( $url ); |
189 |
|
190 |
warn dump( $category ); |
191 |
|
192 |
title is _('Layout %1 : %2', |
193 |
$category->{sitename}, |
194 |
$category->{naziv}, |
195 |
); |
196 |
|
197 |
render_region( |
198 |
name => 'selected-instances', |
199 |
path => '/strix/selected-instances' |
200 |
); |
201 |
|
202 |
hyperlink( |
203 |
url => 'http://' . $category->{sitename} . '/' . $category->{url}, |
204 |
label => $category->{naziv}, |
205 |
); |
206 |
|
207 |
my $layout = strix->layout( $url ); |
208 |
|
209 |
pre { |
210 |
dump( $layout ); |
211 |
} |
212 |
|
213 |
}; |
214 |
|
215 |
=head1 REGIONS |
216 |
|
217 |
=head2 execute-sql |
218 |
|
219 |
Execute SQL query on instance |
220 |
|
221 |
=cut |
222 |
|
223 |
template 'execute-sql' => sub { |
224 |
|
225 |
my $action = new_action( |
226 |
class => 'StrixSQL', |
227 |
moniker => 'strix-sql', |
228 |
sticky_on_success => 1, |
229 |
sticky_on_failure => 1, |
230 |
arguments => { |
231 |
instance => get('instance') |
232 |
} |
233 |
); |
234 |
|
235 |
form { |
236 |
render_action( $action => [ 'instance', 'sql' ] ); |
237 |
form_submit( label => _('Execute SQL') ); |
238 |
}; |
239 |
|
240 |
if ( my $sql = $action->result->content('sql') ) { |
241 |
div { _('Found %1 results', $sql->count ) } |
242 |
table { |
243 |
row { map { th { $_ } } $sql->_column_names }; |
244 |
while (my $row = $sql->next) { |
245 |
row { |
246 |
foreach my $col ( $sql->_column_names ) { |
247 |
cell { $row->$col } |
248 |
} |
249 |
} |
250 |
} |
251 |
} |
252 |
} |
253 |
}; |
254 |
|
255 |
=head2 search-instances |
256 |
|
257 |
=cut |
258 |
|
259 |
template 'search-instances' => sub { |
260 |
|
261 |
h1 { _('Find instance') } |
262 |
|
263 |
my $action = new_action( |
264 |
class => 'SearchStrixInstance', |
265 |
moniker => 'search-strix-instance', |
266 |
sticky_on_success => 1, |
267 |
sticky_on_failure => 1, |
268 |
); |
269 |
|
270 |
|
271 |
form { |
272 |
render_action( $action => [ 'instance_contains', '_site_name_contains' ] ); |
273 |
form_submit( label => _('Search') ); |
274 |
}; |
275 |
|
276 |
# warn dump( $action->result->content ); |
277 |
|
278 |
if ( my $search = $action->result->content('search') ) { |
279 |
div { _('Found %1 results', $search->count ) } |
280 |
table { |
281 |
while (my $strix = $search->next) { |
282 |
row { |
283 |
cell { tt { $strix->instance } } |
284 |
cell { $strix->_site_name } |
285 |
cell { show( 'instance-op', 'Create', '+', $strix->instance ) } |
286 |
} |
287 |
} |
288 |
} |
289 |
} |
290 |
|
291 |
}; |
292 |
|
293 |
=head2 selected-instances |
294 |
|
295 |
Show Selected instances for current user |
296 |
|
297 |
=cut |
298 |
|
299 |
template 'selected-instances' => sub { |
300 |
my $self = shift; |
301 |
|
302 |
# warn "## IN selected-instances ",dump( @_ ); |
303 |
|
304 |
if ( my $op = get 'op' ) { |
305 |
my $op_instance = get 'op_instance' or die "no op_instance?"; |
306 |
warn "# selected-instances $op on $op_instance"; |
307 |
|
308 |
my $a; |
309 |
|
310 |
if ( $op eq 'Create' ) { |
311 |
|
312 |
$a = new_action( |
313 |
class => $op . 'StrixInstanceSelection', |
314 |
moniker => $op, |
315 |
arguments => { |
316 |
instance => $op_instance, |
317 |
by_user => $self->current_user->id, |
318 |
}, |
319 |
); |
320 |
|
321 |
} elsif ( $op eq 'Delete' ) { |
322 |
|
323 |
my $strix = A3C::Model::StrixInstanceSelection->new; |
324 |
$strix->load_by_cols( instance => $op_instance, by_user => $self->current_user->id ); |
325 |
warn "can't find instance $op_instance" unless $strix->id; |
326 |
$a = $strix->as_delete_action; |
327 |
|
328 |
} |
329 |
# warn "# argument_values = ",dump( $a->argument_values ); |
330 |
$a->run; |
331 |
|
332 |
if ( $a->result->error ) { |
333 |
div { |
334 |
{ class is 'note error' } |
335 |
$a->result->error; |
336 |
} |
337 |
} |
338 |
|
339 |
set( op => '' ); |
340 |
} |
341 |
|
342 |
my $selected = A3C::Model::StrixInstanceSelectionCollection->new; |
343 |
$selected->limit( column => 'by_user', value => Jifty->web->current_user->id ); |
344 |
|
345 |
if ( $selected->count > 0 ) { |
346 |
|
347 |
my $instance = get('instance'); |
348 |
|
349 |
div { _('%1 instances selected', $selected->count ) }; |
350 |
table { |
351 |
while (my $s = $selected->next) { |
352 |
row { |
353 |
cell { tt { |
354 |
if ( $s->instance->instance eq $instance ) { |
355 |
b { $instance } |
356 |
} else { |
357 |
hyperlink( |
358 |
url => '?instance=' . $s->instance->instance, |
359 |
label => $s->instance->instance |
360 |
) |
361 |
} |
362 |
} } |
363 |
cell { $s->instance->_site_name } |
364 |
cell { show( 'instance-op', 'Delete', '-', $s->instance->instance ) } |
365 |
} |
366 |
} |
367 |
} |
368 |
} else { |
369 |
div { _('No instances selected') } |
370 |
} |
371 |
}; |
372 |
|
373 |
=head2 instance-op |
374 |
|
375 |
Display button to add/remove instance from selection |
376 |
|
377 |
show( 'instance-op', 'Delete', '-', $strix->instace ); |
378 |
|
379 |
=cut |
380 |
|
381 |
template 'instance-op' => sub { |
382 |
my $self = shift; |
383 |
|
384 |
# warn "# instance-op = ",dump( @_ ); |
385 |
|
386 |
my ( $op, $label, $instance ) = @_; |
387 |
|
388 |
form { |
389 |
hyperlink( |
390 |
label => $label, |
391 |
onclick => { |
392 |
refresh => 'selected-instances', |
393 |
path => '/strix/selected-instances', |
394 |
args => { |
395 |
op_instance => $instance, |
396 |
op => $op, |
397 |
} |
398 |
}, |
399 |
); |
400 |
} |
401 |
|
402 |
}; |
403 |
|
404 |
|
405 |
1; |