Beispiel #1
0
        public Issue(string name)
        {
            Name = name;

            TotalLoggedTime = new ProjectedObservableValue <TimeSpan>(() => LoggedQuarter.Duration * LoggedQuarters.Count);
            LoggedQuarters.CollectionChanged += TotalLoggedTime.Refresh;
        }
Beispiel #2
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 = "";
            });
        }
        internal IssueCollection()
        {
            var aggregator = new CollectionEventAggregator();

            aggregator.Initialize(this,
                                  issue => issue.LoggedQuarters.CollectionChanged += aggregator.RaiseItemChanged,
                                  issue => issue.LoggedQuarters.CollectionChanged -= aggregator.RaiseItemChanged);
            aggregator.ItemChanged += (s, e) => LoggedQuartersChanged?.Invoke(this, EventArgs.Empty);
            CollectionChanged      += (s, e) => LoggedQuartersChanged?.Invoke(this, EventArgs.Empty);

            TotalActiveTime        = new ProjectedObservableValue <TimeSpan>(() => this.Aggregate(TimeSpan.Zero, (acc, issue) => acc + issue.TotalLoggedTime.Value));
            LoggedQuartersChanged += TotalActiveTime.Refresh;

            Add(new Issue("Coordination"));
            Add(new Issue("Ceremonies"));
        }
Beispiel #4
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 #5
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;
        }