{"size": 1385, "ext": "js", "max_stars_repo_path": "src/lib/plugin/pager/pager.view.js", "max_stars_repo_name": "qgrid/ng2-rollup", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/lib/plugin/pager/pager.view.js", "max_issues_repo_name": "qgrid/ng2-rollup", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/lib/plugin/pager/pager.view.js", "max_forks_repo_name": "qgrid/ng2-rollup", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 20.9848484848, "max_line_length": 106, "alphanum_fraction": 0.638267148}
import {Command} from '../../core/command';
import {PluginView} from '../plugin.view';

export class PagerView extends PluginView {
	constructor(model) {
		super(...arguments);

		this.next = new Command({
			source: 'pager',
			execute: () => model.pagination({current: model.pagination().current + 1}),
			canExecute: () => (model.pagination().current + 1) * model.pagination().size < model.pagination().count
		});

		this.prev = new Command({
			source: 'pager',
			execute: () => model.pagination({current: model.pagination().current - 1}),
			canExecute: () => model.pagination().current > 0
		});
	}

	get resource() {
		return this.model.pagination().resource;
	}

	get size() {
		return this.model.pagination().size;
	}

	set size(value) {
		this.model.pagination({size: value, current: 0});
	}

	get sizeList() {
		return this.model.pagination().sizeList;
	}

	get current() {
		return this.model.pagination().current;
	}

	set current(value) {
		return this.model.pagination({current: value});
	}

	get from() {
		return Math.min(this.total, this.current * this.size + 1);
	}

	get to() {
		return Math.min(this.total, (this.current + 1) * this.size);
	}

	get total() {
		return this.model.pagination().count;
	}

	get totalPages() {
		return this.size === 0
			? 0
			: Math.max(1, Math.ceil(this.total / this.size));
	}

	get scroll() {
		return this.model.scroll();
	}
}