add last scan time to ui
This commit is contained in:
@@ -81,6 +81,13 @@
|
||||
{{ end }}
|
||||
</table>
|
||||
<a href="/admin/start_scan_do">start scan</a>
|
||||
{{ if not .LastScanTime.IsZero }}
|
||||
<br>
|
||||
<span class="light">
|
||||
last completed:
|
||||
<a title="{{ .LastScanTime }}">{{ .LastScanTime | humanDate }}</a>
|
||||
</span>
|
||||
{{ end }}
|
||||
</div>
|
||||
</div>
|
||||
{{ end }}
|
||||
|
||||
@@ -4,6 +4,8 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/sessions"
|
||||
"github.com/jinzhu/gorm"
|
||||
@@ -51,16 +53,13 @@ func (c *Controller) ServeLogout(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
func (c *Controller) ServeHome(w http.ResponseWriter, r *http.Request) {
|
||||
data := &templateData{}
|
||||
//
|
||||
// stats box
|
||||
c.DB.Table("artists").Count(&data.ArtistCount)
|
||||
c.DB.Table("albums").Count(&data.AlbumCount)
|
||||
c.DB.Table("tracks").Count(&data.TrackCount)
|
||||
c.DB.Find(&data.AllUsers)
|
||||
c.DB.
|
||||
Where("tag_artist_id IS NOT NULL").
|
||||
Order("updated_at DESC").
|
||||
Limit(8).
|
||||
Find(&data.RecentFolders)
|
||||
data.CurrentLastFMAPIKey = c.DB.GetSetting("lastfm_api_key")
|
||||
//
|
||||
// lastfm box
|
||||
scheme := firstExisting(
|
||||
"http", // fallback
|
||||
r.Header.Get("X-Forwarded-Proto"),
|
||||
@@ -73,6 +72,20 @@ func (c *Controller) ServeHome(w http.ResponseWriter, r *http.Request) {
|
||||
r.Host,
|
||||
)
|
||||
data.RequestRoot = fmt.Sprintf("%s://%s", scheme, host)
|
||||
data.CurrentLastFMAPIKey = c.DB.GetSetting("lastfm_api_key")
|
||||
if tStr := c.DB.GetSetting("last_scan_time"); tStr != "" {
|
||||
i, _ := strconv.ParseInt(tStr, 10, 64)
|
||||
data.LastScanTime = time.Unix(i, 0)
|
||||
}
|
||||
c.DB.Find(&data.AllUsers)
|
||||
//
|
||||
// recent folders box
|
||||
c.DB.
|
||||
Where("tag_artist_id IS NOT NULL").
|
||||
Order("updated_at DESC").
|
||||
Limit(8).
|
||||
Find(&data.RecentFolders)
|
||||
//
|
||||
renderTemplate(w, r, c.Templates["home.tmpl"], data)
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"html/template"
|
||||
"log"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/sessions"
|
||||
|
||||
@@ -21,6 +22,7 @@ type templateData struct {
|
||||
RequestRoot string
|
||||
RecentFolders []*model.Album
|
||||
AllUsers []*model.User
|
||||
LastScanTime time.Time
|
||||
//
|
||||
CurrentLastFMAPIKey string
|
||||
CurrentLastFMAPISecret string
|
||||
@@ -39,7 +41,7 @@ func renderTemplate(
|
||||
session := r.Context().Value(contextSessionKey).(*sessions.Session)
|
||||
data.Flashes = session.Flashes()
|
||||
sessionLogSave(w, r, session)
|
||||
data.User = r.Context().Value(contextUserKey).(*model.User)
|
||||
data.User, _ = r.Context().Value(contextUserKey).(*model.User)
|
||||
err := tmpl.Execute(w, data)
|
||||
if err != nil {
|
||||
log.Printf("error executing template: %v\n", err)
|
||||
|
||||
Reference in New Issue
Block a user