UI overhaul

pull/24/head
Akhil Gupta 4 years ago
parent 4b329e0a04
commit 55916d584d

@ -42,7 +42,7 @@ hr{
<div class="container">
<section class="header">
<h1>{{ .title }}</h1>
<h1>{{ .title }} ({{ .totalCount }})</h1>
</section>
{{template "navbar"}}
<br>{{$setting := .setting}}
@ -54,8 +54,19 @@ hr{
<img class="u-full-width" src="{{ .Image }}" alt="{{ .Title }}">
</div>
<div class="columns ten">
<h4>{{.Title}} // {{ .Podcast.Title}}</h4>
<small>{{ formatDate .PubDate }}</small>
<div class="row">
<div class="columns nine">
<h4>{{.Title}} // {{ .Podcast.Title}}</h4>
</div>
<div class="columns two">
<small>{{ formatDate .PubDate }}</small>
</div>
<div class="columns one">
<small> {{ formatDuration .Duration}}</small>
</div>
</div>
<p>{{ .Summary }}</p>
{{if .DownloadPath}}
<a class="button button-primary" href="{{ .DownloadPath }}" download>Download</a>
@ -72,7 +83,19 @@ hr{
</div>
<hr>
{{end}}
<div class="row"><div class="columns twelve" style="text-align: center;">
{{if .previousPage }}
<a href="?page={{.previousPage}}" class="button button-primary">Previous Page</a>
{{end}}
{{if .nextPage }}
<a href="?page={{.nextPage}}" class="button button-primary">Next Page</a>
{{end}}
</div></div>
</div>
{{template "scripts"}}
<script>
function downloadToDisk(id){

@ -11,6 +11,15 @@
background-color: indianred;
color:wheat;
}
img{
display: none;
}
/* Larger than tablet */
@media (min-width: 750px) {
img{
display: block
}
}
</style>
</head>
<body>

@ -2,6 +2,7 @@ package controllers
import (
"fmt"
"math"
"net/http"
"strconv"
@ -51,10 +52,28 @@ func AllEpisodesPage(c *gin.Context) {
count = 10
}
var podcastItems []db.PodcastItem
if err := db.GetPaginatedPodcastItems(page, count, &podcastItems); err == nil {
var totalCount int64
if err := db.GetPaginatedPodcastItems(page, count, &podcastItems, &totalCount); err == nil {
setting := c.MustGet("setting").(*db.Setting)
c.HTML(http.StatusOK, "episodes.html", gin.H{"title": "All Episodes", "podcastItems": podcastItems, "setting": setting})
totalPages := math.Ceil(float64(totalCount) / float64(count))
nextPage, previousPage := 0, 0
if float64(page) < totalPages {
nextPage = page + 1
}
if page > 1 {
previousPage = page - 1
}
c.HTML(http.StatusOK, "episodes.html", gin.H{
"title": "All Episodes",
"podcastItems": podcastItems,
"setting": setting,
"page": page,
"count": count,
"totalCount": totalCount,
"totalPages": totalPages,
"nextPage": nextPage,
"previousPage": previousPage,
})
} else {
c.JSON(http.StatusBadRequest, err)
}

@ -27,8 +27,11 @@ func GetAllPodcastItems(podcasts *[]PodcastItem) error {
result := DB.Preload("Podcast").Order("pub_date desc").Find(&podcasts)
return result.Error
}
func GetPaginatedPodcastItems(page int, count int, podcasts *[]PodcastItem) error {
func GetPaginatedPodcastItems(page int, count int, podcasts *[]PodcastItem, total *int64) error {
result := DB.Debug().Preload("Podcast").Limit(count).Offset((page - 1) * count).Order("pub_date desc").Find(&podcasts)
DB.Model(&PodcastItem{}).Count(total)
return result.Error
}
func GetPodcastById(id string, podcast *Podcast) error {

@ -46,6 +46,22 @@ func main() {
}
return latest.Format("Jan 2 2006")
},
"formatDuration": func(total int) string {
if total <= 0 {
return ""
}
mins := total / 60
secs := total % 60
hrs := 0
if mins >= 60 {
hrs = mins / 60
mins = mins % 60
}
if hrs > 0 {
return fmt.Sprintf("%02d:%02d:%02d", hrs, mins, secs)
}
return fmt.Sprintf("%02d:%02d", mins, secs)
},
}
tmpl := template.Must(template.New("main").Funcs(funcMap).ParseGlob("client/*"))

Loading…
Cancel
Save