public override string Render(string[] path, string body = "", object metadata = null) { if (User.userId == 0) { //load login page var page = new Login(context); return(page.Render(path)); } //load boards list var scaffold = new Scaffold("/Views/Boards/boards.html", Server.Scaffold); var query = new Query.Boards(); var boards = query.GetList(User.userId); var html = new StringBuilder(); var item = new Scaffold("/Views/Boards/list-item.html", Server.Scaffold); boards.ForEach((Query.Models.Board b) => { item.Data["favorite"] = b.favorite ? "1" : ""; item.Data["name"] = b.name; item.Data["color"] = "#" + b.color; item.Data["extra"] = b.favorite ? "fav" : ""; item.Data["id"] = b.boardId.ToString(); item.Data["type"] = b.type.ToString(); item.Data["url"] = Uri.EscapeUriString("/board/" + b.boardId + "/" + b.name.Replace(" ", "-").ToLower()); html.Append(item.Render()); }); scaffold.Data["list"] = html.ToString(); //load teams list var queryTeams = new Query.Teams(); var teams = queryTeams.GetList(User.userId); html = new StringBuilder(); teams.ForEach((Query.Models.Team t) => { html.Append("<option value=\"" + t.teamId + "\">" + t.name + "</option>\n"); }); scaffold.Data["team-options"] = html.ToString(); //load page resources AddScript("/js/dashboard.js"); AddCSS("/css/dashboard.css"); //load header LoadHeader(ref scaffold, false); //render page return(base.Render(path, scaffold.Render())); }
public static string RenderBoardsMenu(Datasilk.Request request) { Server Server = Server.Instance; var html = new StringBuilder(); var htm = new StringBuilder(); var section = new Scaffold("/Views/Boards/menu-section.html", Server.Scaffold); var item = new Scaffold("/Views/Boards/menu-item.html", Server.Scaffold); var query = new Query.Boards(); var boards = query.GetList(request.User.userId); var favs = boards.Where((a) => { return(a.favorite); }); var teams = boards.OrderBy((a) => { return(a.datecreated); }).Reverse().OrderBy((a) => { return(a.ownerId == request.User.userId); }); // Favorite Boards ////////////////////////////////////////// if (favs.Count() > 0) { section.Data["title"] = "Starred Boards"; section.Data["id"] = "favs"; section.Data["icon"] = "star-border-sm"; htm = new StringBuilder(); foreach (var fav in favs) { item.Data["id"] = fav.boardId.ToString(); item.Data["url"] = "/board/" + fav.boardId + "/" + fav.name.Replace(" ", "-").ToLower(); item.Data["color"] = "#" + fav.color; item.Data["title"] = fav.name; item.Data["owner"] = fav.ownerName; item.Data["star"] = fav.favorite ? "star" : "star-border"; htm.Append(item.Render()); } section.Data["items"] = htm.ToString(); html.Append(section.Render()); } // Team Boards ////////////////////////////////////////// if (teams.Count() > 0) { var teamId = 0; var isnewTeam = true; htm = new StringBuilder(); foreach (var team in teams) { if (team.teamId != teamId) { if (teamId > 0) { section.Data["items"] = htm.ToString(); html.Append(section.Render()); } isnewTeam = true; teamId = team.teamId; } if (isnewTeam == true) { section.Data["title"] = team.teamName; section.Data["id"] = "team" + team.teamId.ToString(); section.Data["icon"] = "user"; } item.Data["id"] = team.boardId.ToString(); item.Data["url"] = "/board/" + team.boardId + "/" + team.name.Replace(" ", "-").ToLower(); item.Data["color"] = "#" + team.color; item.Data["title"] = team.name; item.Data["owner"] = team.ownerName; item.Data["star"] = team.favorite ? "star" : "star-border"; htm.Append(item.Render()); } section.Data["items"] = htm.ToString(); html.Append(section.Render()); } // Team Boards (sort by user owned, then by date created) ///////// return(html.ToString()); }