/// <summary> /// Writes references of some javascript libraries to the given <see cref="Html32TextWriter"/> to let the bootstrap work. /// </summary> /// <param name='htw'> /// The <see cref="Html32TextWriter"/> to write the content to. /// </param> private void WriteJavascript(Html32TextWriter htw) { htw.AddAttribute (HtmlTextWriterAttribute.Src, "http://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"); htw.RenderBeginTag (HtmlTextWriterTag.Script); htw.RenderEndTag (); htw.WriteLine (); htw.AddAttribute (HtmlTextWriterAttribute.Src, "http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"); htw.RenderBeginTag (HtmlTextWriterTag.Script); {} htw.RenderEndTag (); }
/// <summary> /// Converts the set of <see cref="IdpGie.Shapes.IShape"/> by converting it into a readable format. /// </summary> public override void Process() { using (StreamReader inputStream = new StreamReader (client.GetStream ())) { String request = inputStream.ReadLine (), line; string[] tokens = request.Split (' '); if (tokens.Length != 3) { throw new Exception ("invalid http request line"); } StringBuilder rest = new StringBuilder (); do { line = inputStream.ReadLine (); rest.AppendLine (line); } while(line != string.Empty && line != null); //string http_url = tokens [1]; string http_filename = tokens [1]; Console.WriteLine ("\"{0}\"", http_filename); if (http_filename == "/" + IconName) { this.device.Navigationbar.FavIcon.RenderIcon (this.device.Manager.ServerFolder, this, client.GetStream ()); } else { bool border; IWebPage wp = this.device.Navigationbar.GetPage (http_filename.Substring (0x01), out border); using (StreamWriter sw = new StreamWriter (client.GetStream ())) { using (Html32TextWriter tw = new Html32TextWriter (sw)) { if (border) { tw.WriteLine ("<!DOCTYPE html>"); tw.RenderBeginTag (HtmlTextWriterTag.Html); tw.RenderBeginTag (HtmlTextWriterTag.Head); this.WriteHeader (tw); tw.RenderEndTag (); tw.RenderBeginTag (HtmlTextWriterTag.Body); this.WriteBody (tw, wp); this.WriteJavascript (tw); tw.RenderEndTag (); tw.RenderEndTag (); } else { wp.Render (this.device.Manager.ServerFolder, this, tw); } } } } } }
/// <summary> /// Writes the header of the webpage. The header contains references to bootstrap, a favoicon and some stylefile. /// </summary> /// <param name='htw'> /// A <see cref="Html32TextWriter"/> to write the content to. /// </param> private void WriteHeader(Html32TextWriter htw) { htw.RenderBeginTag (HtmlTextWriterTag.Title); { htw.Write (this.device.Navigationbar.Name); } htw.RenderEndTag (); htw.AddAttribute (HtmlTextWriterAttribute.Name, "generator"); htw.AddAttribute (HtmlTextWriterAttribute.Content, ProgramManager.ProgramNameVersion); htw.RenderBeginTag (HtmlTextWriterTag.Meta); {} htw.RenderEndTag (); htw.WriteLine (); htw.AddAttribute (HtmlTextWriterAttribute.Name, "viewport"); htw.AddAttribute (HtmlTextWriterAttribute.Content, "width=device-width, initial-scale=1.0"); htw.RenderBeginTag (HtmlTextWriterTag.Meta); {} htw.RenderEndTag (); htw.WriteLine (); htw.AddAttribute (HtmlTextWriterAttribute.Href, "http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css"); htw.AddAttribute (HtmlTextWriterAttribute.Rel, "stylesheet"); htw.RenderBeginTag (HtmlTextWriterTag.Link); {} htw.RenderEndTag (); htw.WriteLine (); htw.AddAttribute (HtmlTextWriterAttribute.Href, IconName); htw.AddAttribute (HtmlTextWriterAttribute.Rel, "icon"); htw.AddAttribute (HtmlTextWriterAttribute.Type, "image/x-icon"); htw.RenderBeginTag (HtmlTextWriterTag.Link); {} htw.RenderEndTag (); htw.WriteLine (); htw.RenderBeginTag (HtmlTextWriterTag.Style); { htw.Write ("body {min-height: 2000px;padding-top: 70px;}"); } htw.RenderEndTag (); htw.AddAttribute ("language", "javascript"); htw.RenderBeginTag (HtmlTextWriterTag.Script); { htw.WriteLine ("function genericAjax (source, target) {"); htw.WriteLine (" var xmlhttp;"); htw.WriteLine (" if (window.XMLHttpRequest) {"); htw.WriteLine (" xmlhttp=new XMLHttpRequest();"); htw.WriteLine (" } else {"); htw.WriteLine (" xmlhttp=new ActiveXObject(\"Microsoft.XMLHTTP\");"); htw.WriteLine (" }"); htw.WriteLine (" xmlhttp.onreadystatechange=function() {"); htw.WriteLine (" if (xmlhttp.readyState==4) {"); htw.WriteLine (" if(xmlhttp.status==200) {"); htw.WriteLine (" document.getElementById(target).innerHTML=xmlhttp.responseText;"); htw.WriteLine (" } else {"); htw.WriteLine (" document.getElementById(target).innerHTML=\"<div class='alert alert-warning'><strong>Warning:</strong> something went wrong during an AJAX call. Error code: \"+xmlhttp.status+\", Source: \"+source+\".</div>\";"); htw.WriteLine (" }"); htw.WriteLine (" }"); htw.WriteLine (" }"); htw.WriteLine (" xmlhttp.open(\"GET\",source,true);"); htw.WriteLine (" xmlhttp.send();"); htw.WriteLine ("}"); } htw.RenderEndTag (); htw.WriteLine (); }
public static string Pager(this HtmlHelper htmlHelper, IPagination pagination, string actionName, string controllerName, RouteValueDictionary routeValues) { routeValues = routeValues ?? new RouteValueDictionary(); var routeValueDictionary = new RouteValueDictionary(routeValues); if(!routeValueDictionary.ContainsKey("page")) routeValueDictionary.Add("page", 0); if(!routeValueDictionary.ContainsKey("controller")) routeValueDictionary.Add("controller", controllerName); int min = Math.Max(pagination.PageNumber - 2, 1); int max = Math.Min(pagination.PageNumber + 2, pagination.TotalPages); int startPage = Math.Min(min, 1); int endPage = Math.Max(max, pagination.TotalPages); int currentPage = pagination.PageNumber; var sb = new StringBuilder(); var sw = new StringWriter(sb, System.Globalization.CultureInfo.InvariantCulture); var hw = new Html32TextWriter(sw, " "); hw.WriteFullBeginTag("ul"); if (pagination.HasPreviousPage) { hw.WriteLine(); hw.WriteFullBeginTag("li"); routeValueDictionary["page"] = currentPage - 1; hw.Write(htmlHelper.ActionLink("prev", actionName, routeValueDictionary, new Dictionary<string, object> {{"class", "previous"}})); hw.WriteEndTag("li"); } if(min != startPage) { hw.WriteLine(); hw.WriteFullBeginTag("li"); routeValueDictionary["page"] = startPage; hw.Write(htmlHelper.ActionLink(startPage.ToInvariantString(), actionName, routeValueDictionary)); hw.WriteEndTag("li"); if (min - startPage > 1) { hw.WriteFullBeginTag("li"); hw.Write("..."); hw.WriteEndTag("li"); } } for (var i = min; i <= max; i++) { hw.WriteLine(); hw.WriteFullBeginTag("li"); routeValueDictionary["page"] = i; if (i == currentPage) { hw.WriteFullBeginTag("span"); hw.Write(i.ToInvariantString()); hw.WriteEndTag("span"); } else hw.Write(htmlHelper.ActionLink(i.ToInvariantString(), actionName, routeValueDictionary)); hw.WriteEndTag("li"); } if(max != endPage) { if (endPage - max > 1) { hw.WriteLine(); hw.WriteFullBeginTag("li"); hw.Write("..."); hw.WriteEndTag("li"); } hw.WriteLine(); hw.WriteFullBeginTag("li"); routeValueDictionary["page"] = endPage; hw.Write(htmlHelper.ActionLink(endPage.ToInvariantString(), actionName, routeValueDictionary)); hw.WriteEndTag("li"); } if(pagination.HasNextPage) { hw.WriteLine(); hw.WriteFullBeginTag("li"); routeValueDictionary["page"] = currentPage + 1; hw.Write(htmlHelper.ActionLink("next", actionName, routeValueDictionary, new Dictionary<string, object> {{"class", "next"}})); hw.WriteEndTag("li"); } hw.WriteLine(); hw.WriteEndTag("ul"); return sb.ToString(); //StringBuilder sb1 = new StringBuilder(); //int seed = pagination.PageNumber % pagination.PageSize == 0 ? pagination.PageNumber : pagination.PageNumber - (pagination.PageNumber % pagination.PageSize); //if (pagination.PageNumber > 1) // sb1.AppendLine(htmlHelper.ActionLink("prev", "index", controllerName, new { page = pagination.PageNumber }));// String.Format("<a href=\"{0}/{1}\">Previous</a>", urlPrefix, pagination.PageNumber)); //if (pagination.PageNumber - pagination.PageSize >= 1) //{ // var pageNumber = (pagination.PageNumber - pagination.PageSize) + 1) // sb1.AppendLine(htmlHelper.ActionLink("...", "index", controllerName, new {page = pageNumber})); //} //for (int i = seed; i < Math.Round((pagination.TotalItems / 10) + 0.5) && i < seed + pagination.PageSize; i++) //{ // //sb1.AppendLine(htmlHelper.ActionLink("{0}".ToFormat(i + 1)) String.Format("<a href=\"{0}/{1}\">{1}</a>", urlPrefix, i + 1)); //} //if (pagination.PageNumber + pagination.PageSize <= (Math.Round((pagination.TotalItems / 10) + 0.5) - 1)) // sb1.AppendLine(String.Format("<a href=\"{0}/{1}\">...</a>", urlPrefix, (pagination.PageNumber + pagination.PageSize) + 1)); //if (currentPage < (Math.Round((pagination.TotalItems / 10) + 0.5) - 1)) // sb1.AppendLine(String.Format("<a href=\"{0}/{1}\">Next</a>", urlPrefix, pagination.PageNumber + 2)); //return sb1.ToString(); //var pagesToDisplay = 5; //var sb = new StringBuilder(); //var textWriter = new StringWriter(sb); //var builder = new HtmlTextWriter(textWriter); ////opening ul tag //builder.RenderBeginTag("ul"); ////prev tag //builder.RenderBeginTag("li"); //if (pagination.HasPreviousPage) // builder.Write(urlHelper.ActionLink("prev", actionName, new{id = pagination.PageNumber - 1})); //else // builder.WriteEncodedUrl("prev"); //builder.RenderEndTag(); ////R //builder.RenderBeginTag("li"); //if(pag) ////next tag //builder.RenderBeginTag("li"); //if (pagination.HasPreviousPage) // builder.Write(urlHelper.ActionLink("next", actionName, new { id = pagination.LastItem })); //else // builder.WriteEncodedUrl("next"); //builder.RenderEndTag(); ////close ul tag //builder.RenderEndTag(); //return sb.ToString(); }
// Protected Methods //TODO remove this code block after test //this was the previous code, leaving here until after test protected void OldRender(Html32TextWriter writer) { if (this.RecordCount > 0) { writer.WriteLine(@"<div class=""Paging"">"); if (this.PageNumber > 1) { writer.WriteLine(@"<span class=""PagingPrevious""><a href=""{0}"">« Previous</a></span>", this.BaseUrl + "/page/" + (this.PageNumber - 1)); } writer.WriteLine(@"<span class=""PagingInfo"">Page {0} of {1}</span>", this.PageNumber, this.PageCount); if (this.PageNumber < this.PageCount) { writer.WriteLine(@"<span class=""PagingNext""><a href=""{0}"">Next »</a></span>", this.BaseUrl + "/page/" + (this.PageNumber + 1)); } writer.WriteLine(@"</div>"); } }
/// <summary> /// Render the result of the query onto the give specified engine. /// </summary> /// <param name='serverFolder'> /// The root of the folder of the web server. /// </param> /// <param name='engine'> /// The given specified engine. /// </param> /// <param name='writer'> /// The html writer to write content to. /// </param> public override void Render(string serverFolder, HttpEngine engine, Html32TextWriter writer) { writer.WriteLine (Error404); }
/// <summary> /// Render the webpage onto the give specified engine. /// </summary> /// <param name="serverFolder">The root of the folder of the web server.</param> /// <param name="engine">The given specified engine.</param> /// <param name="writer">The html writer to write content to.</param> public override void Render(string serverFolder, HttpEngine engine, Html32TextWriter writer) { string landingName = this.LandingName; writer.AddAttribute (HtmlTextWriterAttribute.Id, landingName); writer.RenderBeginTag (HtmlTextWriterTag.Div); writer.RenderEndTag (); if (this.QueryPage != null) { writer.RenderBeginTag (HtmlTextWriterTag.Script); writer.WriteLine ("genericAjax (\"{0}\", \"{1}\");", this.QueryPage.Href, landingName); writer.RenderEndTag (); } }
/// <summary> /// Render the webpage onto the give specified engine. /// </summary> /// <param name="serverFolder">The root of the folder of the web server.</param> /// <param name="engine">The given specified engine.</param> /// <param name="writer">The html writer to write content to.</param> public override void Render(string serverFolder, HttpEngine engine, Html32TextWriter writer) { writer.AddAttribute (HtmlTextWriterAttribute.Class, "table table-hover table-condensed table-bordered"); writer.RenderBeginTag (HtmlTextWriterTag.Table); { writer.RenderBeginTag (HtmlTextWriterTag.Thead); { writer.RenderBeginTag (HtmlTextWriterTag.Tr); { foreach (WebPredicateTableColumn column in this.Columns) { writer.RenderBeginTag (HtmlTextWriterTag.Th); writer.Write (column.Name); writer.RenderEndTag (); } writer.RenderBeginTag (HtmlTextWriterTag.Th); writer.AddAttribute (HtmlTextWriterAttribute.Class, "btn-group"); writer.RenderBeginTag (HtmlTextWriterTag.Div); { writer.AddAttribute (HtmlTextWriterAttribute.Onclick, string.Format ("genericAjax (\"{0}\", \"landing{1}\");", this.Href, this.Id)); writer.AddAttribute (HtmlTextWriterAttribute.Class, "btn btn-info btn-xs"); writer.RenderBeginTag (HtmlTextWriterTag.Button); writer.WriteLine ("<i class=\"glyphicon glyphicon-refresh\"></i>"); writer.RenderEndTag (); writer.AddAttribute (HtmlTextWriterAttribute.Class, "btn btn-success btn-xs"); writer.RenderBeginTag (HtmlTextWriterTag.Button); writer.WriteLine ("<i class=\"glyphicon glyphicon-plus\"></i>"); writer.RenderEndTag (); } writer.RenderEndTag (); writer.RenderEndTag (); } writer.RenderEndTag (); } writer.RenderEndTag (); writer.RenderBeginTag (HtmlTextWriterTag.Tbody); { IEnumerable<int> indices = this.Columns.Select (x => x.Index).ToArray (); foreach (IEnumerable<object> row in this.Source) { writer.WriteLine (); writer.RenderBeginTag (HtmlTextWriterTag.Tr); foreach (object item in row.IndicesOrdered (indices)) { writer.RenderBeginTag (HtmlTextWriterTag.Td); writer.Write (item); writer.RenderEndTag (); } writer.RenderBeginTag (HtmlTextWriterTag.Td); writer.AddAttribute (HtmlTextWriterAttribute.Class, "btn-group"); writer.RenderBeginTag (HtmlTextWriterTag.Div); { writer.AddAttribute (HtmlTextWriterAttribute.Onclick, string.Format ("genericAjax (\"{0}\", \"landing{1}\");", this.Href, this.Id)); writer.AddAttribute (HtmlTextWriterAttribute.Class, "btn btn-warning btn-xs"); writer.RenderBeginTag (HtmlTextWriterTag.Button); writer.WriteLine ("<i class=\"glyphicon glyphicon-edit\"></i>"); writer.RenderEndTag (); writer.AddAttribute (HtmlTextWriterAttribute.Class, "btn btn-danger btn-xs"); writer.RenderBeginTag (HtmlTextWriterTag.Button); writer.WriteLine ("<i class=\"glyphicon glyphicon-remove\"></i>"); writer.RenderEndTag (); } writer.RenderEndTag (); writer.RenderEndTag (); writer.RenderEndTag (); } } writer.RenderEndTag (); } writer.RenderEndTag (); }