Skip to content

Commit 1c56f0d

Browse files
committed
Started comments implementation
Frustrating day....
1 parent 169534d commit 1c56f0d

29 files changed

+549
-156
lines changed

Docs/Dev/Images/Assignees.png

6.9 KB
Loading

Docs/Dev/Images/OtherUser32.png

5.54 KB
Loading

Docs/Dev/Images/WillyRound32.png

1.53 KB
Loading

VisGit.Core/Controllers/GitController.cs

+30-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ internal void SendOperationErrorMessage(string message, Exception exception = nu
3131
{ Exception = exception, AssociatedObject = associatedObject });
3232
}
3333

34+
#region Users =========================================================================================
35+
3436
internal async Task<bool> AuthenticateUserAsync(string personalAccessToken)
3537
{
3638
try
@@ -47,6 +49,18 @@ internal async Task<bool> AuthenticateUserAsync(string personalAccessToken)
4749
return false;
4850
}
4951

52+
internal async Task<SearchUsersResult> SearchUsersAsync(string loginname)
53+
{
54+
try
55+
{
56+
return await gitService.SearchUsersAsync(loginname);
57+
}
58+
catch (Exception ex) { SendOperationErrorMessage("Error searching users", ex); }
59+
return null;
60+
}
61+
62+
#endregion End: Users ---------------------------------------------------------------------------------
63+
5064
internal async Task<ObservableCollection<RepositoryViewModel>> GetAllRepositoriesAsync()
5165
{
5266
ObservableCollection<RepositoryViewModel> repositoryViewModels = new ObservableCollection<RepositoryViewModel>();
@@ -205,10 +219,24 @@ internal async Task<ObservableCollection<IssueViewModel>> GetAllIssuesForRepoAsy
205219

206220
return issueViewModels;
207221
}
208-
catch (Exception ex)
222+
catch (Exception ex) { SendOperationErrorMessage("Error loading Issues", ex); }
223+
return null;
224+
}
225+
226+
internal async Task<ObservableCollection<IssueCommentViewModel>> GetAllCommentsForIssueAsync(long repositoryId, int issueNumber)
227+
{
228+
ObservableCollection<IssueCommentViewModel> issueCommentViewModels = new ObservableCollection<IssueCommentViewModel>();
229+
230+
try
209231
{
210-
SendOperationErrorMessage("Error loading Issues", ex);
232+
IReadOnlyList<IssueComment> repositoryIssueComments = await gitService.GetAllCommentsForIssueAsync(repositoryId, issueNumber);
233+
foreach (IssueComment issueComment in repositoryIssueComments)
234+
{
235+
issueCommentViewModels.Add(new IssueCommentViewModel(this, issueComment, repositoryId));
236+
}
237+
return issueCommentViewModels;
211238
}
239+
catch (Exception ex) { SendOperationErrorMessage("Error loading Issue Comments", ex); }
212240
return null;
213241
}
214242

VisGit.Core/Services/GitService.cs

+13
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using VisGitCore.Data;
55
using System;
66
using VisGitCore.ViewModels;
7+
using System.Collections.ObjectModel;
78

89
namespace VisGitCore.Services
910
{
@@ -42,6 +43,13 @@ internal void Logout()
4243
gitHubClient.Credentials = new Credentials("NULLED - FORCE LOGOUT ON ANY MORE REQUESTS");
4344
}
4445

46+
internal async Task<SearchUsersResult> SearchUsersAsync(string loginName)
47+
{
48+
SearchUsersRequest searchUsersRequest = new SearchUsersRequest(loginName);
49+
searchUsersRequest.In = new List<UserInQualifier>() { UserInQualifier.Username };
50+
return await gitHubClient.Search.SearchUsers(searchUsersRequest);
51+
}
52+
4553
// Repositories ==============================================================================================
4654

4755
internal async Task<IReadOnlyList<Repository>> GetAllUserRepositoriesAsync()
@@ -125,6 +133,11 @@ internal async Task<IReadOnlyList<Issue>> GetAllIssuesForRepositoryAsync(long re
125133
return await gitHubClient.Issue.GetAllForRepository(repositoryId);
126134
}
127135

