Code coverage report for models/AjaxDataGrid.js

Statements: 100% (112 / 112)      Branches: 100% (74 / 74)      Functions: 100% (19 / 19)      Lines: 100% (42 / 42)      Ignored: 16 statements, 15 branches     

All files » models/ » AjaxDataGrid.js
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 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112                      1 1 1 1                                     1   7 7 6 6 6       12       11 3   8 8       12       9 1   8 8       12       9 1   8 8       12       9 1   8 8         3 2 2 2   2       2 2 2 2 2   2        
/**
 * AjaxDataGrid class
 *
 * @module AjaxDataGrid
 *
 * @author Luca Pau <luca.pau82@gmail.com>
 */
 
import AjaxList from './AjaxList';
import config from '../config';
 
let _totalItems = Symbol();
let _currentPage = Symbol();
let _totalPages = Symbol();
let _itemsPerPage = Symbol();
 
/**
 * AjaxDataGrid class
 *
 * Perform ajax call for pagination
 *
 * @class AjaxDataGrid
 * @extends AjaxList
 */
class AjaxDataGrid extends AjaxList {
  /**
   * @constructor
   *
   * @param {int} [totalItems] total items
   * @param {int} [currentPage] current page
   * @param {int} [totalPages] total pages
   * @param {int} [itemsPerPage] number of items per page
   */
  constructor(totalItems=0, currentPage=1, totalPages=0,
              itemsPerPage=config.resultsPerPageDefault) {
    super();
    this.totalItems = totalItems;
    this.currentPage = currentPage;
    this.totalPages = totalPages;
    this.itemsPerPage = itemsPerPage;
  }
 
  get totalItems() {
    return this[_totalItems];
  }
 
  set totalItems(totalItems) {
    if(typeof(totalItems) !== 'number')
      throw new TypeError('totalItems must be a number');
 
    this[_totalItems] = totalItems;
    return this;
  }
 
  get currentPage() {
    return this[_currentPage];
  }
 
  set currentPage(currentPage) {
    if(typeof(currentPage) !== 'number')
      throw new TypeError('currentPage must be a number');
 
    this[_currentPage] = currentPage;
    return this;
  }
 
  get totalPages() {
    return this[_totalPages];
  }
 
  set totalPages(totalPages) {
    if(typeof(totalPages) !== 'number')
      throw new TypeError('totalPages must be a number');
 
    this[_totalPages] = totalPages;
    return this;
  }
 
  get itemsPerPage() {
    return this[_itemsPerPage];
  }
 
  set itemsPerPage(itemsPerPage) {
    if(typeof(itemsPerPage) !== 'number')
      throw new TypeError('itemsPerPage must be a number');
 
    this[_itemsPerPage] = itemsPerPage;
    return this;
  }
 
  reInit(totalItems=0, currentPage=1, totalPages=0,
         itemsPerPage=config.resultsPerPageDefault) {
    this.totalItems = totalItems;
    this.currentPage = currentPage;
    this.totalPages = totalPages;
    this.itemsPerPage = itemsPerPage;
 
    return this;
  }
 
  getStruct() {
    var superStruct = super.getStruct();
    superStruct.totalItems = this.totalItems;
    superStruct.currentPage = this.currentPage;
    superStruct.totalPages = this.totalPages;
    superStruct.itemsPerPage = this.itemsPerPage;
 
    return superStruct;
  }
}
 
export default AjaxDataGrid;