• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

contributte / datagrid / 8780667983

13 Mar 2024 12:24PM UTC coverage: 34.102%. Remained the same
8780667983

push

github

web-flow
[7.x] Next (#1060)

* PHP 8.0

* Translator: switch from ITranslator to Translator (#973)

* [7.x] Bootstrap 5 + PHP 8 + vanilla javascript (#1021)

* Bootstrap 5

* Bootstrap 5 (docs)

* Bootstrap 5

* form-control -> form-select

* Bump bootstrap-select for Bootstrap 5 support

* Removed `input-sm` from Bootstrap 3

See https://getbootstrap.com/docs/4.0/migration/#forms-1

* Bootstrap 5: When selectpicker, replace form-select classes with form-control and refresh it

* Hide `underline` also for `dropdown-item`. And merged into one CSS rule.

* Update the filterMultiSelect initialization

* Text-align: left -> start

Co-authored-by: Radim Vaculík <radim.vaculik@gmail.com>
Co-authored-by: Jaroslav Líbal <jaroslav.libal@neatous.cz>

* [7.x] phpstan-deprecation-rules (#1061)

* Fix sort

* Add method for setting custom Action href, v6.x (#853)

* [7.x] Nextras ORM 4 support, closes #984

* Fix ElasticsearchDataSource.php data source (#1041)

* Error: Typed property Ublaboo\DataGrid\InlineEdit\InlineEdit::$itemID must not be accessed before initialization

* composer: allow-plugins: php-http/discovery

* ItemDetailForm: $httpPost: Typed property must not be accessed...

* phpstan: revert  --memory-limit=4G

* NetteDatabaseSelectionHelper: Context -> Explorer, getSupplementalDriver -> getDriver

* Update README.md

* Templates: fix variables

* data-bs-toggle attribute for multiaction button (#1072)

* dependabot.yml (#1078)

* Allow nette/utils:4.0 (#1077)

* Add onColumnShow and onColumnHide event methods (#1076)

* Add onColumnShow and onColumnHide event methods

* Add native type array

* Removed duplicity

* Return value of BackedEnum when reading Doctrine entity property. (#1081)

* Return value of BackedEnum when reading array value (#1083)

* Added method to check if filter is on default values; Closes #1082 (#1084)

* ublaboo -> contributte (#1067) (#1075)

* Delete depe... (continued)

117 of 435 new or added lines in 54 files covered. (26.9%)

1455 existing lines in 67 files now uncovered.

1124 of 3296 relevant lines covered (34.1%)

0.34 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Components/DatagridPaginator/DatagridPaginator.php
1
<?php declare(strict_types = 1);
2

3
/**
4
 * Nette Framework Extras
5
 *
6
 * This source file is subject to the New BSD License.
7
 *
8
 * For more information please see http://addons.nette.org
9
 *
10
 * @link http://addons.nette.org
11
 */
12

13
namespace Contributte\Datagrid\Components\DatagridPaginator;
14

15
use Contributte\Datagrid\Datagrid;
16
use Nette\Application\UI\Control;
17
use Nette\Bridges\ApplicationLatte\Template;
18
use Nette\Localization\Translator;
19
use Nette\Utils\Paginator;
20
use UnexpectedValueException;
21

22
class DatagridPaginator extends Control
23
{
24

25
        private ?Paginator $paginator = null;
26

27
        private ?string $templateFile = null;
28

NEW
29
        public function __construct(private Translator $translator, private string $iconPrefix = 'fa fa-', private string $btnSecondaryClass = 'btn-default btn-secondary')
×
30
        {
31
        }
32

33
        public function setTemplateFile(string $templateFile): void
34
        {
35
                $this->templateFile = $templateFile;
×
36
        }
37

38
        public function getTemplateFile(): string
39
        {
40
                return $this->templateFile ?? __DIR__ . '/templates/data_grid_paginator.latte';
×
41
        }
42

43
        public function getOriginalTemplateFile(): string
44
        {
45
                return __DIR__ . '/templates/data_grid_paginator.latte';
×
46
        }
47

48
        public function getPaginator(): Paginator
49
        {
UNCOV
50
                if ($this->paginator === null) {
×
UNCOV
51
                        $this->paginator = new Paginator();
×
52
                }
53

UNCOV
54
                return $this->paginator;
×
55
        }
56

57
        public function render(): void
58
        {
UNCOV
59
                $paginator = $this->getPaginator();
×
UNCOV
60
                $page = $paginator->page;
×
61

62
                if ($paginator->pageCount < 2) {
×
UNCOV
63
                        $steps = [$page];
×
64

65
                } else {
66
                        $arr = range(max($paginator->firstPage, $page - 2), (int) min($paginator->lastPage, $page + 2));
×
67

68
                        /**
69
                         * Something to do with steps in template...
70
                         * [Default $count = 3;]
71
                         */
UNCOV
72
                        $count = 1;
×
73

UNCOV
74
                        $perPage = $paginator->pageCount;
×
75

UNCOV
76
                        $quotient = ($perPage - 1) / $count;
×
77

78
                        for ($i = 0; $i <= $count; $i++) {
×
UNCOV
79
                                $arr[] = round($quotient * $i) + $paginator->firstPage;
×
80
                        }
81

UNCOV
82
                        sort($arr);
×
UNCOV
83
                        $steps = array_values(array_unique($arr));
×
84
                }
85

UNCOV
86
                if (!$this->getTemplate() instanceof Template) {
×
UNCOV
87
                        throw new UnexpectedValueException();
×
88
                }
89

UNCOV
90
                $this->getTemplate()->setTranslator($this->translator);
×
91

UNCOV
92
                if (!isset($this->getTemplate()->steps)) {
×
UNCOV
93
                        $this->getTemplate()->steps = $steps;
×
94
                }
95

UNCOV
96
                if (!isset($this->getTemplate()->paginator)) {
×
UNCOV
97
                        $this->getTemplate()->paginator = $paginator;
×
98
                }
99

UNCOV
100
                $this->getTemplate()->iconPrefix = $this->iconPrefix;
×
UNCOV
101
                $this->getTemplate()->btnSecondaryClass = $this->btnSecondaryClass;
×
UNCOV
102
                $this->getTemplate()->originalTemplate = $this->getOriginalTemplateFile();
×
UNCOV
103
                $this->getTemplate()->setFile($this->getTemplateFile());
×
UNCOV
104
                $this->getTemplate()->render();
×
105
        }
106

107
        /**
108
         * Loads state informations.
109
         */
110
        public function loadState(array $params): void
111
        {
UNCOV
112
                parent::loadState($params);
×
113

NEW
114
                if ($this->getParent() instanceof Datagrid) {
×
UNCOV
115
                        $this->getPaginator()->page = $this->getParent()->page;
×
116
                }
117
        }
118

119
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc