Skip to content

Commit b727cf1

Browse files
committed
Introduce support for RelativeTopicPath
Previously, we added a `RelativeTopicPath` attribute to `TopicListAttribute`, and accounted for it the `TopicListAttributeTopicViewModel`, but we never integrated that functionality into `TopicListViewComponent`. Oops. As part of that, I rearranged the logic so that the code for the `GetTopics()` call is centralized, instead of handling it separately for `RelativeTopicBase` and `RootTopic`.
1 parent 7f027c6 commit b727cf1

1 file changed

Lines changed: 19 additions & 15 deletions

File tree

OnTopic.Editor.AspNetCore/Components/TopicListViewComponent.cs

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using OnTopic.Editor.Models;
1313
using OnTopic.Editor.Models.Metadata;
1414
using OnTopic.Editor.Models.Queryable;
15+
using OnTopic.Querying;
1516
using OnTopic.Repositories;
1617

1718
namespace OnTopic.Editor.AspNetCore.Components {
@@ -87,39 +88,42 @@ public IViewComponentResult Invoke(
8788
var defaultValue = currentTopic.Attributes.ContainsKey(attribute.Key)? currentTopic.Attributes[attribute.Key] : null;
8889

8990
/*------------------------------------------------------------------------------------------------------------------------
90-
| Get values
91+
| Get root topic
9192
\-----------------------------------------------------------------------------------------------------------------------*/
92-
var topics = (List<QueryResultTopicViewModel>)null;
93+
var rootTopic = (Topic)null;
9394

9495
if (attribute.RelativeTopicBase != null) {
9596
var baseTopic = _topicRepository.Load(currentTopic.UniqueKey);
96-
var rootTopic = attribute.RelativeTopicBase switch {
9797
if (String.IsNullOrEmpty(currentTopic.Key)) {
9898
baseTopic = TopicFactory.Create("NewTopic", currentTopic.ContentType, baseTopic);
9999
baseTopic.Parent.Children.Remove(baseTopic);
100100
}
101+
rootTopic = attribute.RelativeTopicBase switch {
101102
"CurrentTopic" => baseTopic,
102103
"ParentTopic" => baseTopic.Parent,
103104
"GrandparentTopic" => (Topic)baseTopic.Parent?.Parent,
104105
"ContentTypeDescriptor" => (Topic)_topicRepository.GetContentTypeDescriptors().FirstOrDefault(t => t.Key.Equals(baseTopic.ContentType)),
105106
_ => baseTopic
106107
};
107-
topics = GetTopics(
108-
rootTopic,
109-
attribute.AttributeKey,
110-
attribute.AttributeValue,
111-
allowedKeys
112-
);
113108
}
114109
else {
115-
topics = GetTopics(
116-
_topicRepository.Load(attribute.RootTopic?.UniqueKey?? attribute.RootTopicKey),
117-
attribute.AttributeKey,
118-
attribute.AttributeValue,
119-
allowedKeys
120-
);
110+
rootTopic = _topicRepository.Load(attribute.RootTopic?.UniqueKey?? attribute.RootTopicKey);
111+
}
112+
113+
if (rootTopic != null && !String.IsNullOrEmpty(attribute.RelativeTopicPath)) {
114+
rootTopic = rootTopic.GetByUniqueKey(rootTopic.GetUniqueKey() + ":" + attribute.RelativeTopicPath);
121115
}
122116

117+
/*------------------------------------------------------------------------------------------------------------------------
118+
| Get values
119+
\-----------------------------------------------------------------------------------------------------------------------*/
120+
var topics = GetTopics(
121+
rootTopic,
122+
attribute.AttributeKey,
123+
attribute.AttributeValue,
124+
allowedKeys
125+
);
126+
123127
/*------------------------------------------------------------------------------------------------------------------------
124128
| Get values from repository
125129
\-----------------------------------------------------------------------------------------------------------------------*/

0 commit comments

Comments
 (0)