/* Collection of pages which handles everything admin-panel related. Login page collects information and passes it via post method to backend which processes passed form and shows templ AdminPanelPage(). If form incorrected than it shows nothing. */ package templates import "github.com/dixxe/personal-website/web/static/styling" import "strconv" import "github.com/dixxe/personal-website/iternal/pkg/repositories" // Template to reduce boilerplate and untie everything templ postsTable(blogPosts []repositories.Post) { if len(blogPosts) == 0 { <h1 class={ styling.Header() }>База данных блога не загрузилась.</h1> } <table class={ styling.DefaultTable() }> <thead> <tr> <th> ID </th> <th> Header </th> <th> Content </th> </tr> </thead> <tbody> for _, post := range blogPosts { <tr> <td><span> {strconv.Itoa(post.Id)} </span></td> <td><span> {post.Header} </span></td> <td><span> {post.Content} </span></td> </tr> } </tbody> </table> } templ AdminPanelPage(blogPosts []repositories.Post) { @BasicPageBlock() <h1 class={ styling.FileHeader() }>Очень защищенная админ-панель</h1> <hr> <div class={ styling.Textcontainer() }> <h2 class={ styling.Header() }> Добавление новых постов </h2> <form action="/post" method="post"> <p>Header: <input type="text" name="header" /> </p> <p>Content: <textarea class={ styling.BlogFormInput() } type="text" name="content" /> </p> <p><input type="submit" value="Submit" /> <input type="reset" value="Reset"></p> </form> <hr> <h2 class={ styling.Header() }> Удаление постов </h2> <form action="/post/delete" method="post"> <p>Please specify post ID: <input type="number" name="id" value="id"/></p> <p><input type="submit" value="Submit" /> <input type="reset" value="Reset"></p> </form> </div> <hr> @postsTable(blogPosts) } templ LoginPage() { @BasicPageBlock() <div class={ styling.CenterPageContainer(), styling.Textcontainer() }> <form action="/admin/login" method="post"> <p>Login: <input type="text" name="login" /> </p> <p>Password: <input type="password" name="password" /> </p> <p><input type="submit" value="Submit" /> <input type="reset" value="Reset"></p> </form> </div> }