1
1
using rubberduckvba . Server . Model ;
2
+ using rubberduckvba . Server . Model . Entity ;
2
3
3
4
namespace rubberduckvba . Server . Api . Features ;
4
5
5
6
public class FeatureViewModel
6
7
{
7
- public FeatureViewModel ( Feature model )
8
+ public FeatureViewModel ( Feature model , bool summaryOnly = false )
8
9
{
9
10
Id = model . Id ;
10
11
DateInserted = model . DateTimeInserted ;
11
12
DateUpdated = model . DateTimeUpdated ;
12
13
14
+ FeatureId = model . FeatureId ;
15
+ FeatureName = model . FeatureName ;
16
+
13
17
Name = model . Name ;
14
- Title = model . Title ;
18
+ Title = string . IsNullOrWhiteSpace ( model . Title ) ? model . Name : model . Title ;
19
+
15
20
ShortDescription = model . ShortDescription ;
16
- Description = model . Description ;
21
+ Description = summaryOnly ? string . Empty : model . Description ;
22
+
17
23
IsNew = model . IsNew ;
24
+ IsDiscontinued = model . IsDiscontinued ;
18
25
IsHidden = model . IsHidden ;
26
+
19
27
HasImage = model . HasImage ;
28
+ Links = model . Links . ToArray ( ) ;
20
29
21
- if ( model is FeatureGraph graph )
30
+ if ( ! summaryOnly && model is FeatureGraph graph )
22
31
{
23
- Features = graph . Features . Select ( e => new FeatureViewModel ( e ) { FeatureId = e . ParentId , FeatureName = graph . Name , FeatureTitle = graph . Title } ) . ToArray ( ) ;
32
+ Features = graph . Features . Select ( e => new FeatureViewModel ( e ) { FeatureId = graph . Id , FeatureName = graph . Name } ) . ToArray ( ) ;
24
33
}
25
34
}
26
35
@@ -30,48 +39,234 @@ public FeatureViewModel(Feature model)
30
39
31
40
public int ? FeatureId { get ; init ; }
32
41
public string ? FeatureName { get ; init ; }
33
- public string ? FeatureTitle { get ; init ; }
34
42
35
43
public string Name { get ; init ; }
36
44
public string Title { get ; init ; }
37
45
public string ShortDescription { get ; init ; }
38
46
public string Description { get ; init ; }
39
47
public bool IsNew { get ; init ; }
48
+ public bool IsDiscontinued { get ; init ; }
40
49
public bool IsHidden { get ; init ; }
41
50
public bool HasImage { get ; init ; }
42
51
43
52
public FeatureViewModel [ ] Features { get ; init ; } = [ ] ;
53
+ public BlogLink [ ] Links { get ; init ; } = [ ] ;
54
+ }
55
+
56
+ public class InspectionViewModel
57
+ {
58
+ public InspectionViewModel ( Inspection model , IDictionary < int , Tag > tagsByAssetId )
59
+ {
60
+ Id = model . Id ;
61
+ DateTimeInserted = model . DateTimeInserted ;
62
+ DateTimeUpdated = model . DateTimeUpdated ;
63
+
64
+ FeatureId = model . FeatureId ;
65
+ FeatureName = model . FeatureName ;
66
+
67
+ SourceUrl = model . SourceUrl ;
68
+ TagAssetId = model . TagAssetId ;
69
+ TagName = tagsByAssetId [ model . TagAssetId ] . Name ;
70
+
71
+ IsHidden = model . IsHidden ;
72
+ IsNew = model . IsNew ;
73
+ IsDiscontinued = model . IsDiscontinued ;
74
+
75
+ Name = model . Name ;
76
+ Summary = model . Summary ;
77
+ Remarks = model . Remarks ;
78
+
79
+ InspectionType = model . InspectionType ;
80
+ DefaultSeverity = model . DefaultSeverity ;
81
+ QuickFixes = model . QuickFixes ;
82
+
83
+ Reasoning = model . Reasoning ;
84
+ HostApp = model . HostApp ;
85
+ References = model . References ;
86
+
87
+ Examples = model . Examples ;
88
+ }
89
+
90
+ public int Id { get ; init ; }
91
+ public DateTime DateTimeInserted { get ; init ; }
92
+ public DateTime ? DateTimeUpdated { get ; init ; }
93
+ public int TagAssetId { get ; init ; }
94
+ public string SourceUrl { get ; init ; } = string . Empty ;
95
+
96
+ public int FeatureId { get ; init ; }
97
+ public string FeatureName { get ; init ; }
98
+
99
+ public string TagName { get ; init ; }
100
+
101
+ public bool IsNew { get ; init ; }
102
+ public bool IsDiscontinued { get ; init ; }
103
+ public bool IsHidden { get ; init ; }
104
+
105
+ public string Name { get ; init ; } = string . Empty ;
106
+ public string InspectionType { get ; init ; } = string . Empty ;
107
+ public string DefaultSeverity { get ; init ; } = string . Empty ;
108
+ public string Summary { get ; init ; } = string . Empty ;
109
+ public string Reasoning { get ; init ; } = string . Empty ;
110
+ public string ? Remarks { get ; init ; }
111
+ public string ? HostApp { get ; init ; }
112
+ public string [ ] References { get ; init ; } = [ ] ;
113
+ public string [ ] QuickFixes { get ; init ; } = [ ] ;
114
+ public InspectionExample [ ] Examples { get ; init ; } = [ ] ;
115
+ }
116
+
117
+ public class AnnotationViewModel
118
+ {
119
+ public AnnotationViewModel ( Annotation model , IDictionary < int , Tag > tagsByAssetId )
120
+ {
121
+ Id = model . Id ;
122
+ DateTimeInserted = model . DateTimeInserted ;
123
+ DateTimeUpdated = model . DateTimeUpdated ;
124
+ FeatureId = model . FeatureId ;
125
+
126
+ SourceUrl = model . SourceUrl ;
127
+ TagAssetId = model . TagAssetId ;
128
+ TagName = tagsByAssetId [ model . TagAssetId ] . Name ;
129
+
130
+ IsHidden = model . IsHidden ;
131
+ IsNew = model . IsNew ;
132
+ IsDiscontinued = model . IsDiscontinued ;
133
+
134
+ Name = model . Name ;
135
+ Summary = model . Summary ;
136
+ Remarks = model . Remarks ;
137
+
138
+ Parameters = model . Parameters ;
139
+ Examples = model . Examples ;
140
+ }
141
+
142
+ public int Id { get ; init ; }
143
+ public DateTime DateTimeInserted { get ; init ; }
144
+ public DateTime ? DateTimeUpdated { get ; init ; }
145
+ public int FeatureId { get ; init ; }
146
+ public int TagAssetId { get ; init ; }
147
+ public string SourceUrl { get ; init ; } = string . Empty ;
148
+
149
+ public string TagName { get ; init ; }
150
+
151
+ public bool IsNew { get ; init ; }
152
+ public bool IsDiscontinued { get ; init ; }
153
+ public bool IsHidden { get ; init ; }
154
+
155
+ public string Name { get ; init ; } = string . Empty ;
156
+
157
+ public string Summary { get ; init ; } = string . Empty ;
158
+ public string ? Remarks { get ; init ; }
159
+
160
+ public AnnotationParameter [ ] Parameters { get ; init ; } = [ ] ;
161
+ public AnnotationExample [ ] Examples { get ; init ; } = [ ] ;
162
+ }
163
+
164
+ public class QuickFixViewModel
165
+ {
166
+ public QuickFixViewModel ( QuickFix model , IDictionary < int , Tag > tagsByAssetId , IDictionary < string , Inspection > inspectionsByName )
167
+ {
168
+ Id = model . Id ;
169
+ DateTimeInserted = model . DateTimeInserted ;
170
+ DateTimeUpdated = model . DateTimeUpdated ;
171
+ FeatureId = model . FeatureId ;
172
+
173
+ SourceUrl = model . SourceUrl ;
174
+ TagAssetId = model . TagAssetId ;
175
+ TagName = tagsByAssetId [ model . TagAssetId ] . Name ;
176
+
177
+ IsHidden = model . IsHidden ;
178
+ IsNew = model . IsNew ;
179
+ IsDiscontinued = model . IsDiscontinued ;
180
+
181
+ Name = model . Name ;
182
+ Summary = model . Summary ;
183
+ Remarks = model . Remarks ;
184
+
185
+ CanFixAll = model . CanFixAll ;
186
+ CanFixMultiple = model . CanFixMultiple ;
187
+ CanFixProcedure = model . CanFixProcedure ;
188
+ CanFixModule = model . CanFixModule ;
189
+ CanFixProject = model . CanFixProject ;
190
+
191
+ Inspections = ( from name in model . Inspections
192
+ let inspection = inspectionsByName [ name ]
193
+ select new QuickFixInspectionLinkViewModel
194
+ {
195
+ Name = inspection . Name ,
196
+ Summary = inspection . Summary ,
197
+ InspectionType = inspection . InspectionType ,
198
+ DefaultSeverity = inspection . DefaultSeverity
199
+ } ) . ToArray ( ) ;
200
+
201
+ Examples = model . Examples ;
202
+ }
203
+
204
+ public int Id { get ; init ; }
205
+ public DateTime DateTimeInserted { get ; init ; }
206
+ public DateTime ? DateTimeUpdated { get ; init ; }
207
+ public int FeatureId { get ; init ; }
208
+ public int TagAssetId { get ; init ; }
209
+ public string SourceUrl { get ; init ; } = string . Empty ;
210
+
211
+ public string TagName { get ; init ; }
212
+
213
+ public bool IsNew { get ; init ; }
214
+ public bool IsDiscontinued { get ; init ; }
215
+ public bool IsHidden { get ; init ; }
216
+
217
+ public string Name { get ; init ; } = string . Empty ;
218
+
219
+ public string Summary { get ; init ; } = string . Empty ;
220
+ public string ? Remarks { get ; init ; }
221
+
222
+ public bool CanFixProcedure { get ; init ; }
223
+ public bool CanFixModule { get ; init ; }
224
+ public bool CanFixProject { get ; init ; }
225
+ public bool CanFixAll { get ; init ; }
226
+ public bool CanFixMultiple { get ; init ; }
227
+
228
+ public QuickFixInspectionLinkViewModel [ ] Inspections { get ; init ; } = [ ] ;
229
+ public QuickFixExample [ ] Examples { get ; init ; } = [ ] ;
230
+ }
231
+
232
+ public record class QuickFixInspectionLinkViewModel
233
+ {
234
+ public string Name { get ; init ; }
235
+ public string Summary { get ; init ; }
236
+ public string InspectionType { get ; init ; }
237
+ public string DefaultSeverity { get ; init ; }
44
238
}
45
239
46
240
public class InspectionsFeatureViewModel : FeatureViewModel
47
241
{
48
- public InspectionsFeatureViewModel ( FeatureGraph model )
49
- : base ( model )
242
+ public InspectionsFeatureViewModel ( FeatureGraph model , IDictionary < int , Tag > tagsByAssetId , bool summaryOnly = false )
243
+ : base ( model , summaryOnly )
50
244
{
51
- Inspections = model . Inspections . ToArray ( ) ;
245
+
246
+ Inspections = model . Inspections . OrderBy ( e => e . Name ) . Select ( e => new InspectionViewModel ( e , tagsByAssetId ) ) . ToArray ( ) ;
52
247
}
53
248
54
- public Inspection [ ] Inspections { get ; init ; } = [ ] ;
249
+ public InspectionViewModel [ ] Inspections { get ; init ; } = [ ] ;
55
250
}
56
251
57
252
public class QuickFixesFeatureViewModel : FeatureViewModel
58
253
{
59
- public QuickFixesFeatureViewModel ( FeatureGraph model )
60
- : base ( model )
254
+ public QuickFixesFeatureViewModel ( FeatureGraph model , IDictionary < int , Tag > tagsByAssetId , IDictionary < string , Inspection > inspectionsByName , bool summaryOnly = false )
255
+ : base ( model , summaryOnly )
61
256
{
62
- QuickFixes = model . QuickFixes . ToArray ( ) ;
257
+ QuickFixes = model . QuickFixes . OrderBy ( e => e . Name ) . Select ( e => new QuickFixViewModel ( e , tagsByAssetId , inspectionsByName ) ) . ToArray ( ) ;
63
258
}
64
259
65
- public QuickFix [ ] QuickFixes { get ; init ; } = [ ] ;
260
+ public QuickFixViewModel [ ] QuickFixes { get ; init ; } = [ ] ;
66
261
}
67
262
68
263
public class AnnotationsFeatureViewModel : FeatureViewModel
69
264
{
70
- public AnnotationsFeatureViewModel ( FeatureGraph model )
71
- : base ( model )
265
+ public AnnotationsFeatureViewModel ( FeatureGraph model , IDictionary < int , Tag > tagsByAssetId , bool summaryOnly = false )
266
+ : base ( model , summaryOnly )
72
267
{
73
- Annotations = model . Annotations . ToArray ( ) ;
268
+ Annotations = model . Annotations . OrderBy ( e => e . Name ) . Select ( e => new AnnotationViewModel ( e , tagsByAssetId ) ) . ToArray ( ) ;
74
269
}
75
270
76
- public Annotation [ ] Annotations { get ; init ; } = [ ] ;
271
+ public AnnotationViewModel [ ] Annotations { get ; init ; } = [ ] ;
77
272
}
0 commit comments