Hex Artifact Content
Not logged in

Artifact 475277fbb26e9ca086cd4a8e310c62f96746644a:

File src/tagview.c part of check-in [02d1ed6ad2] - added /tagview page - a simple browse-by-tag interface by stephan on 2008-02-02 21:10:17.

0000: 2f 2a 0a 2a 2a 20 43 6f 70 79 72 69 67 68 74 20  /*.** Copyright 
0010: 28 63 29 20 32 30 30 37 20 44 2e 20 52 69 63 68  (c) 2007 D. Rich
0020: 61 72 64 20 48 69 70 70 0a 2a 2a 0a 2a 2a 20 54  ard Hipp.**.** T
0030: 68 69 73 20 70 72 6f 67 72 61 6d 20 69 73 20 66  his program is f
0040: 72 65 65 20 73 6f 66 74 77 61 72 65 3b 20 79 6f  ree software; yo
0050: 75 20 63 61 6e 20 72 65 64 69 73 74 72 69 62 75  u can redistribu
0060: 74 65 20 69 74 20 61 6e 64 2f 6f 72 0a 2a 2a 20  te it and/or.** 
0070: 6d 6f 64 69 66 79 20 69 74 20 75 6e 64 65 72 20  modify it under 
0080: 74 68 65 20 74 65 72 6d 73 20 6f 66 20 74 68 65  the terms of the
0090: 20 47 4e 55 20 47 65 6e 65 72 61 6c 20 50 75 62   GNU General Pub
00a0: 6c 69 63 0a 2a 2a 20 4c 69 63 65 6e 73 65 20 61  lic.** License a
00b0: 73 20 70 75 62 6c 69 73 68 65 64 20 62 79 20 74  s published by t
00c0: 68 65 20 46 72 65 65 20 53 6f 66 74 77 61 72 65  he Free Software
00d0: 20 46 6f 75 6e 64 61 74 69 6f 6e 3b 20 65 69 74   Foundation; eit
00e0: 68 65 72 0a 2a 2a 20 76 65 72 73 69 6f 6e 20 32  her.** version 2
00f0: 20 6f 66 20 74 68 65 20 4c 69 63 65 6e 73 65 2c   of the License,
0100: 20 6f 72 20 28 61 74 20 79 6f 75 72 20 6f 70 74   or (at your opt
0110: 69 6f 6e 29 20 61 6e 79 20 6c 61 74 65 72 20 76  ion) any later v
0120: 65 72 73 69 6f 6e 2e 0a 2a 2a 0a 2a 2a 20 54 68  ersion..**.** Th
0130: 69 73 20 70 72 6f 67 72 61 6d 20 69 73 20 64 69  is program is di
0140: 73 74 72 69 62 75 74 65 64 20 69 6e 20 74 68 65  stributed in the
0150: 20 68 6f 70 65 20 74 68 61 74 20 69 74 20 77 69   hope that it wi
0160: 6c 6c 20 62 65 20 75 73 65 66 75 6c 2c 0a 2a 2a  ll be useful,.**
0170: 20 62 75 74 20 57 49 54 48 4f 55 54 20 41 4e 59   but WITHOUT ANY
0180: 20 57 41 52 52 41 4e 54 59 3b 20 77 69 74 68 6f   WARRANTY; witho
0190: 75 74 20 65 76 65 6e 20 74 68 65 20 69 6d 70 6c  ut even the impl
01a0: 69 65 64 20 77 61 72 72 61 6e 74 79 20 6f 66 0a  ied warranty of.
01b0: 2a 2a 20 4d 45 52 43 48 41 4e 54 41 42 49 4c 49  ** MERCHANTABILI
01c0: 54 59 20 6f 72 20 46 49 54 4e 45 53 53 20 46 4f  TY or FITNESS FO
01d0: 52 20 41 20 50 41 52 54 49 43 55 4c 41 52 20 50  R A PARTICULAR P
01e0: 55 52 50 4f 53 45 2e 20 20 53 65 65 20 74 68 65  URPOSE.  See the
01f0: 20 47 4e 55 0a 2a 2a 20 47 65 6e 65 72 61 6c 20   GNU.** General 
0200: 50 75 62 6c 69 63 20 4c 69 63 65 6e 73 65 20 66  Public License f
0210: 6f 72 20 6d 6f 72 65 20 64 65 74 61 69 6c 73 2e  or more details.
0220: 0a 2a 2a 0a 2a 2a 20 59 6f 75 20 73 68 6f 75 6c  .**.** You shoul
0230: 64 20 68 61 76 65 20 72 65 63 65 69 76 65 64 20  d have received 
0240: 61 20 63 6f 70 79 20 6f 66 20 74 68 65 20 47 4e  a copy of the GN
0250: 55 20 47 65 6e 65 72 61 6c 20 50 75 62 6c 69 63  U General Public
0260: 0a 2a 2a 20 4c 69 63 65 6e 73 65 20 61 6c 6f 6e  .** License alon
0270: 67 20 77 69 74 68 20 74 68 69 73 20 6c 69 62 72  g with this libr
0280: 61 72 79 3b 20 69 66 20 6e 6f 74 2c 20 77 72 69  ary; if not, wri
0290: 74 65 20 74 6f 20 74 68 65 0a 2a 2a 20 46 72 65  te to the.** Fre
02a0: 65 20 53 6f 66 74 77 61 72 65 20 46 6f 75 6e 64  e Software Found
02b0: 61 74 69 6f 6e 2c 20 49 6e 63 2e 2c 20 35 39 20  ation, Inc., 59 
02c0: 54 65 6d 70 6c 65 20 50 6c 61 63 65 20 2d 20 53  Temple Place - S
02d0: 75 69 74 65 20 33 33 30 2c 0a 2a 2a 20 42 6f 73  uite 330,.** Bos
02e0: 74 6f 6e 2c 20 4d 41 20 20 30 32 31 31 31 2d 31  ton, MA  02111-1
02f0: 33 30 37 2c 20 55 53 41 2e 0a 2a 2a 0a 2a 2a 20  307, USA..**.** 
0300: 41 75 74 68 6f 72 20 63 6f 6e 74 61 63 74 20 69  Author contact i
0310: 6e 66 6f 72 6d 61 74 69 6f 6e 3a 0a 2a 2a 20 20  nformation:.**  
0320: 20 64 72 68 40 68 77 61 63 69 2e 63 6f 6d 0a 2a   drh@hwaci.com.*
0330: 2a 20 20 20 68 74 74 70 3a 2f 2f 77 77 77 2e 68  *   http://www.h
0340: 77 61 63 69 2e 63 6f 6d 2f 64 72 68 2f 0a 2a 2a  waci.com/drh/.**
0350: 0a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  .***************
0360: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0370: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0380: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0390: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
03a0: 0a 2a 2a 0a 2a 2a 20 49 6d 70 6c 65 6d 65 6e 74  .**.** Implement
03b0: 61 74 69 6f 6e 20 6f 66 20 74 68 65 20 54 61 67  ation of the Tag
03c0: 20 56 69 65 77 20 70 61 67 65 0a 2a 2f 0a 23 69   View page.*/.#i
03d0: 6e 63 6c 75 64 65 20 3c 61 73 73 65 72 74 2e 68  nclude <assert.h
03e0: 3e 0a 23 69 6e 63 6c 75 64 65 20 22 63 6f 6e 66  >.#include "conf
03f0: 69 67 2e 68 22 0a 23 69 6e 63 6c 75 64 65 20 22  ig.h".#include "
0400: 74 61 67 76 69 65 77 2e 68 22 0a 0a 0a 2f 2a 0a  tagview.h".../*.
0410: 2a 2a 20 4f 75 74 70 75 74 20 61 20 73 69 6e 67  ** Output a sing
0420: 6c 65 20 65 6e 74 72 79 20 66 6f 72 20 61 20 6d  le entry for a m
0430: 65 6e 75 20 67 65 6e 65 72 61 74 65 64 20 75 73  enu generated us
0440: 69 6e 67 20 61 6e 20 48 54 4d 4c 20 74 61 62 6c  ing an HTML tabl
0450: 65 2e 0a 2a 2a 20 49 66 20 7a 4c 69 6e 6b 20 69  e..** If zLink i
0460: 73 20 6e 6f 74 20 4e 55 4c 4c 20 6f 72 20 61 6e  s not NULL or an
0470: 20 65 6d 70 74 79 20 73 74 72 69 6e 67 2c 20 74   empty string, t
0480: 68 65 6e 20 69 74 20 69 73 20 74 68 65 20 70 61  hen it is the pa
0490: 67 65 20 74 68 61 74 0a 2a 2a 20 74 68 65 20 6d  ge that.** the m
04a0: 65 6e 75 20 65 6e 74 72 79 20 77 69 6c 6c 20 68  enu entry will h
04b0: 79 70 65 72 6c 69 6e 6b 20 74 6f 2e 20 20 49 66  yperlink to.  If
04c0: 20 7a 4c 69 6e 6b 20 69 73 20 4e 55 4c 4c 20 6f   zLink is NULL o
04d0: 72 20 22 22 2c 20 74 68 65 6e 0a 2a 2a 20 74 68  r "", then.** th
04e0: 65 20 6d 65 6e 75 20 65 6e 74 72 79 20 68 61 73  e menu entry has
04f0: 20 6e 6f 20 68 79 70 65 72 6c 69 6e 6b 20 2d 20   no hyperlink - 
0500: 69 74 20 69 73 20 64 69 73 61 62 6c 65 64 2e 0a  it is disabled..
0510: 2a 2f 0a 76 6f 69 64 20 74 61 67 76 69 65 77 5f  */.void tagview_
0520: 6d 65 6e 75 5f 65 6e 74 72 79 28 0a 20 20 63 6f  menu_entry(.  co
0530: 6e 73 74 20 63 68 61 72 20 2a 7a 54 69 74 6c 65  nst char *zTitle
0540: 2c 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a  ,.  const char *
0550: 7a 4c 69 6e 6b 2c 0a 20 20 63 6f 6e 73 74 20 63  zLink,.  const c
0560: 68 61 72 20 2a 7a 44 65 73 63 0a 29 7b 0a 20 20  har *zDesc.){.  
0570: 40 20 3c 74 72 3e 3c 74 64 20 76 61 6c 69 67 6e  @ <tr><td valign
0580: 3d 22 74 6f 70 22 20 61 6c 69 67 6e 3d 22 72 69  ="top" align="ri
0590: 67 68 74 22 3e 0a 20 20 69 66 28 20 7a 4c 69 6e  ght">.  if( zLin
05a0: 6b 20 26 26 20 7a 4c 69 6e 6b 5b 30 5d 20 29 7b  k && zLink[0] ){
05b0: 0a 20 20 20 20 40 20 3c 61 20 68 72 65 66 3d 22  .    @ <a href="
05c0: 25 73 28 7a 4c 69 6e 6b 29 22 3e 25 68 28 7a 54  %s(zLink)">%h(zT
05d0: 69 74 6c 65 29 3c 2f 61 3e 0a 20 20 7d 65 6c 73  itle)</a>.  }els
05e0: 65 7b 0a 20 20 20 20 40 20 25 68 28 7a 54 69 74  e{.    @ %h(zTit
05f0: 6c 65 29 0a 20 20 7d 0a 20 20 40 20 3c 2f 74 64  le).  }.  @ </td
0600: 3e 3c 74 64 20 76 61 6c 69 67 6e 3d 22 74 6f 70  ><td valign="top
0610: 22 3e 25 68 28 7a 44 65 73 63 29 3c 2f 74 64 3e  ">%h(zDesc)</td>
0620: 3c 2f 74 72 3e 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 57  </tr>.}../*.** W
0630: 45 42 50 41 47 45 3a 20 2f 74 61 67 76 69 65 77  EBPAGE: /tagview
0640: 0a 2a 2f 0a 76 6f 69 64 20 74 61 67 76 69 65 77  .*/.void tagview
0650: 5f 70 61 67 65 28 76 6f 69 64 29 7b 0a 20 20 53  _page(void){.  S
0660: 74 6d 74 20 73 74 3b 0a 0a 20 20 6c 6f 67 69 6e  tmt st;..  login
0670: 5f 63 68 65 63 6b 5f 63 72 65 64 65 6e 74 69 61  _check_credentia
0680: 6c 73 28 29 3b 0a 20 20 69 66 28 20 21 67 2e 6f  ls();.  if( !g.o
0690: 6b 53 65 74 75 70 20 29 7b 0a 20 20 20 20 6c 6f  kSetup ){.    lo
06a0: 67 69 6e 5f 6e 65 65 64 65 64 28 29 3b 0a 20 20  gin_needed();.  
06b0: 7d 0a 20 20 73 74 79 6c 65 5f 68 65 61 64 65 72  }.  style_header
06c0: 28 22 54 61 67 73 20 4c 69 73 74 22 29 3b 0a 20  ("Tags List");. 
06d0: 20 40 20 3c 74 61 62 6c 65 20 63 65 6c 6c 70 61   @ <table cellpa
06e0: 64 64 69 6e 67 3d 27 34 70 78 27 20 62 6f 72 64  dding='4px' bord
06f0: 65 72 3d 27 31 27 3e 3c 74 62 6f 64 79 3e 0a 20  er='1'><tbody>. 
0700: 20 40 20 3c 74 72 3e 3c 74 68 3e 54 61 67 20 6e   @ <tr><th>Tag n
0710: 61 6d 65 3c 2f 74 68 3e 3c 74 68 3e 54 69 6d 65  ame</th><th>Time
0720: 73 74 61 6d 70 3c 2f 74 68 3e 3c 74 68 3e 56 65  stamp</th><th>Ve
0730: 72 73 69 6f 6e 3c 2f 74 68 3e 3c 2f 74 72 3e 0a  rsion</th></tr>.
0740: 20 20 64 62 5f 70 72 65 70 61 72 65 28 20 26 73    db_prepare( &s
0750: 74 2c 0a 09 20 20 20 20 20 20 22 73 65 6c 65 63  t,..      "selec
0760: 74 20 74 2e 74 61 67 6e 61 6d 65 2c 20 44 41 54  t t.tagname, DAT
0770: 45 54 49 4d 45 28 74 78 2e 6d 74 69 6d 65 29 2c  ETIME(tx.mtime),
0780: 20 62 2e 75 75 69 64 20 22 0a 09 20 20 20 20 20   b.uuid "..     
0790: 20 22 46 52 4f 4d 20 74 61 67 20 74 2c 20 74 61   "FROM tag t, ta
07a0: 67 78 72 65 66 20 74 78 2c 20 62 6c 6f 62 20 62  gxref tx, blob b
07b0: 20 22 0a 09 20 20 20 20 20 20 22 57 48 45 52 45   "..      "WHERE
07c0: 20 74 2e 74 61 67 69 64 3d 74 78 2e 74 61 67 69   t.tagid=tx.tagi
07d0: 64 20 61 6e 64 20 74 78 2e 72 69 64 3d 62 2e 72  d and tx.rid=b.r
07e0: 69 64 20 22 0a 09 20 20 20 20 20 20 22 41 4e 44  id "..      "AND
07f0: 20 74 78 2e 74 61 67 74 79 70 65 20 21 3d 20 30   tx.tagtype != 0
0800: 20 22 0a 09 20 20 20 20 20 20 22 4f 52 44 45 52   "..      "ORDER
0810: 20 42 59 20 74 78 2e 6d 74 69 6d 65 20 44 45 53   BY tx.mtime DES
0820: 43 22 0a 09 20 20 20 20 20 20 29 3b 0a 20 20 77  C"..      );.  w
0830: 68 69 6c 65 28 20 53 51 4c 49 54 45 5f 52 4f 57  hile( SQLITE_ROW
0840: 20 3d 3d 20 64 62 5f 73 74 65 70 28 26 73 74 29   == db_step(&st)
0850: 20 29 0a 20 20 7b 0a 09 20 20 63 68 61 72 20 63   ).  {..  char c
0860: 6f 6e 73 74 20 2a 20 74 61 67 6e 61 6d 65 20 3d  onst * tagname =
0870: 20 64 62 5f 63 6f 6c 75 6d 6e 5f 74 65 78 74 28   db_column_text(
0880: 20 26 73 74 2c 20 30 20 29 3b 0a 09 20 20 63 68   &st, 0 );..  ch
0890: 61 72 20 63 6f 6e 73 74 20 2a 20 74 61 67 74 69  ar const * tagti
08a0: 6d 65 20 3d 20 64 62 5f 63 6f 6c 75 6d 6e 5f 74  me = db_column_t
08b0: 65 78 74 28 20 26 73 74 2c 20 31 20 29 3b 0a 09  ext( &st, 1 );..
08c0: 20 20 63 68 61 72 20 63 6f 6e 73 74 20 2a 20 75    char const * u
08d0: 75 69 64 20 3d 20 64 62 5f 63 6f 6c 75 6d 6e 5f  uid = db_column_
08e0: 74 65 78 74 28 20 26 73 74 2c 20 32 20 29 3b 0a  text( &st, 2 );.
08f0: 09 20 20 63 6f 6e 73 74 20 69 6e 74 20 6f 66 66  .  const int off
0900: 73 65 74 20 3d 20 31 30 3b 0a 09 20 20 63 68 61  set = 10;..  cha
0910: 72 20 73 68 6f 72 74 6e 61 6d 65 5b 6f 66 66 73  r shortname[offs
0920: 65 74 2b 31 5d 3b 0a 09 73 68 6f 72 74 6e 61 6d  et+1];..shortnam
0930: 65 5b 6f 66 66 73 65 74 5d 20 3d 20 27 5c 30 27  e[offset] = '\0'
0940: 3b 0a 09 6d 65 6d 63 70 79 28 20 73 68 6f 72 74  ;..memcpy( short
0950: 6e 61 6d 65 2c 20 75 75 69 64 2c 20 6f 66 66 73  name, uuid, offs
0960: 65 74 20 29 3b 0a 09 20 20 40 20 3c 74 72 3e 0a  et );..  @ <tr>.
0970: 09 20 20 40 20 3c 74 64 3e 3c 74 74 3e 25 73 28  .  @ <td><tt>%s(
0980: 74 61 67 6e 61 6d 65 29 3c 2f 74 74 3e 3c 2f 74  tagname)</tt></t
0990: 64 3e 0a 09 20 20 40 20 3c 74 64 20 61 6c 69 67  d>..  @ <td alig
09a0: 6e 3d 27 63 65 6e 74 65 72 27 3e 3c 74 74 3e 25  n='center'><tt>%
09b0: 73 28 74 61 67 74 69 6d 65 29 3c 2f 74 74 3e 3c  s(tagtime)</tt><
09c0: 2f 74 64 3e 0a 09 20 20 40 20 3c 74 64 3e 3c 74  /td>..  @ <td><t
09d0: 74 3e 0a 20 20 20 20 20 20 20 20 20 20 40 20 3c  t>.          @ <
09e0: 61 20 68 72 65 66 3d 27 2f 76 69 6e 66 6f 2f 25  a href='/vinfo/%
09f0: 73 28 75 75 69 64 29 27 3e 3c 73 74 72 6f 6e 67  s(uuid)'><strong
0a00: 3e 25 73 28 73 68 6f 72 74 6e 61 6d 65 29 3c 2f  >%s(shortname)</
0a10: 73 74 72 6f 6e 67 3e 25 73 28 75 75 69 64 2b 6f  strong>%s(uuid+o
0a20: 66 66 73 65 74 29 3c 2f 61 3e 3c 2f 74 74 3e 0a  ffset)</a></tt>.
0a30: 09 20 20 40 20 3c 2f 74 64 3e 3c 2f 74 72 3e 0a  .  @ </td></tr>.
0a40: 20 20 7d 0a 20 20 64 62 5f 66 69 6e 61 6c 69 7a    }.  db_finaliz
0a50: 65 28 20 26 73 74 20 29 3b 0a 20 20 40 20 3c 2f  e( &st );.  @ </
0a60: 74 62 6f 64 79 3e 3c 2f 74 61 62 6c 65 3e 0a 20  tbody></table>. 
0a70: 20 40 20 3c 68 72 2f 3e 54 4f 44 4f 73 20 69 6e   @ <hr/>TODOs in
0a80: 63 6c 75 64 65 3a 0a 20 20 40 20 3c 75 6c 3e 0a  clude:.  @ <ul>.
0a90: 20 20 40 20 20 3c 6c 69 3e 50 61 67 65 20 74 68    @  <li>Page th
0aa0: 72 6f 75 67 68 20 6c 6f 6e 67 20 74 61 67 73 20  rough long tags 
0ab0: 6c 69 73 74 73 2e 3c 2f 6c 69 3e 0a 20 20 40 20  lists.</li>.  @ 
0ac0: 20 3c 6c 69 3e 46 6f 72 6d 61 74 20 74 68 65 20   <li>Format the 
0ad0: 74 69 6d 65 73 74 61 6d 70 20 66 69 65 6c 64 2e  timestamp field.
0ae0: 3c 2f 6c 69 3e 0a 20 20 40 20 20 3c 6c 69 3e 41  </li>.  @  <li>A
0af0: 6c 6c 6f 77 20 64 69 66 66 65 72 65 6e 74 20 73  llow different s
0b00: 6f 72 74 69 6e 67 2e 3c 2f 6c 69 3e 0a 20 20 40  orting.</li>.  @
0b10: 20 20 3c 6c 69 3e 3f 3c 2f 6c 69 3e 0a 20 20 40    <li>?</li>.  @
0b20: 20 3c 2f 75 6c 3e 0a 20 20 73 74 79 6c 65 5f 66   </ul>.  style_f
0b30: 6f 6f 74 65 72 28 29 3b 0a 7d 0a 0a              ooter();.}..