public string GetBooksList() { if (!CheckSecurity()) { return(AccessDenied()); } var html = new StringBuilder(); var scaffold = new Scaffold("/Services/Books/list-item.html", S.Server.Scaffold); var query = new Query.Books(S.Server.sqlConnectionString); var books = query.GetList(S.User.userId); books.ForEach((Query.Models.Book book) => { scaffold.Data["id"] = book.bookId.ToString(); scaffold.Data["title"] = book.title; html.Append(scaffold.Render()); }); return(html.ToString()); }
public override string Render(string[] path, string body = "", object metadata = null) { if (!CheckSecurity()) { return(AccessDenied(true, new Pages.Login(S))); } //add scripts to page //AddCSS("/css/utility/font-awesome.css"); //AddScript("/js/utility/simplemde.min.js"); //AddCSS("/css/utility/simplemde.min.css"); //AddScript("/js/utility/highlight.min.js"); //AddCSS("/css/utility/highlight/atelier-forest-light.css"); // <-- define custom code highlight theme here //AddScript("/js/utility/remarkable.min.js"); //AddScript("/js/pages/dashboard/dashboard.js"); AddScript("/js/dashboard.js"); AddCSS("/css/dashboard.css"); var dash = new Scaffold("/Pages/Dashboard/dashboard.html", S.Server.Scaffold); //get list of books var html = new StringBuilder(); var query = new Query.Books(S.Server.sqlConnectionString); var books = query.GetList(S.User.userId); if (books.Count > 0) { //books exist var list = new Scaffold("/Services/Books/list-item.html", S.Server.Scaffold); var i = 0; books.ForEach((Query.Models.Book book) => { if (i == 0) { list.Data["selected"] = "selected"; } else { list.Data["selected"] = ""; } list.Data["id"] = book.bookId.ToString(); list.Data["title"] = book.title; html.Append(list.Render()); i++; }); dash.Data["books"] = html.ToString(); //get list of entries for top book var entries = new Services.Entries(S); var bookId = 0; if (books.Count > 0) { bookId = books[0].bookId; var first = new Query.Entries(S.Server.sqlConnectionString).GetFirst(S.User.userId, bookId, (int)Services.Entries.SortType.byChapter); if (first != null) { scripts += "<script language=\"javascript\">S.entries.bookId=" + bookId + ";S.editor.entryId=" + first.entryId.ToString() + ";</script>"; //load content of first entry dash.Data["editor-content"] = entries.LoadEntry(first.entryId, bookId); } else { dash.Data["no-entries"] = "hide"; scripts += "<script language=\"javascript\">S.entries.noentries();</script>"; } } dash.Data["entries"] = entries.GetList(bookId, 1, 50, Services.Entries.SortType.byChapter); } else { dash.Data["no-books"] = "hide"; dash.Data["no-entries"] = "hide"; dash.Data["no-content"] = S.Server.LoadFileFromCache("/Pages/Dashboard/templates/nobooks.html"); } //get count for tags & trash var tags = 0; var trash = 0; dash.Data["tags-count"] = tags.ToString(); dash.Data["trash-count"] = trash.ToString(); //load script templates (for popups) dash.Data["templates"] = S.Server.LoadFileFromCache("/Pages/Dashboard/templates/newbook.html") + S.Server.LoadFileFromCache("/Pages/Dashboard/templates/newentry.html") + S.Server.LoadFileFromCache("/Pages/Dashboard/templates/newchapter.html") + S.Server.LoadFileFromCache("/Pages/Dashboard/templates/noentries.html"); return(base.Render(path, dash.Render(), metadata)); }