Some pointes mentioned in #63

pull/64/head
Akhil Gupta 4 years ago
parent b492ff91f2
commit 1a2d17c785

@ -188,19 +188,43 @@
<div class="row"> <div class="row">
<div class="columns twelve" style="text-align: center"> <div class="columns twelve" style="text-align: center">
{{if .previousPage }}
<a
href="?page=1&downloadedOnly={{.downloadedOnly}}"
class="button"
>Newest</a
>
{{end}}
{{if .previousPage }} {{if .previousPage }}
<a <a
href="?page={{.previousPage}}&downloadedOnly={{.downloadedOnly}}" href="?page={{.previousPage}}&downloadedOnly={{.downloadedOnly}}"
class="button" class="button"
>Newer</a >Newer</a
> >
{{end}} {{if .nextPage }} {{end}}
<select name="page" id="pageDdl">
{{ $page:=.page }}
{{range $y := intRange 1 .totalPages}}
<option {{if eq $page $y }} selected="selected" {{end}}}>{{$y}}</option>
{{end}}
</select>
{{if .nextPage }}
<a <a
href="?page={{.nextPage}}&downloadedOnly={{.downloadedOnly}}" href="?page={{.nextPage}}&downloadedOnly={{.downloadedOnly}}"
class="button" class="button"
>Older</a >Older</a
> >
{{end}} {{end}}
{{if gt .totalPages .page }}
<a
href="?page={{.totalPages}}&downloadedOnly={{.downloadedOnly}}"
class="button"
>Oldest</a
>
{{end}}
</div> </div>
</div> </div>
</div> </div>
@ -319,6 +343,18 @@
.then(function () {}); .then(function () {});
return false; return false;
} }
document.getElementById('pageDdl').addEventListener('change', function() {
currentPage= {{.page}};
if(parseInt(this.value)===currentPage){
return;
}
var queryParams = new URLSearchParams(window.location.search);
// Set new or modify existing parameter value.
queryParams.set("page", this.value);
window.top.location= window.top.location.origin+window.top.location.pathname+"?"+queryParams.toString();
});
</script> </script>
<script> <script>

@ -474,6 +474,8 @@
case "dateAdded-desc":compareFunction=(a,b)=>Date.parse(b.CreatedAt)-Date.parse(a.CreatedAt);break; case "dateAdded-desc":compareFunction=(a,b)=>Date.parse(b.CreatedAt)-Date.parse(a.CreatedAt);break;
case "lastEpisode-asc":compareFunction=(a,b)=>Date.parse(a.LastEpisode)-Date.parse(b.LastEpisode);break; case "lastEpisode-asc":compareFunction=(a,b)=>Date.parse(a.LastEpisode)-Date.parse(b.LastEpisode);break;
case "lastEpisode-desc":compareFunction=(a,b)=>Date.parse(b.LastEpisode)-Date.parse(a.LastEpisode);break; case "lastEpisode-desc":compareFunction=(a,b)=>Date.parse(b.LastEpisode)-Date.parse(a.LastEpisode);break;
case "episodesCount-asc":compareFunction=(a,b)=>a.AllEpisodesCount-b.AllEpisodesCount;break;
case "episodesCount-desc":compareFunction=(a,b)=>b.AllEpisodesCount-a.AllEpisodesCount;break;
case "name-asc":compareFunction=(a,b)=>{ case "name-asc":compareFunction=(a,b)=>{
var nameA = a.Title.toUpperCase(); // ignore upper and lowercase var nameA = a.Title.toUpperCase(); // ignore upper and lowercase
var nameB = b.Title.toUpperCase(); // ignore upper and lowercase var nameB = b.Title.toUpperCase(); // ignore upper and lowercase
@ -645,6 +647,14 @@
key:"dateAdded-desc", key:"dateAdded-desc",
label:"Date Added (New First)" label:"Date Added (New First)"
}, },
{
key:"episodesCount-asc",
label:"Episodes Count (Asc)"
},
{
key:"episodesCount-desc",
label:"Episodes Count (Desc)"
},
], ],
podcasts:[], podcasts:[],
{{ $len := len .podcasts}} {{ $len := len .podcasts}}

