@using SharedLibraryCore.Configuration.Attributes @using SharedLibraryCore.Configuration; @model SharedLibraryCore.Configuration.ApplicationConfiguration @{ ViewData["Title"] = SharedLibraryCore.Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CONFIGURATION_TITLE"]; string optionalText = SharedLibraryCore.Utilities.CurrentLocalization.LocalizationIndex["COMMAND_HELP_OPTIONAL"]; string advancedText = SharedLibraryCore.Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CONFIGURATION_ADVANCED"]; string addText = SharedLibraryCore.Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CONFIGURATION_ADD"]; string saveText = SharedLibraryCore.Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CONFIGURATION_SAVE"]; string noticeText = SharedLibraryCore.Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CONFIGURATION_SAVING_CHANGES"]; string addServerText = SharedLibraryCore.Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CONFIGURATION_SERVER_ADD"]; var properties = Model.GetType().GetProperties(); string[] getLinkedPropertyName(System.Reflection.PropertyInfo info) { var test = (info.GetCustomAttributes(false) .Where(_attr => _attr.GetType() == typeof(ConfigurationLinked)) .FirstOrDefault() as ConfigurationLinked); return test?.LinkedPropertyNames ?? new string[0]; } bool shouldIgnore(System.Reflection.PropertyInfo info) => (info.GetCustomAttributes(false) .Where(_attr => _attr.GetType() == typeof(ConfigurationIgnore)) .FirstOrDefault() as ConfigurationIgnore) != null; bool isOptional(System.Reflection.PropertyInfo info) => (info.GetCustomAttributes(false) .Where(_attr => _attr.GetType() == typeof(ConfigurationOptional)) .FirstOrDefault() as ConfigurationOptional) != null; bool hasLinkedParent(System.Reflection.PropertyInfo info) { return Model.GetType().GetProperties().SelectMany(_prop => getLinkedPropertyName(_prop)).Contains(info.Name); } }

@ViewData["Title"]

@noticeText
@foreach (var property in properties) { if (shouldIgnore(property)) { continue; } string[] linkedPropertyNames = getLinkedPropertyName(property); // bool type if (property.PropertyType == typeof(bool)) {
@Html.Editor(property.Name, linkedPropertyNames.Length > 0 ? new {htmlAttributes = new {@class = "has-related-content mb-0", data_related_content = string.Join(',', linkedPropertyNames.Select(_id => $"#{_id}_content"))}} : null) @Html.Label(property.Name, null, new {@class = "form-check-label ml-1"})
} // array type else if (property.PropertyType.IsArray) { // special type for server config, I don't like this but for now it's ok @if (property.PropertyType.GetElementType() == typeof(ServerConfiguration)) {
@for (int i = 0; i < Model.Servers.Length; i++) { @Html.EditorFor(model => model.Servers[i]) ; } @addServerText
} else if (hasLinkedParent(property)) {
@if (linkedPropertyNames.Length == 0) { @Html.Label(property.Name, null, new {@class = "mt-2 d-block"}) } @Html.Editor(property.Name, new {htmlAttributes = new {@class = $"form-group form-control bg-dark text-white-50 {(linkedPropertyNames.Length == 0 ? "mb-3" : "mb-0")}"}}) @addText
} else { @Html.Label(property.Name, null, new {@class = "bg-primary pl-3 pr-3 p-2 mb-0 w-100"})
@Html.Editor(property.Name, new {htmlAttributes = new {@class = "form-control bg-dark text-white-50 mt-3 mb-3", placeholder = isOptional(property) ? optionalText : ""}}) @addText
} } else { if (hasLinkedParent(property)) {
@Html.Label(property.Name, null, new {@class = "mt-1"}) @Html.Editor(property.Name, new {htmlAttributes = new {@class = "form-group form-control bg-dark text-white-50 mb-0", placeholder = isOptional(property) ? optionalText : ""}})
} else { @Html.Label(property.Name, null, new {@class = "bg-primary pl-3 pr-3 p-2 mb-0 w-100"})
@Html.Editor(property.Name, new {htmlAttributes = new {@class = "form-group form-control bg-dark text-white-50 mb-0", placeholder = isOptional(property) ? optionalText : ""}})
} } }
@section scripts { }