Skip to content

Commit 4fee666

Browse files
committed
Merge branch 'feature/SelectableTreeView-Expansion' into develop
Previously, when a relationship was exposed via the editor via the `OnTopic.SelectableTreeView` script, all nodes were closed. This could make it cumbersome to identify which topics, if any, were selected, and especially when working with a large tree. Given this, a new feature has been introduced to allow the `OnTopic.SelectableTreeView` to default to expanding any nodes leading to a selected (related) value. This functionality can be controlled via the new `TopicQueryOptions.ExpandRelated` value, which by default is set to `true`, assuming `TopicQueryOptions.MarkRelated` is set to `true`. (There's no point in expanding to related topics if those topics themselves are not checked.) Further, this option is exposed as a configuration attribute on the `RelationshipAttribute` content type descriptor, thus allowing the preference to be configured on a per-relationship basis. The `RelationshipViewComponent` relays this to the view via the `RelationshipAttributeTopicViewModel`, which then binds it to the `OnTopic.SelectableTreeView`'s `dataUrl` configuration, which is in turn used by the `EditorController.Json()` action to relay that information to the `TopicQueryService`, where is it bound to an `TopicQueryOptions` instance, and used to control the output of the service.
2 parents 57c6714 + 1fa2d52 commit 4fee666

5 files changed

Lines changed: 53 additions & 6 deletions

File tree

OnTopic.Editor.AspNetCore/Areas/Editor/Views/Editor/Components/Relationship/Default.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<script type="text/javascript">
1717
Ext.onReady(function(){
1818
var tree = new OnTopic.SelectableTreeView({
19-
dataUrl : '/OnTopic/Json/@rootTopicKey?ShowRoot=@descriptor.ShowRoot&ShowAll=true&RelatedNamespace=@descriptor.Key&RelatedTopicID=@Model.CurrentTopic.Id&AttributeName=@descriptor.AttributeKey&AttributeValue=@descriptor.AttributeValue',
19+
dataUrl : '/OnTopic/Json/@rootTopicKey?ShowRoot=@descriptor.ShowRoot&ShowAll=true&RelatedNamespace=@descriptor.Key&RelatedTopicID=@Model.CurrentTopic.Id&AttributeName=@descriptor.AttributeKey&AttributeValue=@descriptor.AttributeValue&ExpandRelated=@descriptor.ExpandRelated',
2020
checkAscendants : @((descriptor.CheckAscendants is true).ToString().ToLower()),
2121
backingField : '@Html.IdFor(m => m.Value)'
2222
});

OnTopic.Editor.AspNetCore/Infrastructure/TopicQueryService.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ private void MapQueryResult(
100100
topic.GetUniqueKey(),
101101
topic.GetWebPath(),
102102
options.EnableCheckboxes ? (options.MarkRelated ? related.Contains(topic) : true) : new bool?(),
103-
topic.Attributes.GetValue("DisableDelete", "0").Equals("0")
103+
topic.Attributes.GetValue("DisableDelete", "0").Equals("0"),
104+
options.ExpandRelated && related.Any(r => r.GetUniqueKey().StartsWith(topic.GetUniqueKey(), StringComparison.Ordinal))
104105
);
105106

106107
//Add topic to topic list

OnTopic.Editor.Models/Metadata/RelationshipAttributeTopicViewModel.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ public class RelationshipAttributeTopicViewModel: QueryableTopicListAttributeTop
2525
/// </summary>
2626
public bool? ShowRoot { get; set; }
2727

28+
/*==========================================================================================================================
29+
| PROPERTY: EXPAND RELATED?
30+
\-------------------------------------------------------------------------------------------------------------------------*/
31+
/// <summary>
32+
/// Determines whether or not the tree panel should be expanded to ensure visibility of any related (checked)
33+
/// relationships upon load. Defaults to <c>true</c>.
34+
/// </summary>
35+
public bool? ExpandRelated { get; set; }
36+
2837
/*==========================================================================================================================
2938
| PROPERTY: CHECK ASCENDANTS
3039
\-------------------------------------------------------------------------------------------------------------------------*/

OnTopic.Editor.Models/Queryable/QueryResultTopicViewModel.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ public QueryResultTopicViewModel(
3535
string uniqueKey,
3636
string webPath,
3737
bool? isChecked = null,
38-
bool isDraggable = true
38+
bool isDraggable = true,
39+
bool isExpanded = false
3940
) {
4041

4142
/*------------------------------------------------------------------------------------------------------------------------
@@ -47,6 +48,7 @@ public QueryResultTopicViewModel(
4748
UniqueKey = uniqueKey;
4849
WebPath = webPath;
4950
IsDraggable = isDraggable;
51+
IsExpanded = isExpanded;
5052

5153
if (isChecked.HasValue) {
5254
IsChecked = isChecked.Value;
@@ -138,6 +140,24 @@ public bool IsDraggable {
138140
[JsonPropertyName("leaf")]
139141
public bool IsLeaf => Children.Count.Equals(0);
140142

143+
/*==========================================================================================================================
144+
| IS EXPANDED?
145+
\-------------------------------------------------------------------------------------------------------------------------*/
146+
/// <summary>
147+
/// Determines whether the current node should be expanded, assuming it's not a <see cref="IsLead"/> node.
148+
/// </summary>
149+
/// <remarks>
150+
/// The <c>TopicQueryService</c> will set this value based if a <see cref="TopicQueryOptions.RelatedTopicId"/> is
151+
/// specified, and <see cref="TopicQueryOptions.MarkRelated"/> is set to <c>true</c>. Specifically, it will mark any item
152+
/// whose <see cref="Topic.GetUniqueKey()"/> starts with the <see cref="Topic.GetUniqueKey()"/> of any <see cref="Topic.
153+
/// Relationships"/> associated with the <see cref="TopicQueryOptions.RelatedTopicId"/>, thus ensuring that all selected
154+
/// items are expanded.
155+
/// </remarks>
156+
[JsonPropertyName("expanded")]
157+
public bool IsExpanded {
158+
get;
159+
}
160+
141161
/*==========================================================================================================================
142162
| CHILDREN
143163
\-------------------------------------------------------------------------------------------------------------------------*/

OnTopic.Editor.Models/Queryable/TopicQueryOptions.cs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public class TopicQueryOptions {
1919
| PRIVATE VARIABLES
2020
\-------------------------------------------------------------------------------------------------------------------------*/
2121
bool _markRelated = false;
22+
bool _expandRelated = true;
2223
bool _showCheckboxes = false;
2324

2425
/*==========================================================================================================================
@@ -44,6 +45,7 @@ public TopicQueryOptions() {
4445
AttributeValue = null;
4546
Query = null;
4647
MarkRelated = false;
48+
ExpandRelated = true;
4749
RelatedTopicId = -1;
4850
RelatedNamespace = null;
4951
EnableCheckboxes = false;
@@ -195,18 +197,33 @@ public bool EnableCheckboxes {
195197
| MARK RELATED
196198
\-------------------------------------------------------------------------------------------------------------------------*/
197199
/// <summary>
198-
/// Determines whether <see cref="QueryResultTopicViewModel"/>s should be marked as <see cref="QueryResultTopicViewModel.IsChecked"/>
199-
/// based on their presence in related topics.
200+
/// Determines whether <see cref="QueryResultTopicViewModel"/>s should be marked as <see cref="QueryResultTopicViewModel.
201+
/// IsChecked"/> based on their presence in related topics.
200202
/// </summary>
201203
/// <remarks>
202-
/// This will automatically be set to true is <see cref="RelatedTopicId"/> or <see cref="RelatedNamespace"/> are set. If
204+
/// This will automatically be set to true if <see cref="RelatedTopicId"/> or <see cref="RelatedNamespace"/> are set. If
203205
/// <see cref="RelatedTopicId"/> is <i>not</i> set, then the current <see cref="Topic"/> should be assumed.
204206
/// </remarks>
205207
public bool MarkRelated {
206208
get => (RelatedTopicId > 0 || !String.IsNullOrEmpty(RelatedNamespace) || _markRelated);
207209
set => _markRelated = value;
208210
}
209211

212+
/*==========================================================================================================================
213+
| EXPAND RELATED
214+
\-------------------------------------------------------------------------------------------------------------------------*/
215+
/// <summary>
216+
/// Determines whether <see cref="QueryResultTopicViewModel"/>s should be marked ascendants as nodes marked as <see
217+
/// cref="QueryResultTopicViewModel.IsChecked"/> as <see cref="QueryResultTopicViewModel.IsExpanded"/>.
218+
/// </summary>
219+
/// <remarks>
220+
/// This will automatically be set to true if <see cref="MarkRelated"/> is set to true.
221+
/// </remarks>
222+
public bool ExpandRelated {
223+
get => (MarkRelated && _expandRelated);
224+
set => _expandRelated = value;
225+
}
226+
210227
/*==========================================================================================================================
211228
| RELATED TOPIC ID
212229
\-------------------------------------------------------------------------------------------------------------------------*/

0 commit comments

Comments
 (0)