Added soundtrack drafts

This commit is contained in:
Eduard Urbach 2017-10-15 21:11:12 +02:00
parent e635be5291
commit 68901ac25e
4 changed files with 23 additions and 9 deletions

View File

@ -94,9 +94,10 @@ func RenderField(b *bytes.Buffer, v *reflect.Value, field reflect.StructField, i
if field.Name == "IsDraft" { if field.Name == "IsDraft" {
if fieldValue.Bool() { if fieldValue.Bool() {
b.WriteString(`<div class="buttons"><button class="action" data-action="publish" data-trigger="click">` + utils.Icon("unlock-alt") + `Publish</button></div>`) b.WriteString(`<div class="buttons"><button class="action" data-action="publish" data-trigger="click">` + utils.Icon("unlock-alt") + `Publish</button></div>`)
} else {
b.WriteString(`<div class="buttons"><button class="action" data-action="unpublish" data-trigger="click">` + utils.Icon("lock") + `Unpublish</button></div>`)
} }
// else {
// b.WriteString(`<div class="buttons"><button class="action" data-action="unpublish" data-trigger="click">` + utils.Icon("lock") + `Unpublish</button></div>`)
// }
} }
case "[]*arn.ExternalMedia": case "[]*arn.ExternalMedia":
for sliceIndex := 0; sliceIndex < fieldValue.Len(); sliceIndex++ { for sliceIndex := 0; sliceIndex < fieldValue.Len(); sliceIndex++ {

View File

@ -6,12 +6,15 @@ import (
"github.com/aerogo/aero" "github.com/aerogo/aero"
"github.com/animenotifier/arn" "github.com/animenotifier/arn"
"github.com/animenotifier/notify.moe/components" "github.com/animenotifier/notify.moe/components"
"github.com/animenotifier/notify.moe/utils"
) )
const maxTracks = 9 const maxTracks = 9
// Get renders the soundtracks page. // Get renders the soundtracks page.
func Get(ctx *aero.Context) string { func Get(ctx *aero.Context) string {
user := utils.GetUser(ctx)
tracks, err := arn.FilterSoundTracks(func(track *arn.SoundTrack) bool { tracks, err := arn.FilterSoundTracks(func(track *arn.SoundTrack) bool {
return !track.IsDraft && len(track.Media) > 0 return !track.IsDraft && len(track.Media) > 0
}) })
@ -26,5 +29,5 @@ func Get(ctx *aero.Context) string {
tracks = tracks[:maxTracks] tracks = tracks[:maxTracks]
} }
return ctx.HTML(components.SoundTracks(tracks)) return ctx.HTML(components.SoundTracks(tracks, user))
} }

View File

@ -1,10 +1,16 @@
component SoundTracks(tracks []*arn.SoundTrack) component SoundTracks(tracks []*arn.SoundTrack, user *arn.User)
h1 Soundtracks h1 Soundtracks
.music-buttons .music-buttons
a.button.action(data-action="newSoundTrack", data-trigger="click") if user != nil
Icon("plus") if user.DraftIndex().SoundTrackID == ""
span Add soundtrack button.action(data-action="newSoundTrack", data-trigger="click")
Icon("plus")
span Add soundtrack
else
a.button.ajax(href="/soundtrack/" + user.DraftIndex().SoundTrackID + "/edit")
Icon("pencil")
span Edit draft
.sound-tracks .sound-tracks
each track in tracks each track in tracks

View File

@ -199,7 +199,7 @@ export function createThread(arn: AnimeNotifier) {
export function newSoundTrack(arn: AnimeNotifier, button: HTMLButtonElement) { export function newSoundTrack(arn: AnimeNotifier, button: HTMLButtonElement) {
arn.post("/api/new/soundtrack", "") arn.post("/api/new/soundtrack", "")
.then(response => response.json()) .then(response => response.json())
.then(response => console.log(response)) .then(track => arn.app.load(`/soundtrack/${track.id}/edit`))
.catch(err => arn.statusMessage.showError(err)) .catch(err => arn.statusMessage.showError(err))
} }
@ -208,7 +208,7 @@ export function publish(arn: AnimeNotifier, button: HTMLButtonElement) {
let endpoint = arn.findAPIEndpoint(button) let endpoint = arn.findAPIEndpoint(button)
arn.post(endpoint + "/publish", "") arn.post(endpoint + "/publish", "")
.then(() => arn.reloadContent()) .then(() => arn.app.load(arn.app.currentPath.replace("/edit", "")))
.catch(err => arn.statusMessage.showError(err)) .catch(err => arn.statusMessage.showError(err))
} }
@ -356,6 +356,10 @@ export function arrayAppend(arn: AnimeNotifier, element: HTMLElement) {
// Remove element from array // Remove element from array
export function arrayRemove(arn: AnimeNotifier, element: HTMLElement) { export function arrayRemove(arn: AnimeNotifier, element: HTMLElement) {
if(!confirm("Are you sure you want to remove this element?")) {
return
}
let field = element.dataset.field let field = element.dataset.field
let index = element.dataset.index let index = element.dataset.index
let apiEndpoint = arn.findAPIEndpoint(element) let apiEndpoint = arn.findAPIEndpoint(element)