File

src/app/components/sending-money/select-account/select-account.component.ts

Implements

OnInit

Metadata

Index

Properties
Methods
Inputs
Outputs
Accessors

Constructor

constructor(app: AppStateStore, templateService: TemplateService, authService: AuthService)
Parameters :
Name Type Optional
app AppStateStore No
templateService TemplateService No
authService AuthService No

Inputs

template
Type : Template
type
Type : TemplateType
Default value : TemplateType.Debit

Outputs

close
Type : EventEmitter

Methods

closeMe
closeMe(event: Event)
Parameters :
Name Type Optional
event Event No
Returns : void
Private filterByCategory
filterByCategory(template: Template)

Used to filter out templates that are limited by a previously selected template. Example: one cannot debit and credit 2 different FiVerified accounts.

Parameters :
Name Type Optional Description
template Template No

A2APaymentTemplate

Returns : boolean
Private filterBySelf
filterBySelf(template: Template)

Used to filter out a template that has already been selected. Example: One cannot credit and debit the same template.

Parameters :
Name Type Optional Description
template Template No

A2APaymentTemplate

Returns : boolean
Private filterByType
filterByType(template: Template)

Used to filter out templates that are either not the correct type or do not have the correct permissions.

Parameters :
Name Type Optional Description
template Template No

A2APaymentTemplate

Returns : boolean
ngOnInit
ngOnInit()
Returns : void
setTemplate
setTemplate(template: Template)
Parameters :
Name Type Optional
template Template No
Returns : void
stopPropagation
stopPropagation(event: Event)
Parameters :
Name Type Optional
event Event No
Returns : void

Properties

isLoading
Default value : false
templates
Type : Template[]

Accessors

label
getlabel()
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import 'rxjs/add/operator/filter';
import { AccountCategory } from '../../../enums';
import { TemplateType } from '../../../enums/template-type.enum';
import { Template } from '../../../models';
import { AuthService, TemplateService } from '../../../providers';
import { AppStateStore } from '../../../providers/stores/app-state.store';

@Component({
  selector: 'app-select-account',
  templateUrl: './select-account.component.html',
  styleUrls: ['./select-account.component.css']
})
export class SelectAccountComponent implements OnInit {
  @Output() close = new EventEmitter();
  @Input() template: Template;
  @Input() type: TemplateType = TemplateType.Debit;
  isLoading = false;
  templates: Template[];

  constructor(
    private app: AppStateStore,
    private templateService: TemplateService,
    private authService: AuthService
  ) {}

  ngOnInit() {
    this.isLoading = true;
    this.templateService.templates$
      .filter(templates => templates !== null)
      .filter(templates => templates !== undefined)
      .filter(templates => templates.length > 0)
      .subscribe(templates => {
        this.templates = templates
          .filter(accounts => this.filterByType(accounts))
          .filter(accounts => this.filterByCategory(accounts))
          .filter(accounts => this.filterBySelf(accounts));
        this.isLoading = false;
      });
  }

  /**
   * Used to filter out templates that are either not the correct type or do not have the correct permissions.
   * @param template A2APaymentTemplate
   */
  private filterByType(template: Template): boolean {
    switch (this.type) {
      case TemplateType.Debit:
        return template.canDebit;
      case TemplateType.Credit:
        return template.canCredit;
    }
  }

  /**
   * Used to filter out templates that are limited by a previously selected template.
   * Example: one cannot debit and credit 2 different FiVerified accounts.
   * @param template A2APaymentTemplate
   */
  private filterByCategory(template: Template): boolean {
    switch (this.type) {
      case TemplateType.Debit:
        return this.app.creditTemplate &&
          ((this.app.creditTemplate.accountCategory ===
            AccountCategory.FiVerified &&
            template.accountCategory === AccountCategory.FiVerified) ||
            (this.app.creditTemplate.accountCategory ===
              AccountCategory.CustomerEntered &&
              template.accountCategory === AccountCategory.CustomerEntered))
          ? false
          : true;
      case TemplateType.Credit:
        return this.app.debitTemplate &&
          ((this.app.debitTemplate.accountCategory ===
            AccountCategory.FiVerified &&
            template.accountCategory === AccountCategory.FiVerified) ||
            (this.app.debitTemplate.accountCategory ===
              AccountCategory.CustomerEntered &&
              template.accountCategory === AccountCategory.CustomerEntered))
          ? false
          : true;
    }
  }

