/
CardDetailPivotViewModel.cs
115 lines (101 loc) · 3.91 KB
/
CardDetailPivotViewModel.cs
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
using System;
using System.Windows;
using Caliburn.Micro;
using JetBrains.Annotations;
using trello.Services.Handlers;
using trello.Views;
using trellow.api;
namespace trello.ViewModels
{
public class CardDetailPivotViewModel : PivotViewModel,
IHandle<CardNameChanged>,
IHandle<CardDetailPivotViewModel.PivotRequestingNavigation>
{
public enum Screen
{
Overview = 0,
Checklists = 1,
Attachments = 2,
Members = 3
}
private readonly ITrello _api;
private readonly INavigationService _navigation;
private readonly Func<CardDetailChecklistViewModel> _checklists;
private readonly Func<CardDetailAttachmentsViewModel> _attachments;
private readonly Func<CardDetailMembersViewModel> _members;
private readonly IEventAggregator _eventAggregator;
private readonly Func<CardDetailOverviewViewModel> _overview;
private readonly IWindowManager _windowManager;
private string _name;
public string Id { get; set; }
public string Name
{
get { return _name; }
set
{
if (value == _name) return;
_name = value;
NotifyOfPropertyChange(() => Name);
}
}
public CardDetailPivotViewModel(ITrello api,
ITrelloApiSettings settings,
INavigationService navigation,
IEventAggregator eventAggregator,
IWindowManager windowManager,
Func<CardDetailOverviewViewModel> overview,
Func<CardDetailChecklistViewModel> checklists,
Func<CardDetailAttachmentsViewModel> attachments,
Func<CardDetailMembersViewModel> members)
: base(settings, navigation)
{
_api = api;
_navigation = navigation;
_windowManager = windowManager;
_overview = overview;
_checklists = checklists;
_attachments = attachments;
_members = members;
_eventAggregator = eventAggregator;
_eventAggregator.Subscribe(this);
}
protected override async void OnInitialize()
{
var card = await _api.Cards.WithId(Id);
if (card == null)
{
MessageBox.Show("The card could not be found. Usually this means that someone else has removed it " +
"while you were browsing.");
_navigation.GoBack();
return;
}
Name = card.Name;
Items.Add(_overview().Initialize(card));
Items.Add(_checklists().Initialize(card));
Items.Add(_attachments().Initialize(card));
Items.Add(_members().Initialize(card));
ActivateItem(Items[0]);
}
[UsedImplicitly]
public void ChangeName()
{
var model = new ChangeCardNameViewModel(GetView(), _eventAggregator, Id)
{
Name = Name
};
_windowManager.ShowDialog(model);
}
public void Handle(CardNameChanged message)
{
Name = message.Name;
}
public void Handle(PivotRequestingNavigation message)
{
UsingView<CardDetailPivotView>(view => view.Items.SelectedIndex = (int) message.Screen);
}
public class PivotRequestingNavigation
{
public Screen Screen { get; set; }
}
}
}