Skip to content

Commit 07820af

Browse files
committed
Started MIlestones view
1 parent d74c8ef commit 07820af

15 files changed

+195
-41
lines changed

Docs/Hacks.md

+3
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@ The two don't play nicely together, thus had to separate out VMs etc into a sepa
1010
## VisGit.OptionsPage
1111

1212
Due to above, tried to put the OptionsPage in VisGit.Core. However, no end of compile errors - likely to do with VSIX. Tried to access this in VisGit via interface, but again, got strange errors at compile time. Thus, had to leverage the Settings system.
13+
14+
[StackOverflow](https://stackoverflow.com/questions/78655570/creating-an-optionsprovider-in-a-separate-project-library-to-the-vsix-project-in)
15+

VisGit.Core/Controllers/GitController.cs

+15-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ internal async Task<bool> AuthenticateUserAsync(string personalAccessToken)
2323
else return false;
2424
}
2525

26-
internal async Task<ObservableCollection<RepositoryViewModel>> GetRepositoriesAsync()
26+
internal async Task<ObservableCollection<RepositoryViewModel>> GetAllRepositoriesAsync()
2727
{
2828
ObservableCollection<RepositoryViewModel> repositoryViewModels = new ObservableCollection<RepositoryViewModel>();
2929

@@ -36,5 +36,19 @@ internal async Task<ObservableCollection<RepositoryViewModel>> GetRepositoriesAs
3636

3737
return repositoryViewModels;
3838
}
39+
40+
internal async Task<ObservableCollection<MilestoneViewModel>> GetAllMilestonesForRepoAsync(long repositoryId)
41+
{
42+
ObservableCollection<MilestoneViewModel> milestoneViewModels = new ObservableCollection<MilestoneViewModel>();
43+
44+
IReadOnlyList<Milestone> repositoryMilestones = await gitService.GetAllMilestonesForRepositoryAsync(repositoryId);
45+
46+
foreach (Milestone milestone in repositoryMilestones)
47+
{
48+
milestoneViewModels.Add(new MilestoneViewModel(milestone));
49+
}
50+
51+
return milestoneViewModels;
52+
}
3953
}
4054
}

VisGit.Core/Interfaces/IUserSettings.cs

-13
This file was deleted.

VisGit.Core/Services/GitService.cs

+5
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ internal async Task<IReadOnlyList<Repository>> GetAllUserRepositoriesAsync()
3434
return await gitHubClient.Repository.GetAllForCurrent();
3535
}
3636

