All files / app/component/page-controls page-controls.component.ts

78.12% Statements 25/32
81.25% Branches 13/16
62.5% Functions 10/16
76% Lines 19/25

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 9875x                                       75x         5x   5x   5x   5x 5x 5x     5x 5x         19x                 3x       3x       3x       6x       19x               19x     19x                       19x              
import { Component, HostBinding, Input } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { RouterLink, RouterLinkActive } from '@angular/router';
import { delay } from 'lodash-es';
import { Page } from '../../model/page';
import { BookmarkService } from '../../service/bookmark.service';
import { Store } from '../../store/store';
 
@Component({
  selector: 'app-page-controls',
  templateUrl: './page-controls.component.html',
  styleUrls: ['./page-controls.component.scss'],
  host: { 'class': 'page-controls' },
  imports: [
    RouterLink,
    RouterLinkActive,
    ReactiveFormsModule,
    FormsModule,
  ]
})
export class PageControlsComponent {
 
  @Input()
  page?: Page<any>;
  @Input()
  showPageLast = true;
  @Input()
  hideCols = false;
  @Input()
  showPrev = true;
 
  pageSizes = [6, 24, 48, 96, 480];
  colSizes = [1, 2, 3, 4, 5, 6];
  colsChanged = false;
 
  constructor(
    public store: Store,
    private bookmarks: BookmarkService,
  ) { }
 
  @HostBinding('class.print-hide')
  get fullResults() {
    return this.page?.page.totalPages === 1;
  }
 
  @Input()
  set defaultCols(value: number | undefined) {
    this.colsChanged ||= value !== undefined;
  }
 
  get hasQuery() {
    return this.store.view.pageNumber !== undefined;
  }
 
  get prev() {
    return Math.max(0, this.page!.page.number - 1);
  }
 
  get next() {
    return Math.max(0, Math.min(this.last, this.page!.page.number + 1));
  }
 
  get last() {
    return Math.max(0, this.page!.page.totalPages - 1);
  }
 
  get pageSize() {
    return this.store.view.pageSize;
  }
 
  set pageSize(value: number) {
    this.bookmarks.pageSize = value;
  }
 
  get cols() {
    Iif (this.store.view.cols) {
      this.colsChanged = true;
    }
    return this.store.view.cols;
  }
 
  set cols(value: number) {
    this.bookmarks.cols = value;
  }
 
  scrollUp() {
    delay(() => window.scrollTo(0, 0), 400);
  }
 
  outOfPageSizeRange(size: number) {
    return !this.pageSizes.includes(size);
  }
 
  outOfColSizeRange(size: number) {
    return !this.colSizes.includes(size);
  }
}