Skip to content
This repository has been archived by the owner on Jun 27, 2020. It is now read-only.

Refactor server code #84

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions booklist/authorlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ package booklist

import "sort"

type AuthorList []struct{ Name, ID string }
type AuthorList []Author

type Author struct {
Name, ID string
}

func (bl BookList) Authors() *AuthorList {
authors := AuthorList{}
Expand All @@ -15,13 +19,19 @@ func (bl BookList) Authors() *AuthorList {
if done[b.AuthorID()] {
continue
}
authors = append(authors, struct{ Name, ID string }{b.Author, b.AuthorID()})
authors = append(authors, Author{b.Author, b.AuthorID()})
done[b.AuthorID()] = true
}
return &authors
}

func (al AuthorList) Sorted(less func(a, b struct{ Name, ID string }) bool) AuthorList {
func (bl BookList) ByAuthor(a Author) BookList {
return bl.Filtered(func(b *Book) bool {
return b.AuthorID() == a.ID
})
}

func (al AuthorList) Sorted(less func(a, b Author) bool) AuthorList {
nal := al[:]
sort.SliceStable(nal, func(i, j int) bool {
return less(al[i], al[j])
Expand Down
16 changes: 13 additions & 3 deletions booklist/serieslist.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ package booklist

import "sort"

type SeriesList []struct{ Name, ID string }
type SeriesList []Series

type Series struct {
Name, ID string
}

func (bl BookList) Series() *SeriesList {
series := SeriesList{}
Expand All @@ -15,13 +19,19 @@ func (bl BookList) Series() *SeriesList {
if done[b.SeriesID()] {
continue
}
series = append(series, struct{ Name, ID string }{b.Series, b.SeriesID()})
series = append(series, Series{b.Series, b.SeriesID()})
done[b.SeriesID()] = true
}
return &series
}

func (sl SeriesList) Sorted(less func(a, b struct{ Name, ID string }) bool) SeriesList {
func (bl BookList) BySeries(s Series) BookList {
return bl.Filtered(func(b *Book) bool {
return b.SeriesID() == s.ID
})
}

func (sl SeriesList) Sorted(less func(a, b Series) bool) SeriesList {
nsl := sl[:]
sort.SliceStable(nsl, func(i, j int) bool {
return less(sl[i], sl[j])
Expand Down
6 changes: 3 additions & 3 deletions public/public-packr.go

Large diffs are not rendered by default.

214 changes: 57 additions & 157 deletions public/static/style.css
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
@import url('https://cdnjs.cloudflare.com/ajax/libs/normalize/7.0.0/normalize.min.css');
@import url('https://fonts.googleapis.com/css?family=Nunito:200,200i,300,300i,400,400i,600,600i,700,700i');
@import url('https://fonts.googleapis.com/css?family=PT+Sans:200,200i,300,300i,400,400i,600,600i,700,700i');
@import url('https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css');

* {
box-sizing: border-box;
}

html {
font-family: Nunito, Lato, 'Open Sans', sans-serif;
font-family: PT Sans, Lato, 'Open Sans', sans-serif;
background: #eee;
}

Expand Down Expand Up @@ -144,201 +144,101 @@ h1.title {
font-weight: 300;
}

.books.cards {
.books {
display: flex;
flex-direction: row;
flex-wrap: wrap;
align-items: stretch;
margin: 10px auto;
justify-content: center;
padding: 5px;
padding: 8px;
}

.books.cards .book {
.books .book {
display: flex;
flex-direction: column;
justify-content: space-between;
align-items: stretch;
flex: 0 0 150px;
width: 150px;
min-width: 150px;
max-width: 150px;
overflow: hidden;
margin: 20px 15px;
border: 1px solid #d3d3d3;
box-shadow: 0 1px 6px rgba(0, 0, 0, 0.07);
border-radius: 2px;
margin: 8px;
}

.books.cards .book:hover {
border: 1px solid #b0b0b0;
box-shadow: 0 1px 6px rgba(0, 0, 0, 0.09);
}

.books.cards .book .cover {
.books .book .cover {
display: block;
flex: 0 0 auto;
max-width: 100%;
background: #ddd;
}

.books.cards .book .cover img {
.books .book .cover img {
display: block;
margin: 0 auto;
max-width: 100%;
max-height: 100%;
}

.books.cards .book .meta {
display: block;
padding: 2px 5px;
.books .book:hover .cover {
filter: brightness(80%);
}

.books.cards .book .meta .title {
display: block;
font-weight: bold;
font-size: 14px;
color: inherit;
text-decoration: none;
width: 100%;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
-o-text-overflow: ellipsis;
-webkit-text-overflow: ellipsis;
margin-bottom: 2px;
.books .book .meta {
display: flex;
flex-direction: column;
justify-content: center;
align-items: stretch;
flex: 1;
padding: 4px 8px;
background: #eaeaea;
min-width: 0px;
}

.books.cards .book .meta .author {
display: block;
color: inherit;
font-size: 12px;
text-decoration: none;
width: 100%;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
-o-text-overflow: ellipsis;
-webkit-text-overflow: ellipsis;
margin-bottom: 3px;
.books .book:hover .meta {
background: #e1e1e1;
}

.books.cards .book .meta .series {
.books .book .meta .title,
.books .book .meta .author,
.books .book .meta .series,
.books .book .meta .title:link,
.books .book .meta .author:link,
.books .book .meta .series:link,
.books .book .meta .title:visited,
.books .book .meta .author:visited,
.books .book .meta .series:visited {
display: block;
font-size: 12px;
color: inherit;
text-decoration: none;
width: 100%;
white-space: nowrap;
/*overflow: hidden;*/
text-overflow: ellipsis;
-o-text-overflow: ellipsis;
-webkit-text-overflow: ellipsis;
text-transform: uppercase;
}

.books.cards .book .meta .series .name {
display: inline-block;
color: inherit;
text-decoration: none;
}

.books.cards .book .meta .series .index {
display: inline-block;
flex: 0 0 auto;
color: inherit;
text-decoration: none;
}

.books.list {
display: block;
margin: 10px 5px;
}

.books.list .book {
display: flex;
flex-direction: row;
justify-content: flex-start;
border-bottom: 1px solid rgba(0, 0, 0, .15);
margin: 0 5px;
padding: 10px 5px;
padding-bottom: 5px;
/**/
margin: 10px 5px;
border: 1px solid #d3d3d3;
box-shadow: 0 1px 6px rgba(0, 0, 0, 0.07);
border-radius: 2px;
}

.books.list .book:hover {
/*background: rgba(0,0,0,.05);*/
border: 1px solid #b0b0b0;
box-shadow: 0 1px 6px rgba(0, 0, 0, 0.09);
}

.books.list .book .cover {
flex: 0 0 45px;
}

.books.list .book .cover img {
min-width: 0px;
max-width: 100%;
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
}

.books.list .book .meta {
flex: 1;
padding: 4px 10px;
}

.books.list .book .meta .title {
display: block;
.books .book .meta .title {
font-weight: bold;
font-size: 14px;
color: inherit;
text-decoration: none;
width: 100%;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
-o-text-overflow: ellipsis;
-webkit-text-overflow: ellipsis;
margin-bottom: 2px;
}

.books.list .book .meta .author {
display: block;
color: inherit;
font-size: 12px;
text-decoration: none;
width: 100%;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
-o-text-overflow: ellipsis;
-webkit-text-overflow: ellipsis;
margin-bottom: 3px;
}

.books.list .book .meta .series {
display: block;
.books .book .meta .author,
.books .book .meta .series {
font-size: 12px;
color: inherit;
text-decoration: none;
width: 100%;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
-o-text-overflow: ellipsis;
-webkit-text-overflow: ellipsis;
text-transform: uppercase;
}

.books.list .book .meta .series .name {
display: inline-block;
color: inherit;
text-decoration: none;
}

.books.list .book .meta .series .index {
display: inline-block;
color: inherit;
text-decoration: none;
.books.list .book {
flex-direction: row;
flex: 1;
height: 80px;
min-height: 80px;
max-height: 80px;
width: auto;
min-width: 250px;
max-width: 100%;
}

@media only screen and (max-width: 600px) {
.books.cards .book {
margin: 7px;
}
.books.list .book .cover {
flex: 0 0 60px;
}

.items.cards {
Expand Down
8 changes: 3 additions & 5 deletions public/templates/books.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
{{if .Author}}
<a href="/authors/{{.AuthorID}}" class="author">{{.Author}}</a>
{{end}} {{if .Series}}
<div class="series">
<a href="/series/{{.SeriesID}}" class="name">{{.Series}}</a>
-
<span class="index">{{.SeriesIndex}}</span>
</div>
<a href="/series/{{.SeriesID}}" class="series">
{{.Series}} - {{.SeriesIndex}}
</a>
{{end}}
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ func (s *Server) handleAuthors(w http.ResponseWriter, r *http.Request, _ httprou
"ShowSearch": false,
"ShowViewSelector": true,
"Title": "Authors",
"Authors": s.Indexer.BookList().Authors().Sorted(func(a, b struct{ Name, ID string }) bool {
"Authors": s.Indexer.BookList().Authors().Sorted(func(a, b booklist.Author) bool {
return a.Name < b.Name
}),
})
Expand Down Expand Up @@ -357,7 +357,7 @@ func (s *Server) handleSeriess(w http.ResponseWriter, r *http.Request, _ httprou
"ShowSearch": false,
"ShowViewSelector": true,
"Title": "Series",
"Series": s.Indexer.BookList().Series().Sorted(func(a, b struct{ Name, ID string }) bool {
"Series": s.Indexer.BookList().Series().Sorted(func(a, b booklist.Series) bool {
return a.Name < b.Name
}),
})
Expand Down