-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
65 changed files
with
1,377 additions
and
488 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
/* | ||
This TH was written by Rick Strahl | ||
Usage: | ||
<error-display message = "@model.Message" | ||
icon="warning" | ||
header="Error!" | ||
> | ||
</error-display> | ||
Add font-awesome | ||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css"> | ||
*/ | ||
|
||
namespace Dgmjr.AspNetCore.TagHelpers.Bootstrap; | ||
|
||
/// <summary> | ||
/// Taghelper to display a BootStrap Alert box and FontAwesome icon. | ||
/// | ||
/// Message and Header values can be assigned from model values using | ||
/// standard Razor expressions. | ||
/// | ||
/// The Helper only displays content when message or header are set | ||
/// otherwise the content is not displayed, so when binding to your | ||
/// model and the model value is empty nothing displays. | ||
/// </summary> | ||
/// <remarks> | ||
/// Requires FontAwesome in addition to bootstrap in order to display icons | ||
/// </remarks> | ||
[HtmlTargetElement("alert")] | ||
public class AlertTagHelper : TagHelper | ||
{ | ||
/// <summary> | ||
/// the main message that gets displayed | ||
/// </summary> | ||
[HtmlAttributeName("message")] | ||
public string message { get; set; } | ||
|
||
/// <summary> | ||
/// Optional header that is displayed in big text. Use for | ||
/// 'noisy' warnings and stop errors only please :-) | ||
/// The message is displayed below the header. | ||
/// </summary> | ||
[HtmlAttributeName("header")] | ||
public string header { get; set; } | ||
|
||
/// <summary> | ||
/// Font-awesome icon name without the fa- prefix. | ||
/// Example: info, warning, lightbulb-o, | ||
/// If none is specified - "warning" is used | ||
/// To force no icon use "none" | ||
/// </summary> | ||
[HtmlAttributeName("icon")] | ||
public string icon { get; set; } | ||
|
||
/// <summary> | ||
/// CSS class. Handled here so we can capture the existing | ||
/// class value and append the BootStrap alert class. | ||
/// </summary> | ||
[HtmlAttributeName("class")] | ||
public string cssClass { get; set; } | ||
|
||
/// <summary> | ||
/// Optional - specifies the alert class used on the top level | ||
/// window. If not specified uses the same as the icon. | ||
/// Override this if the icon and alert classes are different | ||
/// (often they are not). | ||
/// </summary> | ||
[HtmlAttributeName("alert-class")] | ||
public string alertClass { get; set; } | ||
|
||
/// <summary> | ||
/// If true embeds the message text as HTML. Use this | ||
/// flag if you need to display HTML text. If false | ||
/// the text is HtmlEncoded. | ||
/// </summary> | ||
[HtmlAttributeName("message-as-html")] | ||
public bool messageAsHtml { get; set; } | ||
|
||
/// <summary> | ||
/// If true embeds the header text as HTML. Use this | ||
/// flag if you need to display raw HTML text. If false | ||
/// the text is HtmlEncoded. | ||
/// </summary> | ||
[HtmlAttributeName("header-as-html")] | ||
public bool headerAsHtml { get; set; } | ||
|
||
/// <summary> | ||
/// If true displays a close icon to close the alert. | ||
/// </summary> | ||
[HtmlAttributeName("dismissible")] | ||
public bool dismissible { get; set; } | ||
|
||
public override void Process(TagHelperContext context, TagHelperOutput output) | ||
{ | ||
if (string.IsNullOrEmpty(message) && string.IsNullOrEmpty(header)) | ||
return; | ||
|
||
if (string.IsNullOrEmpty(icon)) | ||
icon = "warning"; | ||
else | ||
icon = icon.Trim(); | ||
if (icon == "none") | ||
icon = ""; | ||
|
||
// assume alertclass to match icon by default | ||
// override it when icon and alert class are diff (ie. info, info-circle) | ||
if (string.IsNullOrEmpty(alertClass)) | ||
alertClass = icon; | ||
|
||
if (icon == "info") | ||
icon = "info-circle"; | ||
if (icon == "danger") | ||
{ | ||
icon = "warning"; | ||
if (string.IsNullOrEmpty(alertClass)) | ||
alertClass = "alert-danger"; | ||
} | ||
if (icon == "success") | ||
{ | ||
icon = "check"; | ||
if (string.IsNullOrEmpty(alertClass)) | ||
alertClass = "success"; | ||
} | ||
|
||
if (icon == "warning" || icon == "error" || icon == "danger") | ||
icon = icon + " text-danger"; // force to error color | ||
|
||
if (dismissible && !alertClass.Contains("alert-dismissible")) | ||
alertClass += " alert-dismissible"; | ||
|
||
string messageText = !messageAsHtml ? System.Net.WebUtility.HtmlEncode(message) : message; | ||
string headerText = !headerAsHtml ? System.Net.WebUtility.HtmlEncode(header) : header; | ||
|
||
output.TagName = "div"; | ||
|
||
// fix up CSS class | ||
if (cssClass != null) | ||
cssClass = cssClass + " alert alert-" + alertClass; | ||
else | ||
cssClass = "alert alert-" + alertClass; | ||
output.Attributes.Add("class", cssClass); | ||
output.Attributes.Add("role", "alert"); | ||
|
||
StringBuilder sb = new StringBuilder(); | ||
|
||
if (dismissible) | ||
sb.Append( | ||
"<button type =\"button\" class=\"close\" data-dismiss=\"alert\" aria-label=\"Close\">\r\n" | ||
+ " <span aria-hidden=\"true\">×</span>\r\n" | ||
+ "</button>\r\n" | ||
); | ||
|
||
if (string.IsNullOrEmpty(header)) | ||
{ | ||
if (!string.IsNullOrEmpty(icon)) | ||
{ | ||
sb.Append($"<i class='fa fa-{icon}'></i> "); | ||
} | ||
sb.Append($"{messageText}"); | ||
} | ||
else | ||
{ | ||
sb.Append($"<h3>"); | ||
if (!string.IsNullOrEmpty(icon)) | ||
{ | ||
sb.Append($"<i class='fa fa-{icon}'></i> "); | ||
} | ||
sb.Append($"{headerText}</h3>\r\n" + "<hr/>\r\n" + $"{messageText}\r\n"); | ||
} | ||
output.Content.SetHtmlContent(sb.ToString()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
namespace Dgmjr.Extensions.Configuration; | ||
|
||
public class ConfigurationJsonConverter : JsonConverter<IConfiguration> | ||
{ | ||
public override IConfiguration? Read(ref Utf8JsonReader reader, type typeToConvert, Jso options) | ||
{ | ||
using var jsonStream = new MemoryStream(reader.ValueSpan.ToArray()); | ||
return new ConfigurationBuilder().AddJsonStream(jsonStream).Build(); | ||
} | ||
|
||
public override void Write(Utf8JsonWriter writer, IConfiguration value, Jso options) | ||
{ | ||
writer.WriteStartObject(); | ||
foreach (var section in value.GetChildren()) | ||
{ | ||
writer.WritePropertyName(section.Key); | ||
if (section.GetChildren().Any()) | ||
{ | ||
Write(writer, section, options); | ||
} | ||
else | ||
{ | ||
writer.WriteStringValue(section.Value); | ||
} | ||
} | ||
writer.WriteEndObject(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{B283EBC2-E01F-412D-9339-FD56EF114549}" | ||
ProjectSection(SolutionItems) = preProject | ||
..\..\Directory.Build.props = ..\..\Directory.Build.props | ||
..\..\..\..\Directory.Build.targets = ..\..\..\..\Directory.Build.targets | ||
..\..\..\..\global.json = ..\..\..\..\global.json | ||
..\..\..\..\Packages\Versions.Local.props = ..\..\..\..\Packages\Versions.Local.props | ||
EndProjectSection | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dgmjr.Configuration.Extensions", "Dgmjr.Configuration.Extensions.csproj", "{C10E1908-6EE4-4069-ABBB-33427AC25720}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Local|Any CPU = Local|Any CPU | ||
Debug|Any CPU = Debug|Any CPU | ||
Testing|Any CPU = Testing|Any CPU | ||
Staging|Any CPU = Staging|Any CPU | ||
Production|Any CPU = Production|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{C10E1908-6EE4-4069-ABBB-33427AC25720}.Local|Any CPU.ActiveCfg = Local|Any CPU | ||
{C10E1908-6EE4-4069-ABBB-33427AC25720}.Local|Any CPU.Build.0 = Local|Any CPU | ||
{C10E1908-6EE4-4069-ABBB-33427AC25720}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{C10E1908-6EE4-4069-ABBB-33427AC25720}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{C10E1908-6EE4-4069-ABBB-33427AC25720}.Testing|Any CPU.ActiveCfg = Testing|Any CPU | ||
{C10E1908-6EE4-4069-ABBB-33427AC25720}.Testing|Any CPU.Build.0 = Testing|Any CPU | ||
{C10E1908-6EE4-4069-ABBB-33427AC25720}.Staging|Any CPU.ActiveCfg = Staging|Any CPU | ||
{C10E1908-6EE4-4069-ABBB-33427AC25720}.Staging|Any CPU.Build.0 = Staging|Any CPU | ||
{C10E1908-6EE4-4069-ABBB-33427AC25720}.Production|Any CPU.ActiveCfg = Local|Any CPU | ||
{C10E1908-6EE4-4069-ABBB-33427AC25720}.Production|Any CPU.Build.0 = Local|Any CPU | ||
{C10E1908-6EE4-4069-ABBB-33427AC25720}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{C10E1908-6EE4-4069-ABBB-33427AC25720}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {E8FAF0BF-8DF5-4922-A103-786B5533648B} | ||
EndGlobalSection | ||
EndGlobal |
Oops, something went wrong.