Skip to content
This repository was archived by the owner on Jul 2, 2022. It is now read-only.

Commit e47c95f

Browse files
committed
Made it easier to edit issues from the IssueView instead of having to go to "edit"
1 parent 1b4df38 commit e47c95f

File tree

10 files changed

+249
-71
lines changed

10 files changed

+249
-71
lines changed

CodeHub.Core/ViewModels/Issues/IssueAssignedToViewModel.cs

Lines changed: 54 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@
33
using GitHubSharp.Models;
44
using System.Threading.Tasks;
55
using CodeHub.Core.Messages;
6+
using System.Linq;
67

78
namespace CodeHub.Core.ViewModels.Issues
89
{
910
public class IssueAssignedToViewModel : LoadableViewModel
1011
{
11-
private readonly CollectionViewModel<BasicUserModel> _users = new CollectionViewModel<BasicUserModel>();
12-
1312
private BasicUserModel _selectedUser;
14-
1513
public BasicUserModel SelectedUser
1614
{
1715
get
@@ -25,43 +23,82 @@ public BasicUserModel SelectedUser
2523
}
2624
}
2725

26+
private bool _isSaving;
27+
public bool IsSaving
28+
{
29+
get { return _isSaving; }
30+
private set {
31+
_isSaving = value;
32+
RaisePropertyChanged(() => IsSaving);
33+
}
34+
}
35+
36+
private readonly CollectionViewModel<BasicUserModel> _users = new CollectionViewModel<BasicUserModel>();
2837
public CollectionViewModel<BasicUserModel> Users
2938
{
3039
get { return _users; }
3140
}
3241

33-
public string Username
34-
{
35-
get;
36-
private set;
37-
}
42+
public string Username { get; private set; }
3843

39-
public string Repository
40-
{
41-
get;
42-
private set;
43-
}
44+
public string Repository { get; private set; }
45+
46+
public ulong Id { get; private set; }
47+
48+
public bool SaveOnSelect { get; private set; }
4449

4550
public void Init(NavObject navObject)
4651
{
4752
Username = navObject.Username;
4853
Repository = navObject.Repository;
54+
Id = navObject.Id;
55+
SaveOnSelect = navObject.SaveOnSelect;
56+
4957
SelectedUser = TxSevice.Get() as BasicUserModel;
50-
this.Bind(x => x.SelectedUser, x => {
58+
this.Bind(x => x.SelectedUser, x => SelectUser(x));
59+
}
60+
61+
private async Task SelectUser(BasicUserModel x)
62+
{
63+
if (SaveOnSelect)
64+
{
65+
try
66+
{
67+
IsSaving = true;
68+
var assignee = x != null ? x.Login : null;
69+
var updateReq = this.GetApplication().Client.Users[Username].Repositories[Repository].Issues[Id].UpdateAssignee(assignee);
70+
var newIssue = await this.GetApplication().Client.ExecuteAsync(updateReq);
71+
Messenger.Publish(new IssueEditMessage(this) { Issue = newIssue.Data });
72+
73+
}
74+
catch (Exception e)
75+
{
76+
DisplayException(e);
77+
}
78+
finally
79+
{
80+
IsSaving = false;
81+
}
82+
}
83+
else
84+
{
5185
Messenger.Publish(new SelectedAssignedToMessage(this) { User = x });
52-
ChangePresentation(new Cirrious.MvvmCross.ViewModels.MvxClosePresentationHint(this));
53-
});
86+
}
87+
88+
ChangePresentation(new Cirrious.MvvmCross.ViewModels.MvxClosePresentationHint(this));
5489
}
5590

5691
protected override Task Load(bool forceCacheInvalidation)
5792
{
58-
return Users.SimpleCollectionLoad(this.GetApplication().Client.Users[Username].Repositories[Repository].GetCollaborators(), forceCacheInvalidation);
93+
return Users.SimpleCollectionLoad(this.GetApplication().Client.Users[Username].Repositories[Repository].GetAssignees(), forceCacheInvalidation);
5994
}
6095

6196
public class NavObject
6297
{
6398
public string Username { get; set; }
6499
public string Repository { get; set; }
100+
public ulong Id { get; set; }
101+
public bool SaveOnSelect { get; set; }
65102
}
66103
}
67104
}

CodeHub.Core/ViewModels/Issues/IssueLabelsViewModel.cs

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,86 @@
33
using System.Threading.Tasks;
44
using GitHubSharp.Models;
55
using System.Collections.Generic;
6-
using Cirrious.MvvmCross.Plugins.Messenger;
76
using CodeHub.Core.Messages;
87
using System.Linq;
8+
using System.Windows.Input;
9+
using Cirrious.MvvmCross.ViewModels;
910

