Show functional Updates page when checks are disabled

Ref T572
This commit is contained in:
Matt Baer 2020-02-15 12:19:06 -05:00
parent a06bb457de
commit 389dc8b9db
3 changed files with 17 additions and 1 deletions

View file

@ -583,6 +583,7 @@ func handleViewAdminUpdates(app *App, u *User, w http.ResponseWriter, r *http.Re
p := struct { p := struct {
*UserPage *UserPage
CurReleaseNotesURL string
LastChecked string LastChecked string
LastChecked8601 string LastChecked8601 string
LatestVersion string LatestVersion string
@ -592,6 +593,7 @@ func handleViewAdminUpdates(app *App, u *User, w http.ResponseWriter, r *http.Re
}{ }{
UserPage: NewUserPage(app, r, u, "Updates", nil), UserPage: NewUserPage(app, r, u, "Updates", nil),
} }
p.CurReleaseNotesURL = wfReleaseNotesURL(p.Version)
if app.cfg.App.UpdateChecks { if app.cfg.App.UpdateChecks {
p.LastChecked = app.updates.lastCheck.Format("January 2, 2006, 3:04 PM") p.LastChecked = app.updates.lastCheck.Format("January 2, 2006, 3:04 PM")
p.LastChecked8601 = app.updates.lastCheck.Format("2006-01-02T15:04:05Z") p.LastChecked8601 = app.updates.lastCheck.Format("2006-01-02T15:04:05Z")

View file

@ -5,11 +5,16 @@
p.intro { p.intro {
text-align: left; text-align: left;
} }
p.disabled {
font-style: italic;
color: #999;
}
</style> </style>
<div class="content-container snug"> <div class="content-container snug">
{{template "admin-header" .}} {{template "admin-header" .}}
{{ if .UpdateChecks }}
{{if not .UpdateAvailable}} {{if not .UpdateAvailable}}
<p class="intro"><span class="check">&check;</span> WriteFreely is <strong>up to date</strong>.</p> <p class="intro"><span class="check">&check;</span> WriteFreely is <strong>up to date</strong>.</p>
<p>Installed version: <strong>{{.Version}}</strong> (<a href="{{.LatestReleaseNotesURL}}" target="changelog-wf">release notes</a>).</p> <p>Installed version: <strong>{{.Version}}</strong> (<a href="{{.LatestReleaseNotesURL}}" target="changelog-wf">release notes</a>).</p>
@ -27,6 +32,11 @@
var d = new Date(displayEl.getAttribute("datetime")); var d = new Date(displayEl.getAttribute("datetime"));
displayEl.textContent = d.toLocaleDateString(navigator.language || "en-US", { dateStyle: 'long', timeStyle: 'short' }); displayEl.textContent = d.toLocaleDateString(navigator.language || "en-US", { dateStyle: 'long', timeStyle: 'short' });
</script> </script>
{{ else }}
<p class="intro disabled">Automated update checks are disabled.</p>
<p>Installed version: <strong>{{.Version}}</strong> (<a href="{{.CurReleaseNotesURL}}" target="changelog-wf">release notes</a>).</p>
<p>Learn about latest releases on the <a href="https://blog.writefreely.org/tag:release" target="changelog-wf">WriteFreely blog</a> or <a href="https://discuss.write.as/c/writefreely/updates" target="forum-wf">forum</a>.</p>
{{ end }}
{{template "footer" .}} {{template "footer" .}}

View file

@ -70,7 +70,11 @@ func (uc updatesCache) ReleaseURL() string {
// ReleaseNotesURL returns the full URL to the blog.writefreely.org release notes // ReleaseNotesURL returns the full URL to the blog.writefreely.org release notes
// for the latest version as stored in the cache. // for the latest version as stored in the cache.
func (uc updatesCache) ReleaseNotesURL() string { func (uc updatesCache) ReleaseNotesURL() string {
ver := strings.TrimPrefix(uc.latestVersion, "v") return wfReleaseNotesURL(uc.latestVersion)
}
func wfReleaseNotesURL(v string) string {
ver := strings.TrimPrefix(v, "v")
ver = strings.TrimSuffix(ver, ".0") ver = strings.TrimSuffix(ver, ".0")
// hack until go 1.12 in build/travis // hack until go 1.12 in build/travis
seg := strings.Split(ver, ".") seg := strings.Split(ver, ".")