Skip to content

Commit 5a8a23d

Browse files
ibelarmvorisekromaninsh
authored
[refactor] AutoComplete into Lookup (#1018)
* [refactor] AutoComplete into Lookup * setup proper file name for test * update php doc reference * Fix StyleCI * fix test * Apply fixes from StyleCI (#1032) Co-authored-by: Michael Voříšek <mvorisek@mvorisek.cz> Co-authored-by: Romans Malinovskis <me@nearly.guru>
1 parent e347831 commit 5a8a23d

27 files changed

Lines changed: 411 additions & 927 deletions

demos/card-deck.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
$info_action->args = [
3939
'email' => ['type'=>'email', 'required'=>true, 'caption' => 'Please let us know your email address:'],
40-
'country'=> ['required' => true, 'ui' => ['form' => ['AutoComplete', 'model'=> new Country($db), 'placeholder' => 'Please select a country.']]],
40+
'country'=> ['required' => true, 'ui' => ['form' => ['Lookup', 'model'=> new Country($db), 'placeholder' => 'Please select a country.']]],
4141
];
4242

4343
$deck = \atk4\ui\CardDeck::addTo($app, ['noRecordScopeActions' => ['request_info'], 'singleScopeActions' => ['book']]);

demos/cascade-dropdown.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
require_once __DIR__ . '/init.php';
34
require_once __DIR__ . '/database.php';
45

demos/dropdown-plus.php

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,18 @@
66
$form = \atk4\ui\Form::addTo($app);
77

88
//standard with model: use id_field as Value, title_field as Title for each DropDown option
9-
$form->addField('withModel',
10-
['DropDown',
9+
$form->addField(
10+
'withModel',
11+
['DropDown',
1112
'caption' => 'DropDown with data from Model',
1213
'model' => new Country($db),
13-
]);
14+
]
15+
);
1416

1517
//custom callback: alter title
16-
$form->addField('withModel2',
17-
['DropDown',
18+
$form->addField(
19+
'withModel2',
20+
['DropDown',
1821
'caption' => 'DropDown with data from Model',
1922
'model' => new Country($db),
2023
'renderRowFunction' => function ($row) {
@@ -23,11 +26,13 @@
2326
'title' => $row->getTitle() . ' (' . $row->get('iso3') . ')',
2427
];
2528
},
26-
]);
29+
]
30+
);
2731

2832
//custom callback: add icon
29-
$form->addField('withModel3',
30-
['DropDown',
33+
$form->addField(
34+
'withModel3',
35+
['DropDown',
3136
'caption' => 'DropDown with data from Model',
3237
'model' => new File($db),
3338
'renderRowFunction' => function ($row) {
@@ -37,35 +42,44 @@
3742
'icon' => $row->get('is_folder') ? 'folder' : 'file',
3843
];
3944
},
40-
]);
45+
]
46+
);
4147

42-
$form->addField('enum',
43-
['DropDown',
48+
$form->addField(
49+
'enum',
50+
['DropDown',
4451
'caption' => 'Using Single Values',
4552
'values' => ['default', 'option1', 'option2', 'option3'],
46-
]);
53+
]
54+
);
4755

48-
$form->addField('values',
49-
['DropDown',
56+
$form->addField(
57+
'values',
58+
['DropDown',
5059
'caption' => 'Using values with default text',
5160
'empty' => 'Choose an option',
5261
'values' => ['default' => 'Default', 'option1' => 'Option 1', 'option2' => 'Option 2', 'option3' => 'Option 3'],
53-
]);
62+
]
63+
);
5464

55-
$form->addField('icon',
56-
['DropDown',
65+
$form->addField(
66+
'icon',
67+
['DropDown',
5768
'caption' => 'Using icon',
5869
'empty' => 'Choose an icon',
5970
'values' => ['tag' => ['Tag', 'icon' => 'tag icon'], 'globe' => ['Globe', 'icon' => 'globe icon'], 'registered' => ['Registered', 'icon' => 'registered icon'], 'file' => ['File', 'icon' => 'file icon']],
60-
]);
71+
]
72+
);
6173

62-
$form->addField('multi',
63-
['DropDown',
74+
$form->addField(
75+
'multi',
76+
['DropDown',
6477
'caption' => 'Multiple selection',
6578
'empty' => 'Choose has many options needed',
6679
'isMultiple' => true,
6780
'values' => ['default' => 'Default', 'option1' => 'Option 1', 'option2' => 'Option 2'],
68-
]);
81+
]
82+
);
6983

