-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueryResultTopicViewModel.cs
More file actions
170 lines (153 loc) · 7.79 KB
/
QueryResultTopicViewModel.cs
File metadata and controls
170 lines (153 loc) · 7.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*==============================================================================================================================
| Author Ignia, LLC
| Client Ignia, LLC
| Project Topics Library
\=============================================================================================================================*/
using System.ComponentModel;
using System.Text.Json.Serialization;
using OnTopic.Editor.AspNetCore.Controllers;
namespace OnTopic.Editor.AspNetCore.Models.Queryable {
/*============================================================================================================================
| CLASS: QUERY RESULT (TOPIC VIEW MODEL)
\---------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Provides a view model for query results returned from the <see cref="TopicQueryService"/>.
/// </summary>
/// The <see cref="QueryResultTopicViewModel"/> includes annotations that allow it to be serialized as JSON in compliance
/// with the expectations of the <see cref="EditorController.Json(TopicQueryOptions)"/> action.
/// <remarks>
/// </remarks>
public record QueryResultTopicViewModel {
/*==========================================================================================================================
| CONSTRUCTOR
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Initializes a new instance of the <see cref="QueryResultTopicViewModel"/> class by specifying each of the property
/// values.
/// </summary>
public QueryResultTopicViewModel(
int id,
string key,
string title,
string uniqueKey,
string webPath,
bool? isChecked = null,
bool isMovable = true,
bool isExpanded = false
) {
/*------------------------------------------------------------------------------------------------------------------------
| Set properties
\-----------------------------------------------------------------------------------------------------------------------*/
Id = id;
Key = key;
Title = title;
UniqueKey = uniqueKey;
WebPath = webPath;
IsMovable = isMovable;
IsExpanded = isExpanded;
if (isChecked.HasValue) {
IsChecked = isChecked.Value;
}
}
/*==========================================================================================================================
| ID
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// The unique identifier as set in the database as the primary key.
/// </summary>
public int Id {
get;
}
/*==========================================================================================================================
| KEY
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// The key property of the topic.
/// </summary>
public string Key {
get;
}
/*==========================================================================================================================
| TITLE
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// The title of the topic, which will fall back to <see cref="Key"/> if not set.
/// </summary>
[JsonPropertyName("text")]
public string Title {
get;
}
/*==========================================================================================================================
| UNIQUE KEY
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// The fully-qualified, unique key for the topic, in OnTopic format.
/// </summary>
[JsonPropertyName("path")]
public string UniqueKey {
get;
}
/*==========================================================================================================================
| WEB PATH
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// The fully-qualified, unique path to the topic, in HTTP format.
/// </summary>
public string WebPath {
get;
}
/*==========================================================================================================================
| IS CHECKED?
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Determines whether the current topic is selected or not.
/// </summary>
[JsonPropertyName("checked")]
public bool? IsChecked {
get;
}
/*==========================================================================================================================
| IS MOVABLE?
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Determines whether the current topic is permitted to be movable or not.
/// </summary>
[JsonPropertyName("isMovable")]
[DefaultValue(true)]
public bool IsMovable {
get;
}
/*==========================================================================================================================
| IS LEAF?
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Determines whether the current topic is a leaf node or not.
/// </summary>
[JsonPropertyName("leaf")]
public bool IsLeaf => Children.Count is 0;
/*==========================================================================================================================
| IS EXPANDED?
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Determines whether the current node should be expanded, assuming it's not a <see cref="IsLeaf"/> node.
/// </summary>
/// <remarks>
/// The <c>TopicQueryService</c> will set this value based if a <see cref="TopicQueryOptions.RelatedTopicId"/> is
/// specified, and <see cref="TopicQueryOptions.MarkRelated"/> is set to <c>true</c>. Specifically, it will mark any item
/// whose <see cref="Topic.GetUniqueKey()"/> starts with the <see cref="Topic.GetUniqueKey()"/> of any <see cref="Topic.
/// Relationships"/> associated with the <see cref="TopicQueryOptions.RelatedTopicId"/>, thus ensuring that all selected
/// items are expanded.
/// </remarks>
[JsonPropertyName("expanded")]
public bool IsExpanded {
get;
}
/*==========================================================================================================================
| CHILDREN
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Provides a collection of child objects.
/// </summary>
public Collection<QueryResultTopicViewModel> Children { get; } = new();
} // Class
} // Namespace