@ -1020,7 +1020,7 @@ div#large-visualization{
}, },
data:{ data:{
speed:1, speed:1,
speedOptions:[0.75,1,1.1,1.25,1.5,1.75,2], speedOptions:[0.75,1,1.1,1.25,1.5,1.75,2,2.5,3],
songLoaded:[], songLoaded:[],
socket:null, socket:null,
allItems: {{ .podcastItems }}, allItems: {{ .podcastItems }},

@ -66,9 +66,9 @@ func PodcastPage(c *gin.Context) {
} }
setting := c.MustGet("setting").(*db.Setting) setting := c.MustGet("setting").(*db.Setting)
totalCount := len(podcast.PodcastItems) totalCount := len(podcast.PodcastItems)
totalPages := math.Ceil(float64(totalCount) / float64(count)) totalPages := int(math.Ceil(float64(totalCount) / float64(count)))
nextPage, previousPage := 0, 0 nextPage, previousPage := 0, 0
if float64(page) < totalPages { if page < totalPages {
nextPage = page + 1 nextPage = page + 1
} }
if page > 1 { if page > 1 {
@ -250,18 +250,23 @@ func AllEpisodesPage(c *gin.Context) {
} }
if err := db.GetPaginatedPodcastItems(page, count, if err := db.GetPaginatedPodcastItems(page, count,
filter.DownloadedOnly, filter.PlayedOnly, fromDate, nil, filter.PlayedOnly, fromDate,
&podcastItems, &totalCount); err == nil { &podcastItems, &totalCount); err == nil {
setting := c.MustGet("setting").(*db.Setting) setting := c.MustGet("setting").(*db.Setting)
totalPages := math.Ceil(float64(totalCount) / float64(count)) totalPages := int(math.Ceil(float64(totalCount) / float64(count)))
nextPage, previousPage := 0, 0 nextPage, previousPage := 0, 0
if float64(page) < totalPages { if page < totalPages {
nextPage = page + 1 nextPage = page + 1
} }
if page > 1 { if page > 1 {
previousPage = page - 1 previousPage = page - 1
} }
downloadedOnly := false
if filter.DownloadedOnly != nil {
downloadedOnly = *filter.DownloadedOnly
fmt.Println(downloadedOnly)
}
toReturn := gin.H{ toReturn := gin.H{
"title": "All Episodes", "title": "All Episodes",
"podcastItems": podcastItems, "podcastItems": podcastItems,
@ -272,7 +277,7 @@ func AllEpisodesPage(c *gin.Context) {
"totalPages": totalPages, "totalPages": totalPages,
"nextPage": nextPage, "nextPage": nextPage,
"previousPage": previousPage, "previousPage": previousPage,
"downloadedOnly": filter.DownloadedOnly, "downloadedOnly": downloadedOnly,
} }
fmt.Printf("%+v\n", totalCount) fmt.Printf("%+v\n", totalCount)
c.HTML(http.StatusOK, "episodes.html", toReturn) c.HTML(http.StatusOK, "episodes.html", toReturn)

@ -51,10 +51,10 @@ func GetPaginatedPodcastItems(page int, count int, downloadedOnly *bool, playedO
query = query.Where("pub_date>=?", fromDate) query = query.Where("pub_date>=?", fromDate)
} }
result := query.Limit(count).Offset((page - 1) * count).Order("pub_date desc").Find(&podcasts) totalsQuery := query.Order("pub_date desc").Find(&podcasts)
totalsQuery.Count(total)
query.Count(total)
result := query.Limit(count).Offset((page - 1) * count).Order("pub_date desc").Find(&podcasts)
return result.Error return result.Error
} }
func GetPaginatedTags(page int, count int, tags *[]Tag, total *int64) error { func GetPaginatedTags(page int, count int, tags *[]Tag, total *int64) error {

@ -34,6 +34,14 @@ func main() {
r.Use(location.Default()) r.Use(location.Default())
funcMap := template.FuncMap{ funcMap := template.FuncMap{
"intRange": func(start, end int) []int {
n := end - start + 1
result := make([]int, n)
for i := 0; i < n; i++ {
result[i] = start + i
}
return result
},
"removeStartingSlash": func(raw string) string { "removeStartingSlash": func(raw string) string {
fmt.Println(raw) fmt.Println(raw)
if string(raw[0]) == "/" { if string(raw[0]) == "/" {

Loading…
Cancel
Save