|
12 | 12 | using OnTopic.Editor.Models; |
13 | 13 | using OnTopic.Editor.Models.Metadata; |
14 | 14 | using OnTopic.Editor.Models.Queryable; |
| 15 | +using OnTopic.Querying; |
15 | 16 | using OnTopic.Repositories; |
16 | 17 |
|
17 | 18 | namespace OnTopic.Editor.AspNetCore.Components { |
@@ -87,39 +88,42 @@ public IViewComponentResult Invoke( |
87 | 88 | var defaultValue = currentTopic.Attributes.ContainsKey(attribute.Key)? currentTopic.Attributes[attribute.Key] : null; |
88 | 89 |
|
89 | 90 | /*------------------------------------------------------------------------------------------------------------------------ |
90 | | - | Get values |
| 91 | + | Get root topic |
91 | 92 | \-----------------------------------------------------------------------------------------------------------------------*/ |
92 | | - var topics = (List<QueryResultTopicViewModel>)null; |
| 93 | + var rootTopic = (Topic)null; |
93 | 94 |
|
94 | 95 | if (attribute.RelativeTopicBase != null) { |
95 | 96 | var baseTopic = _topicRepository.Load(currentTopic.UniqueKey); |
96 | | - var rootTopic = attribute.RelativeTopicBase switch { |
97 | 97 | if (String.IsNullOrEmpty(currentTopic.Key)) { |
98 | 98 | baseTopic = TopicFactory.Create("NewTopic", currentTopic.ContentType, baseTopic); |
99 | 99 | baseTopic.Parent.Children.Remove(baseTopic); |
100 | 100 | } |
| 101 | + rootTopic = attribute.RelativeTopicBase switch { |
101 | 102 | "CurrentTopic" => baseTopic, |
102 | 103 | "ParentTopic" => baseTopic.Parent, |
103 | 104 | "GrandparentTopic" => (Topic)baseTopic.Parent?.Parent, |
104 | 105 | "ContentTypeDescriptor" => (Topic)_topicRepository.GetContentTypeDescriptors().FirstOrDefault(t => t.Key.Equals(baseTopic.ContentType)), |
105 | 106 | _ => baseTopic |
106 | 107 | }; |
107 | | - topics = GetTopics( |
108 | | - rootTopic, |
109 | | - attribute.AttributeKey, |
110 | | - attribute.AttributeValue, |
111 | | - allowedKeys |
112 | | - ); |
113 | 108 | } |
114 | 109 | 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); |
121 | 115 | } |
122 | 116 |
|
| 117 | + /*------------------------------------------------------------------------------------------------------------------------ |
| 118 | + | Get values |
| 119 | + \-----------------------------------------------------------------------------------------------------------------------*/ |
| 120 | + var topics = GetTopics( |
| 121 | + rootTopic, |
| 122 | + attribute.AttributeKey, |
| 123 | + attribute.AttributeValue, |
| 124 | + allowedKeys |
| 125 | + ); |
| 126 | + |
123 | 127 | /*------------------------------------------------------------------------------------------------------------------------ |
124 | 128 | | Get values from repository |
125 | 129 | \-----------------------------------------------------------------------------------------------------------------------*/ |
|
0 commit comments