/[A3C]/lib/A3C/View/Strix.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /lib/A3C/View/Strix.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 197 - (show annotations)
Tue Jun 17 21:32:12 2008 UTC (15 years, 10 months ago) by dpavlin
File size: 8285 byte(s)
implemented StrixSelectSite action with two drop-down
menus (which are kept in sync) to select site for
which to show navigation
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 site-navigation
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 'site-navigation' => page {
136
137 title is _('Site navigation');
138
139 render_region(
140 name => 'select-strix-site',
141 path => '/strix/select-site'
142 );
143
144 };
145
146 =head2 layout
147
148 =cut
149
150 template 'layout' => page {
151
152 my $url = get('url') || '/';
153
154 my $category = strix->category( $url );
155
156 warn dump( $category );
157
158 title is _('Layout %1 : %2',
159 $category->{sitename},
160 $category->{naziv},
161 );
162
163 render_region(
164 name => 'selected-instances',
165 path => '/strix/selected-instances'
166 );
167
168 strix_link( $category->{url}, $category->{naziv} );
169
170 my $layout = strix->layout( $url );
171
172 pre {
173 dump( $layout );
174 }
175
176 };
177
178 =head1 REGIONS
179
180 =head2 execute-sql
181
182 Execute SQL query on instance
183
184 =cut
185
186 template 'execute-sql' => sub {
187
188 my $action = new_action(
189 class => 'StrixSQL',
190 moniker => 'strix-sql',
191 sticky_on_success => 1,
192 sticky_on_failure => 1,
193 arguments => {
194 instance => get('instance')
195 }
196 );
197
198 form {
199 render_action( $action => [ 'instance', 'sql' ] );
200 form_submit( label => _('Execute SQL') );
201 };
202
203 if ( my $sql = $action->result->content('sql') ) {
204 div { _('Found %1 results', $sql->count ) }
205 table {
206 row { map { th { $_ } } $sql->_column_names };
207 while (my $row = $sql->next) {
208 row {
209 foreach my $col ( $sql->_column_names ) {
210 cell { $row->$col }
211 }
212 }
213 }
214 }
215 }
216 };
217
218 =head2 search-instances
219
220 =cut
221
222 template 'search-instances' => sub {
223
224 h1 { _('Find instance') }
225
226 my $action = new_action(
227 class => 'SearchStrixInstance',
228 moniker => 'search-strix-instance',
229 sticky_on_success => 1,
230 sticky_on_failure => 1,
231 );
232
233
234 form {
235 render_action( $action => [ 'instance_contains', '_site_name_contains' ] );
236 form_submit( label => _('Search') );
237 };
238
239 # warn dump( $action->result->content );
240
241 if ( my $search = $action->result->content('search') ) {
242 div { _('Found %1 results', $search->count ) }
243 table {
244 while (my $strix = $search->next) {
245 row {
246 cell { show( 'instance-op', 'Create', '+', $strix->instance ) }
247 cell { tt { $strix->instance } }
248 cell { $strix->_site_name }
249 }
250 }
251 }
252 }
253
254 };
255
256 =head2 selected-instances
257
258 Show Selected instances for current user
259
260 =cut
261
262 template 'selected-instances' => sub {
263 my $self = shift;
264
265 # warn "## IN selected-instances ",dump( @_ );
266
267 if ( my $op = get 'op' ) {
268 my $op_instance = get 'op_instance' or die "no op_instance?";
269 warn "# selected-instances $op on $op_instance";
270
271 my $a;
272
273 if ( $op eq 'Create' ) {
274
275 $a = new_action(
276 class => $op . 'StrixInstanceSelection',
277 moniker => $op,
278 arguments => {
279 instance => $op_instance,
280 by_user => $self->current_user->id,
281 },
282 );
283
284 } elsif ( $op eq 'Delete' ) {
285
286 my $strix = A3C::Model::StrixInstanceSelection->new;
287 $strix->load_by_cols( instance => $op_instance, by_user => $self->current_user->id );
288 warn "can't find instance $op_instance" unless $strix->id;
289 $a = $strix->as_delete_action;
290
291 }
292 # warn "# argument_values = ",dump( $a->argument_values );
293 $a->run;
294
295 if ( $a->result->error ) {
296 div {
297 { class is 'note error' }
298 $a->result->error;
299 }
300 }
301
302 set( op => '' );
303 }
304
305 my $selected = A3C::Model::StrixInstanceSelectionCollection->new;
306 $selected->limit( column => 'by_user', value => Jifty->web->current_user->id );
307
308 if ( $selected->count > 0 ) {
309
310 my $instance = get('instance');
311
312 div { _('%1 instances selected', $selected->count ) };
313 table {
314 while (my $s = $selected->next) {
315 row {
316 cell { tt {
317 if ( $s->instance->instance eq $instance ) {
318 b { $instance }
319 } else {
320 hyperlink(
321 url => '?instance=' . $s->instance->instance,
322 label => $s->instance->instance
323 )
324 }
325 } }
326 cell { $s->instance->_site_name }
327 cell { show( 'instance-op', 'Delete', '-', $s->instance->instance ) }
328 }
329 }
330 }
331 } else {
332 div { _('No instances selected') }
333 }
334 };
335
336 =head2 instance-op
337
338 Display button to add/remove instance from selection
339
340 show( 'instance-op', 'Delete', '-', $strix->instace );
341
342 =cut
343
344 template 'instance-op' => sub {
345 my $self = shift;
346
347 # warn "# instance-op = ",dump( @_ );
348
349 my ( $op, $label, $instance ) = @_;
350
351 form {
352 hyperlink(
353 label => $label,
354 onclick => {
355 refresh => 'selected-instances',
356 path => '/strix/selected-instances',
357 args => {
358 op_instance => $instance,
359 op => $op,
360 }
361 },
362 );
363 }
364
365 };
366
367 =head2 select-site
368
369 =cut
370
371 template 'select-site' => sub {
372
373 my $action = new_action(
374 class => 'StrixSelectSite',
375 moniker => 'strix-select-site',
376 );
377
378 #warn "action = ", dump( $action );
379
380 form {
381 render_param( $action, 'instance', onchange => { submit => $action, refresh_self => 1 }, default => get('instance') );
382 render_param( $action, 'site_id', onchange => { submit => $action, refresh_self => 1 } );
383 };
384
385 warn "## select-site action ",dump( $action->result );
386
387 if ( my $site_id = $action->result->content('site_id') ) {
388 show('strix-site-navigation-tree', $action->result->content('instance'), $site_id);
389 }
390 };
391
392 =head1 PRIVATE TEMPLATES
393
394 =head2 strix-site-navigation-tree
395
396 show('strix-site-navigation-tree',$instance,$site_id);
397
398 =cut
399
400 private template 'strix-site-navigation-tree' => sub {
401 my $self = shift;
402 my ( $instance, $site_id ) = @_;
403
404 warn ">>>> instance: $instance site_id: $site_id";
405
406 set 'instance' => $instance;
407
408 sub full_url {
409 my $p = shift;
410 strix_link( $p->{url}, $p->{naziv} );
411 if ( $p->{type} eq 'category' ) {
412 outs_raw(' ');
413 hyperlink(
414 url => '/strix/layout?url=' . $p->{url} . ';instance=' . get('instance'),
415 label => _('layout'),
416 class => 'layout',
417 );
418 }
419 }
420
421 sub children {
422 my $c = shift;
423 return unless defined $c->{children};
424 ul {
425 foreach my $p ( @{ $c->{children} } ) {
426 li {
427 { class is $p->{class} };
428 full_url( $p );
429 children( $p );
430 }
431 }
432 }
433 }
434
435 my $strix = Strix->new({ instance => $instance });
436
437 my @navigation = @{ $strix->site_navigation( $site_id ) };
438 if ( @navigation ) {
439 ul {
440 foreach my $p ( @navigation ) {
441 li {
442 full_url( $p );
443 children( $p );
444 }
445 }
446 }
447 } else {
448 div {
449 { class is 'note error' }
450 _('No navigation found for instance %1 site_id %2', $instance, $site_id)
451 }
452
453 }
454
455 };
456
457 1;

  ViewVC Help
Powered by ViewVC 1.1.26