SHARE
TWEET

Untitled

a guest Apr 18th, 2019 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { FormControl } from '@angular/forms';
  2. import { Productionorder } from './../../models/productionorder.model';
  3. import { ProductionorderService } from '../../services/productionorder.service';
  4. import { Subject } from 'rxjs';
  5. import { Component, OnInit, OnDestroy } from '@angular/core';
  6. import { Page, IChangePagination } from '../../../shared/models/page.model';
  7. import { PageSizeService } from '../../../core/services/page-size.service';
  8. import { debounceTime, takeUntil } from 'rxjs/operators';
  9. import { AlertifyService } from '../../../_service/alertify.service';
  10.  
  11.  
  12. @Component({
  13.   selector: 'app-productionorder-list',
  14.   templateUrl: './productionorder-list.component.html',
  15.   styleUrls: ['./productionorder-list.component.css']
  16. })
  17. export class ProductionorderListComponent implements OnInit, OnDestroy {
  18.  
  19.   productionorders: Productionorder[];
  20.   totalCount: number;
  21.   searchQuery = '';
  22.   destroy$: Subject<boolean> = new Subject<boolean>();
  23.   orderSearch = new FormControl();
  24.  
  25.   private pages: Page;
  26.  
  27.   constructor(
  28.     private productionorderService: ProductionorderService,
  29.     private pageSizeService: PageSizeService,
  30.     private alertify: AlertifyService
  31.   ) { }
  32.  
  33.   ngOnInit() {
  34.     this.orderSearch.valueChanges
  35.       .pipe(
  36.         debounceTime(1000),
  37.         takeUntil(this.destroy$)
  38.       )
  39.       .subscribe(newValue => {
  40.         this.searchQuery = newValue;
  41.         this.onSearch();
  42.       });
  43.     this.reloadPages();
  44.     this.loadProductionOrders();
  45.     this.loadSearchProductionOrders();
  46.   }
  47.  
  48.   ngOnDestroy() {
  49.     this.destroy$.next(true);
  50.     this.destroy$.unsubscribe();
  51.   }
  52.  
  53.   onPaginationChange($event: IChangePagination) {
  54.     this.pages.page = $event.pageIndex;
  55.     this.pages.pageSize = $event.pageSize;
  56.     if (this.searchQuery === null || this.searchQuery === '') {
  57.       this.loadProductionOrders();
  58.     } else {
  59.       this.loadSearchProductionOrders();
  60.     }
  61.   }
  62.  
  63.   private onSearch() {
  64.     this.reloadPages();
  65.     this.loadSearchProductionOrders();
  66.   }
  67.  
  68.   private loadSearchProductionOrders() {
  69.     this.productionorderService
  70.       .getAllSearchProductionOrders(this.pages, this.searchQuery)
  71.       .pipe(
  72.         takeUntil(this.destroy$)
  73.       )
  74.       .subscribe(res => {
  75.         this.productionorders = (res.data as unknown as Productionorder[]);
  76.         this.totalCount = res.data.total;
  77.       });
  78.   }
  79.  
  80.   private loadProductionOrders() {
  81.     this.productionorderService
  82.       .getAllProductionOrders(this.pages)
  83.       .pipe(
  84.         takeUntil(this.destroy$)
  85.       )
  86.       .subscribe(res => {
  87.         this.productionorders = (res.data as unknown as Productionorder[]);
  88.         this.totalCount = res.data.total;
  89.  
  90.       });
  91.   }
  92.  
  93.   private reloadPages() {
  94.     this.pages = this.pageSizeService.reloadPages();
  95.   }
  96.  
  97.  
  98.   // private loadOrders() {
  99.   //   this.productionorderService
  100.   //     .getAllProductionOrders(this.pages)
  101.   //     .subscribe(data => {this.productionorders = (data as unknown as Productionorder[]);
  102.   //     }, err => {
  103.   //       this.alertify.error('Nie udało się pobrać listy zleceń produkcyjnych');
  104.   //     });
  105.   //   }
  106.  
  107.   //   private reloadPages() {
  108.   //     this.pages = this.pageSizeService.reloadPages();
  109.   //   }
  110. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top