| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 1 | /* |
| 2 | Copyright 2020 TATA ELXSI |
| 3 | |
| 4 | Licensed under the Apache License, Version 2.0 (the 'License'); |
| 5 | you may not use this file except in compliance with the License. |
| 6 | You may obtain a copy of the License at |
| 7 | |
| 8 | http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | Unless required by applicable law or agreed to in writing, software |
| 11 | distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | See the License for the specific language governing permissions and |
| 14 | limitations under the License. |
| 15 | |
| 16 | Author: KUMARAN M (kumaran.m@tataelxsi.co.in), RAJESH S (rajesh.s@tataelxsi.co.in), BARATH KUMAR R (barath.r@tataelxsi.co.in) |
| 17 | */ |
| 18 | |
| 19 | /** |
| 20 | * @file PagePerRow Model |
| 21 | */ |
| 22 | import { Component, EventEmitter, Injector, Output } from '@angular/core'; |
| 23 | import { TranslateService } from '@ngx-translate/core'; |
| 24 | import { PAGERSMARTTABLE } from 'CommonModel'; |
| 25 | import { SharedService } from 'SharedService'; |
| 26 | |
| 27 | /** |
| 28 | * Creating component |
| 29 | * @Component takes PagePerRow.html as template url |
| 30 | */ |
| 31 | @Component({ |
| 32 | selector: 'page-per-row', |
| 33 | templateUrl: './PagePerRow.html', |
| 34 | styleUrls: ['./PagePerRow.scss'] |
| 35 | }) |
| 36 | /** Exporting a class @exports PagePerRow */ |
| 37 | export class PagePerRow { |
| 38 | /** To inject services @public */ |
| 39 | public injector: Injector; |
| 40 | |
| 41 | /** handle translate @public */ |
| 42 | public translateService: TranslateService; |
| 43 | |
| 44 | /** get the pagaintion default select value @public */ |
| 45 | public getDefaultSelected: number; |
| 46 | |
| 47 | /** Controls the pagination List Count form @public */ |
| 48 | public pageCount: { value: number; viewValue: number; }[] = |
| 49 | [ |
| 50 | { value: 10, viewValue: 10 }, |
| 51 | { value: 25, viewValue: 25 }, |
| 52 | { value: 50, viewValue: 50 }, |
| 53 | { value: 100, viewValue: 100 } |
| 54 | ]; |
| 55 | |
| 56 | /** Contains all methods related to shared @private */ |
| 57 | public sharedService: SharedService; |
| 58 | |
| 59 | /** Event emitter to emit selected page number @public */ |
| 60 | @Output() public pagePerRow: EventEmitter<number> = new EventEmitter(); |
| 61 | |
| 62 | constructor(injector: Injector) { |
| 63 | this.injector = injector; |
| 64 | this.translateService = this.injector.get(TranslateService); |
| 65 | this.sharedService = this.injector.get(SharedService); |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Lifecyle Hooks the trigger before component is instantiate |
| 70 | */ |
| 71 | public ngOnInit(): void { |
| 72 | const getPaginationValues: PAGERSMARTTABLE = this.sharedService.paginationPagerConfig(); |
| 73 | this.getDefaultSelected = getPaginationValues.perPage; |
| 74 | } |
| 75 | |
| 76 | /** Handles select event @public */ |
| 77 | public onSelectRow(e: number): void { |
| 78 | this.pagePerRow.emit(e); |
| 79 | } |
| 80 | } |