/[SQLSession]/trunk/share/web/templates/fragments/queries
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 /trunk/share/web/templates/fragments/queries

Parent Directory Parent Directory | Revision Log Revision Log


Revision 117 - (show annotations)
Thu Mar 27 00:20:44 2008 UTC (14 years, 10 months ago) by dpavlin
File size: 3946 byte(s)
make it somewhat work on latest jifty
1 <%args>
2 $on_database => undef
3 $created_on => undef
4 $order
5 $reformat => 0
6 </%args>
7 <%init>
8 my $queries = SQLSession::Model::QueryCollection->new();
9
10 my $edit = Jifty->web->current_user->role('edit');
11
12 use Data::Dump qw/dump/;
13 #warn "current_user = ", dump( Jifty->web->current_user );
14 #warn "edit = $edit";
15
16 $queries->unlimit;
17 $queries->limit( column => 'on_database', value => $on_database ) if ( $on_database );
18 $queries->limit( column => 'created_on', operator => 'STARTSWITH', value => $created_on ) if ( $created_on );
19 $queries->order_by( column => $order, order => 'asc' );
20
21 #warn $queries->build_select_query,$/;
22
23 ###
24 ### sort by
25 ###
26
27 my $sort_label = {
28 name => 'Query name',
29 created_on => 'Creation date',
30 owner => 'Creator',
31 };
32
33 my $sort_menu = Jifty::Web::Menu->new( label => 'Sort by: ' . $sort_label->{$order} );
34 foreach my $c ( qw/name created_on owner/ ) {
35 #next if ($c eq $order);
36 $sort_menu->child( $c,
37 active => $c eq $order,
38 link => Jifty->web->link(
39 label => $sort_label->{$c},
40 onclick => {
41 replace_with => '/fragments/queries',
42 args => {
43 order => $c,
44 },
45 },
46 ),
47 );
48 }
49
50 ###
51 ### date filter
52 ###
53
54 my $date_menu = Jifty::Web::Menu->new( label => 'Date filter' . ( $created_on ? ": $created_on" : '' ) );
55 $date_menu->child( 'clear',
56 link => Jifty->web->link(
57 label => 'clear',
58 onclick => {
59 replace_with => '/fragments/queries',
60 args => {
61 created_on => '',
62 },
63 },
64 ),
65 ) if ($created_on);
66
67 # select created_on,count(date(created_on)) from queries group by date(created_on) order by created_on;
68 my $date_coll = SQLSession::Model::QueryCollection->new( results_are_readable => 1 );
69 my $created_on_date = $date_coll->column( function => 'date(created_on)', column => 'date' );
70 my $count = $date_coll->column( function => 'count(date(created_on))', column => 'count' );
71 $date_coll->group_by( function => $created_on_date );
72 $date_coll->order_by( column => 'date', order => 'DESC' );
73 $date_coll->unlimit;
74 $date_coll->limit( column => 'on_database', value => $on_database ) if ( $on_database );
75
76 #warn "## ", $date_coll->build_select_query;
77
78 my $dates = 0;
79
80 while (my $q = $date_coll->next) {
81 warn dump( $q );
82 my $date = $q->{values}->{date} || warn "no date?";
83 my $count = $q->{values}->{count} || warn "no count?";
84 if ( $date && $count ) {
85 $date_menu->child( $date,
86 active => $created_on && $created_on eq $date ? 1 : 0,
87 link => Jifty->web->link(
88 label => "$date ($count)",
89 onclick => {
90 replace_with => '/fragments/queries',
91 args => {
92 created_on => $date,
93 },
94 },
95 ),
96 );
97
98 $dates++; # why is this different from $date_coll->count ?
99 };
100 }
101
102 my $u;
103 if ($reformat) {
104 use SQLSession::Utils;
105 $u = Jifty->app_class('Utils');
106 }
107
108 </%init>
109
110 <div class="sort">
111 <% $sort_menu->render_as_context_menu %>
112 % if ( $dates > 0 ) {
113 <% $date_menu->render_as_context_menu %>
114 % }
115 <ul class="context_menu">
116 <% Jifty->web->link(
117 label => $reformat ? 'Original formatting' : 'Pretty print SQL',
118 onclick => {
119 replace_with => '/fragments/queries',
120 args => {
121 reformat => $reformat ? 0 : 1,
122 },
123 },
124 ) %>
125 </ul>
126 </div>
127
128 <dl style="clear: left;">
129 % $queries->goto_first_item;
130 % while (my $q = $queries->next) {
131 <div <% $q->visible ? '' : ' class=invisible' %>>
132 <dt><% Jifty->web->tangent(
133 url => '/sql/' . $q->id,
134 label => $q->name,
135 ) %>
136
137 <span class="database-name">
138 <% $q->on_database->name %>
139 |
140 <% defined($q->owner->name) ? $q->owner->name : '?' %>
141 |
142 <% $q->created_on->ymd . ' ' . $q->created_on->hms %>
143
144 <span class="database-schema">
145 <%perl>
146 my $name = $q->on_database->dsn;
147 $name =~ s/^.*dbname=//;
148 $m->out("<a href=\"/static/spy/$name/index.html\" target=\"_spy\">$name shema</a>");
149 </%perl>
150 </span>
151
152 </span>
153
154 </dt>
155 <dd>
156 % if ($q->note) {
157 <div class="sql-note"><% $q->note %></div>
158 % }
159 % my $sql = $q->sql_query;
160 % $sql = $u->reformat_sql( $sql ) if ($reformat);
161 <pre class="sql"><% $sql %></pre>
162 </dd>
163 </div>
164 % }
165 </dl>

  ViewVC Help
Powered by ViewVC 1.1.26