adding a clear button to elm

This commit is contained in:
SonjaKhan 2014-12-04 11:55:56 -08:00
parent 17e5811a97
commit 234c9ec935
5 changed files with 72 additions and 33 deletions

View File

@ -36,7 +36,13 @@ namespace Microsoft.AspNet.Diagnostics.Elm
return; return;
} }
var options = ParseParams(context); var t = await ParseParams(context);
var options = t.Item1;
var redirect = t.Item2;
if (redirect)
{
return;
}
if (context.Request.Path == _options.Path) if (context.Request.Path == _options.Path)
{ {
RenderMainLogPage(options, context); RenderMainLogPage(options, context);
@ -81,27 +87,38 @@ namespace Microsoft.AspNet.Diagnostics.Elm
await requestPage.ExecuteAsync(context); await requestPage.ExecuteAsync(context);
} }
private ViewOptions ParseParams(HttpContext context) private async Task<Tuple<ViewOptions, bool>> ParseParams(HttpContext context)
{ {
var options = new ViewOptions() var options = new ViewOptions()
{ {
MinLevel = LogLevel.Verbose, MinLevel = LogLevel.Verbose,
NamePrefix = string.Empty NamePrefix = string.Empty
}; };
if (context.Request.Query.ContainsKey("level")) var isRedirect = false;
var form = await context.Request.GetFormAsync();
if (form.ContainsKey("clear"))
{ {
var minLevel = options.MinLevel; _store.Clear();
if (Enum.TryParse<LogLevel>(context.Request.Query["level"], out minLevel)) context.Response.Redirect(context.Request.PathBase.Add(_options.Path).ToString());
isRedirect = true;
}
else
{
if (context.Request.Query.ContainsKey("level"))
{ {
options.MinLevel = minLevel; var minLevel = options.MinLevel;
if (Enum.TryParse<LogLevel>(context.Request.Query["level"], out minLevel))
{
options.MinLevel = minLevel;
}
}
if (context.Request.Query.ContainsKey("name"))
{
var namePrefix = context.Request.Query.GetValues("name")[0];
options.NamePrefix = namePrefix;
} }
} }
if (context.Request.Query.ContainsKey("name")) return Tuple.Create(options, isRedirect);
{
var namePrefix = context.Request.Query.GetValues("name")[0];
options.NamePrefix = namePrefix;
}
return options;
} }
} }
} }

View File

@ -48,6 +48,14 @@ namespace Microsoft.AspNet.Diagnostics.Elm
} }
} }
/// <summary>
/// Removes all activity contexts that have been stored.
/// </summary>
public void Clear()
{
Activities.Clear();
}
/// <summary> /// <summary>
/// Returns the total number of logs in all activities in the store /// Returns the total number of logs in all activities in the store
/// </summary> /// </summary>

View File

