~pkal/llist

81e5c24975beca886a074207747bcfb31567d4cb — Philip K 4 years ago 28d58b8
Reworked users comment list
3 files changed, 40 insertions(+), 12 deletions(-)

M gtml/user.gtml
M main.go
M util.go
M gtml/user.gtml => gtml/user.gtml +9 -3
@@ 32,6 32,10 @@
     text-decoration: none;
 }

 a.plink {
     font-style: italic;
 }

 span.posted, span.domain, a#clear {
     color: gray;
     font-size: 0.75em;


@@ 89,9 93,11 @@
	<ul>
	    {{ range .Comms }}
		<li class="c" name="{{ .Id }}">
		    <a class="uname" href="../user?id={{ .Name }}">{{ .Name }}</a> |
		    <a href="#{{ .Id }}" title="{{ .Posted.Format "02 Jan 06 15:04" }}">{{ since .Posted }}</a> |
		    <a href="{{ $base }}/delete?t=comm&id={{ .Id }}">delete</a>
		    <a class="plink" href="../post?id={{ .Response }}#{{ .Id }}">{{ cGetTitle .Response }}</a>	    
		    <span  class="posted">
			<span title="{{ .Posted.Format "02 Jan 06 15:04" }}">{{ since .Posted }}</span> |
			<a href="{{ $base }}/delete?t=comm&id={{ .Id }}">delete</a>
		    </span>
		    <br/>
		    <p>{{ .Text }}</p>
		</li>

M main.go => main.go +13 -5
@@ 73,8 73,9 @@ const (
                         GROUP BY a.name
                         ORDER BY count(1) DESC
                         LIMIT 10;`
	SE_TAGS = `SELECT name FROM tags WHERE link = ?`
	IN_LINK = `INSERT INTO links (title, url, posted, name)
	SE_TAGS  = `SELECT name FROM tags WHERE link = ?`
	SE_TITLE = `SELECT title FROM links WHERE id = ?`
	IN_LINK  = `INSERT INTO links (title, url, posted, name)
                   values (?, ?, datetime("now"), ?)`
	IN_COMM = `INSERT INTO comments (link, reply, posted, name, content)
                   values (?, ?, datetime("now"), ?, ?)`


@@ 84,9 85,10 @@ const (
)

var (
	tmpl  *template.Template
	db    *sql.DB
	users map[string]User
	tmpl   *template.Template
	db     *sql.DB
	users  map[string]User
	titles map[int]string
)

type User struct {


@@ 175,6 177,12 @@ func init() {
			default: // if posted less than 1m ago
				return "just now"
			}
		}, "cGetTitle": func(id int) string {
			title, err := queryTitle(id)
			if err != nil {
				return "N/A"
			}
			return title
		},
	}).ParseGlob(dir + "/*.gtml"))
}

M util.go => util.go +18 -4
@@ 172,10 172,11 @@ func queryUser(name string, lpage, cpage int) ([]Link, []Comment, error) {
		)
		rows.Scan(&id, &link, &content, &posted)
		comms = append(comms, Comment{
			Id:     id,
			Name:   name,
			Posted: posted,
			Text:   content,
			Id:       id,
			Name:     name,
			Posted:   posted,
			Text:     content,
			Response: link,
		})
	}



@@ 197,3 198,16 @@ func queryTags() ([]string, error) {

	return tags, rows.Err()
}

func queryTitle(id int) (string, error) {
	title, ok := titles[id]
	if ok {
		return title, nil
	}

	row := db.QueryRow(SE_TITLE, id)
	if err := row.Scan(&title); err != nil {
		return "", err
	}
	return title, nil
}