/[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 161 by dpavlin, Sun Jun 15 16:11:17 2008 UTC revision 197 by dpavlin, Tue Jun 17 21:32:12 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  =head1 TEMPLATES
12    
# Line 20  use Data::Dump qw/dump/; Line 20  use Data::Dump qw/dump/;
20    
21  =head2 /  =head2 /
22    
23  Display sites search and some stats  Display instaces search and some stats
24    
25  =cut  =cut
26    
27  template 'index.html' => page {  template 'index.html' => page {
28    
29          title is _('Strix sites');          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(          render_region(
37                  name => 'user-selected-sites',                  name => 'selected-instances',
38                  path => '/strix/selected-sites'                  path => '/strix/selected-instances'
39          );          );
40    
41          render_region(          render_region(
42                  name => 'search_sites',                  name => 'search-instances',
43                  path => '/strix/search_sites',                  path => '/strix/search-instances',
44          );          );
45    
         h1 { _('Statistics') }  
   
         my $orgs = A3C::Model::StrixSiteCollection->new;  
         $orgs->unlimit;  
   
         dt { _('Number of Strix sites') }  
         dd { $orgs->count }  
   
46  };  };
47    
48  =head2 name_diff  =head2 name_diff
# Line 54  template 'index.html' => page { Line 51  template 'index.html' => page {
51    
52  template 'name_diff' => page {  template 'name_diff' => page {
53    
54          title is _('Strix sites | name differences between php config and internal state');          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  =head2 sql
96    
97  Execute SQL query on site  Execute SQL query on instance
98    
99  =cut  =cut
100    
# Line 95  template 'sql' => page { Line 102  template 'sql' => page {
102    
103          title is _('Execute SQL');          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(          my $action = new_action(
189                  class   => 'StrixSQL',                  class   => 'StrixSQL',
190                  moniker => 'strix-sql',                  moniker => 'strix-sql',
191                  sticky_on_success => 1,                  sticky_on_success => 1,
192                  sticky_on_failure => 1,                  sticky_on_failure => 1,
193                    arguments => {
194                            instance => get('instance')
195                    }
196          );          );
197    
198          form {          form {
199                  render_action( $action => [ 'strix', 'sql' ] );                  render_action( $action => [ 'instance', 'sql' ] );
200                  form_submit( label => _('Execute SQL') );                  form_submit( label => _('Execute SQL') );
201          };          };
202    
# Line 114  template 'sql' => page { Line 207  template 'sql' => page {
207                          while (my $row = $sql->next) {                          while (my $row = $sql->next) {
208                                  row {                                  row {
209                                          foreach my $col ( $sql->_column_names ) {                                          foreach my $col ( $sql->_column_names ) {
                                                 warn "++ $col\n";  
210                                                  cell { $row->$col }                                                  cell { $row->$col }
211                                          }                                          }
212                                  }                                  }
# Line 123  template 'sql' => page { Line 215  template 'sql' => page {
215          }          }
216  };  };
217    
218  =head1 REGIONS  =head2 search-instances
   
 =head2 search_sites  
219    
220  =cut  =cut
221    
222  template 'search_sites' => sub {  template 'search-instances' => sub {
223    
224          h1 { _('Find site') }          h1 { _('Find instance') }
225    
226          my $action = new_action(          my $action = new_action(
227                  class   => 'SearchStrixSite',                  class   => 'SearchStrixInstance',
228                  moniker => 'search-strix-site',                  moniker => 'search-strix-instance',
229                  sticky_on_success => 1,                  sticky_on_success => 1,
230                  sticky_on_failure => 1,                  sticky_on_failure => 1,
231          );          );
232    
233    
234          form {          form {
235                  render_action( $action => [ 'site_contains', '_site_name_contains' ] );                  render_action( $action => [ 'instance_contains', '_site_name_contains' ] );
236                  form_submit( label => _('Search') );                  form_submit( label => _('Search') );
237          };          };
238    
# Line 153  template 'search_sites' => sub { Line 243  template 'search_sites' => sub {
243                  table {                  table {
244                          while (my $strix = $search->next) {                          while (my $strix = $search->next) {
245                                  row {                                  row {
246                                          cell { tt { $strix->site } }                                          cell { show( 'instance-op', 'Create', '+', $strix->instance ) }
247                                            cell { tt { $strix->instance } }
248                                          cell { $strix->_site_name }                                          cell { $strix->_site_name }
                                         cell { show( 'site_selection', 'Create', '+', $strix->site ) }  
249                                  }                                  }
250                          }                          }
251                  }                  }
# Line 163  template 'search_sites' => sub { Line 253  template 'search_sites' => sub {
253    
254  };  };
255    
256  =head2 selected_sites  =head2 selected-instances
257    
258  Show Selected sites for current user  Show Selected instances for current user
259    
260  =cut  =cut
261    
262  template 'selected-sites' => sub {  template 'selected-instances' => sub {
263          my $self = shift;          my $self = shift;
264    
265          warn "## IN selected-sites ",dump( @_ );  #       warn "## IN selected-instances ",dump( @_ );
266    
267          if ( my $op = get 'op' ) {          if ( my $op = get 'op' ) {
268                  my $site = get 'site' or die "no site?";                  my $op_instance = get 'op_instance' or die "no op_instance?";
269                  warn "# selected-sites $op on $site";                  warn "# selected-instances $op on $op_instance";
270    
271                  my $a;                  my $a;
272    
273                  if ( $op eq 'Create' ) {                  if ( $op eq 'Create' ) {
274    
275                          $a = new_action(                          $a = new_action(
276                                  class => $op . 'StrixSiteSelection',                                  class => $op . 'StrixInstanceSelection',
277                                  moniker => $op,                                  moniker => $op,
278                                  arguments => {                                  arguments => {
279                                          strix => $site,                                          instance => $op_instance,
280                                          by_user => $self->current_user->id,                                          by_user => $self->current_user->id,
281                                  },                                  },
282                          );                          );
283    
284                  } elsif ( $op eq 'Delete' ) {                  } elsif ( $op eq 'Delete' ) {
285    
286                          my $strix = A3C::Model::StrixSiteSelection->new;                          my $strix = A3C::Model::StrixInstanceSelection->new;
287                          $strix->load_by_cols( strix => $site, by_user => $self->current_user->id );                          $strix->load_by_cols( instance => $op_instance, by_user => $self->current_user->id );
288                          die "can't find site $site" unless $strix->id;                          warn "can't find instance $op_instance" unless $strix->id;
289                          $a = $strix->as_delete_action;                          $a = $strix->as_delete_action;
290    
291                  }                  }
292                  warn "# argument_values = ",dump( $a->argument_values );  #               warn "# argument_values = ",dump( $a->argument_values );
293                  $a->run;                  $a->run;
294                  warn "can't $op site $site" unless $a->result->success;  
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::StrixSiteSelectionCollection->new;          my $selected = A3C::Model::StrixInstanceSelectionCollection->new;
306          $selected->limit( column => 'by_user', value => Jifty->web->current_user->id );          $selected->limit( column => 'by_user', value => Jifty->web->current_user->id );
307    
308          if ( $selected->count > 0 ) {          if ( $selected->count > 0 ) {
309    
310                  div { _('%1 sites selected', $selected->count ) }                  my $instance = get('instance');
311    
312                    div { _('%1 instances selected', $selected->count ) };
313                  table {                  table {
314                          while (my $s = $selected->next) {                          while (my $s = $selected->next) {
315                                  row {                                  row {
316                                          cell { tt { $s->strix->site } }                                          cell { tt {
317                                          cell { $s->strix->_site_name }                                                  if ( $s->instance->instance eq $instance ) {
318                                          cell { show( 'site_selection', 'Delete', '-', $s->strix->site ) }                                                          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 {          } else {
332                  div { _('No sites selected') }                  div { _('No instances selected') }
333          }          }
334  };  };
335    
336  =head2 site_selection  =head2 instance-op
337    
338  Display button to add/remove site from selection  Display button to add/remove instance from selection
339    
340    show( 'site_selection', 'Delete', '-', $strix->site );    show( 'instance-op', 'Delete', '-', $strix->instace );
341    
342  =cut  =cut
343    
344  template 'site_selection' => sub {  template 'instance-op' => sub {
345          my $self = shift;          my $self = shift;
346    
347          warn "# site_selection = ",dump( @_ );  #       warn "# instance-op = ",dump( @_ );
348    
349          my ( $op, $label, $site ) = @_;          my ( $op, $label, $instance ) = @_;
350    
351          form {          form {
352                  hyperlink(                  hyperlink(
353                          label => $label,                          label => $label,
354                          onclick => {                          onclick => {
355                                  refresh => 'user-selected-sites',                                  refresh => 'selected-instances',
356                                  path => '/strix/selected-sites',                                  path => '/strix/selected-instances',
357                                  args => {                                  args => {
358                                          site => $site,                                          op_instance => $instance,
359                                          op => $op,                                          op => $op,
360                                  }                                  }
361                          },                          },
# Line 255  template 'site_selection' => sub { Line 364  template 'site_selection' => sub {
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;  1;

Legend:
Removed from v.161  
changed lines
  Added in v.197

  ViewVC Help
Powered by ViewVC 1.1.26