Beispiel #1
0
        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 = "";
            });
        }
Beispiel #2
0
        public QuarterBoxViewModel(LoggedQuarter quarter, IssueCollection issues, IssueLogger logger, IEnumerable <IssueRowViewModel> issueRows, IssueColors issueColors)
        {
            Margin = new Thickness(1, 1, quarter.Quarter == 3 ? 1 : 0, 1);

            Background = new ProjectedObservableValue <Brush>(() => issueColors.GetColor(issues.FindLoggedIn(quarter)));
            issues.LoggedQuartersChanged += Background.Refresh;

            LogCommand = new DelegateCommand(() =>
            {
                IssueRowViewModel checkedIssueRow = issueRows.SingleOrDefault(i => i.IsColorChecked.Value == true);
                if (checkedIssueRow != null)
                {
                    logger.Log(quarter, checkedIssueRow.Issue);
                }
            });
            RemoveLogCommand = new DelegateCommand(() => logger.RemoveLog(quarter));
        }
Beispiel #3
0
        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;
        }