Check-in [2ab3a2f603]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Added a few search features (name/id/name-like). Changed default view to only show the 10 [arbitrarily chosen #] most recent tags. Still need to sort out tags for different types of entries (wiki/ticket/baseline)
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 2ab3a2f6034c1064d19878001e3359ddf0993c66
User & Date: stephan 2008-02-03 01:25:07.000
Context
2008-02-03
01:36
Merged importer to mainline. check-in: 0523983440 user: aku tags: trunk
01:25
Added a few search features (name/id/name-like). Changed default view to only show the 10 [arbitrarily chosen #] most recent tags. Still need to sort out tags for different types of entries (wiki/ticket/baseline) check-in: 2ab3a2f603 user: stephan tags: trunk
2008-02-02
23:48
Stylistic changes to the C code that implements the tagview page. check-in: 10437374a7 user: drh tags: trunk
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/tagview.c.
1
2

3
4
5
6
7
8
9
/*
** Copyright (c) 2007 D. Richard Hipp

**
** This program is free software; you can redistribute it and/or
** modify it under the terms of the GNU General Public
** License as published by the Free Software Foundation; either
** version 2 of the License, or (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,


>







1
2
3
4
5
6
7
8
9
10
/*
** Copyright (c) 2007 D. Richard Hipp
** Copyright (c) 2008 Stephan Beal
**
** This program is free software; you can redistribute it and/or
** modify it under the terms of the GNU General Public
** License as published by the Free Software Foundation; either
** version 2 of the License, or (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55

56




57
























































58

59










60
61



62












63
64
65
66
67
68
69
70
71
72
73

74
75
76
77
78
79
80
81
82
83
84
85
86
87
88

89
































90


91
92



93
94
95
96






97

















98
99
void tagview_menu_entry(
  const char *zTitle,
  const char *zLink,
  const char *zDesc
){
  @ <tr><td valign="top" align="right">
  if( zLink && zLink[0] ){
    @ <a href="%s(zLink)">%h(zTitle)</a>
  }else{
    @ %h(zTitle)
  }
  @ </td><td valign="top">%h(zDesc)</td></tr>
}

/*
** WEBPAGE: /tagview
*/
void tagview_page(void){

  Stmt st;





























































  login_check_credentials();

  if( !g.okSetup ){










    login_needed();
  }



  style_header("Tags List");












  @ <table cellpadding='4px' border='1'><tbody>
  @ <tr><th>Tag name</th><th>Timestamp</th><th>Version</th></tr>
  db_prepare( &st,
     "SELECT t.tagname, DATETIME(tx.mtime), b.uuid "
     "  FROM tag t, tagxref tx, blob b"
     " WHERE t.tagid=tx.tagid and tx.rid=b.rid"
     "   AND tx.tagtype != 0"
     /* "   AND t.tagname NOT GLOB 'wiki-*'" // Do we want this?? */
     " ORDER BY tx.mtime DESC"
  );
  while( SQLITE_ROW == db_step(&st) ){

    char const * tagname = db_column_text( &st, 0 );
    char const * tagtime = db_column_text( &st, 1 );
    char const * uuid = db_column_text( &st, 2 );
    const int offset = 10;
    char shortname[offset+1];
    shortname[offset] = '\0';
    memcpy( shortname, uuid, offset );
    @ <tr>
    @ <td><tt>%s(tagname)</tt></td>
    @ <td align='center'><tt>%s(tagtime)</tt></td>
    @ <td><tt>
    @ <a href='/vinfo/%s(uuid)'>
    @ <strong>%s(shortname)</strong>%s(uuid+offset)</a></tt>
    @ </td></tr>
  }

  db_finalize( &st );
































  @ </tbody></table>


  @ <hr/>TODOs include:
  @ <ul>



  @  <li>Page through long tags lists.</li>
  @  <li>Format the timestamp field.</li>
  @  <li>Allow different sorting.</li>
  @  <li>?</li>






  @ </ul>

















  style_footer();
}







|






<
<
<
|
>

>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
|
>
>
>
>
>
>
>
>
>
>
|
|
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>


<
<
<
<
<
<
<
<
|
>








|


<
|
|

>

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

>
>
|
|
>
>
>
|
|
<
<
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


39
40
41
42
43
44
45
46
47
48
49
50
51
52



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149








150
151
152
153
154
155
156
157
158
159
160
161
162

163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209


210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
void tagview_menu_entry(
  const char *zTitle,
  const char *zLink,
  const char *zDesc
){
  @ <tr><td valign="top" align="right">
  if( zLink && zLink[0] ){
    @ <a href="%s(g.zBaseURL)/%s(zLink)">%h(zTitle)</a>
  }else{
    @ %h(zTitle)
  }
  @ </td><td valign="top">%h(zDesc)</td></tr>
}




static void tagview_page_list_tags( char const * like )
{
  Stmt st;
  char * likeclause = 0;
  const int limit = 10;
  char * limitstr = 0;
  if( like && strlen(like) )
  {
    likeclause = mprintf( "AND t.tagname LIKE '%%%%%q%%%%'", like );
    @ <h2>Tags matching [%s(likeclause)]:</h2>
  }
  else
  {
    limitstr = mprintf( "LIMIT %d", limit );
    @ <h2>%d(limit) most recent tags:</h2>
  }
  @ <table cellpadding='4px' border='1'><tbody>
  @ <tr>
  @ <th>Tag ID</th>
  @ <th>Tag name</th>
  @ <th>Timestamp</th>
  @ <th>Version</th>
  @ </tr>
  char * sql = mprintf( 
    "SELECT t.tagid, t.tagname, DATETIME(tx.mtime), b.uuid "
    "FROM tag t, tagxref tx, blob b "
    "WHERE (t.tagid=tx.tagid) and (tx.srcid=b.rid) "
    "AND (tx.tagtype != 0) %s "
    "ORDER BY tx.mtime DESC %s",
    likeclause ? likeclause : " ",
    limitstr ? limitstr : " "
    );
  db_prepare( &st, sql );
  if( likeclause ) free( likeclause );
  free( sql );
  while( SQLITE_ROW == db_step(&st) ){
    int tagid = db_column_int( &st, 0 );
    char const * tagname = db_column_text( &st, 1 );
    char const * tagtime = db_column_text( &st, 2 );
    char const * uuid = db_column_text( &st, 3 );
    const int offset = 10;
    char shortname[offset+1];
    shortname[offset] = '\0';
    memcpy( shortname, uuid, offset );
    @ <tr>
    @ <td><tt>
    @ <a href='%s(g.zBaseURL)/tagview?tagid=%d(tagid)'>%d(tagid)</a>
    @ </tt></td>
    @ <td><tt><a href='%s(g.zBaseURL)/tagview/%q(tagname)'>%s(tagname)</a></tt></td>
    @ <td align='center'><tt>%s(tagtime)</tt></td>
    @ <td><tt>
    @ <a href='%s(g.zBaseURL)/vinfo/%s(uuid)'><strong>%s(shortname)</strong>%s(uuid+offset)</a>
    @ </tt></td></tr>
  }
  db_finalize( &st );
  @ </tbody></table>
  @ <hr/>TODOs include:
  @ <ul>
  @  <li>Page through long tags lists.</li>
  @  <li>Refactor the internal report routines to be reusable.</li>
  @  <li>Allow different sorting.</li>
  @  <li>Selectively filter out wiki/ticket/baseline</li>
  @  <li>?</li>
  @ </ul>

}

static void tagview_page_search_miniform(void){
  char const * like = P("like");
  @ <div style='font-size:smaller'>
  @ <form action='/tagview' method='post'>
  @ Search for tags: 
  @ <input type='text' name='like' value='%s((like?like:""))' size='10'/>
  @ <input type='submit'/>
  @ </form>
  @ </div>
}


static void tagview_page_default(void){
  tagview_page_list_tags( 0 );
}

static void tagview_page_tag_by_id( int tagid )
{
  Stmt st;
  char * sql = mprintf( 
    "SELECT DISTINCT (t.tagname), DATETIME(tx.mtime), b.uuid "
    "FROM tag t, tagxref tx, blob b "
    "WHERE (t.tagid=%d) AND (t.tagid=tx.tagid) AND (tx.srcid=b.rid) "
    "ORDER BY tx.mtime DESC",
  tagid);
  db_prepare( &st, sql );
  free( sql );
  @ <h2>Tag ID %d(tagid):</h2>
  @ <table cellpadding='4px' border='1'><tbody>
  @ <tr><th>Tag name</th><th>Timestamp</th><th>Version</th></tr>








  while( SQLITE_ROW == db_step(&st) )
  {
    char const * tagname = db_column_text( &st, 0 );
    char const * tagtime = db_column_text( &st, 1 );
    char const * uuid = db_column_text( &st, 2 );
    const int offset = 10;
    char shortname[offset+1];
    shortname[offset] = '\0';
    memcpy( shortname, uuid, offset );
    @ <tr>
    @ <td><tt><a href='%s(g.zBaseURL)/tagview/%q(tagname)'>%s(tagname)</a></tt></td>
    @ <td align='center'><tt>%s(tagtime)</tt></td>
    @ <td><tt>

    @ <a href='%s(g.zBaseURL)/vinfo/%s(uuid)'><strong>%s(shortname)</strong>%s(uuid+offset)</a>
    @ </tt></td></tr>
  }
  @ </tbody></table>
  db_finalize( &st );
}

static void tagview_page_tag_by_name( char const * tagname )
{
  Stmt st;
  char * sql = mprintf( 
    "SELECT DISTINCT t.tagid, DATETIME(tx.mtime), b.uuid "
    "FROM tag t, tagxref tx, blob b "
    "WHERE (t.tagname='%q') AND (t.tagid=tx.tagid) AND (tx.srcid=b.rid) "
    "ORDER BY tx.mtime DESC",
    tagname);
  db_prepare( &st, sql );
  free( sql );
  @ <h2>Tag '%s(tagname)':</h2>
  @ <table cellpadding='4px' border='1'><tbody>
  @ <tr><th>Tag ID</th><th>Timestamp</th><th>Version</th></tr>
  while( SQLITE_ROW == db_step(&st) )
  {
    int tagid = db_column_int( &st, 0 );
    char const * tagtime = db_column_text( &st, 1 );
    char const * uuid = db_column_text( &st, 2 );
    const int offset = 10;
    char shortname[offset+1];
    shortname[offset] = '\0';
    memcpy( shortname, uuid, offset );
    @ <tr>
    @ <td><tt><a href='%s(g.zBaseURL)/tagview?tagid=%d(tagid)'>%d(tagid)</a></tt></td>
    @ <td align='center'><tt>%s(tagtime)</tt></td>
    @ <td><tt>
    @ <a href='%s(g.zBaseURL)/vinfo/%s(uuid)'><strong>%s(shortname)</strong>%s(uuid+offset)</a>
    @ </tt></td></tr>
  }
  @ </tbody></table>
  db_finalize( &st );
}


/*
** WEBPAGE: /tagview
*/
void tagview_page(void){



  login_check_credentials();
  if( !g.okSetup ){
    login_needed();
  }
  style_header("Tags");
  tagview_page_search_miniform();
  @ <hr/>
  char const * check = 0;
  if( 0 != (check = P("tagid")) )
  {
    tagview_page_tag_by_id( atoi(check) );
  }
  else if( 0 != (check = P("like")) )
  {
    tagview_page_list_tags( check );
  }
  else if( 0 != (check = P("name")) )
  {
    tagview_page_tag_by_name( check );
  }
  else
  {
    tagview_page_default();
  }
  style_footer();
}