Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { FormControl } from '@angular/forms';
- import { Productionorder } from './../../models/productionorder.model';
- import { ProductionorderService } from '../../services/productionorder.service';
- import { Subject } from 'rxjs';
- import { Component, OnInit, OnDestroy } from '@angular/core';
- import { Page, IChangePagination } from '../../../shared/models/page.model';
- import { PageSizeService } from '../../../core/services/page-size.service';
- import { debounceTime, takeUntil } from 'rxjs/operators';
- import { AlertifyService } from '../../../_service/alertify.service';
- @Component({
- selector: 'app-productionorder-list',
- templateUrl: './productionorder-list.component.html',
- styleUrls: ['./productionorder-list.component.css']
- })
- export class ProductionorderListComponent implements OnInit, OnDestroy {
- productionorders: Productionorder[];
- totalCount: number;
- searchQuery = '';
- destroy$: Subject<boolean> = new Subject<boolean>();
- orderSearch = new FormControl();
- private pages: Page;
- constructor(
- private productionorderService: ProductionorderService,
- private pageSizeService: PageSizeService,
- private alertify: AlertifyService
- ) { }
- ngOnInit() {
- this.orderSearch.valueChanges
- .pipe(
- debounceTime(1000),
- takeUntil(this.destroy$)
- )
- .subscribe(newValue => {
- this.searchQuery = newValue;
- this.onSearch();
- });
- this.reloadPages();
- this.loadProductionOrders();
- this.loadSearchProductionOrders();
- }
- ngOnDestroy() {
- this.destroy$.next(true);
- this.destroy$.unsubscribe();
- }
- onPaginationChange($event: IChangePagination) {
- this.pages.page = $event.pageIndex;
- this.pages.pageSize = $event.pageSize;
- if (this.searchQuery === null || this.searchQuery === '') {
- this.loadProductionOrders();
- } else {
- this.loadSearchProductionOrders();
- }
- }
- private onSearch() {
- this.reloadPages();
- this.loadSearchProductionOrders();
- }
- private loadSearchProductionOrders() {
- this.productionorderService
- .getAllSearchProductionOrders(this.pages, this.searchQuery)
- .pipe(
- takeUntil(this.destroy$)
- )
- .subscribe(res => {
- this.productionorders = (res.data as unknown as Productionorder[]);
- this.totalCount = res.data.total;
- });
- }
- private loadProductionOrders() {
- this.productionorderService
- .getAllProductionOrders(this.pages)
- .pipe(
- takeUntil(this.destroy$)
- )
- .subscribe(res => {
- this.productionorders = (res.data as unknown as Productionorder[]);
- this.totalCount = res.data.total;
- });
- }
- private reloadPages() {
- this.pages = this.pageSizeService.reloadPages();
- }
- // private loadOrders() {
- // this.productionorderService
- // .getAllProductionOrders(this.pages)
- // .subscribe(data => {this.productionorders = (data as unknown as Productionorder[]);
- // }, err => {
- // this.alertify.error('Nie udało się pobrać listy zleceń produkcyjnych');
- // });
- // }
- // private reloadPages() {
- // this.pages = this.pageSizeService.reloadPages();
- // }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement