forked from Azure/azure-sdk-tools
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCodePanelModels.cs
More file actions
153 lines (143 loc) · 6.85 KB
/
CodePanelModels.cs
File metadata and controls
153 lines (143 loc) · 6.85 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
using APIView.TreeToken;
using APIView;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Text.Json.Serialization;
using APIView.Model.V2;
using ApiView;
using Microsoft.CodeAnalysis;
using System.Text;
namespace APIViewWeb.LeanModels
{
public class CodePanelRawData
{
public IEnumerable<CommentItemModel> Comments { get; set; } = new List<CommentItemModel>();
public CodeFile activeRevisionCodeFile{ get; set; }
public CodeFile diffRevisionCodeFile { get; set; }
public bool ApplySkipDiff { get; set; }
public bool SkipDocsWhenDiffing { get; set; }
}
public class CodePanelRowData
{
public CodePanelRowDatatype Type { get; set; }
public int? LineNumber { get; set; }
[JsonIgnore]
public List<StructuredToken> RowOfTokensObj { get; set; } = new List<StructuredToken>();
public List<StructuredToken> RowOfTokens => RowOfTokensObj.Count > 0 ? RowOfTokensObj : null;
public string NodeId { get; set; }
public string NodeIdHashed { get; set; }
public int RowPositionInGroup { get; set; } // The position / index of the row within the group of similar rows
public int AssociatedRowPositionInGroup { get; set; } // For comment threads, this is the position of the associated code line within the group of similar rows
[JsonIgnore]
public HashSet<string> RowClassesObj { get; set; } = new HashSet<string>();
public HashSet<string> RowClasses => RowClassesObj.Count > 0 ? RowClassesObj : null;
public int? Indent { get; set; }
public DiffKind DiffKind { get; set; }
public string ToggleDocumentationClasses { get; set; }
public string ToggleCommentsClasses { get; set; }
public CodeDiagnostic Diagnostics { get; set; }
[JsonIgnore]
public List<CommentItemModel> CommentsObj { get; set; } = new List<CommentItemModel>();
public List<CommentItemModel> Comments => CommentsObj.Count > 0 ? CommentsObj : null;
public bool IsResolvedCommentThread { get; set; }
public bool IsHiddenAPI { get; set; }
public override string ToString()
{
StringBuilder sb = new StringBuilder();
foreach(var token in RowOfTokensObj)
{
sb.Append(token.Value);
}
return sb.ToString();
}
public override bool Equals(object obj)
{
if (obj is CodePanelRowData other)
{
return ToString() == other.ToString();
}
return false;
}
public override int GetHashCode()
{
return ToString().GetHashCode();
}
}
public class CodePanelNodeMetaData
{
[JsonIgnore]
public List<CodePanelRowData> DocumentationObj { get; set; } = new List<CodePanelRowData>();
public List<CodePanelRowData> Documentation => DocumentationObj.Count > 0 ? DocumentationObj : null;
[JsonIgnore]
public List<CodePanelRowData> DiagnosticsObj { get; set; } = new List<CodePanelRowData>();
public List<CodePanelRowData> Diagnostics => DiagnosticsObj.Count > 0 ? DiagnosticsObj : null;
[JsonIgnore]
public List<CodePanelRowData> CodeLinesObj { get; set; } = new List<CodePanelRowData>();
public List<CodePanelRowData> CodeLines => CodeLinesObj.Count > 0 ? CodeLinesObj : null;
[JsonIgnore]
public Dictionary<int, CodePanelRowData> CommentThreadObj { get; set; } = []; //Dictionary key map to the index of the code line within this node which the comment thread is mapped to
public Dictionary<int, CodePanelRowData> CommentThread => CommentThreadObj.Count > 0 ? CommentThreadObj : null;
public NavigationTreeNode NavigationTreeNode { get; set; }
public string ParentNodeIdHashed { get; set; }
[JsonIgnore]
public Dictionary<int, string> ChildrenNodeIdsInOrderObj { get; set; } = [];
public Dictionary<int, string> ChildrenNodeIdsInOrder => ChildrenNodeIdsInOrderObj.Count > 0 ? ChildrenNodeIdsInOrderObj : null;
public bool IsNodeWithDiff { get; set; }
public bool IsNodeWithDiffInDescendants { get; set; }
public bool IsNodeWithNoneDocDiffInDescendants { get; set; }
public string BottomTokenNodeIdHash { get; set; }
public string RelatedNodeIdHash { get; set; }
}
public class CodePanelData
{
[JsonIgnore]
public Dictionary<string, CodePanelNodeMetaData> NodeMetaDataObj { get; set; } = new Dictionary<string, CodePanelNodeMetaData>();
public Dictionary<string, CodePanelNodeMetaData> NodeMetaData => NodeMetaDataObj.Count > 0 ? NodeMetaDataObj : null;
public bool HasDiff { get; set; } = false;
[JsonIgnore]
public Dictionary<string, string> LineIdToNodeIdHashed { get; set; } = new Dictionary<string, string>();
[JsonIgnore]
public Dictionary<string, List<CodePanelRowData>> ActiveDocumentationMap { get; set; } = new Dictionary<string, List<CodePanelRowData>>();
[JsonIgnore]
public Dictionary<string, List<CodePanelRowData>> DiffDocumentationMap { get; set; } = new Dictionary<string, List<CodePanelRowData>>();
public void AddLineIdNodeHashMapping(string lineId, string nodeId)
{
if (!string.IsNullOrEmpty(lineId) && !string.IsNullOrEmpty(nodeId))
{
LineIdToNodeIdHashed[lineId] = nodeId;
}
}
public string GetNodeIdHashFromLineId(string lineId)
{
if (!string.IsNullOrEmpty(lineId) && LineIdToNodeIdHashed.ContainsKey(lineId))
{
return LineIdToNodeIdHashed[lineId];
}
return string.Empty;
}
public void SetLineAsRelated(string nodeIdHashed, string relatedLine)
{
var relatedNodeHashId = GetNodeIdHashFromLineId(relatedLine);
if (!string.IsNullOrEmpty(relatedNodeHashId) && NodeMetaDataObj.ContainsKey(nodeIdHashed))
{
NodeMetaDataObj[nodeIdHashed].RelatedNodeIdHash = relatedNodeHashId;
}
}
public void AddNavigation(string nodeIdHash, NavigationTreeNode node)
{
if (!string.IsNullOrEmpty(nodeIdHash) && node != null)
{
NodeMetaDataObj[nodeIdHash].NavigationTreeNode = node;
}
}
public void ConnectNodeToParent(string nodeIdHashed, string parentNodeIdHashed, int nodePosition)
{
if (!NodeMetaDataObj.ContainsKey(nodeIdHashed))
{
NodeMetaDataObj.TryAdd(nodeIdHashed, new CodePanelNodeMetaData());
}
NodeMetaDataObj[nodeIdHashed].ParentNodeIdHashed = parentNodeIdHashed;
NodeMetaDataObj[parentNodeIdHashed].ChildrenNodeIdsInOrderObj.TryAdd(nodePosition, nodeIdHashed);
}
}
}