@ -318,6 +318,10 @@ col:nth-child(2) {
background-color: #FAFAFA; background-color: #FAFAFA;
} }
form {
display: inline-block;
}
h1 { h1 {
margin-left: 25px; margin-left: 25px;
} }
@ -501,6 +505,9 @@ tr:nth-child(2n) {
WriteLiteral(@" /> WriteLiteral(@" />
<input type=""submit"" value=""filter"" /> <input type=""submit"" value=""filter"" />
</form> </form>
<form id=""clear"" method=""post"" action="""">
<button type=""submit"" name=""clear"" value=""1"">Clear Logs</button>
</form>
<table id=""requestTable""> <table id=""requestTable"">
<thead id=""requestHeader""> <thead id=""requestHeader"">
@ -518,13 +525,13 @@ tr:nth-child(2n) {
<col /> <col />
</colgroup> </colgroup>
"); ");
#line 136 "LogPage.cshtml" #line 139 "LogPage.cshtml"
#line default #line default
#line hidden #line hidden
#line 136 "LogPage.cshtml" #line 139 "LogPage.cshtml"
foreach (var activity in Model.Activities.Reverse()) foreach (var activity in Model.Activities.Reverse())
{ {
@ -532,13 +539,13 @@ tr:nth-child(2n) {
#line hidden #line hidden
WriteLiteral(" <tbody>\r\n <tr class=\"requestRow\">\r\n"); WriteLiteral(" <tbody>\r\n <tr class=\"requestRow\">\r\n");
#line 140 "LogPage.cshtml" #line 143 "LogPage.cshtml"
#line default #line default
#line hidden #line hidden
#line 140 "LogPage.cshtml" #line 143 "LogPage.cshtml"
if (activity.HttpInfo != null) if (activity.HttpInfo != null)
{ {
@ -548,30 +555,30 @@ tr:nth-child(2n) {
#line hidden #line hidden
WriteLiteral(" <td><a"); WriteLiteral(" <td><a");
WriteAttribute("href", Tuple.Create(" href=\"", 4400), Tuple.Create("\"", 4419), WriteAttribute("href", Tuple.Create(" href=\"", 4534), Tuple.Create("\"", 4553),
Tuple.Create(Tuple.Create("", 4407), Tuple.Create<System.Object, System.Int32>(requestPath, 4407), false)); Tuple.Create(Tuple.Create("", 4541), Tuple.Create<System.Object, System.Int32>(requestPath, 4541), false));
WriteAttribute("title", Tuple.Create(" title=\"", 4420), Tuple.Create("\"", 4451), WriteAttribute("title", Tuple.Create(" title=\"", 4554), Tuple.Create("\"", 4585),
Tuple.Create(Tuple.Create("", 4428), Tuple.Create<System.Object, System.Int32>(activity.HttpInfo.Path, 4428), false)); Tuple.Create(Tuple.Create("", 4562), Tuple.Create<System.Object, System.Int32>(activity.HttpInfo.Path, 4562), false));
WriteLiteral(">"); WriteLiteral(">");
#line 144 "LogPage.cshtml" #line 147 "LogPage.cshtml"
Write(activity.HttpInfo.Path); Write(activity.HttpInfo.Path);
#line default #line default
#line hidden #line hidden
WriteLiteral("</a></td>\r\n <td>"); WriteLiteral("</a></td>\r\n <td>");
#line 145 "LogPage.cshtml" #line 148 "LogPage.cshtml"
Write(activity.HttpInfo.Host); Write(activity.HttpInfo.Host);
#line default #line default
#line hidden #line hidden
WriteLiteral("</td>\r\n <td>"); WriteLiteral("</td>\r\n <td>");
#line 146 "LogPage.cshtml" #line 149 "LogPage.cshtml"
Write(activity.HttpInfo.StatusCode); Write(activity.HttpInfo.StatusCode);
#line default #line default
#line hidden #line hidden
WriteLiteral("</td>\r\n"); WriteLiteral("</td>\r\n");
#line 147 "LogPage.cshtml" #line 150 "LogPage.cshtml"
} }
else else
{ {
@ -580,13 +587,13 @@ tr:nth-child(2n) {
#line hidden #line hidden
WriteLiteral(" <td colspan=\"3\">"); WriteLiteral(" <td colspan=\"3\">");
#line 150 "LogPage.cshtml" #line 153 "LogPage.cshtml"
Write(activity.Root.State); Write(activity.Root.State);
#line default #line default
#line hidden #line hidden
WriteLiteral("</td>\r\n"); WriteLiteral("</td>\r\n");
#line 151 "LogPage.cshtml" #line 154 "LogPage.cshtml"
} }
@ -608,13 +615,13 @@ tr:nth-child(2n) {
</thead> </thead>
<tbody> <tbody>
"); ");
#line 166 "LogPage.cshtml" #line 169 "LogPage.cshtml"
#line default #line default
#line hidden #line hidden
#line 166 "LogPage.cshtml" #line 169 "LogPage.cshtml"
if (activity.Id.Equals(Guid.Empty)) if (activity.Id.Equals(Guid.Empty))
{ {
// message not within a scope // message not within a scope
@ -623,12 +630,12 @@ tr:nth-child(2n) {
#line default #line default
#line hidden #line hidden
#line 169 "LogPage.cshtml" #line 172 "LogPage.cshtml"
Write(LogRow(activity.Root.Messages.FirstOrDefault(), 0)); Write(LogRow(activity.Root.Messages.FirstOrDefault(), 0));
#line default #line default
#line hidden #line hidden
#line 169 "LogPage.cshtml" #line 172 "LogPage.cshtml"
} }
else else
@ -638,12 +645,12 @@ tr:nth-child(2n) {
#line default #line default
#line hidden #line hidden
#line 173 "LogPage.cshtml" #line 176 "LogPage.cshtml"
Write(Traverse(activity.Root, 0)); Write(Traverse(activity.Root, 0));
#line default #line default
#line hidden #line hidden
#line 173 "LogPage.cshtml" #line 176 "LogPage.cshtml"
} }
@ -652,7 +659,7 @@ tr:nth-child(2n) {
WriteLiteral(" </tbody>\r\n </table>\r\n " + WriteLiteral(" </tbody>\r\n </table>\r\n " +
" </td>\r\n </tr>\r\n </tbody>\r\n"); " </td>\r\n </tr>\r\n </tbody>\r\n");
#line 180 "LogPage.cshtml" #line 183 "LogPage.cshtml"
} }
#line default #line default

View File

@ -117,6 +117,9 @@
<input type="text" name="name" value="@Model.Options.NamePrefix" /> <input type="text" name="name" value="@Model.Options.NamePrefix" />
<input type="submit" value="filter" /> <input type="submit" value="filter" />
</form> </form>
<form id="clear" method="post" action="">
<button type="submit" name="clear" value="1">Clear Logs</button>
</form>
<table id="requestTable"> <table id="requestTable">
<thead id="requestHeader"> <thead id="requestHeader">

View File

@ -8,6 +8,10 @@ col:nth-child(2) {
background-color: #FAFAFA; background-color: #FAFAFA;
} }
form {
display: inline-block;
}
h1 { h1 {
margin-left: 25px; margin-left: 25px;
} }