<commit_before>﻿using Money.Services.Models;
using Money.Services.Models.Queries;
using Money.ViewModels.Navigation;
using Neptuo;
using Neptuo.Activators;
using Neptuo.Observables;
using Neptuo.Observables.Collections;
using Neptuo.Queries;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.UI;

namespace Money.ViewModels
{
    public partial class SummaryViewModel : ViewModel
    {
        private readonly IQueryDispatcher queryDispatcher;

        private bool isLoading;
        public bool IsLoading
        {
            get { return isLoading; }
            internal set
            {
                if (isLoading != value)
                {
                    isLoading = value;
                    RaisePropertyChanged();
                }
            }
        }

        private Price totalAmount;
        public Price TotalAmount
        {
            get { return totalAmount; }
            set
            {
                if (totalAmount != value)
                {
                    totalAmount = value;
                    RaisePropertyChanged();
                }
            }
        }

        private MonthModel month;
        public MonthModel Month
        {
            get { return month; }
            set
            {
                if (month != value)
                {
                    month = value;
                    RaisePropertyChanged();

                    Year = null;
                    ReloadMonth();
                }
            }
        }

        private YearModel year;
        public YearModel Year
        {
            get { return year; }
            set
            {
                if (year != value)
                {
                    year = value;
                    RaisePropertyChanged();

                    Month = null;
                    ReloadYear();
                }
            }
        }

        public SortableObservableCollection<ISummaryItemViewModel> Items { get; private set; }

        public SummaryViewModel(INavigator navigator, IQueryDispatcher queryDispatcher)
            : base(navigator)
        {
            Ensure.NotNull(queryDispatcher, "queryDispatcher");
            this.queryDispatcher = queryDispatcher;
            Items = new SortableObservableCollection<ISummaryItemViewModel>();
        }
        
        private async Task ReloadMonth()
        {
            if (Month != null)
            {
                IsLoading = true;
                Items.Clear();

                IEnumerable<CategoryWithAmountModel> categories = await queryDispatcher.QueryAsync(new ListMonthCategoryWithOutcome(Month));
                foreach (CategoryWithAmountModel category in categories)
                {
                    Items.Add(new SummaryCategoryViewModel()
                    {
                        CategoryKey = category.Key,
                        Name = category.Name,
                        Color = category.Color,
                        Amount = category.TotalAmount
                    });
                }

                TotalAmount = await queryDispatcher.QueryAsync(new GetTotalMonthOutcome(Month));
                Items.Add(new SummaryTotalViewModel(TotalAmount));

                IsLoading = false;
            }
        }

        private async Task ReloadYear()
        {
            if (Year != null)
            {
                throw new NotImplementedException();
            }
        }
    }
}
<commit_msg>Load total summary, hide loading and the load categories summaries.<commit_after>﻿using Money.Services.Models;
using Money.Services.Models.Queries;
using Money.ViewModels.Navigation;
using Neptuo;
using Neptuo.Activators;
using Neptuo.Observables;
using Neptuo.Observables.Collections;
using Neptuo.Queries;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.UI;

namespace Money.ViewModels
{
    public partial class SummaryViewModel : ViewModel
    {
        private readonly IQueryDispatcher queryDispatcher;

        private bool isLoading;
        public bool IsLoading
        {
            get { return isLoading; }
            internal set
            {
                if (isLoading != value)
                {
                    isLoading = value;
                    RaisePropertyChanged();
                }
            }
        }

        private Price totalAmount;
        public Price TotalAmount
        {
            get { return totalAmount; }
            set
            {
                if (totalAmount != value)
                {
                    totalAmount = value;
                    RaisePropertyChanged();
                }
            }
        }

        private MonthModel month;
        public MonthModel Month
        {
            get { return month; }
            set
            {
                if (month != value)
                {
                    month = value;
                    RaisePropertyChanged();

                    Year = null;
                    ReloadMonth();
                }
            }
        }

        private YearModel year;
        public YearModel Year
        {
            get { return year; }
            set
            {
                if (year != value)
                {
                    year = value;
                    RaisePropertyChanged();

                    Month = null;
                    ReloadYear();
                }
            }
        }

        public SortableObservableCollection<ISummaryItemViewModel> Items { get; private set; }

        public SummaryViewModel(INavigator navigator, IQueryDispatcher queryDispatcher)
            : base(navigator)
        {
            Ensure.NotNull(queryDispatcher, "queryDispatcher");
            this.queryDispatcher = queryDispatcher;
            Items = new SortableObservableCollection<ISummaryItemViewModel>();
        }
        
        private async Task ReloadMonth()
        {
            if (Month != null)
            {
                IsLoading = true;
                Items.Clear();

                TotalAmount = await queryDispatcher.QueryAsync(new GetTotalMonthOutcome(Month));
                Items.Add(new SummaryTotalViewModel(TotalAmount));

                IsLoading = false;

                IEnumerable<CategoryWithAmountModel> categories = await queryDispatcher.QueryAsync(new ListMonthCategoryWithOutcome(Month));
                int index = 0;
                foreach (CategoryWithAmountModel category in categories)
                {
                    Items.Insert(index, new SummaryCategoryViewModel()
                    {
                        CategoryKey = category.Key,
                        Name = category.Name,
                        Color = category.Color,
                        Amount = category.TotalAmount
                    });
                    index++;
                }
            }
        }

        private async Task ReloadYear()
        {
            if (Year != null)
            {
                throw new NotImplementedException();
            }
        }
    }
}

{'fraction_non_alphanumeric': 0.06692160611854685, 'fraction_numerical': 0.0001365747063643813, 'mean_word_length': 1.2497695852534563, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5926271', 'n_tokens_mistral': 1718, 'n_tokens_neox': 1574, 'n_words': 376}