1011
namespace CodeHub.Core.ViewModels.Issues
1112
{
1213
public class IssueLabelsViewModel : LoadableViewModel
1314
{
14-
private readonly CollectionViewModel<LabelModel> _labels = new CollectionViewModel<LabelModel>();
15-
private readonly CollectionViewModel<LabelModel> _selectedLabels = new CollectionViewModel<LabelModel>();
15+
private bool _isSaving;
16+
public bool IsSaving
17+
{
18+
get { return _isSaving; }
19+
private set {
20+
_isSaving = value;
21+
RaisePropertyChanged(() => IsSaving);
22+
}
23+
}
1624

25+
private readonly CollectionViewModel<LabelModel> _labels = new CollectionViewModel<LabelModel>();
1726
public CollectionViewModel<LabelModel> Labels
1827
{
1928
get { return _labels; }
2029
}
2130

31+
private readonly CollectionViewModel<LabelModel> _selectedLabels = new CollectionViewModel<LabelModel>();
2232
public CollectionViewModel<LabelModel> SelectedLabels
2333
{
2434
get { return _selectedLabels; }
2535
}
2636

27-
public string Username { get; private set; }
37+
public string Username { get; private set; }
2838

2939
public string Repository { get; private set; }
3040

41+
public ulong Id { get; private set; }
42+
43+
public bool SaveOnSelect { get; private set; }
44+
3145
public void Init(NavObject navObject)
3246
{
3347
Username = navObject.Username;
3448
Repository = navObject.Repository;
49+
Id = navObject.Id;
50+
SaveOnSelect = navObject.SaveOnSelect;
3551
SelectedLabels.Items.Reset(GetService<CodeFramework.Core.Services.IViewModelTxService>().Get() as IEnumerable<LabelModel>);
52+
}
53+
54+
public ICommand SaveLabelChoices
55+
{
56+
get { return new MvxCommand(() => SelectLabels(SelectedLabels)); }
57+
}
58+
59+
private async Task SelectLabels(IEnumerable<LabelModel> x)
60+
{
61+
if (SaveOnSelect)
62+
{
63+
try
64+
{
65+
IsSaving = true;
66+
var labels = x != null ? x.Select(y => y.Name).ToArray() : null;
67+
var updateReq = this.GetApplication().Client.Users[Username].Repositories[Repository].Issues[Id].UpdateLabels(labels);
68+
var newIssue = await this.GetApplication().Client.ExecuteAsync(updateReq);
69+
Messenger.Publish(new IssueEditMessage(this) { Issue = newIssue.Data });
70+
}
71+
catch (Exception e)
72+
{
73+
DisplayException(e);
74+
}
75+
finally
76+
{
77+
IsSaving = false;
78+
}
79+
}
80+
else
81+
{
82+
Messenger.Publish(new SelectIssueLabelsMessage(this) { Labels = SelectedLabels.Items.ToArray() });
83+
}
3684

37-
var messenger = GetService<IMvxMessenger>();
38-
this.BindCollection(x => x.SelectedLabels, x => messenger.Publish(new SelectIssueLabelsMessage(this) { Labels = SelectedLabels.Items.ToArray() }));
85+
ChangePresentation(new MvxClosePresentationHint(this));
3986
}
4087

4188
protected override Task Load(bool forceCacheInvalidation)
@@ -47,6 +94,8 @@ public class NavObject
4794
{
4895
public string Username { get; set; }
4996
public string Repository { get; set; }
97+
public ulong Id { get; set; }
98+
public bool SaveOnSelect { get; set; }
5099
}
51100
}
52101
}

CodeHub.Core/ViewModels/Issues/IssueMilestonesViewModel.cs

Lines changed: 59 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
using CodeFramework.Core.ViewModels;
33
using GitHubSharp.Models;
44
using CodeHub.Core.Messages;
5+
using System.Linq;
6+
using System;
57

