<commit_before>import {Component, OnInit} from "@angular/core";
import {MenuDisplayService} from "../core/menu-display.service";
import {AccountBalancesService} from "./account-balances.service";
import {FormControl} from "@angular/forms";

@Component({
  template: `
    <div align="end">
      <md-checkbox [formControl]="includeClosedControl">
          Include Closed Accounts?
      </md-checkbox>
    </div>
        <!--
    <div
    <md-checkbox
       (click)="setupAccountCategories()"
        [(ngModel)]="includeClosed"
    >
        Include Closed Accounts?
    </md-checkbox>
        <div class="col-xs-6">
            <div class="text-right">
                    <label>
                        <input type="checkbox"
                               ng-click="vm.refresh()"
                               ng-model="vm.searchParams.include_closed" />
                        Include Closed Accounts?
                    </label>
            </div>
        </div>
        -->
    <ec-account-balance-list title="Current Accounts" [bankAccounts]="currentAccounts">
    </ec-account-balance-list>
        
    <ec-account-balance-list title="Current Accounts" [bankAccounts]="assetAccounts">
    </ec-account-balance-list>
    
    <ec-account-balance-list title="Liability Accounts" [bankAccounts]="liabilityAccounts">
    </ec-account-balance-list>
    
    <ec-card>
        <h3>Net Worth: </h3>
    </ec-card>
    <!--
    <div class="row">
        <div class="col-xs-12">
           <h3 class="net-worth text-right">
                Net Worth: &nbsp; <ec-amount-formatted amount="vm.netWorth(vm.bankAccounts)">
                           </ec-amount-formatted>
           </h3>
        </div>
    </div>
    -->
  `
})
export class AccountBalancesComponent implements OnInit{

  bankAccounts = [];
  currentAccounts = [];
  assetAccounts = [];
  liabilityAccounts = [];

  includeClosedControl = new FormControl(false);

  constructor(
    private menuDisplayService: MenuDisplayService,
    private accountBalancesService: AccountBalancesService
  ){}

  ngOnInit(){
    this.menuDisplayService.setHeading('Account Balances');
    this.includeClosedControl
        .valueChanges
        .subscribe(includeClosed => this.setupAccountCategories(includeClosed));

    this.setupAccountCategories();

  }

  setupAccountCategories(include_closed?: boolean){

    this.accountBalancesService
      .getAccountBalances({include_closed})
      .subscribe(bankAccounts => {

        this.bankAccounts = bankAccounts;
        this.currentAccounts = this.bankAccounts.filter( b => b.account_category == 'current');
        this.assetAccounts = this.bankAccounts.filter( b => b.account_category == 'asset');
        this.liabilityAccounts = this.bankAccounts.filter( b => b.account_category == 'liability');
    });

  }

}<commit_msg>add net worth display to account balances view<commit_after>import {Component, OnInit} from "@angular/core";
import {MenuDisplayService} from "../core/menu-display.service";
import {AccountBalancesService} from "./account-balances.service";
import {FormControl} from "@angular/forms";

@Component({
  template: `
    <div align="end">
      <md-checkbox [formControl]="includeClosedControl">
          Include Closed Accounts?
      </md-checkbox>
    </div>
    
    <ec-account-balance-list title="Current Accounts" [bankAccounts]="currentAccounts">
    </ec-account-balance-list>
        
    <ec-account-balance-list title="Current Accounts" [bankAccounts]="assetAccounts">
    </ec-account-balance-list>
    
    <ec-account-balance-list title="Liability Accounts" [bankAccounts]="liabilityAccounts">
    </ec-account-balance-list>
    
    <ec-card>
        <h3 align="end">Net Worth: <ec-amount-formatted [amount]="netWorth"></ec-amount-formatted> </h3>
    </ec-card>
  `
})
export class AccountBalancesComponent implements OnInit{

  bankAccounts = [];
  netWorth: number;
  currentAccounts = [];
  assetAccounts = [];
  liabilityAccounts = [];

  includeClosedControl = new FormControl(false);

  constructor(
    private menuDisplayService: MenuDisplayService,
    private accountBalancesService: AccountBalancesService
  ){}

  ngOnInit(){
    this.menuDisplayService.setHeading('Account Balances');
    this.includeClosedControl
        .valueChanges
        .subscribe(includeClosed => this.setupAccountCategories(includeClosed));

    this.setupAccountCategories();

  }

  setupAccountCategories(include_closed?: boolean){

    this.accountBalancesService
      .getAccountBalances({include_closed})
      .subscribe(bankAccounts => {

        this.bankAccounts = bankAccounts;
        this.currentAccounts = this.bankAccounts.filter( b => b.account_category == 'current');
        this.assetAccounts = this.bankAccounts.filter( b => b.account_category == 'asset');
        this.liabilityAccounts = this.bankAccounts.filter( b => b.account_category == 'liability');

        this.netWorth = this.accountBalancesService.netWorth(bankAccounts);
    });

  }

}
{'fraction_non_alphanumeric': 0.13325354079393575, 'fraction_numerical': 0.0017953321364452424, 'mean_word_length': 2.93563579277865, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 62, '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': '1218933', 'n_tokens_mistral': 1481, 'n_tokens_neox': 1424, 'n_words': 247}