File

libs/employee-list/src/employee-list/employee-list.component.ts

Metadata

selector employee-list
templateUrl ./employee-list.component.html

Index

Properties

Constructor

constructor(api: EmployeeApi)
Parameters :
Name Type Optional
api EmployeeApi no

Properties

employees
employees: Observable<[]>
Type : Observable<[]>
selectedEmployee
selectedEmployee: Observable<IEmployeeListing>
Type : Observable<IEmployeeListing>
selectedEmployeeId
selectedEmployeeId:
Default value : new Subject<number>()
showEmployeeDetails
showEmployeeDetails: Observable<boolean>
Type : Observable<boolean>
status
status: Observable<string>
Type : Observable<string>
import { Component } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { Subject } from 'rxjs/Subject';
import { filter, map, share } from 'rxjs/operators';

import { EmployeeApi } from '@enterprise-example/employee-api';
import { IEmployeeListing } from '@enterprise-example/app-schema';
import { StatusStrings, LoadResultStatus, loadWithRetry, faulty } from '@enterprise-example/retry-loader';

@Component({
  selector: 'employee-list',
  templateUrl: './employee-list.component.html'
})
export class EmployeeListComponent {
  selectedEmployee: Observable<IEmployeeListing>;
  status: Observable<string>;
  selectedEmployeeId = new Subject<number>();
  employees: Observable<IEmployeeListing[]>;
  showEmployeeDetails: Observable<boolean>;

  constructor(api: EmployeeApi) {
    this.employees = api.listAll();

    const loadResults = loadWithRetry(
      this.selectedEmployeeId,
      id => api.loadOne(id)
        .pipe(faulty<IEmployeeListing>())   // simulate bad connection
    ).pipe(share());

    this.status = loadResults
      .pipe(map(result => StatusStrings[result.status]));

    this.showEmployeeDetails = loadResults
      .pipe(map(result => result.status === LoadResultStatus.Success));

    this.selectedEmployee = loadResults
      .pipe(filter(result => result.status === LoadResultStatus.Success),
        map(result => result.data));
  }
}
<div class="row">
  <div class="col s12 m6">
    <section class="card">
      <div class="card-content">
        <div class="card-title">Employees</div>

        <employee-list-table-view [list]="employees | async"
          [selectedId]="selectedEmployeeId | async"
          (selectId)="selectedEmployeeId.next($event)"></employee-list-table-view>

      </div>
    </section>
  </div>

  <section class="col s12 m6">
    <section class="card">
      <div class="card-content">
        <div class="card-title">Employee detail</div>
        <p>Loading status: <b>{{ status | async }}</b></p>
        <employee-detail-view
          [style.visibility]="(showEmployeeDetails | async) ? 'visible' : 'hidden'"
          [employee]="selectedEmployee | async"></employee-detail-view>
      </div>
    </section>
  </section>
</div>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""