Skip to content

Commit

Permalink
Merge branch 'release/4.6.0' into master
Browse files Browse the repository at this point in the history
This is primarily a maintenance update focused on a number of under-the-hood improvements, such as adoption of C# 9.0, as well as some minor bug fixes related to the user interface, such as ensuring nested topics can be rolled back. Normally, this would be considered a patch (i.e., 4.5.1) since it contains no new features. We're sticking with 4.6.0, however, to align it with the corresponding release of OnTopic 4.6.0.

Bug Fixes
- Reset content type in `ContentTypeListViewComponent` when modal window is triggered (b6868cf)
- Display `PermittedContentTypes` from parent topic on left rail when creating a new topic (9beeb8a)
- Hide `DisableDelete` warning when creating new topics of protected content types (5ddbd26)
- Allow rollback to previous versions of nested topics within large-window modals (780e7ed)
- Ensure versions in version history don't wrap even when using long date/times (0072c55)

Improvements
- Updated code to use C# 9.0 pattern matching and implicitly typed initializers (4962a85)
- Updated to latest versions of internal packages, including OnTopic 4.6.0 (dee88f0)
- Updated to latest version of Code Analysis and fixed most issues introduced with C# 9.0 (11331ea)
  • Loading branch information
JeremyCaney committed Dec 1, 2020
2 parents 22b5f4f + dee88f0 commit f28a6c9
Show file tree
Hide file tree
Showing 50 changed files with 395 additions and 216 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<LangVersion>9.0</LangVersion>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
<UserSecretsId>aff0d52c-eab2-4c07-88b2-5af34649f874</UserSecretsId>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="OnTopic" Version="4.5.0" />
<PackageReference Include="OnTopic.ViewModels" Version="4.5.0" />
<PackageReference Include="OnTopic.AspNetCore.Mvc" Version="4.5.0" />
<PackageReference Include="OnTopic.Data.Caching" Version="4.5.0" />
<PackageReference Include="OnTopic.Data.Sql" Version="4.5.0" />
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.3.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="OnTopic" Version="4.6.0" />
<PackageReference Include="OnTopic.ViewModels" Version="4.6.0" />
<PackageReference Include="OnTopic.AspNetCore.Mvc" Version="4.6.0" />
<PackageReference Include="OnTopic.Data.Caching" Version="4.6.0" />
<PackageReference Include="OnTopic.Data.Sql" Version="4.6.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="3.1.8" />
</ItemGroup>

