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

contributte / datagrid / 8685602316

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

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/InlineEdit/InlineEdit.php
1
<?php declare(strict_types = 1);
2

3
namespace Contributte\Datagrid\InlineEdit;
4

5
use Contributte\Datagrid\Datagrid;
6
use Contributte\Datagrid\Row;
7
use Contributte\Datagrid\Traits\TButtonClass;
8
use Contributte\Datagrid\Traits\TButtonIcon;
9
use Contributte\Datagrid\Traits\TButtonText;
10
use Contributte\Datagrid\Traits\TButtonTitle;
11
use Contributte\Datagrid\Traits\TButtonTryAddIcon;
12
use Nette\Forms\Container;
13
use Nette\SmartObject;
14
use Nette\Utils\ArrayHash;
15
use Nette\Utils\Html;
16

17
/**
18
 * @method onSubmit($id, ArrayHash $values)
19
 * @method onControlAdd(Container $container)
20
 * @method onControlAfterAdd(Container $container)
21
 * @method onSetDefaults(Container $container, $item)
22
 * @method onCustomRedraw(string $buttonName)
23
 */
24
class InlineEdit
25
{
26

27
        use SmartObject;
28
        use TButtonTryAddIcon;
29
        use TButtonIcon;
30
        use TButtonClass;
31
        use TButtonTitle;
32
        use TButtonText;
33

34
        /** @var array|callable[] */
35
        public array $onSubmit = [];
36

37
        /** @var array|callable[] */
38
        public array $onControlAdd = [];
39

40
        /** @var array|callable[] */
41
        public array $onControlAfterAdd = [];
42

43
        /** @var array|callable[] */
44
        public array $onSetDefaults = [];
45

46
        /** @var array|callable[] */
47
        public array $onCustomRedraw = [];
48

49
        protected mixed $itemID = null;
50

51
        /**
52
         * Inline adding - render on the top or in the bottom?
53
         */
54
        protected bool $positionTop = false;
55

56
        /**
57
         * Columns that are not edited can displey normal value instaad of nothing..
58
         */
59
        protected bool $showNonEditingColumns = true;
60

NEW
61
        public function __construct(protected Datagrid $grid, protected ?string $primaryWhereColumn = null)
×
62
        {
NEW
63
                $this->title = 'contributte_datagrid.edit';
×
UNCOV
64
                $this->class = sprintf('btn btn-xs %s ajax', $grid::$btnSecondaryClass);
×
UNCOV
65
                $this->icon = 'pencil pencil-alt';
×
66

67
                $this->onControlAfterAdd[] = [$this, 'addControlsClasses'];
×
68
        }
69

70
        /**
71
         * @return static
72
         */
73
        public function setItemId(mixed $id): self
74
        {
75
                $this->itemID = $id;
×
76

77
                return $this;
×
78
        }
79

80
        public function getItemId(): mixed
81
        {
82
                return $this->itemID;
×
83
        }
84

85
        public function getPrimaryWhereColumn(): ?string
86
        {
87
                return $this->primaryWhereColumn;
×
88
        }
89

90
        public function renderButton(Row $row): Html
91
        {
UNCOV
92
                $a = Html::el('a')
×
93
                        ->href($this->grid->link('inlineEdit!', ['id' => $row->getId()]));
×
94

UNCOV
95
                $this->tryAddIcon($a, $this->getIcon(), $this->getText());
×
96

97
                $a->addText($this->text);
×
98

UNCOV
99
                if ($this->title !== null) {
×
UNCOV
100
                        $a->setAttribute(
×
UNCOV
101
                                'title',
×
UNCOV
102
                                $this->grid->getTranslator()->translate($this->title)
×
103
                        );
104
                }
105

NEW
106
                if ($this->class !== '') {
×
107
                        $a->appendAttribute('class', $this->class);
×
108
                }
109

UNCOV
110
                $a->appendAttribute('class', 'datagrid-inline-edit-trigger');
×
111

112
                return $a;
×
113
        }
114

115
        /**
116
         * Render row item detail button
117
         */
118
        public function renderButtonAdd(): Html
119
        {
UNCOV
120
                $a = Html::el('a')
×
121
                        ->href($this->grid->link('showInlineAdd!'));
×
122

123
                $this->tryAddIcon($a, $this->getIcon(), $this->getText());
×
124

125
                $a->addText($this->text);
×
126

127
                if ($this->title !== null) {
×
UNCOV
128
                        $a->setAttribute(
×
129
                                'title',
×
130
                                $this->grid->getTranslator()->translate($this->title)
×
131
                        );
132
                }
133

NEW
134
                if ($this->class !== '') {
×
UNCOV
135
                        $a->appendAttribute('class', $this->class);
×
136
                }
137

UNCOV
138
                return $a;
×
139
        }
140

141
        /**
142
         * @return static
143
         */
144
        public function setPositionTop(bool $positionTop = true): self
145
        {
UNCOV
146
                $this->positionTop = $positionTop;
×
147

UNCOV
148
                return $this;
×
149
        }
150

151
        public function isPositionTop(): bool
152
        {
UNCOV
153
                return $this->positionTop;
×
154
        }
155

156
        public function isPositionBottom(): bool
157
        {
UNCOV
158
                return !$this->positionTop;
×
159
        }
160

161
        public function addControlsClasses(Container $container): void
162
        {
UNCOV
163
                foreach ($container->getControls() as $key => $control) {
×
UNCOV
164
                        switch ($key) {
×
UNCOV
165
                                case 'submit':
×
UNCOV
166
                                        $control->setValidationScope([$container]);
×
UNCOV
167
                                        $control->setAttribute('class', 'btn btn-xs btn-primary');
×
168

UNCOV
169
                                        break;
×
170

UNCOV
171
                                case 'cancel':
×
UNCOV
172
                                        $control->setValidationScope([]);
×
UNCOV
173
                                        $control->setAttribute('class', 'btn btn-xs btn-danger');
×
174

UNCOV
175
                                        break;
×
176

177
                                default:
UNCOV
178
                                        if ($control->getControl()->getAttribute('class') === null) {
×
NEW
179
                                                $control->setAttribute('class', 'form-control form-control-sm');
×
180
                                        }
181

UNCOV
182
                                        break;
×
183
                        }
184
                }
185
        }
186

187
        /**
188
         * @return static
189
         */
190
        public function setShowNonEditingColumns(bool $show = true): self
191
        {
UNCOV
192
                $this->showNonEditingColumns = $show;
×
193

UNCOV
194
                return $this;
×
195
        }
196

197
        public function showNonEditingColumns(): bool
198
        {
UNCOV
199
                return $this->showNonEditingColumns;
×
200
        }
201

202
}
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