/[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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

Legend:
Removed from v.142  
changed lines
  Added in v.211

  ViewVC Help
Powered by ViewVC 1.1.26