Expand Down
10 changes: 10 additions & 0 deletions OnTopic.Editor.AspNetCore.Host/SampleActivator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ public SampleActivator(string connectionString, IWebHostEnvironment webHostEnvir
/// <returns>A concrete instance of an <see cref="IController"/>.</returns>
public object Create(ControllerContext context) {

/*------------------------------------------------------------------------------------------------------------------------
| Validate parameters
\-----------------------------------------------------------------------------------------------------------------------*/
Contract.Requires(context, nameof(context));

/*------------------------------------------------------------------------------------------------------------------------
| Determine controller type
\-----------------------------------------------------------------------------------------------------------------------*/
Expand All @@ -111,6 +116,11 @@ public object Create(ControllerContext context) {
/// <returns>A concrete instance of an <see cref="IController"/>.</returns>
public object Create(ViewComponentContext context) {

/*------------------------------------------------------------------------------------------------------------------------
| Validate parameters
\-----------------------------------------------------------------------------------------------------------------------*/
Contract.Requires(context, nameof(context));

/*------------------------------------------------------------------------------------------------------------------------
| Determine view component type
\-----------------------------------------------------------------------------------------------------------------------*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@model ContentTypeListViewModel

@if (Model.TopicList.Count == 1) {
@if (Model.TopicList.Count is 1) {
<!-- New topics are not permitted in this context -->
}

Expand All @@ -20,7 +20,9 @@ else if (Model.TopicList.Count > 2) {
var option = $('option:selected', this);
@if (Model.EnableModal?? false) {
<text>
initEditorModal('@Model.AttributeKey', option.text(), option.val(), @Model.OnModalClose); return false;
initEditorModal('@Model.AttributeKey', option.text(), option.val(), @Model.OnModalClose);
$(this).prop('selectedIndex', 0);
return false;
</text>
}
else {
Expand All @@ -37,7 +39,7 @@ else if (Model.TopicList.Count > 2) {

else {
<div class="ChildTopic">
@if (Model.EnableModal == true) {
@if (Model.EnableModal is true) {
<a onclick="initEditorModal('@Model.AttributeKey', '@Model.TopicList.LastOrDefault().Text', '@Model.TopicList.LastOrDefault().Value', @Model.OnModalClose); return false;" class="btn btn-info btn-sm">
<span class="fa fa-plus"></span>
@Model.TopicList.LastOrDefault().Text
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<div id="FormArea" class="row form area">

<div class="col-md-12">
@if (Model.ContentTypeDescriptor.DisableDelete) {
@if (Model.ContentTypeDescriptor.DisableDelete && !Model.IsNew) {
<div class="alert alert-warning" role="alert">
<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<strong>Warning:</strong> This topic is part of the OnTopic internal organizational structure and is not intended to be modified. Deletion of this Topic has been disabled.
Expand All @@ -31,7 +31,7 @@
@Model.ContentTypeDescriptor.Description
</div>
}
@if (Model.Topic.DerivedTopic != null) {
@if (Model.Topic.DerivedTopic is not null) {
<div class="alert alert-primary" role="alert">
<strong>Note:</strong> This topic derives from <a href="@Url.Action("Edit", new { path = Model.Topic.DerivedTopic.WebPath })">@Model.Topic.DerivedTopic.Title</a>. Any values not explicitly defined here will be inherited from that topic.
</div>
Expand All @@ -46,7 +46,7 @@

var displayGroupId = displayGroupName.Replace(" ", String.Empty);

<div id="Group_@displayGroupId" class="tab-pane fade@(index == 0 ? " show active" : "")" role="tabpanel" aria-labelledby="Tab_@displayGroupId">
<div id="Group_@displayGroupId" class="tab-pane fade@(index is 0 ? " show active" : "")" role="tabpanel" aria-labelledby="Tab_@displayGroupId">
<section id="Section_@displayGroupId">

@foreach (var attribute in Model.ContentTypeDescriptor.GetAttributeDescriptors(displayGroupName)) {
Expand Down Expand Up @@ -105,7 +105,7 @@
}
});

@if (Model.Topic.DerivedTopic != null) {
@if (Model.Topic.DerivedTopic is not null) {
<text>
/**
* Disable required fields if derived topic, as missing values will be inherited
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@

@if (Model.Topic.VersionHistory.Count > 1) {
<!-- Versions -->
<div id="VersionsDropdown" class="dropdown d-none d-lg-inline-block" style="display:inline-block;">
<div id="VersionsDropdown" class="dropdown d-none d-md-inline-block" style="display:inline-block;">
<button class="btn btn-sm btn-ancillary dropdown-toggle" type="button" id="VersionsButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="fa fa-history"></span>
Versions
<span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu" aria-labelledby="VersionsButton" style="left: 3px; top: 98%;">
<ul class="dropdown-menu" role="menu" aria-labelledby="VersionsButton">
@foreach (DateTime version in Model.Topic.VersionHistory) {
<li role="presentation" class="small">
<a tabindex="-1" role="menuitem" href="@Url.Action("SetVersion", "Editor", new { path=Model.Topic.WebPath, version=version.ToString("MM/dd/yyyy hh:mm:ss.fff tt"), isModal=Model.IsModal })">@version.ToString()</a>
Expand Down Expand Up @@ -64,7 +64,7 @@
var displayGroupName = displayGroups[i];
var displayGroupId = displayGroups[i].Replace(" ", String.Empty);
<li class="nav-item">
<a id="Tab_@displayGroupId" class="nav-link @(i == 0 ? "active" : "")" href="#Group_@displayGroupId" data-toggle="tab" role="tab" aria-controls="#Group_@displayGroupId" aria-expanded="@(i == 0 ? "true" : "false")">@displayGroupName</a>
<a id="Tab_@displayGroupId" class="nav-link @(i is 0 ? "active" : "")" href="#Group_@displayGroupId" data-toggle="tab" role="tab" aria-controls="#Group_@displayGroupId" aria-expanded="@(i is 0 ? "true" : "false")">@displayGroupName</a>
</li>
}
</ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using OnTopic.Editor.AspNetCore.Models;
using OnTopic.Editor.Models;
using OnTopic.Editor.Models.Metadata;
using OnTopic.Internal.Diagnostics;
using OnTopic.Repositories;

namespace OnTopic.Editor.AspNetCore.Components {
Expand Down Expand Up @@ -58,6 +59,11 @@ public IViewComponentResult Invoke(
string onModalClose = null
) {

/*------------------------------------------------------------------------------------------------------------------------
| Validate parameters
\-----------------------------------------------------------------------------------------------------------------------*/
Contract.Requires(currentTopic, nameof(currentTopic));

/*------------------------------------------------------------------------------------------------------------------------
| Establish view model
\-----------------------------------------------------------------------------------------------------------------------*/
Expand All @@ -72,7 +78,7 @@ public IViewComponentResult Invoke(
| Set label
\-----------------------------------------------------------------------------------------------------------------------*/
viewModel.TopicList.Add(
new SelectListItem {
new() {
Value = null,
Text = "Add a child topic…"
}
Expand All @@ -83,7 +89,7 @@ public IViewComponentResult Invoke(
\-----------------------------------------------------------------------------------------------------------------------*/
foreach (var contentType in values.OrderBy(c => c.Title)) {
viewModel.TopicList.Add(
new SelectListItem {
new() {
Value = getValue(contentType.Key),
Text = contentType.Title
}
Expand All @@ -94,13 +100,14 @@ public IViewComponentResult Invoke(
| Get content type
>-------------------------------------------------------------------------------------------------------------------------
| If the database is uninitialized, the content type won't be found. In that case, return an empty view, which will
| effectively hide the component.
| effectively hide the component. If the topic cannot be found, assume it is a new topic and attempt to load the parent
| for context.
\-----------------------------------------------------------------------------------------------------------------------*/
var contentTypes = _topicRepository.GetContentTypeDescriptors();
var actualTopic = _topicRepository.Load(currentTopic.Id);
var actualTopic = _topicRepository.Load(currentTopic.Id)?? _topicRepository.Load(currentTopic.Parent.Id);
var actualContentType = contentTypes.GetTopic(currentTopic.ContentType);

if (actualContentType == null) {
if (actualContentType is null || actualTopic is null) {
return View(viewModel);
}

Expand All @@ -118,7 +125,7 @@ public IViewComponentResult Invoke(
.Relationships
.GetTopics("ContentTypes")
.Select(c =>
new SelectListItem {
new SelectListItem() {
Value = getValue(c.Key),
Text = c.Title
}
Expand All @@ -136,7 +143,7 @@ public IViewComponentResult Invoke(
| content types explicitly annotated as "implicitly permitted", and which are not marked as hidden are displayed. This
| typically include the Page content type, and popular derivatives of it, such as Content List.
\-----------------------------------------------------------------------------------------------------------------------*/
if (viewModel.TopicList.Count.Equals(1) && !actualContentType.DisableChildTopics) {
if (viewModel.TopicList.Count is 1 && !actualContentType.DisableChildTopics) {
viewModel.TopicList.AddRange(
contentTypes
.Where(c => actualContentType.Equals("Container") || c.Attributes.GetBoolean("ImplicitlyPermitted", false))
Expand Down
7 changes: 7 additions & 0 deletions OnTopic.Editor.AspNetCore/Components/DateTimeViewComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using OnTopic.Editor.Models;
using OnTopic.Editor.Models.Components.ViewModels;
using OnTopic.Editor.Models.Metadata;
using OnTopic.Internal.Diagnostics;

namespace OnTopic.Editor.AspNetCore.Components {

Expand Down Expand Up @@ -39,6 +40,12 @@ public IViewComponentResult Invoke(
string htmlFieldPrefix
) {

/*------------------------------------------------------------------------------------------------------------------------
| Validate parameters
\-----------------------------------------------------------------------------------------------------------------------*/
Contract.Requires(currentTopic, nameof(currentTopic));
Contract.Requires(attribute, nameof(attribute));

/*------------------------------------------------------------------------------------------------------------------------
| Set HTML prefix
\-----------------------------------------------------------------------------------------------------------------------*/
Expand Down
22 changes: 17 additions & 5 deletions OnTopic.Editor.AspNetCore/Components/FileListViewComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using OnTopic.Editor.AspNetCore.Models;
using OnTopic.Editor.Models;
using OnTopic.Editor.Models.Metadata;
using OnTopic.Internal.Diagnostics;

#nullable enable

Expand Down Expand Up @@ -52,6 +53,12 @@ public IViewComponentResult Invoke(
string htmlFieldPrefix
) {

/*------------------------------------------------------------------------------------------------------------------------
| Validate parameters
\-----------------------------------------------------------------------------------------------------------------------*/
Contract.Requires(currentTopic, nameof(currentTopic));
Contract.Requires(attribute, nameof(attribute));

/*------------------------------------------------------------------------------------------------------------------------
| Set HTML prefix
\-----------------------------------------------------------------------------------------------------------------------*/
Expand All @@ -73,7 +80,7 @@ string htmlFieldPrefix
/*------------------------------------------------------------------------------------------------------------------------
| Set model values
\-----------------------------------------------------------------------------------------------------------------------*/
model.Files = GetFiles(model.InheritedValue, attribute, model.AbsolutePath);
model.Files.AddRange(GetFiles(model.InheritedValue, attribute, model.AbsolutePath));
model.AbsolutePath = _webHostEnvironment.ContentRootPath + attribute.Path;

/*------------------------------------------------------------------------------------------------------------------------
Expand All @@ -95,6 +102,11 @@ public static List<SelectListItem> GetFiles(
string absolutePath
) {

/*------------------------------------------------------------------------------------------------------------------------
| Validate parameters
\-----------------------------------------------------------------------------------------------------------------------*/
Contract.Requires(attribute, nameof(attribute));

/*------------------------------------------------------------------------------------------------------------------------
| INSTANTIATE OBJECTS
\-----------------------------------------------------------------------------------------------------------------------*/
Expand All @@ -111,14 +123,14 @@ string absolutePath
/*------------------------------------------------------------------------------------------------------------------------
| Filter file list based on extension
\-----------------------------------------------------------------------------------------------------------------------*/
if (attribute.Extension != null) {
if (attribute.Extension is not null) {
searchPattern = searchPattern + "." + attribute.Extension;
}

/*------------------------------------------------------------------------------------------------------------------------
| Filter file list based on filter criteria
\-----------------------------------------------------------------------------------------------------------------------*/
if (attribute.Filter != null) {
if (attribute.Filter is not null) {
searchPattern = attribute.Filter + searchPattern;
}

Expand All @@ -128,12 +140,12 @@ string absolutePath
var foundFiles = Directory.GetFiles(absolutePath, searchPattern, searchOption);

if (!String.IsNullOrEmpty(inheritedValue)) {
files.Add(new SelectListItem("", inheritedValue));
files.Add(new("", inheritedValue));
}
foreach (var foundFile in foundFiles) {
var fileName = foundFile.Replace(absolutePath, "");
var fileNameKey = fileName.Replace("." + attribute.Extension, "");
files.Add(new SelectListItem(fileNameKey, fileName));
files.Add(new(fileNameKey, fileName));
}

/*------------------------------------------------------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit f28a6c9

Please sign in to comment.