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="columns twelve" style="text-align: center">
{{if .previousPage }}
<a
href="?page=1&downloadedOnly={{.downloadedOnly}}"
class="button"
>Newest</a
>
{{end}}
{{if .previousPage }}
<a
href="?page={{.previousPage}}&downloadedOnly={{.downloadedOnly}}"
class="button"
>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
href="?page={{.nextPage}}&downloadedOnly={{.downloadedOnly}}"
class="button"
>Older</a
>
{{end}}
{{if gt .totalPages .page }}
<a
href="?page={{.totalPages}}&downloadedOnly={{.downloadedOnly}}"
class="button"
>Oldest</a
>
{{end}}
</div>
</div>
</div>
@ -319,6 +343,18 @@
.then(function () {});
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>

@ -474,6 +474,8 @@
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-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)=>{
var nameA = a.Title.toUpperCase(); // ignore upper and lowercase
var nameB = b.Title.toUpperCase(); // ignore upper and lowercase
@ -645,6 +647,14 @@
key:"dateAdded-desc",
label:"Date Added (New First)"
},
{
key:"episodesCount-asc",
label:"Episodes Count (Asc)"
},
{
key:"episodesCount-desc",
label:"Episodes Count (Desc)"
},
],
podcasts:[],
{{ $len := len .podcasts}}

@ -1020,7 +1020,7 @@ div#large-visualization{
},
data:{
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:[],
socket:null,
allItems: {{ .podcastItems }},

@ -66,9 +66,9 @@ func PodcastPage(c *gin.Context) {
}
setting := c.MustGet("setting").(*db.Setting)
totalCount := len(podcast.PodcastItems)
totalPages := math.Ceil(float64(totalCount) / float64(count))
totalPages := int(math.Ceil(float64(totalCount) / float64(count)))
nextPage, previousPage := 0, 0
if float64(page) < totalPages {
if page < totalPages {
nextPage = page + 1
}
if page > 1 {
@ -250,18 +250,23 @@ func AllEpisodesPage(c *gin.Context) {
}
if err := db.GetPaginatedPodcastItems(page, count,
filter.DownloadedOnly, filter.PlayedOnly, fromDate,
nil, filter.PlayedOnly, fromDate,
&podcastItems, &totalCount); err == nil {
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
if float64(page) < totalPages {
if page < totalPages {
nextPage = page + 1
}
if page > 1 {
previousPage = page - 1
}
downloadedOnly := false
if filter.DownloadedOnly != nil {
downloadedOnly = *filter.DownloadedOnly
fmt.Println(downloadedOnly)
}
toReturn := gin.H{
"title": "All Episodes",
"podcastItems": podcastItems,
@ -272,7 +277,7 @@ func AllEpisodesPage(c *gin.Context) {
"totalPages": totalPages,
"nextPage": nextPage,
"previousPage": previousPage,
"downloadedOnly": filter.DownloadedOnly,
"downloadedOnly": downloadedOnly,
}
fmt.Printf("%+v\n", totalCount)
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)
}
result := query.Limit(count).Offset((page - 1) * count).Order("pub_date desc").Find(&podcasts)
query.Count(total)
totalsQuery := query.Order("pub_date desc").Find(&podcasts)
totalsQuery.Count(total)
result := query.Limit(count).Offset((page - 1) * count).Order("pub_date desc").Find(&podcasts)
return result.Error
}
func GetPaginatedTags(page int, count int, tags *[]Tag, total *int64) error {

@ -34,6 +34,14 @@ func main() {
r.Use(location.Default())
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 {
fmt.Println(raw)
if string(raw[0]) == "/" {

Loading…
Cancel
Save