Skip to content

Commit adf7ff8

Browse files
committed
Centralized key navigation properties to INavigableTopicViewModel
These were already defined on `INavigationTopicViewModel<T>`, but that _also_ implemented `IHierarchicalTopicViewModel<T>`. Sometimes, there are topics that should be evaluated for navigation, but which _aren't_ hierarchical, and which _don't_ necessitate the use of e.g. the `IHierarchicalTopicMappingService` or `NavigationViewComponentBase<T>`. For example, offering a list of child topics on a page. In this case, these _may_ implement `IHierarchicalTopicViewModel<T>`, but they only _need_ `Title`, `ShortTitle`, and `WebPath`. To support this, the `INavigableTopicViewModel` extracts these from the `INavigationTopicViewModel<T>` so they can, optionally, be applied independently. Then, the `INavigationTopicViewModel<T>` effectively becomes a composite of `INavigableTopicViewModel` and `IHierarchicalTopicViewModel<T>`, adding only `IsSelected()`. This is useful since the view models for the `NavigationTopicViewComponent<T>` are likely going to be independent from other view models, since most view models don't want or need a `Children` collection. But many basic view models will satisfy the `INavigableTopicViewModel` interface, and should be usable for that purpose. This allows different view models types from different chains (e.g., `OnTopic.ViewModels` and a separate customer implementation) to be handled by e.g. the same partial control.
1 parent 3e60dea commit adf7ff8

File tree

2 files changed

+51
-22
lines changed

2 files changed

+51
-22
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*==============================================================================================================================
2+
| Author Ignia, LLC
3+
| Client Ignia
4+
| Project Website
5+
\=============================================================================================================================*/
6+
using System.ComponentModel.DataAnnotations;
7+
using System.Diagnostics.CodeAnalysis;
8+
9+
namespace OnTopic.Models {
10+
11+
/*============================================================================================================================
12+
| INTERFACE: NAVIGABLE TOPIC VIEW MODEL
13+
\---------------------------------------------------------------------------------------------------------------------------*/
14+
/// <summary>
15+
/// Ensures basic properties needed to treat a view model as a navigable entry.
16+
/// </summary>
17+
/// <remarks>
18+
/// No topics are expected to have a <c>Navigable</c> content type. Instead, implementers of this view model are expected
19+
/// to manually construct instances.
20+
/// </remarks>
21+
public interface INavigableTopicViewModel {
22+
23+
/*==========================================================================================================================
24+
| PROPERTY: TITLE
25+
\-------------------------------------------------------------------------------------------------------------------------*/
26+
/// <inheritdoc cref="ITopicViewModel.Title"/>
27+
[Required, NotNull, DisallowNull]
28+
string? Title { get; init; }
29+
30+
/*==========================================================================================================================
31+
| PROPERTY: SHORT TITLE
32+
\-------------------------------------------------------------------------------------------------------------------------*/
33+
/// <summary>
34+
/// In addition to the Title, a site may opt to define a Short Title used exclusively in the navigation. If present, this
35+
/// value should be used instead of Title.
36+
/// </summary>
37+
string? ShortTitle { get; init; }
38+
39+
/*==========================================================================================================================
40+
| PROPERTY: WEB PATH
41+
\-------------------------------------------------------------------------------------------------------------------------*/
42+
/// <inheritdoc cref="ITopicViewModel.WebPath"/>
43+
[Required, NotNull, DisallowNull]
44+
string? WebPath { get; init; }
45+
46+
} //Class
47+
} //Namespace

OnTopic/Models/INavigationTopicViewModel{T}.cs

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,10 @@ namespace OnTopic.Models {
1616
/// No topics are expected to have a <c>Navigation</c> content type. Instead, implementers of this view model are expected
1717
/// to manually construct instances.
1818
/// </remarks>
19-
public interface INavigationTopicViewModel<T> : IHierarchicalTopicViewModel<T> where T: INavigationTopicViewModel<T> {
20-
21-
/*==========================================================================================================================
22-
| PROPERTY: TITLE
23-
\-------------------------------------------------------------------------------------------------------------------------*/
24-
/// <inheritdoc cref="ITopicViewModel.Title"/>
25-
string? Title { get; init; }
26-
27-
/*==========================================================================================================================
28-
| PROPERTY: SHORT TITLE
29-
\-------------------------------------------------------------------------------------------------------------------------*/
30-
/// <summary>
31-
/// In addition to the Title, a site may opt to define a Short Title used exclusively in the navigation. If present, this
32-
/// value should be used instead of Title.
33-
/// </summary>
34-
string? ShortTitle { get; init; }
35-
36-
/*==========================================================================================================================
37-
| PROPERTY: WEB PATH
38-
\-------------------------------------------------------------------------------------------------------------------------*/
39-
/// <inheritdoc cref="ITopicViewModel.WebPath"/>
40-
string? WebPath { get; init; }
19+
public interface INavigationTopicViewModel<T> :
20+
INavigableTopicViewModel,
21+
IHierarchicalTopicViewModel<T> where T: INavigationTopicViewModel<T>
22+
{
4123

4224
/*==========================================================================================================================
4325
| METHOD: IS SELECTED?

0 commit comments

Comments
 (0)