37+
internal async Task<IReadOnlyList<Milestone>> GetAllMilestonesForRepositoryAsync(long repositoryId)
38+
{
39+
return await gitHubClient.Issue.Milestone.GetAllForRepository(repositoryId, new MilestoneRequest { State = ItemStateFilter.All });
40+
}
41+
3742
internal void Logout()
3843
{
3944
gitHubClient.Credentials = new Credentials("NULLED - FORCE LOGOUT ON ANY MORE REQUESTS");
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using CommunityToolkit.Mvvm.ComponentModel;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace VisGit.Core.ViewModels
9+
{
10+
public class BaseViewModel : ObservableObject
11+
{
12+
}
13+
}

VisGit.Core/ViewModels/MainViewModel.cs

+34-2
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
using CommunityToolkit.Mvvm.ComponentModel;
33
using CommunityToolkit.Mvvm.Input;
44
using Newtonsoft.Json.Linq;
5+
using System.Collections.ObjectModel;
56
using System.Diagnostics;
67
using System.Threading.Tasks;
78
using VisGit.Core.Controllers;
8-
using VisGit.Core.Interfaces;
99
using VisGit.Core.Services;
1010

1111
namespace VisGit.Core.ViewModels
1212
{
13-
public partial class MainViewModel : ObservableObject
13+
public partial class MainViewModel : BaseViewModel
1414
{
1515
#region Properties =========================================================================================
1616

@@ -20,6 +20,17 @@ public partial class MainViewModel : ObservableObject
2020
[ObservableProperty]
2121
private string _visualStudioStatusText = string.Empty;
2222

23+
// Repository objects
24+
[ObservableProperty]
25+
private ObservableCollection<RepositoryViewModel> _userRepositoryVMs;
26+
27+
[ObservableProperty]
28+
private RepositoryViewModel _selectedRespositoryVM;
29+
30+
// Milestone objects
31+
[ObservableProperty]
32+
private ObservableCollection<MilestoneViewModel> _repositoryMilestonesVMs = new ObservableCollection<MilestoneViewModel>();
33+
2334
#endregion End: Properties
2435

2536
#region Property Changed Methods =========================================================================================
@@ -29,6 +40,11 @@ partial void OnVisualStudioStatusTextChanged(string value)
2940
_ = VS.StatusBar.ShowMessageAsync(value);
3041
}
3142

43+
partial void OnSelectedRespositoryVMChanged(RepositoryViewModel value)
44+
{
45+
_ = GetAllMilestonesForRepoAsync(value.GitRepository.Id);
46+
}
47+
3248
#endregion End: Property Changed Methods
3349

3450
#region Operational Vars =========================================================================================
@@ -49,6 +65,7 @@ private void InitialiseView()
4965
{
5066
gitController = new GitController(gitClient);
5167
TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;
68+
UserRepositoryVMs = new ObservableCollection<RepositoryViewModel>();
5269
}
5370

5471
[RelayCommand]
@@ -60,6 +77,9 @@ private async Task AuthenticateUserAsync()
6077

6178
if (UserAuthenicated) UpdateVsStatusText("Login Successful");
6279
else UpdateVsStatusText("Login error. Check connection and PAT.");
80+
81+
// Now get all repos for user
82+
await GetUserRespositoriesAsync();
6383
}
6484

6585
#endregion End: Commands
@@ -77,6 +97,18 @@ private void TaskScheduler_UnobservedTaskException(object sender, UnobservedTask
7797
//SingleLineFeedback = e.Exception.Message;
7898
}
7999

100+
private async Task GetUserRespositoriesAsync()
101+
{
102+
UserRepositoryVMs.Clear();
103+
UserRepositoryVMs = await gitController.GetAllRepositoriesAsync();
104+
}
105+
106+
private async Task GetAllMilestonesForRepoAsync(long repositoryId)
107+
{
108+
RepositoryMilestonesVMs.Clear();
109+
RepositoryMilestonesVMs = await gitController.GetAllMilestonesForRepoAsync(repositoryId);
110+
}
111+
80112
#endregion End: Private Methods
81113

82114
public MainViewModel()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using CommunityToolkit.Mvvm.ComponentModel;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using Octokit;
8+
9+
namespace VisGit.Core.ViewModels
10+
{
11+
public partial class MilestoneViewModel : BaseViewModel
12+
{
13+
#region PROPERTIES =========================================================================================
14+
15+
// Fields
16+
[ObservableProperty]
17+
private Milestone _gitMilestone;
18+
19+
// Obs Props
20+
[ObservableProperty]
21+
private string _title;
22+
23+
#endregion End: PROPERTIES
24+
25+
public MilestoneViewModel()
26+
{
27+
}
28+
29+
public MilestoneViewModel(Milestone milestone)
30+
{
31+
UpdateProperties(milestone);
32+
}
33+
34+
private void UpdateProperties(Milestone milestone)
35+
{
36+
Title = milestone.Title;
37+
GitMilestone = milestone;
38+
}
39+
}
40+
}

VisGit.Core/ViewModels/RepositoryViewModel.cs

+7-7
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,23 @@
99

1010
namespace VisGit.Core.ViewModels
1111
{
12-
public class RepositoryViewModel : ObservableObject
12+
public partial class RepositoryViewModel : BaseViewModel
1313
{
1414
#region Properties =========================================================================================
1515

1616
// Fields
17+
[ObservableProperty]
1718
private Repository _gitRepository;
1819

20+
[ObservableProperty]
1921
private string _name;
20-
private string _id;
21-
private DateTime _createdDate;
2222

2323
// Public Members
24-
public Repository GitRepository { get => _gitRepository; set => SetProperty(ref _gitRepository, value); }
24+
//public Repository GitRepository { get => _gitRepository; set => SetProperty(ref _gitRepository, value); }
2525

26-
public string Name { get => _name; set => SetProperty(ref _name, value); }
27-
public string Id { get => _gitRepository.Id.ToString(); }
28-
public string CreatedAt { get => _gitRepository.CreatedAt.ToString(); }
26+
// public string Name { get => _name; set => SetProperty(ref _name, value); }
27+
//public string Id { get => _gitRepository.Id.ToString(); }
28+
//public string CreatedAt { get => _gitRepository.CreatedAt.ToString(); }
2929

3030
#endregion Properties =========================================================================================
3131

VisGit.Core/VisGit.Core.csproj

+2-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
<ItemGroup>
5050
<Compile Include="Controllers\GitController.cs" />
5151
<Compile Include="Data\Constants.cs" />
52-
<Compile Include="Interfaces\IUserSettings.cs" />
5352
<Compile Include="Properties\AssemblyInfo.cs" />
5453
<Compile Include="Properties\Settings.Designer.cs">
5554
<AutoGen>True</AutoGen>
@@ -58,7 +57,9 @@
5857
</Compile>
5958
<Compile Include="Services\Encryption.cs" />
6059
<Compile Include="Services\GitService.cs" />
60+
<Compile Include="ViewModels\BaseViewModel.cs" />
6161
<Compile Include="ViewModels\MainViewModel.cs" />
62+
<Compile Include="ViewModels\MilestoneViewModel.cs" />
6263
<Compile Include="ViewModels\RepositoryViewModel.cs" />
6364
</ItemGroup>
6465
<ItemGroup>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System.ComponentModel;
2+
using System.Globalization;
3+
using System.Windows;
4+
using System.Windows.Data;
5+
6+
namespace VisGit.Converters
7+
{
8+
public class BoolToVisibilityConverter : IValueConverter
9+
{
10+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
11+
{
12+
if ((bool)value)
13+
return Visibility.Visible;
14+
15+
return Visibility.Collapsed;
16+
}
17+
18+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
19+
{
20+
throw new NotImplementedException();
21+
}
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System.Globalization;
2+
using System.Windows;
3+
using System.Windows.Data;
4+
5+
namespace VisGit.Converters
6+
{
7+
public class InverseBoolToVisibilityConverter : IValueConverter
8+
{
9+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
10+
{
11+
if ((bool)value)
12+
return Visibility.Collapsed;
13+
14+
return Visibility.Visible;
15+
}
16+
17+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
18+
{
19+
throw new NotImplementedException();
20+
}
21+
}
22+
}

VisGit/Resources/Converters.xaml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3+
xmlns:vsshell="clr-namespace:Microsoft.VisualStudio.Shell;assembly=Microsoft.VisualStudio.Shell.15.0"
4+
xmlns:ComponentModel="clr-namespace:System.ComponentModel;assembly=PresentationFramework"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:mwt1="clr-namespace:Microsoft.VisualStudio.PlatformUI;assembly=Microsoft.VisualStudio.Shell.15.0"
7+
xmlns:converters="clr-namespace:VisGit.Converters">
8+
9+
<converters:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />
10+
<converters:InverseBoolToVisibilityConverter x:Key="InverseBoolToVisibilityConverter" />
11+
</ResourceDictionary>

VisGit/Views/MainView.xaml

+13-5
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
<ResourceDictionary Source="../Resources/Styles/ComboBox.xaml" />
3434
<!-- MEDIA -->
3535
<ResourceDictionary Source="../Resources/Media/UiImages.xaml" />
36+
<!-- OTHER -->
37+
<ResourceDictionary Source="../Resources/Converters.xaml" />
3638
</ResourceDictionary.MergedDictionaries>
3739
</ResourceDictionary>
3840
</UserControl.Resources>
@@ -50,7 +52,9 @@
5052

5153
<!-- UNAUTHENTICATED TOOLBAR -->
5254
<controls:ToolBar x:Name="UnauthenticatedTBar" Style="{StaticResource ToolBarStyle}"
53-
VerticalAlignment="Center" ToolBarTray.IsLocked="true">
55+
VerticalAlignment="Center" ToolBarTray.IsLocked="true"
56+
Visibility="{Binding UserAuthenicated, Converter={StaticResource InverseBoolToVisibilityConverter}}"
57+
d:Visibility="Visible">
5458

5559
<Button x:Name="AuthenticateBT" Content="{DynamicResource UiLogInUserImage}"
5660
d:Content="{DynamicResource UILogInUserImageDT}" Command="{Binding AuthenticateUserCommand}" />
@@ -59,12 +63,16 @@
5963
<!-- AUTHENTICATED TOOLBAR -->
6064

6165
<controls:ToolBar x:Name="AuthenticatedTBar" Style="{StaticResource ToolBarStyle}"
62-
VerticalAlignment="Center" ToolBarTray.IsLocked="true">
66+
VerticalAlignment="Center" ToolBarTray.IsLocked="true"
67+
Visibility="{Binding UserAuthenicated, Converter={StaticResource BoolToVisibilityConverter}}"
68+
d:Visibility="Visible">
6369

64-
<Button x:Name="Authenticate" Content="{StaticResource UiIssueImage}" d:Background="Transparent"
65-
d:Content="{StaticResource UiIssueImageDT}" />
70+
<ComboBox x:Name="RepositoryCB" Style="{DynamicResource ComboBoxStyle}" Width="104" Margin="2,0,2,0"
71+
ItemsSource="{Binding UserRepositoryVMs}" DisplayMemberPath="Name"
72+
SelectedItem="{Binding SelectedRespositoryVM, Mode=TwoWay}">
73+
</ComboBox>
6674

67-
<ComboBox x:Name="GitObjectCB" Style="{DynamicResource ComboBoxStyle}" Width="104">
75+
<ComboBox x:Name="GitObjectCB" Style="{DynamicResource ComboBoxStyle}" Width="104" Margin="2,0,2,0">
6876
<ComboBoxItem>
6977
<StackPanel Orientation="Horizontal">
7078
<ContentControl Content="{StaticResource UiIssueImage}" d:Content="{StaticResource UiIssueImageDT}" />

VisGit/Views/MainView.xaml.cs

-9
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,11 @@ namespace VisGit.Views
77
{
88
public partial class MainView : UserControl
99
{
10-
private MainViewModel viewModel;
11-
1210
public MainView()
1311
{
1412
CouldNotLoadFileOrAssemblyHack();
1513

1614
InitializeComponent();
17-
18-
viewModel = (MainViewModel)this.DataContext;
19-
20-
//var dave = OptionsPage.Instance;
21-
22-
//viewModel.UserSettings = new UserSettings();
23-
//viewModel.UserSettings.PersonalAccessToken = dave.PersonalAccessToken;
2415
}
2516

2617
private void CouldNotLoadFileOrAssemblyHack()

0 commit comments

Comments
 (0)