/*-------------------------------------------------------------------------------------------------------------- * Copyright (c) insite-gmbh. All rights reserved. * Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------------------------*/ import { Component, OnInit, OnDestroy, Input, Output, EventEmitter } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; import { InaxTranslateService } from '../../../../@inax/translate'; import { Subscription } from 'rxjs/Rx'; import { CommonUiResourceManager } from './../resources/resource.service'; @Component({ selector: 'paging', templateUrl: './@inax/commonUi/src/paging/paging.component.html', styleUrls: ['./@inax/commonUi/src/paging/paging.component.css'] }) export class PagingComponent implements OnInit, OnDestroy { private _currentPage: number = 0; @Input() firstPage: number = 0; @Input() lastPage: number = 0; @Output() pageChanged = new EventEmitter(); public get pageNumber(): number { return this._currentPage; } public set pageNumber(page:number) { let old = this._currentPage; this._currentPage = page; this.onGoToPage(page); } constructor( //private _resourceManager: CommonUiResourceManager //this service is necessary because it will register the translations ) { } ngOnInit() { this._currentPage = Number(this.firstPage); } ngOnDestroy() { } public onNextPage() { let page:number = this._currentPage + 1; if (page <= this.lastPage) { this._currentPage++; this.pageChanged.emit(this._currentPage); } } public onPrevPage() { let page:number = this._currentPage - 1; if (page >= this.firstPage) { this._currentPage--; this.pageChanged.emit(this._currentPage); } } //TODO: reset to prev page if number is not in range public onGoToPage(page: number):boolean { if (page >= this.firstPage && page <= this.lastPage) { this._currentPage = page; this.pageChanged.emit(this._currentPage); return true; } return false; } }