7084
$form->onSubmit(function ($form) {
7185
$echo = print_r($form->model['enum'], true) . ' / ';

demos/form3.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@
2525
isset($_GET['m']) ? (
2626
$_GET['m'] == 'country' ? new Country($db) : (
2727
$_GET['m'] == 'file' ? new File($db) : new Stat($db)
28-
)) : new Stat($db)
29-
)->tryLoadAny();
28+
)
29+
) : new Stat($db)
30+
)->tryLoadAny();
3031

3132
$form->onSubmit(function ($form) {
3233
$errors = [];

demos/grid.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333

3434
$sel = $g->addSelection();
3535
$g->menu->addItem('show selection')->on('click', new \atk4\ui\jsExpression(
36-
'alert("Selected: "+[])', [$sel->jsChecked()]
36+
'alert("Selected: "+[])',
37+
[$sel->jsChecked()]
3738
));
3839

3940
//Setting ipp with an array will add an ItemPerPageSelector to paginator.

demos/grid_action.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
'ui' => ['Grid' => ['Executor' => $edit_executor, 'Button' => ['icon' => 'edit']]],
2323
]);
2424

25-
$del_executor = new atk4\ui\ActionExecutor\Preview([
25+
$del_executor = new atk4\ui\ActionExecutor\Preview(
26+
[
2627
'previewType' => 'text',
2728
'hasHeader' => false,
2829
'jsSuccess' => function ($ex, $model) use ($g) {

demos/index.php

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@
2626

2727
$wizard->addStep('User Interface', function ($page) {
2828
$t = \atk4\ui\Text::addTo($page);
29-
$t->addParagraph(<<< 'EOF'
29+
$t->addParagraph(
30+
<<< 'EOF'
3031
Agile Toolkit is a "Low Code Framework" written in PHP. It is designed to simplify all aspects of web application creation:
3132
EOF
3233
);
33-
$t->addHTML(<<< 'HTML'
34+
$t->addHTML(
35+
<<< 'HTML'
3436
<ul>
3537
<li>No front-end coding necessary (like JavaScript)</li>
3638
<li>No Database coding required (like SQL)</li>
@@ -44,7 +46,8 @@
4446

4547
$t->addParagraph('Your ATK code instead takes a more declarative approach. You work with things like:');
4648

47-
$t->addHTML(<<< 'HTML'
49+
$t->addHTML(
50+
<<< 'HTML'
4851
<ul>
4952
<li>Models and fields</li>
5053
<li>Model User actions</li>
@@ -56,7 +59,8 @@
5659
HTML
5760
);
5861

59-
$t->addParagraph(<<< 'EOF'
62+
$t->addParagraph(
63+
<<< 'EOF'
6064
Since 2017 our collection of built-in widgets, add-ons have grown significantly and today Agile Toolkit is a mature
6165
and production ready framework.
6266
EOF
@@ -69,13 +73,15 @@
6973

7074
$wizard->addStep('Interactivity', function ($page) {
7175
$t = \atk4\ui\Text::addTo($page);
72-
$t->addParagraph(<<< 'EOF'
76+
$t->addParagraph(
77+
<<< 'EOF'
7378
PHP is a server-side language. That prompted us to implement server-side UI actions. They are very easy to define -
7479
no need to create any routes or custom routines, simply define a PHP closure like this:
7580
EOF
7681
);
7782

78-
Demo::addTo($page)->setCode(<<<'CODE'
83+
Demo::addTo($page)->setCode(
84+
<<<'CODE'
7985
$button = \atk4\ui\Button::addTo($app, ["Click for the greeting!"]);
8086
$button->on('click', function() {
8187
return 'Hello World!';
@@ -85,13 +91,15 @@
8591
);
8692

8793
$t = \atk4\ui\Text::addTo($page);
88-
$t->addParagraph(<<< 'EOF'
94+
$t->addParagraph(
95+
<<< 'EOF'
8996
A component of Agile Toolkit (callback) enables seamless communication between the frontend components (which are often
9097
written in VueJS) and the backend. We also support seamless reloading of any UI widget:
9198
EOF
9299
);
93100

94-
Demo::addTo($page)->setCode(<<<'CODE'
101+
Demo::addTo($page)->setCode(
102+
<<<'CODE'
95103
96104
$seg = \atk4\ui\View::addTo($app, ['ui'=>'segment']);
97105
@@ -113,7 +121,8 @@
113121
);
114122

115123
$t = \atk4\ui\Text::addTo($page);
116-
$t->addParagraph(<<< 'EOF'
124+
$t->addParagraph(
125+
<<< 'EOF'
117126
This demo also shows you how to create composite views. The '$seg' above contains text, paginator, divider and some
118127
buttons. Interestingly, Paginator view also consists of buttons and Agile Toolkit renders everything reliably.
119128
EOF
@@ -122,13 +131,15 @@
122131

123132
$wizard->addStep('Business Model', function ($page) {
124133
$t = \atk4\ui\Text::addTo($page);
125-
$t->addParagraph(<<< 'EOF'
134+
$t->addParagraph(
135+
<<< 'EOF'
126136
One major benefit of Server Side Rendered applications is ability to directly interact with data. In other applications
127137
you may need to manually process data but in Agile Toolkit we use data mapping framework.
128138
EOF
129139
);
130140

131-
Demo::addTo($page)->setCode(<<<'CODE'
141+
Demo::addTo($page)->setCode(
142+
<<<'CODE'
132143
133144
class Invoice extends \atk4\data\Model {
134145
public $title_field = 'reference';
@@ -155,11 +166,13 @@ function init() {
155166
);
156167

157168
$t = \atk4\ui\Text::addTo($page);
158-
$t->addParagraph(<<< 'EOF'
169+
$t->addParagraph(
170+
<<< 'EOF'
159171
This code shows you a combination of 3 objects:
160172
EOF
161173
);
162-
$t->addHTML(<<< 'HTML'
174+
$t->addHTML(
175+
<<< 'HTML'
163176
<ul>
164177
<li>Form - a generic view that can display and handle any form</li>
165178
<li>Model - defines fields for a business object</li>
@@ -168,15 +181,17 @@ function init() {
168181

169182
HTML
170183
);
171-
$t->addParagraph(<<< 'EOF'
184+
$t->addParagraph(
185+
<<< 'EOF'
172186
All three are combined by "setModel()" function and that is consistent throughout all the views.
173187
EOF
174188
);
175189
});
176190

177191
$wizard->addStep('Persistence', function ($page) {
178192
$t = \atk4\ui\Text::addTo($page);
179-
$t->addParagraph(<<< 'EOF'
193+
$t->addParagraph(
194+
<<< 'EOF'
180195
Once your model is defined, it can be re-used later with any generic view:
181196
EOF
182197
);
@@ -195,7 +210,8 @@ public function init()
195210
}
196211
session_start();
197212

198-
Demo::addTo($page)->setCode(<<<'CODE'
213+
Demo::addTo($page)->setCode(
214+
<<<'CODE'
199215
$session = new atk4\data\Persistence\Array_($_SESSION['x']);
200216
201217
$model = new Invoice($session);
@@ -206,7 +222,8 @@ public function init()
206222
);
207223

208224
$t = \atk4\ui\Text::addTo($page);
209-
$t->addParagraph(<<< 'EOF'
225+
$t->addParagraph(
226+
<<< 'EOF'
210227
Re-use of your Business Model code, generic and interactive views and principles of composition and a simple PHP
211228
code offers a most efficient way of constructing Web Applications.
212229
EOF
@@ -215,12 +232,14 @@ public function init()
215232

216233
$wizard->addFinish(function ($page) use ($wizard) {
217234
$t = \atk4\ui\Text::addTo($page);
218-
$t->addParagraph(<<< 'EOF'
235+
$t->addParagraph(
236+
<<< 'EOF'
219237
Agile Toolkit base package includes:
220238
EOF
221239
);
222240

223-
$t->addHTML(<<< 'HTML'
241+
$t->addHTML(
242+
<<< 'HTML'
224243
<ul>
225244
<li>Over 40 ready-to-use and nicely styled UI components</li>
226245
<li>Over 10 ways to build interraction</li>

demos/init.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public function highLightCode()
8989
$form->addItem('Data Integration', ['form2']);
9090
$form->addItem('Form Multi-column layout', ['form3']);
9191
$form->addItem(['Integration with Columns'], ['form5']);
92-
$form->addItem(['AutoComplete Field', 'icon'=>'yellow star'], ['autocomplete']);
92+
$form->addItem(['Lookup Field', 'icon'=>'yellow star'], ['lookup']);
9393
$form->addItem(['DropDown Field'], ['dropdown-plus']);
9494
$form->addItem(['Value Selectors'], ['form6']);
9595
$form->addItem(['Conditional Fields'], ['jscondform']);

demos/jsactionsgrid.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@
4646
return 'Confirm ok ' . $m->getTitle();
4747
}]);
4848

49-
$country->addAction('multi_step',
49+
$country->addAction(
50+
'multi_step',
5051
[
5152
'args' => [
5253
'age' => ['type'=>'integer', 'required'=> true],

0 commit comments

Comments
 (0)