Skip to content

Commit f3c790a

Browse files
committed
Multiple Improvments
* Support for chaining * Improve constructure of DateInput * Set footer as hidden in vuetify data table * Documentation
1 parent cc6a8a1 commit f3c790a

File tree

7 files changed

+59
-27
lines changed

7 files changed

+59
-27
lines changed

wfc/ui/vuetify/ActionsContainer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class ActionsContainer extends HTMLNode {
1616
*/
1717
public function __construct() {
1818
parent::__construct('div', [
19-
'class' => 'text-center'
19+
//'class' => 'text-center'
2020
]);
2121

2222
}

wfc/ui/vuetify/DateInput.php

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,12 @@ class DateInput extends HTMLNode {
3131
* @param string $menuModel The name of the model that will be associated with
3232
* date picker's menu component.
3333
*
34-
* @param string $label An optional label to show on the component.
3534
*
36-
* @param string $placeholder An optional placeholder to show on the
37-
* component.
35+
* @param string $textFieldProps An optional array that holds properties of the
36+
* text field that will hold date value.
3837
*
3938
*/
40-
public function __construct(string $model = null, string $menuModel = null, string $label = null, string $placeholder = null) {
39+
public function __construct(string $model = null, string $menuModel = null, array $textFieldProps = []) {
4140
parent::__construct('v-menu', [
4241
':close-on-content-click' => "false",
4342
'transition' => "scale-transition",
@@ -57,12 +56,9 @@ public function __construct(string $model = null, string $menuModel = null, stri
5756

5857
$this->datePicker = $this->addChild('v-date-picker', $pickerAttrs);
5958

60-
if ($label !== null) {
61-
$this->getTextField()->setAttribute('label', $label);
62-
}
63-
if ($placeholder !== null) {
64-
$this->getTextField()->setAttribute('placeholder', $placeholder);
65-
} else {
59+
$this->getTextField()->setAttributes($textFieldProps);
60+
61+
if (!isset($textFieldAttrs['placeholder'])) {
6662
$this->getTextField()->setAttribute('placeholder', 'YYYY-MM-DD');
6763
}
6864
if ($menuModel !== null) {
@@ -78,28 +74,40 @@ public function __construct(string $model = null, string $menuModel = null, stri
7874
* date select.
7975
*
8076
* @param string $method The name of JavaScript method.
77+
*
78+
* @return DateInput
8179
*/
82-
public function setOnInput(string $method) {
80+
public function setOnInput(string $method) : DateInput {
8381
$this->getTextField()->setAttribute('@input', $method);
8482
$this->getDatePicker()->setAttribute('@change', $method);
83+
84+
return $this;
8585
}
8686
/**
8787
* Sets the v-model of the menu component.
8888
*
8989
* @param string $model The name of the model.
90+
*
91+
* @return DateInput
9092
*/
91-
public function setMenuVModel(string $model) {
93+
public function setMenuVModel(string $model) : DateInput {
9294
$this->setAttribute('v-model', $model);
9395
$this->getDatePicker()->setAttribute('@input', $model.' = false');
96+
97+
return $this;
9498
}
9599
/**
96100
* Sets v-model of the text field and the date picker.
97101
*
98102
* @param string $model The name of the model.
103+
*
104+
* @return DateInput
99105
*/
100-
public function setVModel(string $model) {
106+
public function setVModel(string $model) : DateInput {
101107
$this->getTextField()->setAttribute('v-model', $model);
102108
$this->getDatePicker()->setAttribute('v-model', $model);
109+
110+
return $this;
103111
}
104112
/**
105113
* Returns the 'v-text-field' component of the picker.

wfc/ui/vuetify/Heading.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,16 @@ public function __construct($title, $level = 1) {
3232
* @param HTMLNode|string $textOrNode This can be an object of type HTMLNode
3333
* or a simple string.
3434
*/
35-
public function setText($textOrNode) {
35+
public function setText($textOrNode) : Heading {
3636
$this->headingNode->removeAllChildren();
3737

3838
if ($textOrNode instanceof HTMLNode) {
3939
$this->headingNode->addChild($textOrNode);
4040
} else if (gettype($textOrNode) == 'string') {
4141
$this->headingNode->text($textOrNode);
4242
}
43+
44+
return $this;
4345
}
4446
/**
4547
* Returns the note that contains heading text.

wfc/ui/vuetify/HijriDateInput.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class HijriDateInput extends HTMLNode {
2828
* @param string $labelTxt The label that will be shown at the top
2929
* of the field.
3030
*/
31-
public function __construct($model, $labelTxt) {
31+
public function __construct(string $model, string $labelTxt) {
3232
parent::__construct('v-row', [
3333
'no-gutters'
3434
]);
@@ -92,12 +92,14 @@ public function getDayInput() {
9292
/**
9393
* Sets a JS function to call in case one of hijri input fields changes value.
9494
*
95-
* @param string $jsFunction The name of JavAscript function which is defined
95+
* @param string $jsFunction The name of JavaScript function which is defined
9696
* in the 'methods'.
9797
*/
98-
public function setOnInput($jsFunction) {
98+
public function setOnInput($jsFunction) : HijriDateInput {
9999
$this->getYearInput()->setAttribute('@input', $jsFunction);
100100
$this->getDayInput()->setAttribute('@input', $jsFunction);
101101
$this->getMonthInput()->setAttribute('@input', $jsFunction);
102+
103+
return $this;
102104
}
103105
}

wfc/ui/vuetify/PrivilegesTree.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class PrivilegesTree extends HTMLNode {
2727
* @param boolean $withSearch If set to true, a search field will be
2828
* included in the component.
2929
*/
30-
public function __construct($model = 'privileges_tree', $title = null, $withSearch = false, ) {
30+
public function __construct(string $model = 'privileges_tree', string $title = null, bool $withSearch = false, ) {
3131
parent::__construct('v-card');
3232
if ($title !== null) {
3333
$this->title = $this->addChild('v-card-title')->text($title);

wfc/ui/vuetify/VDataTable.php

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public function __construct(array $attrs = []) {
5555
':length' => 'page.pages_count',
5656
'@input' => 'loadPage'
5757
]);
58+
$this->setHasFooter(false);
5859
}
5960
/**
6061
* Sets the name of JavaScript function that will be get executed when
@@ -63,9 +64,12 @@ public function __construct(array $attrs = []) {
6364
* Note that the first parameter of the function will be page number.
6465
*
6566
* @param string $func
67+
*
68+
* @return VDataTable
6669
*/
67-
public function setOnPageNumberClick(string $func) {
70+
public function setOnPageNumberClick(string $func) : VDataTable {
6871
$this->getVPagination()->setAttribute('@input', $func);
72+
return $this;
6973
}
7074
/**
7175
* Adds support for expanding table rows.
@@ -104,22 +108,27 @@ public function addExpandedRow($el, string $expandedCallback = null) : HTMLNode
104108
*
105109
* @param string|HTMLNode $el The element that will be added to the slot.
106110
*
111+
* @param array $attrs An optional array of attributes to set for the element.
112+
*
107113
* @return HTMLNode The method will return an object of type HTMLNode
108114
* that represents the added element.
109115
*/
110-
public function addItemSlot(string $slot , $el) : HTMLNode {
116+
public function addItemSlot(string $slot , $el, array $attrs = []) : HTMLNode {
111117
return $this->addChild('template', [
112118
'#item.'.$slot => '{ item }'
113-
])->addChild($el);
119+
])->addChild($el, $attrs);
114120
}
115121
/**
116122
* Sets the name of JavaScript function that will be get executed when
117123
* page size input changes value.
118124
*
119125
* @param string $func
126+
*
127+
* @return VDataTable
120128
*/
121-
public function setOnPageSizeChanged(string $func) {
129+
public function setOnPageSizeChanged(string $func) : VDataTable {
122130
$this->getPageSizeInput()->setAttribute('@input', $func);
131+
return $this;
123132
}
124133
/**
125134
* Returns the node that represents the footer of the table.
@@ -157,8 +166,10 @@ public function getPageSizeInput() : HTMLNode {
157166
* <li>pages_options: An array that contain number of items per page like 5, 10, 20</li>
158167
* </ul>
159168
* @param string $name Name of the model. Defined in 'data' section.
169+
*
170+
* @return VDataTable
160171
*/
161-
public function setPagingModel(string $name) {
172+
public function setPagingModel(string $name) : VDataTable {
162173
$this->getVPagination()->setAttributes([
163174
'v-model' => $name.'.page_number',
164175
':length' => $name.'.pages_count',
@@ -172,29 +183,37 @@ public function setPagingModel(string $name) {
172183
':items-per-page' => $name.'.size',
173184
]);
174185
$this->paginationModelName = $name;
186+
return $this;
175187
}
176188
/**
177189
* Sets if the table will have a footer or not.
178190
*
179191
* @param bool $withFooter If true is passed, the table will have footer.
180192
* Other than that, the table will not have footer.
193+
*
194+
* @return VDataTable
181195
*/
182-
public function setHasFooter(bool $withFooter) {
196+
public function setHasFooter(bool $withFooter) : VDataTable {
183197
if ($withFooter && $this->getFooter()->getParent() === null) {
184198
$this->addChild($this->getFooter());
185199
$this->setAttribute(':items-per-page', $this->paginationModelName.'.size');
186200
} else {
187201
$this->removeChild($this->getFooter());
188202
$this->removeAttribute(':items-per-page');
189203
}
204+
205+
return $this;
190206
}
191207
/**
192208
* Sets the properties of the v-select which is used to select items
193209
* per page.
194210
*
195211
* @param array $attrs
212+
*
213+
* @return VDataTable
196214
*/
197-
public function setPageSizeInputProps(array $attrs) {
215+
public function setPageSizeInputProps(array $attrs) : VDataTable {
198216
$this->pageSizeSelect->setAttributes($attrs);
217+
return $this;
199218
}
200219
}

wfc/ui/vuetify/VTooltip.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ public function setTooltip($el) : HTMLNode {
7171
*
7272
* @param string $position
7373
*/
74-
public function setPosition(string $position) {
74+
public function setPosition(string $position) : VTooltip {
7575
$this->setAttribute($position);
76+
return $this;
7677
}
7778
}

0 commit comments

Comments
 (0)