File

src/app/sending-money/change-account/change-account.component.ts

Implements

OnInit OnChanges

Metadata

selector app-change-account
styleUrls change-account.component.css
templateUrl ./change-account.component.html

Index

Properties
Methods
Inputs
Outputs

Constructor

constructor(app: AppState)
Parameters :
Name Type Optional
app AppState no

Inputs

template

Type: Template

Outputs

closeChangeAccount $event type: EventEmitter
setAndCloseAccount $event type: EventEmitter

Methods

isAccountsValid
isAccountsValid()
Returns : boolean
isIdValid
isIdValid()
Returns : boolean
ngOnChanges
ngOnChanges(changes: SimpleChanges)
Parameters :
Name Type Optional
changes SimpleChanges no
Returns : void
ngOnInit
ngOnInit()
Returns : void
setDefaultAccount
setDefaultAccount(account: BankAccount)
Parameters :
Name Type Optional
account BankAccount no
Returns : void
stopPropagation
stopPropagation(event: Event)
Parameters :
Name Type Optional
event Event no
Returns : void
toggleChangeAccount
toggleChangeAccount(event: Event)
Parameters :
Name Type Optional
event Event no
Returns : void

Properties

accounts
accounts: BankAccount[]
Type : BankAccount[]
session
session: Session
Type : Session
import {
  Component,
  EventEmitter,
  Input,
  OnChanges,
  OnInit,
  Output,
  SimpleChanges
} from '@angular/core';

import { BankAccount, Session, Template } from '../../models';
import { TemplateService } from '../../services';
import { AuthService } from '../../services/auth.service';
import { SessionStore } from '../../stores';
import { AppState } from '../../stores/app-state.store';
import { filter, map } from 'rxjs/operators';

@Component({
  selector: 'app-change-account',
  templateUrl: './change-account.component.html',
  styleUrls: ['./change-account.component.css']
})
export class ChangeAccountComponent implements OnInit, OnChanges {
  @Output()
  closeChangeAccount = new EventEmitter();
  @Output()
  setAndCloseAccount = new EventEmitter();
  @Input()
  template: Template;

  session: Session;
  accounts: BankAccount[];

  constructor(private app: AppState) {}

  ngOnInit() {
    this.app.state$.pipe(filter(state => state !== null)).subscribe(state => {
      this.accounts = state.accounts;
    });
  }

  ngOnChanges(changes: SimpleChanges) {
    if (changes['template'] && this.isIdValid() && this.isAccountsValid()) {
      const matched = this.accounts.filter(a => a.id === this.template.payFromBankAccount.id);
      if (matched.length > 0) {
        this.setDefaultAccount(matched[0]);
      }
    }
  }

  isAccountsValid() {
    return this.accounts !== null && this.accounts !== undefined && this.accounts.length > 0;
  }

  isIdValid(): boolean {
    return this.template !== undefined && this.template !== null;
  }

  toggleChangeAccount(event: Event) {
    this.closeChangeAccount.emit();
  }

  stopPropagation(event: Event) {
    event.stopPropagation();
  }

  setDefaultAccount(account: BankAccount) {
    this.setAndCloseAccount.emit(account);
  }
}
<div class="overlay scroller" id="changeAccountPopup" (click)="toggleChangeAccount($event)">
  <div class="pop-up-ctn" id="changeAccount">

    <div class="close-ctn" (click)="stopPropagation($event)">
      <a id="closeButton" (click)="toggleChangeAccount($event)">
        <i class="material-icons">close</i>
      </a>
    </div>

    <div class="pop-up-ctn-header" (click)="stopPropagation($event)">
      <p class="header-text">Change Account</p>
    </div>
    <div class="pop-up-ctn-body" (click)="stopPropagation($event)">

      <label *ngFor="let account of accounts" (click)="setDefaultAccount(account)">
        <div class="switch-accounts">
          <app-account-label [account]="account"></app-account-label>
          <input type="radio" name="default-checking-account" value="">
          <span class="custom-radio"> </span>
        </div>
      </label>

    </div>
  </div>
</div>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""