Started working on job UI implementation

This commit is contained in:
Eduard Urbach 2018-04-28 19:44:44 +02:00
parent 3983894a27
commit 59633707c1
6 changed files with 61 additions and 1 deletions

View File

@ -33,6 +33,7 @@ component Editor(url string, score int, scoreTitle string, scoreTypes map[string
.footer.mountable .footer.mountable
a.footer-element(href="/editor/mal/diff/anime" + user.Settings().Editor.Filter.Suffix()) MALdiff a.footer-element(href="/editor/mal/diff/anime" + user.Settings().Editor.Filter.Suffix()) MALdiff
a.footer-element(href="/editor/kitsu/new/anime") Kitsu a.footer-element(href="/editor/kitsu/new/anime") Kitsu
a.footer-element(href="/editor/jobs") Jobs
if user.Role == "admin" if user.Role == "admin"
a.footer-element(href="/admin") Admin a.footer-element(href="/admin") Admin

17
pages/editor/jobs/jobs.go Normal file
View File

@ -0,0 +1,17 @@
package jobs
import (
"github.com/aerogo/aero"
"github.com/animenotifier/notify.moe/components"
"github.com/animenotifier/notify.moe/utils"
)
var running = map[string]bool{}
var lastRun = map[string]string{}
// Overview shows all background jobs.
func Overview(ctx *aero.Context) string {
user := utils.GetUser(ctx)
return ctx.HTML(components.EditorJobs(running, lastRun, ctx.URI(), user))
}

View File

@ -0,0 +1,9 @@
component EditorJobs(running bool, url string, user *arn.User)
EditorTabs(url, user)
h1.editor-list-page-title.mountable Background jobs
.buttons
button.mountable.action(data-action="startJob", data-trigger="click", data-job="twist", disabled=running)
Icon("rocket")
span twist

View File

@ -9,6 +9,7 @@ import (
"github.com/animenotifier/notify.moe/pages/editor/filteranime" "github.com/animenotifier/notify.moe/pages/editor/filteranime"
"github.com/animenotifier/notify.moe/pages/editor/filtercompanies" "github.com/animenotifier/notify.moe/pages/editor/filtercompanies"
"github.com/animenotifier/notify.moe/pages/editor/filtersoundtracks" "github.com/animenotifier/notify.moe/pages/editor/filtersoundtracks"
"github.com/animenotifier/notify.moe/pages/editor/jobs"
) )
// Register registers the page routes. // Register registers the page routes.
@ -62,6 +63,9 @@ func Register(l *layout.Layout) {
l.Page("/editor/soundtracks/tags", filtersoundtracks.Tags) l.Page("/editor/soundtracks/tags", filtersoundtracks.Tags)
l.Page("/editor/soundtracks/file", filtersoundtracks.File) l.Page("/editor/soundtracks/file", filtersoundtracks.File)
// Editor - Jobs
l.Page("/editor/jobs", jobs.Overview)
// Log // Log
l.Page("/log", editlog.Get) l.Page("/log", editlog.Get)
l.Page("/log/from/:index", editlog.Get) l.Page("/log/from/:index", editlog.Get)

View File

@ -71,3 +71,16 @@ export async function multiSearchAnime(arn: AnimeNotifier, textarea: HTMLTextAre
results.classList.remove("hidden") results.classList.remove("hidden")
showSearchResults(arn, results) showSearchResults(arn, results)
} }
// Start background job
export async function startJob(arn: AnimeNotifier, button: HTMLButtonElement) {
let jobName = button.dataset.job
if(!confirm(`Are you sure you want to start the "${jobName}" job?`)) {
return
}
await arn.post(`/api/job/${jobName}/start`)
arn.reloadContent()
}

16
utils/JobInfo.go Normal file
View File

@ -0,0 +1,16 @@
package utils
import "time"
// JobInfo gives you information about a background job.
type JobInfo struct {
Name string
LastStarted time.Time
LastFinished time.Time
}
// IsRunning tells you whether the given job is running or not.
func (job *JobInfo) IsRunning() bool {
now := time.Now()
return job.LastStarted.After(job.LastFinished) && !now.After(job.LastFinished)
}