  /**
   * Used to filter out a template that has already been selected.
   * Example: One cannot credit and debit the same template.
   * @param template A2APaymentTemplate
   */
  private filterBySelf(template: Template): boolean {
    // cant credit and debit same account
    switch (this.type) {
      case TemplateType.Debit:
        if (!this.app.creditTemplate) {
          return true;
        }
        return this.app.creditTemplate.id !== template.id;
      case TemplateType.Credit:
        if (!this.app.debitTemplate) {
          return true;
        }
        return this.app.debitTemplate.id !== template.id;
    }
  }

  closeMe(event: Event) {
    this.close.emit();
  }

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

  get label(): string {
    return this.type === TemplateType.Debit ? 'From' : 'To';
  }

  setTemplate(template: Template) {
    switch (this.type) {
      case TemplateType.Debit:
        this.app.debitTemplate = template;
        break;
      case TemplateType.Credit:
        this.app.creditTemplate = template;
        break;
    }
    this.close.emit();
  }
}
<div class="overlay scroller" id="changeAccountPopup" (click)="closeMe($event)">
  <div class="pop-up-ctn" id="changeAccount">

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

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

      <div>

        <app-loading-linear *ngIf="isLoading"></app-loading-linear>

        <label *ngFor="let template of templates;" (click)="setTemplate(template)">
          <div class="switch-accounts">
            <app-template-label [id]="template.id"></app-template-label>
            <input type="radio" name="default-checking-account" value="">
          </div>
        </label>

      </div>

      <a id="addAccountButton" [routerLink]="['/template/plaid']">
        <label>
          <div class="switch-accounts add-account-ctn">
            <span id="add-account-btn">
              <i class="material-icons ">add</i>
            </span>
            <p>
              Add An Account
            </p>
          </div>
        </label>
      </a>

    </div>

  </div>
</div>

./select-account.component.css

#changeAccount {
  margin-top: 250px;
}

#changeAccount .pop-up-ctn-body {
  padding: 0px;
}

.switch-accounts {
  border-bottom: 1px solid #ccc;
  padding: 0px;
  height: auto;
  position: relative;
  text-align: center;
  padding: 10px 25px;
}

.switch-accounts:hover {
  background-color: rgba(158, 158, 158, 0.2);
}

.switch-accounts p.items-list-name {
  text-align: center;
}

#changeAccount input[type='radio'] {
  text-align: right;
  cursor: pointer;
}

#changeAccount label {
  color: #474747;
  font-size: 14px;
  line-height: 40px;
  cursor: pointer;
}

.custom-radio {
  position: absolute;
  right: 25px;
  top: 22px;
  width: 10px;
  height: 10px;
  border: 1px solid #707173;
}

input[type='checkbox']:checked + span,
input[type='radio']:checked + span {
  background-color: #707173;
  border: 1px solid #707173;
  border-radius: 25px;
  box-shadow: 0 0 0 2px #fff inset;
}

label:hover input + span {
  background-color: #707173;
  border: 1px solid #707173;
  border-radius: 25px;
  box-shadow: 0 0 0 2px #fff inset;
}

.items-list-status {
  margin-top: 2px;
}

.add-account-option {
  height: 32px;
}

.add-account-option-btn {
  width: 30px;
  height: 30px;
  border-radius: 0;
  margin: 0px;
  background-color: #be2438;
  color: #fff;
  cursor: pointer;
  display: inline-block;
  vertical-align: middle;
  margin-top: -8px;
}

.add-account-option i {
  vertical-align: middle;
  margin-left: 3px;
  margin-top: -10px;
}

.add-account-option-label {
  display: inline-block;
  margin: -7px 0px 0px 5px;
  vertical-align: middle;
}

/*----- Add Button -----*/

.add-account-btn-ctn {
  padding: 10px;
}

.add-account-ctn p {
  display: inline-block;
  vertical-align: middle;
  color: #be2438;
  margin: 0px;
}

#add-account-btn {
  width: 28px;
  height: 28px;
  display: inline-block;
  background-color: #be2438;
  border: none;
  z-index: 99;
  margin-right: 5px;
  vertical-align: middle;
}

#add-account-btn i {
  font-size: 23px;
  margin-right: 0px;
  margin-top: 3px;
  color: #fff;
  cursor: pointer;
  vertical-align: top;
}

.fap-label {
  background-color: #f7f8fc;
  position: absolute;
  bottom: 21px;
  right: 75px;
  border-radius: 4px;
  padding: 5px 11px;
}

@media only screen and (max-width: 400px) {
  #changeAccount {
    margin-top: 15px;
  }

  .fap-label {
    background-color: #f7f8fc;
    position: absolute;
    bottom: 22px;
    right: 75px;
  }
}
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""