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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 161 - (hide annotations)
Sun Jun 15 16:11:17 2008 UTC (15 years, 9 months ago) by dpavlin
File size: 4590 byte(s)
Send SQL query to any strix site (possibly over ssh tunnel)
1 dpavlin 142 package A3C::View::Strix;
2    
3     =head1 NAME
4    
5     A3C::View::Strix
6    
7     =head1 DESCRIPTION
8    
9     Display information about Strix sites
10    
11 dpavlin 157 =head1 TEMPLATES
12    
13 dpavlin 142 =cut
14    
15     use strict;
16     use warnings;
17    
18     use Jifty::View::Declare -base;
19     use Data::Dump qw/dump/;
20    
21 dpavlin 157 =head2 /
22    
23     Display sites search and some stats
24    
25     =cut
26    
27 dpavlin 142 template 'index.html' => page {
28    
29 dpavlin 153 title is _('Strix sites');
30    
31 dpavlin 157 render_region(
32     name => 'user-selected-sites',
33     path => '/strix/selected-sites'
34     );
35    
36     render_region(
37     name => 'search_sites',
38     path => '/strix/search_sites',
39     );
40    
41 dpavlin 142 h1 { _('Statistics') }
42    
43     my $orgs = A3C::Model::StrixSiteCollection->new;
44     $orgs->unlimit;
45    
46     dt { _('Number of Strix sites') }
47     dd { $orgs->count }
48    
49 dpavlin 153 };
50    
51 dpavlin 157 =head2 name_diff
52    
53     =cut
54    
55 dpavlin 153 template 'name_diff' => page {
56    
57 dpavlin 157 title is _('Strix sites | name differences between php config and internal state');
58 dpavlin 153
59 dpavlin 142 my $name_diff = A3C::SQL->new({ query => qq{
60     select
61     site,hreduorgurl,
62     _site_name,o
63     from strix_sites
64     join hr_edu_orgs on cn = site
65     where o != _site_name
66     }});
67    
68     h1 { _('Name differences') }
69     dd {
70     table {
71     row {
72     th { _('Site') }
73     th { _('Strix site name') }
74     th { _('hrEduOrg.o') }
75     };
76     while ( my $row = $name_diff->next ) {
77     row {
78     cell { hyperlink( url => 'http://' . $row->hreduorgurl, label => $row->site ) }
79     cell { $row->_site_name }
80     cell { $row->o }
81     }
82     }
83     }
84     }
85    
86     };
87    
88 dpavlin 161 =head2 sql
89    
90     Execute SQL query on site
91    
92     =cut
93    
94     template 'sql' => page {
95    
96     title is _('Execute SQL');
97    
98     my $action = new_action(
99     class => 'StrixSQL',
100     moniker => 'strix-sql',
101     sticky_on_success => 1,
102     sticky_on_failure => 1,
103     );
104    
105     form {
106     render_action( $action => [ 'strix', 'sql' ] );
107     form_submit( label => _('Execute SQL') );
108     };
109    
110     if ( my $sql = $action->result->content('sql') ) {
111     div { _('Found %1 results', $sql->count ) }
112     table {
113     row { map { th { $_ } } $sql->_column_names };
114     while (my $row = $sql->next) {
115     row {
116     foreach my $col ( $sql->_column_names ) {
117     warn "++ $col\n";
118     cell { $row->$col }
119     }
120     }
121     }
122     }
123     }
124     };
125    
126 dpavlin 157 =head1 REGIONS
127    
128     =head2 search_sites
129    
130     =cut
131    
132     template 'search_sites' => sub {
133    
134     h1 { _('Find site') }
135    
136     my $action = new_action(
137     class => 'SearchStrixSite',
138     moniker => 'search-strix-site',
139     sticky_on_success => 1,
140     sticky_on_failure => 1,
141     );
142    
143    
144     form {
145     render_action( $action => [ 'site_contains', '_site_name_contains' ] );
146     form_submit( label => _('Search') );
147     };
148    
149     # warn dump( $action->result->content );
150    
151     if ( my $search = $action->result->content('search') ) {
152     div { _('Found %1 results', $search->count ) }
153     table {
154     while (my $strix = $search->next) {
155     row {
156     cell { tt { $strix->site } }
157     cell { $strix->_site_name }
158     cell { show( 'site_selection', 'Create', '+', $strix->site ) }
159     }
160     }
161     }
162     }
163    
164     };
165    
166     =head2 selected_sites
167    
168     Show Selected sites for current user
169    
170     =cut
171    
172     template 'selected-sites' => sub {
173     my $self = shift;
174    
175     warn "## IN selected-sites ",dump( @_ );
176    
177     if ( my $op = get 'op' ) {
178     my $site = get 'site' or die "no site?";
179     warn "# selected-sites $op on $site";
180    
181     my $a;
182    
183     if ( $op eq 'Create' ) {
184    
185     $a = new_action(
186     class => $op . 'StrixSiteSelection',
187     moniker => $op,
188     arguments => {
189     strix => $site,
190     by_user => $self->current_user->id,
191     },
192     );
193    
194     } elsif ( $op eq 'Delete' ) {
195    
196     my $strix = A3C::Model::StrixSiteSelection->new;
197     $strix->load_by_cols( strix => $site, by_user => $self->current_user->id );
198     die "can't find site $site" unless $strix->id;
199     $a = $strix->as_delete_action;
200    
201     }
202     warn "# argument_values = ",dump( $a->argument_values );
203     $a->run;
204     warn "can't $op site $site" unless $a->result->success;
205     }
206    
207     my $selected = A3C::Model::StrixSiteSelectionCollection->new;
208     $selected->limit( column => 'by_user', value => Jifty->web->current_user->id );
209    
210     if ( $selected->count > 0 ) {
211    
212     div { _('%1 sites selected', $selected->count ) }
213     table {
214     while (my $s = $selected->next) {
215     row {
216     cell { tt { $s->strix->site } }
217     cell { $s->strix->_site_name }
218     cell { show( 'site_selection', 'Delete', '-', $s->strix->site ) }
219     }
220     }
221     }
222     } else {
223     div { _('No sites selected') }
224     }
225     };
226    
227     =head2 site_selection
228    
229     Display button to add/remove site from selection
230    
231     show( 'site_selection', 'Delete', '-', $strix->site );
232    
233     =cut
234    
235     template 'site_selection' => sub {
236     my $self = shift;
237    
238     warn "# site_selection = ",dump( @_ );
239    
240     my ( $op, $label, $site ) = @_;
241    
242     form {
243     hyperlink(
244     label => $label,
245     onclick => {
246     refresh => 'user-selected-sites',
247     path => '/strix/selected-sites',
248     args => {
249     site => $site,
250     op => $op,
251     }
252     },
253     );
254     }
255    
256     };
257    
258    
259 dpavlin 142 1;

  ViewVC Help
Powered by ViewVC 1.1.26