1 // 2 // Copyright (c) 2013-2017 Carsten Sonne Larsen <cs@innolan.net> 3 // 4 // Permission is hereby granted, free of charge, to any person obtaining a copy 5 // of this software and associated documentation files (the "Software"), to deal 6 // in the Software without restriction, including without limitation the rights 7 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 // copies of the Software, and to permit persons to whom the Software is 9 // furnished to do so, subject to the following conditions: 10 // 11 // The above copyright notice and this permission notice shall be included in 12 // all copies or substantial portions of the Software. 13 // 14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 // THE SOFTWARE. 21 22 using System; 23 using System.Collections.Generic; 24 using System.Linq; 25 using System.Text; 26 using Ntp.Analyzer.Config.Node.Destination; 27 using Ntp.Analyzer.Config.Node.Page; 28 using Ntp.Analyzer.Data; 29 using Ntp.Common.Web; 30 31 namespace Ntp.Analyzer.Render.Peer 32 { 33 public sealed class BootstrapPeerGraphRender : HtmlObjectRender 34 { BootstrapPeerGraphRender( Uri webPath, Objects.Peer peer, Objects.Host host, PeerPageConfiguration page, IEnumerable<GraphSetConfiguration> graphs)35 public BootstrapPeerGraphRender( 36 Uri webPath, 37 Objects.Peer peer, 38 Objects.Host host, 39 PeerPageConfiguration page, 40 IEnumerable<GraphSetConfiguration> graphs) 41 : base(webPath) 42 { 43 this.peer = peer; 44 this.host = host; 45 this.page = page; 46 this.graphs = new List<GraphSetConfiguration>(graphs); 47 } 48 49 private readonly List<GraphSetConfiguration> graphs; 50 private readonly Objects.Host host; 51 private readonly PeerPageConfiguration page; 52 private readonly Objects.Peer peer; 53 Render()54 public override string Render() 55 { 56 var builder = new StringBuilder(); 57 int count = 1; 58 59 var activity = DataFace.Instance.PeerActivities. 60 Single(p => Equals(p.Host, host) && Equals(p.Peer, peer) && p.IsActive); 61 62 foreach (var graphSet in graphs) 63 { 64 string open = count == 1 ? " in" : string.Empty; 65 66 builder.AppendLine(@" <div class=""panel panel-default"">"); 67 builder.AppendLine(@" <div class=""panel-heading"">"); 68 builder.AppendLine(@" <h4 class=""panel-title"">"); 69 70 // Include panel counter 71 builder.Append(@" <a class=""accordion-toggle"" data-toggle=""collapse"" "); 72 builder.Append(@"data-parent=""#accordion"" href=""#collapse"); 73 builder.Append(count); 74 builder.AppendLine(@""">"); 75 76 builder.AppendLine($@" {graphSet.Title}"); 77 builder.AppendLine(@" </a>"); 78 builder.AppendLine(@" </h4>"); 79 builder.AppendLine(@" </div>"); 80 81 // Include panel counter 82 builder.Append(@" <div id=""collapse"); 83 builder.Append(count); 84 builder.Append($@""" class=""panel-collapse collapse{open}"">"); 85 builder.AppendLine(); 86 builder.AppendLine(@" <div class=""panel-body"">"); 87 88 foreach (var graph in graphSet.Graphs) 89 { 90 builder.Append(@" <div class=""container theme-graph2"">"); 91 92 if (page?.GraphPages != null && page.GraphPages.Count() != 0) 93 { 94 builder.Append(@"<a href="""); 95 builder.Append( 96 page.GraphPages.First().GetLink(host, activity.Name, graphSet, graph).ToHtmlString()); 97 builder.Append(@""">"); 98 } 99 100 builder.Append(@"<img class=""img-responsive"" src="""); 101 builder.Append(graph.GetLink(graphSet, activity.Name).ToHtmlString()); 102 builder.Append(@""" alt="""); 103 builder.Append(graph.GetAltName(graphSet, activity.Name)); 104 builder.Append(@""">"); 105 106 if (page?.GraphPages != null && page.GraphPages.Count() != 0) 107 { 108 builder.Append(@"</a>"); 109 } 110 111 builder.AppendLine(@"</div>"); 112 } 113 114 builder.AppendLine(@" </div>"); 115 builder.AppendLine(@" </div>"); 116 builder.AppendLine(@" </div>"); 117 118 count++; 119 } 120 121 return builder.ToString(); 122 } 123 RenderFooter()124 public override string RenderFooter() 125 { 126 var builder = new StringBuilder(); 127 128 builder.AppendLine(@" </div>"); 129 builder.AppendLine(@" </div>"); 130 131 return builder.ToString(); 132 } 133 RenderHead()134 public override string RenderHead() 135 { 136 var builder = new StringBuilder(); 137 138 builder.AppendLine(@" <div class=""container theme-graph"">"); 139 builder.AppendLine(@" <div class=""panel-group"" id=""accordion"">"); 140 141 return builder.ToString(); 142 } 143 } 144 }