diff --git a/admin/index.html b/admin/index.html deleted file mode 100644 index b2222b7..0000000 --- a/admin/index.html +++ /dev/null @@ -1,35 +0,0 @@ - - -
- - - - -%s - %s
\n", item.Title, elem.Artist) - if elem.Cover != ""{ - item.Description = fmt.Sprintf("%s\n", item.Description, elem.Cover) - } - - if elem.Linkto != "" { - item.Link = &feeds.Link{ Href: elem.Linkto } - } else { - item.Link = &feeds.Link{ Href: "https://danoloan.es/muse" } - } - - feed.Items = append(feed.Items, item) - } - } - - return -} - -func ListController(c echo.Context) (res error) { - var err error - var oval, nval int - - oval, err = strconv.Atoi(c.QueryParam("o")) - if err != nil { - oval = 0 - } - - nval, err = strconv.Atoi(c.QueryParam("n")) - if err != nil { - nval = 0 - } - - slice, err := list.readSliceList(oval, nval) - if err == nil { - res = c.JSON(http.StatusOK, slice) - } else { - response := Response{ false, "Error fetching song list" } - res = c.JSON(http.StatusInternalServerError, response) - } - - return -} - -func AddController(c echo.Context) (error) { +func AddController(c echo.Context) error { var res Response var status int var err error - entry := new(Entry) + entry := new(storage.Entry) if err = c.Bind(entry); err != nil { - res = Response{ false, err.Error() } + res = Response{false, err.Error()} status = http.StatusBadRequest - } else if err = list.addEntry(entry); err != nil { - res = Response{ false, "Failed to write into list" } + } else if err = list.AddEntry(entry); err != nil { + res = Response{false, "Failed to write into list"} status = http.StatusInternalServerError } else { - res = Response{ true, "OK" } + res = Response{true, "OK"} status = http.StatusOK } return c.JSON(status, res) } -func DelController(c echo.Context) (error) { +func DelController(c echo.Context) error { var res Response var status int var pos int pos, err := strconv.Atoi(c.QueryParam("p")) if err == nil { - err = list.deleteElement(pos) + err = list.DeleteElement(pos) } if err == nil { - res = Response{ true, "OK" } + res = Response{true, "OK"} status = http.StatusOK } else { - res = Response{ false, "Failed to delete from list" } + res = Response{false, "Failed to delete from list"} status = http.StatusInternalServerError } @@ -292,7 +102,7 @@ func auth(username, password string, c echo.Context) (bool, error) { } func RSSController(c echo.Context) (err error) { - if blob, err := list.getFeed().ToRss(); err == nil { + if blob, err := list.GetFeed().ToRss(); err == nil { c.Blob(http.StatusOK, "application/xml", []byte(blob)) } return @@ -301,16 +111,19 @@ func RSSController(c echo.Context) (err error) { func main() { e := echo.New() - e.GET("/list", ListController) + e.Renderer = &TemplateRenderer{ + template: template.Must(template.ParseGlob("templates/*.html")), + } + e.GET("/", Template("index.html").TemplateController) e.GET("/rss", RSSController) - e.Static("/", "index.html") + e.Static("/static", "static") admin := e.Group("/admin", middleware.BasicAuth(auth)) admin.POST("/add", AddController) admin.GET("/del", DelController) - admin.Static("/", "admin/index.html") + admin.GET("/", Template("admin.html").TemplateController) admin.Static("/static", "admin/static") e.Logger.Fatal(e.Start(":30303")) diff --git a/static/admin.css b/static/admin.css index 7ce8032..ed1559c 100644 --- a/static/admin.css +++ b/static/admin.css @@ -1,3 +1,7 @@ +* { + max-width: inherit; +} + input { width: 100%; box-sizing: border-box; @@ -17,17 +21,6 @@ footer > a { display: inline-block; } -.action { - padding: 20px; -} -.action[result]::after { - content: attr(result); - display: block; - padding-top: 1em; - text-align: center; - font-size: 0.75em; -} - .action-wrap { margin: 0.5em auto; border-radius: 6px; @@ -61,11 +54,41 @@ footer > a { overflow: auto; } -.cajetin { +/* Dropdown */ +button.dropdown { width: 100%; display: block; padding: 0.5em; } +button.dropdown { + padding: 0; +} +button.dropdown > input[type=checkbox] { + display: none; +} +button.dropdown > label { + padding: 0.5em; + display: block; + cursor: pointer; +} +button.dropdown:has(input[type=checkbox]:checked) ~ .action { + max-height: 50vh; + padding: 20px; +} + +.action { + max-height: 0; + padding: 0; + transition: max-height 0.2s linear; +} + +.action[result]::after { + content: attr(result); + display: block; + padding-top: 1em; + text-align: center; + font-size: 0.75em; +} .data-elem { display: block; diff --git a/static/style.css b/static/style.css index 6c4deae..5689e82 100644 --- a/static/style.css +++ b/static/style.css @@ -58,12 +58,14 @@ button, .button { cursor: pointer; } +input[type=checkbox].button:hover ~ button, input[type=button]:hover, input[type=submit]:hover, button:hover, .button:hover { background-color: #444; } +input[type=checkbox].button:active ~ button, input[type=button]:active, input[type=submit]:active, button:active, @@ -100,6 +102,7 @@ hr { background-color: #eee; } + input[type=checkbox].button:hover ~ button, input[type=button]:hover, input[type=submit]:hover, button:hover, diff --git a/templates/admin.html b/templates/admin.html new file mode 100644 index 0000000..b77f7cc --- /dev/null +++ b/templates/admin.html @@ -0,0 +1,50 @@ + + + + + + + +