Clean up a bit the add book to list interface
This commit is contained in:
parent
11195e258b
commit
a40b5ac534
2 changed files with 17 additions and 6 deletions
|
@ -106,25 +106,26 @@ func (db *pgDB) GetListsByBook(bookID string) ([]BookList, error) {
|
|||
var bookListEntries []BookListEntry
|
||||
|
||||
err := db.sql.Model(&bookListEntries).
|
||||
Column("BookList").
|
||||
Where("book_id = ?", bookID).
|
||||
Select()
|
||||
if err != nil || len(bookListEntries) == 0 {
|
||||
return bookLists, err
|
||||
}
|
||||
|
||||
whereQuery := "id IN ("
|
||||
whereQuery := `list_id IN (`
|
||||
listIDs := make([]interface{}, len(bookListEntries))
|
||||
for i, entry := range bookListEntries {
|
||||
whereQuery += "?"
|
||||
if i < len(bookListEntries)-1 {
|
||||
whereQuery += ", "
|
||||
}
|
||||
listIDs[i] = entry.ID
|
||||
listIDs[i] = entry.BookList.ListID
|
||||
}
|
||||
whereQuery += ")"
|
||||
|
||||
err = db.sql.Model(&bookLists).
|
||||
Column("Books").
|
||||
Column("Books", "User").
|
||||
Where(whereQuery, listIDs...).
|
||||
Select()
|
||||
return bookLists, err
|
||||
|
|
|
@ -78,23 +78,33 @@ function delBook(){
|
|||
|
||||
{{if .Lists}}
|
||||
<br />
|
||||
<div class="row">
|
||||
<div class="span10 offset1">
|
||||
<h4>Book in lists:</h4>
|
||||
<ul class="nav nav-tabs nav-stacked">
|
||||
{{range .Lists}}
|
||||
<li><a href="/list/{{.ListID}}">{{.Title}} ({{len .Books}})</a></li>
|
||||
<li><a href="/list/{{.ListID}}">{{.Title}} ({{len .Books}})
|
||||
<span class="pull-right">By {{.User.Username}}</span></a>
|
||||
</li>
|
||||
{{end}}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
{{else}}
|
||||
<br />
|
||||
{{end}}
|
||||
|
||||
{{if .S.User}}
|
||||
<br />
|
||||
<form class="span6 offset3 form-inline" method="POST" action="/list/">
|
||||
<div class="row">
|
||||
<h5 class="offset1 span2">Add book to a list:</h5>
|
||||
<form class="form-inline" method="POST" action="/list/">
|
||||
<input type="hidden" id="book_id" name="book_id" value="{{.Book.ID}}">
|
||||
<div class="input-append">
|
||||
<input type="text" data-provide="typeahead" id="list" name="list">
|
||||
<button type="submit" class="btn btn-primary">Add to list</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
$(window).load(function() {
|
||||
|
|
Reference in a new issue