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