public MainWindowViewModel(WorkLogCore model) { this.model = model; TotalTimeText = ProjectedObservableValue <string> .FromObservableValue(model.Issues.TotalActiveTime, time => $"Total {time:h\\:mm}"); HourLabels = Enumerable .Range(7, 12 + 1) .Select(hour => new HourLabelViewModel(hour, isLast: hour == 19)) .ToArray(); var issueColors = new IssueColors(); var colorClickedAggregator = new CollectionEventAggregator(); IssueRows = ProjectedObservableCollection <IssueRowViewModel> .Create(this.model.Issues, issue => new IssueRowViewModel(issue, model, colorClickedAggregator, issueColors)); colorClickedAggregator.Initialize(IssueRows, issue => issue.ColorClicked += colorClickedAggregator.RaiseItemChanged, issue => issue.ColorClicked -= colorClickedAggregator.RaiseItemChanged); QuarterBoxes = Enumerable .Range(4 * 7, 4 * 12) .Select(quarterIndex => new LoggedQuarter(quarterIndex / 4, quarterIndex % 4)) .Select(quarter => new QuarterBoxViewModel(quarter, model.Issues, model.Logger, IssueRows, issueColors)) .ToArray(); AddIssueCommand = new DelegateCommand(() => { this.model.Issues.Add(new Issue(NewIssueName.Value)); NewIssueName.Value = ""; }); }
public IssueRowViewModel(Issue issue, WorkLogCore workLog, CollectionEventAggregator colorClickedAggregator, IssueColors issueColors) { Issue = issue; Name = Issue.Name; TimeText = ProjectedObservableValue <string> .FromObservableValue(issue.TotalLoggedTime, time => time.ToString("h\\:mm")); Color = issueColors.GetColor(Issue); Background = ProjectedObservableValue <Brush> .FromObservableValue(workLog.Logger.RunningIssue, runningIssue => runningIssue == Issue?Brushes.LightGreen : Brushes.White); StartStopButtonText = ProjectedObservableValue <string> .FromObservableValue(workLog.Logger.RunningIssue, runningIssue => runningIssue == Issue? "Stop" : "Start"); StartStopButtonCommand = new DelegateCommand(() => workLog.Logger.StartStop(Issue)); RemoveButtonCommand = new DelegateCommand(() => { if (MessageBox.Show($"Do you want to delete '{Name}' issue and its logged time?", "Remove issue", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { workLog.Issues.Remove(Issue); issueColors.RemoveColor(Issue); } }); ColorClickedCommand = new DelegateCommand(() => ColorClicked?.Invoke(this, EventArgs.Empty)); colorClickedAggregator.ItemChanged += (sender, e) => IsColorChecked.Value = sender == this && IsColorChecked.Value == false; }