136+
internal async Task<IReadOnlyList<IssueComment>> GetAllCommentsForIssueAsync(long repositoryId, int issueNumber)
137+
{
138+
return await gitHubClient.Issue.Comment.GetAllForIssue(repositoryId, issueNumber);
139+
}
140+
128141
#endregion End: Issues ---------------------------------------------------------------------------------
129142
}
130143
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using VisGitCore.Controllers;
7+
using Octokit;
8+
using CommunityToolkit.Mvvm.ComponentModel;
9+
10+
namespace VisGitCore.ViewModels
11+
{
12+
public partial class IssueCommentViewModel : ViewModelBase
13+
{
14+
#region Properties =========================================================================================
15+
16+
// Model Related ==============================================================================================
17+
18+
[ObservableProperty]
19+
private string _body;
20+
21+
[ObservableProperty]
22+
private User _author;
23+
24+
[ObservableProperty]
25+
private DateTimeOffset? _createdAt;
26+
27+
[ObservableProperty]
28+
private DateTimeOffset? _updatedAt;
29+
30+
[ObservableProperty]
31+
private ReactionSummary _reactions;
32+
33+
// Operational ==============================================================================================
34+
35+
public IssueComment GitIssueComment { get; set; }
36+
37+
#endregion End: Properties ---------------------------------------------------------------------------------
38+
39+
#region Operational Vars =========================================================================================
40+
41+
internal GitController gitController;
42+
internal long RepositoryId;
43+
44+
#endregion End: Operational Vars ---------------------------------------------------------------------------------
45+
46+
internal IssueCommentViewModel(GitController gitController, IssueComment comment, long repositoryId)
47+
{
48+
this.gitController = gitController;
49+
this.RepositoryId = repositoryId;
50+
_ = UpdateViewmodelProperties(comment);
51+
}
52+
53+
#region Private Methods =========================================================================================
54+
55+
private async Task UpdateViewmodelProperties(IssueComment comment)
56+
{
57+
GitIssueComment = comment;
58+
59+
_body = comment.Body;
60+
_author = comment.User;
61+
_createdAt = comment.CreatedAt;
62+
_updatedAt = comment.UpdatedAt;
63+
_reactions = comment.Reactions;
64+
65+
#endregion End: Private Methods ---------------------------------------------------------------------------------
66+
}
67+
}
68+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using CommunityToolkit.Mvvm.ComponentModel;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Collections.ObjectModel;
5+
using System.ComponentModel;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
using VisGitCore.Controllers;
10+
11+
namespace VisGitCore.ViewModels
12+
{
13+
public partial class IssueCommentsViewModel : ViewModelBase
14+
{
15+
#region Properties =========================================================================================
16+
17+
[ObservableProperty]
18+
private ObservableCollection<IssueCommentViewModel> _repositoryIssueCommentsVMs = new ObservableCollection<IssueCommentViewModel>();
19+
20+
[ObservableProperty]
21+
private ICollectionView _repositoryIssueCommentsView;
22+
23+
[ObservableProperty]
24+
private IssueViewModel _selectedIssueCommentViewModel;
25+
26+
#endregion End: Properties ---------------------------------------------------------------------------------
27+
28+
#region Operational Variables =========================================================================================
29+
30+
internal GitController gitController;
31+
internal RepositoryViewModel repositoryVm;
32+
33+
#endregion End: Operational Variables ---------------------------------------------------------------------------------
34+
35+
internal IssueCommentsViewModel(GitController gitController, RepositoryViewModel gitRepositoryVm)
36+
{
37+
this.gitController = gitController;
38+
this.repositoryVm = gitRepositoryVm;
39+
}
40+
}
41+
}

VisGit.Core/ViewModels/IssueViewModel.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,14 @@ internal IssueViewModel(GitController gitController, Issue issue, long repositor
126126
{
127127
this.gitController = gitController;
128128
RepositoryId = repositoryId;
129-
_ = UpdateViewmodelPropertiesAsync(issue);
129+
UpdateViewmodelProperties(issue);
130130
}
131131

132132
#endregion End: Public Methods ---------------------------------------------------------------------------------
133133

134134
#region Private Methods =========================================================================================
135135

136-
private async Task UpdateViewmodelPropertiesAsync(Issue issue)
136+
private void UpdateViewmodelProperties(Issue issue)
137137
{
138138
GitIssue = issue;
139139

VisGit.Core/ViewModels/IssuesViewModel.cs

+42
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using System.Linq;
1010
using System.Text;
1111
using System.Threading.Tasks;
12+
using System.Web.UI.Design.WebControls;
1213
using System.Windows.Data;
1314
using VisGitCore.Controllers;
1415
using VisGitCore.Messages;
@@ -53,6 +54,12 @@ public partial class IssuesViewModel : ViewModelBase
5354
[ObservableProperty]
5455
private User _selectedAssignee;
5556

57+
[ObservableProperty]
58+
private SearchUsersResult _searchUserResult;
59+
60+
[ObservableProperty]
61+
private IssueCommentsViewModel _issueCommentsVM;
62+
5663
#endregion End: Properties ---------------------------------------------------------------------------------
5764

5865
#region Operational Vars =========================================================================================
@@ -78,6 +85,17 @@ partial void OnSelectedMilestoneVMChanged(MilestoneViewModel value)
7885
// Subtract 1 from open issues
7986
}
8087

88+
partial void OnSelectedIssueViewModelChanged(IssueViewModel oldValue, IssueViewModel newValue)
89+
{
90+
_ = UpdateIssueCommentsAsync(newValue);
91+
}
92+
93+
private async Task UpdateIssueCommentsAsync(IssueViewModel issueViewModel)
94+
{
95+
IssueCommentsVM.RepositoryIssueCommentsVMs = await gitController.GetAllCommentsForIssueAsync(gitRepositoryVm.GitRepository.Id,
96+
issueViewModel.GitIssue.Number);
97+
}
98+
8199
#endregion End: Property Changed Events ---------------------------------------------------------------------------------
82100

83101
#region Commands =========================================================================================
@@ -89,6 +107,29 @@ private void RemoveLabel()
89107
SelectedIssueViewModel.Labels.Remove(SelectedExistingLabel);
90108
}
91109

110+
[RelayCommand]
111+
private async Task SearchUsersAsync(string loginName)
112+
{
113+
SearchUserResult = await gitController.SearchUsersAsync(loginName);
114+
}
115+
116+
[RelayCommand]
117+
private void AssignUser(User user)
118+
{
119+
if (SelectedIssueViewModel.Assignees.Count() < 10
120+
&& !SelectedIssueViewModel.Assignees.Contains(user)
121+
&& user != null)
122+
{
123+
SelectedIssueViewModel.Assignees.Add(user);
124+
}
125+
}
126+
127+
[RelayCommand]
128+
private void UnassignUser()
129+
{
130+
SelectedIssueViewModel.Assignees.Remove(SelectedAssignee);
131+
}
132+
92133
#endregion End: Commands ---------------------------------------------------------------------------------
93134

94135
#region Public Methods =========================================================================================
@@ -99,6 +140,7 @@ internal IssuesViewModel(GitController gitController, RepositoryViewModel gitRep
99140
this.gitController = gitController;
100141
this.gitRepositoryVm = gitRepositoryVm;
101142
_repositoryLabels = repositoryLabels;
143+
IssueCommentsVM = new IssueCommentsViewModel(gitController, gitRepositoryVm);
102144
}
103145

104146
public async Task GetAllIssuesForRepoAsync()

VisGit.Core/VisGitCore.csproj

+2
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@
8383
<Compile Include="Services\GitService.cs" />
8484
<Compile Include="Services\Math.cs" />
8585
<Compile Include="Services\UserSettings.cs" />
86+
<Compile Include="ViewModels\IssueCommentsViewModel.cs" />
87+
<Compile Include="ViewModels\IssueCommentViewModel.cs" />
8688
<Compile Include="ViewModels\IssuesViewModel.cs" />
8789
<Compile Include="ViewModels\IssueViewModel.cs" />
8890
<Compile Include="ViewModels\LabelsViewModel.cs" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Globalization;
4+
using System.Linq;
5+
using System.Reflection.Metadata.Ecma335;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
using System.Windows.Data;
9+
10+
namespace VisGit.Converters
11+
{
12+
internal class ActualWidthMinusScrollbarConverter : IValueConverter
13+
{
14+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
15+
{
16+
return (int)value - 10;
17+
}
18+
19+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
20+
{
21+
throw new NotImplementedException();
22+
}
23+
}
24+
}

VisGit/Resources/Converters.xaml

+1
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,5 @@
2828
<converters:IssueStatusToOpacityConverter x:Key="IssueStatusToOpacityConverter" />
2929
<converters:IssueToKeyDatesConverter x:Key="IssueToKeyDatesConverter" />
3030
<converters:IssueStatusToIconConverter x:Key="IssueStatusToIconConverter" />
31+
<converters:ActualWidthMinusScrollbarConverter x:Key="ActualWidthMinusScrollbarConverter" />
3132
</ResourceDictionary>
6.9 KB
Loading
321 Bytes
Loading
535 Bytes
Loading
814 Bytes
Loading
Loading
1.53 KB
Loading

VisGit/Resources/Media/UiImages.xaml

+17
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
<!-- Stores all UiImages plus a design-time version due to MS bug with monikers -->
1111
<!-- See for details: https://stackoverflow.com/questions/78297622/wpf-moniker-images-not-showing-in-design-view -->
1212

13+
<!-- CrispImages -->
14+
1315
<imaging:CrispImage x:Key="UiLogInUserImage" x:Shared="false" Width="16" Height="16" Moniker="{x:Static catalog:KnownMonikers.LoginUser}" />
1416
<Image x:Key="UILogInUserImageDT" x:Shared="false" Width="16" Height="16" Source="Images/LoginUser.png" />
1517

@@ -63,4 +65,19 @@
6365

6466
<imaging:CrispImage x:Key="UiPecilImage" x:Shared="false" Width="16" Height="16" Moniker="{x:Static catalog:KnownMonikers.Edit}" />
6567
<Image x:Key="UiPecilImageDT" x:Shared="false" Width="16" Height="16" Source="Images/Edit.png" />
68+
69+
<imaging:CrispImage x:Key="UiSearchImage" x:Shared="false" Width="16" Height="16" Moniker="{x:Static catalog:KnownMonikers.Search}" />
70+
<Image x:Key="UiSearchImageDT" x:Shared="false" Width="16" Height="16" Source="Images/Search.png" />
71+
72+
<imaging:CrispImage x:Key="UiAssignees" x:Shared="false" Width="16" Height="16" Moniker="{x:Static catalog:KnownMonikers.AddTeamProject}" />
73+
<Image x:Key="UiAssigneesDT" x:Shared="false" Width="16" Height="16" Source="Images/AddTeamProject.png" />
74+
75+
<imaging:CrispImage x:Key="UiUnassignUserImage" x:Shared="false" Width="16" Height="16" Moniker="{x:Static catalog:KnownMonikers.TeamProjectCollectionOffline}" />
76+
<Image x:Key="UiUnassignUserImageDT" x:Shared="false" Width="16" Height="16" Source="Images/TeamProjectCollectionOffline.png" />
77+
78+
<imaging:CrispImage x:Key="UiCommentImage" x:Shared="false" Width="16" Height="16" Moniker="{x:Static catalog:KnownMonikers.Comment}" />
79+
<Image x:Key="UiCommentImageDT" x:Shared="false" Width="16" Height="16" Source="Images/Comment.png" />
80+
81+
<imaging:CrispImage x:Key="UiCommentsImage" x:Shared="false" Width="16" Height="16" Moniker="{x:Static catalog:KnownMonikers.CommentGroup}" />
82+
<Image x:Key="UiCommentsImageDT" x:Shared="false" Width="16" Height="16" Source="Images/CommentGroup.png" />
6683
</ResourceDictionary>

0 commit comments

Comments
 (0)