68
namespace CodeHub.Core.ViewModels.Issues
79
{
810
public class IssueMilestonesViewModel : LoadableViewModel
911
{
10-
private readonly CollectionViewModel<MilestoneModel> _milestones = new CollectionViewModel<MilestoneModel>();
1112
private MilestoneModel _selectedMilestone;
12-
1313
public MilestoneModel SelectedMilestone
1414
{
1515
get
@@ -22,35 +22,72 @@ public MilestoneModel SelectedMilestone
2222
RaisePropertyChanged(() => SelectedMilestone);
2323
}
2424
}
25-
25+
26+
private bool _isSaving;
27+
public bool IsSaving
28+
{
29+
get { return _isSaving; }
30+
private set {
31+
_isSaving = value;
32+
RaisePropertyChanged(() => IsSaving);
33+
}
34+
}
35+
36+
private readonly CollectionViewModel<MilestoneModel> _milestones = new CollectionViewModel<MilestoneModel>();
2637
public CollectionViewModel<MilestoneModel> Milestones
2738
{
2839
get { return _milestones; }
2940
}
3041

31-
public string Username
32-
{
33-
get;
34-
private set;
35-
}
36-
37-
public string Repository
38-
{
39-
get;
40-
private set;
41-
}
42+
public string Username { get; private set; }
43+
44+
public string Repository { get; private set; }
45+
46+
public ulong Id { get; private set; }
47+
48+
public bool SaveOnSelect { get; private set; }
4249

4350
public void Init(NavObject navObject)
4451
{
45-
Username = navObject.Username;
46-
Repository = navObject.Repository;
52+
Username = navObject.Username;
53+
Repository = navObject.Repository;
54+
Id = navObject.Id;
55+
SaveOnSelect = navObject.SaveOnSelect;
4756
SelectedMilestone = TxSevice.Get() as MilestoneModel;
48-
this.Bind(x => x.SelectedMilestone, x => {
49-
Messenger.Publish(new SelectedMilestoneMessage(this) { Milestone = x });
50-
ChangePresentation(new Cirrious.MvvmCross.ViewModels.MvxClosePresentationHint(this));
51-
});
57+
58+
this.Bind(x => x.SelectedMilestone, x => SelectMilestone(x));
5259
}
5360

61+
private async Task SelectMilestone(MilestoneModel x)
62+
{
63+
if (SaveOnSelect)
64+
{
65+
try
66+
{
67+
IsSaving = true;
68+
uint? milestone = null;
69+
if (x != null) milestone = x.Number;
70+
var updateReq = this.GetApplication().Client.Users[Username].Repositories[Repository].Issues[Id].UpdateMilestone(milestone);
71+
var newIssue = await this.GetApplication().Client.ExecuteAsync(updateReq);
72+
Messenger.Publish(new IssueEditMessage(this) { Issue = newIssue.Data });
73+
}
74+
catch (Exception e)
75+
{
76+
DisplayException(e);
77+
}
78+
finally
79+
{
80+
IsSaving = false;
81+
}
82+
}
83+
else
84+
{
85+
Messenger.Publish(new SelectedMilestoneMessage(this) { Milestone = x });
86+
}
87+
88+
ChangePresentation(new Cirrious.MvvmCross.ViewModels.MvxClosePresentationHint(this));
89+
}
90+
5491
protected override Task Load(bool forceCacheInvalidation)
5592
{
5693
return Milestones.SimpleCollectionLoad(this.GetApplication().Client.Users[Username].Repositories[Repository].Milestones.GetAll(), forceCacheInvalidation);
@@ -60,6 +97,8 @@ public class NavObject
6097
{
6198
public string Username { get; set; }
6299
public string Repository { get; set; }
100+
public ulong Id { get; set; }
101+
public bool SaveOnSelect { get; set; }
63102
}
64103
}
65104
}

CodeHub.Core/ViewModels/Issues/IssueViewModel.cs

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,35 @@ public IssueModel Issue
5656

5757
public ICommand GoToAssigneeCommand
5858
{
59-
get { return new MvxCommand(() => ShowViewModel<ProfileViewModel>(new ProfileViewModel.NavObject { Username = Issue.Assignee.Login }), () => Issue != null && Issue.Assignee != null); }
59+
get
60+
{
61+
return new MvxCommand(() => {
62+
GetService<IViewModelTxService>().Add(Issue.Assignee);
63+
ShowViewModel<IssueAssignedToViewModel>(new IssueAssignedToViewModel.NavObject { Username = Username, Repository = Repository, Id = Id, SaveOnSelect = true });
64+
});
65+
}
66+
}
67+
68+
public ICommand GoToMilestoneCommand
69+
{
70+
get
71+
{
72+
return new MvxCommand(() => {
73+
GetService<IViewModelTxService>().Add(Issue.Milestone);
74+
ShowViewModel<IssueMilestonesViewModel>(new IssueMilestonesViewModel.NavObject { Username = Username, Repository = Repository, Id = Id, SaveOnSelect = true });
75+
});
76+
}
77+
}
78+
79+
public ICommand GoToLabelsCommand
80+
{
81+
get
82+
{
83+
return new MvxCommand(() => {
84+
GetService<IViewModelTxService>().Add(Issue.Labels);
85+
ShowViewModel<IssueLabelsViewModel>(new IssueLabelsViewModel.NavObject { Username = Username, Repository = Repository, Id = Id, SaveOnSelect = true });
86+
});
87+
}
6088
}
6189

6290
public ICommand GoToEditCommand
@@ -75,11 +103,6 @@ public CollectionViewModel<IssueCommentModel> Comments
75103
{
76104
get { return _comments; }
77105
}
78-
79-
public ICommand GoToWeb
80-
{
81-
get { return new MvxCommand<string>(x => ShowViewModel<WebBrowserViewModel>(new WebBrowserViewModel.NavObject { Url = x })); }
82-
}
83106

84107
protected override Task Load(bool forceCacheInvalidation)
85108
{

0 commit comments

Comments
 (0)