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

Legend:
Removed from v.153  
changed lines
  Added in v.200

  ViewVC Help
Powered by ViewVC 1.1.26