<commit_before>import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
import * as _ from 'lodash';

@Component({
  selector: 'pagination',
  styleUrls: [
    './pagination.css'
  ],
  templateUrl: 'pagination.html',
})
export class Pagination implements OnInit {
  @Input() pages: Array<number>;
  @Input() activePage: number;
  @Output() onPageClicked = new EventEmitter();
  visiblePages: Array<number>;

  constructor() {
  }

  ngOnInit() {
  }

  ngOnChanges(changes) {
    this.createPaginationInfo();
  }

  // Used for better readability in template
  get canGoToNextPage() {
    return _.last(this.pages) !== this.activePage;
  }

  // Used for better readability in template
  get canGoToPreviousPage() {
    return _.first(this.pages) !== this.activePage;
  }

  private createPaginationInfo() {
    let adjustBy = 0,
        visiblePages: Array<number> = _.range(
          this.activePage - 2,
          this.activePage + 3
        ),
        firstOfVisiblePages = _.first(visiblePages),
        lastOfVisiblePages = _.last(visiblePages),
        lastOfAllPages = _.last(this.pages);

    if (firstOfVisiblePages < 1) {

      adjustBy = Math.abs(firstOfVisiblePages) + 1;

    } else if (lastOfVisiblePages > lastOfAllPages) {

      adjustBy = lastOfAllPages - lastOfVisiblePages;

    }

    visiblePages = visiblePages
      .map(page => page + adjustBy)

    this.visiblePages = visiblePages;
  }

  private isValidPage(page: number): boolean {
    let isPositive,
        isLessThatMax;

    isPositive = 1 <= page;
    isLessThatMax = page <= _.last(this.pages);

    return isPositive && isLessThatMax;
  }

  forwardOnPageClicked(pageNumber: number) {
    if (!this.isValidPage(pageNumber) || pageNumber === this.activePage) {
      return;
    }

    this.onPageClicked.emit(pageNumber);
  }

  promtForGoToPage() {
    let goToPageNumber: any = Number(
      prompt(`Select page from 1 to ${_.last(this.pages)}`),
    ) || 0;

    this.forwardOnPageClicked(goToPageNumber);
  }

}
<commit_msg>pagination not displaying correct pages count then there is only 1 < real pages count < 5 bugfix<commit_after>import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
import * as _ from 'lodash';

@Component({
  selector: 'pagination',
  styleUrls: [
    './pagination.css'
  ],
  templateUrl: 'pagination.html',
})
export class Pagination implements OnInit {
  @Input() pages: Array<number>;
  @Input() activePage: number;
  @Output() onPageClicked = new EventEmitter();
  visiblePages: Array<number>;

  constructor() {
  }

  ngOnInit() {
  }

  ngOnChanges(changes) {
    this.createPaginationInfo();
  }

  // Used for better readability in template
  get canGoToNextPage() {
    return _.last(this.pages) !== this.activePage;
  }

  // Used for better readability in template
  get canGoToPreviousPage() {
    return _.first(this.pages) !== this.activePage;
  }

  private createPaginationInfo() {
    let adjustBy = 0, visiblePages,
        firstOfVisiblePages, lastOfVisiblePages,
        lastOfAllPages;

    lastOfAllPages = _.last(this.pages);

    visiblePages = lastOfAllPages > 5
      ? _.range(
          this.activePage - 2,
          this.activePage + 3
        )
      : _.range(1, lastOfAllPages + 1);

    firstOfVisiblePages = _.first(visiblePages);
    lastOfVisiblePages = _.last(visiblePages);

    if (firstOfVisiblePages < 1) {

      adjustBy = Math.abs(firstOfVisiblePages) + 1;

    } else if (lastOfVisiblePages > lastOfAllPages) {

      adjustBy = lastOfAllPages - lastOfVisiblePages;

    }

    visiblePages = visiblePages
      .map(page => page + adjustBy)

    this.visiblePages = visiblePages;
  }

  private isValidPage(page: number): boolean {
    let isPositive,
        isLessThatMax;

    isPositive = 1 <= page;
    isLessThatMax = page <= _.last(this.pages);

    return isPositive && isLessThatMax;
  }

  forwardOnPageClicked(pageNumber: number) {
    if (!this.isValidPage(pageNumber) || pageNumber === this.activePage) {
      return;
    }

    this.onPageClicked.emit(pageNumber);
  }

  promtForGoToPage() {
    let goToPageNumber: any = Number(
      prompt(`Select page from 1 to ${_.last(this.pages)}`),
    ) || 0;

    this.forwardOnPageClicked(goToPageNumber);
  }

}

{'fraction_non_alphanumeric': 0.11952469711090401, 'fraction_numerical': 0.0048928238583411, 'mean_word_length': 3.1358381502890174, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3303014', 'n_tokens_mistral': 1399, 'n_tokens_neox': 1336, 'n_words': 297}