File

libs/employee-management/src/management-screen/management-screen.component.ts

Metadata

selector management-screen
templateUrl ./management-screen.component.html

Index

Properties
Methods

Constructor

constructor(api: EmployeeApi, nav: EmployeeNavigation, route: ActivatedRoute)
Parameters :
Name Type Optional
api EmployeeApi no
nav EmployeeNavigation no
route ActivatedRoute no

Methods

addClicked
addClicked()
Returns : void
select
select(id: number)
Parameters :
Name Type Optional
id number no
Returns : void

Properties

filteredList
filteredList: Observable<[]>
Type : Observable<[]>
nameFilter
nameFilter:
Default value : new FormControl('')
sort
sort:
Default value : new FormControl('last_name')
import { Component } from '@angular/core';
import { FormControl } from '@angular/forms';
import { ActivatedRoute } from '@angular/router';
import { Observable } from 'rxjs/Observable';
import { sortBy } from 'lodash';
import { combineLatest } from 'rxjs/observable/combineLatest'
import { startWith, debounceTime, switchMap } from 'rxjs/operators'

import { EmployeeApi } from '@enterprise-example/employee-api';
import { IEmployee } from '@enterprise-example/app-schema';

import { EmployeeNavigation } from '../employee-navigation.service';

@Component({
  selector: 'management-screen',
  templateUrl: './management-screen.component.html'
})
export class ManagementScreenComponent {
  nameFilter = new FormControl('');
  sort = new FormControl('last_name');
  filteredList: Observable<IEmployee[]>;

  constructor(api: EmployeeApi, private nav: EmployeeNavigation, route: ActivatedRoute) {
    this.nav.calculateModuleBaseRoute(route);

    const nameFilter$ = this.nameFilter.valueChanges.pipe(
      startWith(this.nameFilter.value),
      debounceTime(250));
    const sort$ = this.sort.valueChanges.pipe(
      startWith(this.sort.value));

    // List reacts to filter and sort changes
    this.filteredList = combineLatest(
      nameFilter$.pipe(switchMap(x => api.listFiltered(x))),
      sort$,
      (list, sort) => sortBy(list, sort)
    );
  }

  addClicked() {
    this.nav.add();
  }

  select(id: number) {
    this.nav.edit(id);
  }
}
<div class="row">
  <div class="col s12">
    <section class="card">
      <div class="card-content">
        <div class="card-title">Employee management</div>

        <div class="row">
          <div class="col s6 l4">
            <label for="nameFilter">Name filter</label>
            <input id="nameFilter" type="text" autocomplete="off" [formControl]="nameFilter">
          </div>
          <div class="col s6 l4">
            <label for="sort">Sort by</label>
            <select id="sort" type="text" [formControl]="sort">
              <option value="last_name">Last name</option>
              <option value="hours_worked">Hours worked</option>
            </select>
          </div>
        </div>

        <button class="btn" (click)="addClicked()">Add employee</button>

        <div class="row">
          <div class="col s6 l8">
            <employee-list-table-view [list]="filteredList | async"
              (selectId)="select($event)"></employee-list-table-view>
          </div>
        </div>

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

results matching ""

    No results matching ""