Пример #1
0
        public string GetList(int bookId, int start = 1, int length = 50, SortType sort = 0, bool includeCount = false)
        {
            if (!CheckSecurity())
            {
                return(AccessDenied());
            }
            var html        = new StringBuilder();
            var entries     = new Scaffold("/Services/Entries/entries.html", S.Server.Scaffold);
            var item        = new Scaffold("/Services/Entries/list-item.html", S.Server.Scaffold);
            var chapter     = new Scaffold("/Services/Entries/chapter.html", S.Server.Scaffold);
            var books       = new Query.Books(S.Server.sqlConnectionString);
            var query       = new Query.Entries(S.Server.sqlConnectionString);
            var chapters    = new Query.Chapters(S.Server.sqlConnectionString);
            var chapterlist = chapters.GetList(bookId);
            var list        = query.GetList(S.User.userId, bookId, start, length, (int)sort);
            var chapterInc  = -1;
            var book        = books.GetDetails(S.User.userId, bookId);

            entries.Data["book-title"] = book.title;

            if (list.Count > 0)
            {
                list.ForEach((Query.Models.Entry entry) =>
                {
                    if (chapterInc != entry.chapter && sort == 0)
                    {
                        if (entry.chapter > 0)
                        {
                            //display chapter
                            chapter.Data["chapter"] = "Chapter " + entry.chapter.ToString() + ": " +
                                                      chapterlist.Find((Query.Models.Chapter c) => { return(c.chapter == entry.chapter); }).title;
                            html.Append(chapter.Render());
                        }
                        chapterInc = entry.chapter;
                    }
                    item.Data["id"]           = entry.entryId.ToString();
                    item.Data["title"]        = entry.title;
                    item.Data["summary"]      = entry.summary;
                    item.Data["date-created"] = entry.datecreated.ToString("d/MM/yyyy");
                    html.Append(item.Render());
                });
                entries.Data["entries"] = html.ToString();
            }
            else
            {
                html.Append(S.Server.LoadFileFromCache("/Services/Entries/no-entries.html"));
            }

            return((includeCount == true ? list.Count + "|" : "") + entries.Render());
        }
Пример #2
0
        public string CreateBook(string title)
        {
            if (!CheckSecurity())
            {
                return(AccessDenied());
            }
            var query  = new Query.Books(S.Server.sqlConnectionString);
            var bookId = 0;

            try {
                bookId = query.CreateBook(S.User.userId, title, false);
            }
            catch (Exception)
            {
                return(Error());
            }
            return("success|" + bookId + "|" + GetBooksList());
        }
Пример #3
0
        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());
        }
Пример #4
0
        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));
        }