Skip to content

Commit a55fda5

Browse files
authored
Feature/improve tutorials (#872)
* Improving tutorials * fix * Apply fixes from StyleCI * can update demo, that's also OK * wip * Apply fixes from StyleCI * that's not a useful file * cleaned up Actions menu and added more explanations * not sure why tthis wasn't loading * Apply fixes from StyleCI
1 parent 85f684a commit a55fda5

File tree

7 files changed

+545
-222
lines changed

7 files changed

+545
-222
lines changed

.github/workflows/ui-demo.yml

-14
This file was deleted.

demos/index.php

+24-35
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,28 @@
22

33
include_once __DIR__ . '/init.php';
44

5+
/*
6+
$tut_array = [
7+
['id'=>'intro', 'name'=>'Agile UI Intro', 'description'=>'Take a quick stroll through some of the amazing features of Agile Toolkit.'],
8+
['id'=> 'actions', 'name'=>'New in 2.0: Actions', 'description'=>'Version 2.0 introduced support for universal user actions. Easy to add and supported by all Views.'],
9+
];
10+
$db = new \atk4\data\Persistence_Static($tut_array);
11+
$db->app = $app;
12+
$tutorials = new \atk4\data\Model($db, ['read_only'=>true]);
13+
$tutorials->addAction('Watch', function ($m) {
14+
return $m->app->jsRedirect(['tutorial-'.$m->id, 'layout'=>'Centered']);
15+
});
16+
17+
$app->add([
18+
'Header',
19+
'Welcome to Agile Toolkit!',
20+
'size' => 1,
21+
'subHeader'=> 'Below are some tutorials to walk you through core concepts',
22+
]);
23+
$deck = $app->add(['CardDeck']);
24+
$deck->setModel($tutorials, ['description']);
25+
*/
26+
527
if (!$app->stickyget('begin')) {
628
\atk4\ui\Header::addTo($app)->set('Welcome to Agile Toolkit Demo!!');
729

@@ -17,7 +39,7 @@
1739
$t->addParagraph('In this version of Agile Toolkit we introduce "User Actions"!');
1840

1941
\atk4\ui\Button::addTo($app, ['Learn about User Actions', 'huge basic primary fluid', 'iconRight' => 'right arrow'])
20-
->link(['tutorial_actions', 'layout' => 'Centered', 'begin' => true]);
42+
->link(['tutorial-actions', 'layout' => 'Centered', 'begin' => true]);
2143

2244
$app->callExit();
2345
}
@@ -231,40 +253,7 @@ public function init()
231253
});
232254

233255
$wizard->addFinish(function ($page) use ($wizard) {
234-
$t = \atk4\ui\Text::addTo($page);
235-
$t->addParagraph(
236-
<<< 'EOF'
237-
Agile Toolkit base package includes:
238-
EOF
239-
);
240-
241-
$t->addHTML(
242-
<<< 'HTML'
243-
<ul>
244-
<li>Over 40 ready-to-use and nicely styled UI components</li>
245-
<li>Over 10 ways to build interraction</li>
246-
<li>Over 10 configurable field types, relations, aggregation and much more</li>
247-
<li>Over 5 SQL and some NoSQL vendors fully supported</li>
248-
</ul>
249-
250-
HTML
251-
);
252-
253-
$gl = \atk4\ui\GridLayout::addTo($page, [null, 'stackable divided', 'columns'=>4]);
254-
\atk4\ui\Button::addTo($gl, ['Explore UI components', 'primary basic fluid', 'iconRight'=>'right arrow'], ['r1c1'])
255-
->link('https://github.com/atk4/ui/#bundled-and-planned-components');
256-
\atk4\ui\Button::addTo($gl, ['Try out interactive features', 'primary basic fluid', 'iconRight'=>'right arrow'], ['r1c2'])
257-
->link(['loader', 'begin'=>false, 'layout'=>false]);
258-
\atk4\ui\Button::addTo($gl, ['Dive into Agile Data', 'primary basic fluid', 'iconRight'=>'right arrow'], ['r1c3'])
259-
->link('https://git.io/ad');
260-
\atk4\ui\Button::addTo($gl, ['More ATK Add-ons', 'primary basic fluid', 'iconRight'=>'right arrow'], ['r1c4'])
261-
->link('https://github.com/atk4/ui/#add-ons-and-integrations');
262-
256+
PromotionText::addTo($page);
263257
\atk4\ui\Button::addTo($wizard, ['Exit demo', 'primary', 'icon'=>'left arrow'], ['Left'])
264258
->link(['begin'=>false, 'layout'=>false]);
265-
266-
\atk4\ui\View::addTo($page, ['ui'=>'divider']);
267-
268-
\atk4\ui\Message::addTo($page, ['Cool fact!', 'info', 'icon'=>'book'])->text
269-
->addParagraph('This entire demo is coded in Agile Toolkit and takes up less than 300 lines of very simple code code!');
270259
});

demos/init.php

+49-2
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@ class Demo extends \atk4\ui\Columns
1515
public $right;
1616
public static $isInitialized = false;
1717
public $highlightDefaultStyle = 'dark';
18+
public $left_width = 8;
19+
public $right_width = 8;
1820

1921
public function init()
2022
{
2123
parent::init();
2224
$this->addClass('celled');
2325

24-
$this->left = $this->addColumn();
25-
$this->right = $this->addColumn();
26+
$this->left = $this->addColumn($this->left_width);
27+
$this->right = $this->addColumn($this->right_width);
2628
}
2729

2830
public function setCode($code, $lang = 'php')
@@ -45,6 +47,51 @@ public function highLightCode()
4547
}
4648
}
4749

50+
class PromotionText extends \atk4\ui\View
51+
{
52+
public function init()
53+
{
54+
parent::init();
55+
56+
$t = \atk4\ui\Text::addTo($this);
57+
$t->addParagraph(
58+
<<< 'EOF'
59+
Agile Toolkit base package includes:
60+
EOF
61+
);
62+
63+
$t->addHTML(
64+
<<< 'HTML'
65+
<ul>
66+
<li>Over 40 ready-to-use and nicely styled UI components</li>
67+
<li>Over 10 ways to build interraction</li>
68+
<li>Over 10 configurable field types, relations, aggregation and much more</li>
69+
<li>Over 5 SQL and some NoSQL vendors fully supported</li>
70+
</ul>
71+
72+
HTML
73+
);
74+
75+
$gl = \atk4\ui\GridLayout::addTo($this, [null, 'stackable divided', 'columns'=>4]);
76+
\atk4\ui\Button::addTo($gl, ['Explore UI components', 'primary basic fluid', 'iconRight'=>'right arrow'], ['r1c1'])
77+
->link('https://github.com/atk4/ui/#bundled-and-planned-components');
78+
\atk4\ui\Button::addTo($gl, ['Try out interactive features', 'primary basic fluid', 'iconRight'=>'right arrow'], ['r1c2'])
79+
->link(['loader', 'begin'=>false, 'layout'=>false]);
80+
\atk4\ui\Button::addTo($gl, ['Dive into Agile Data', 'primary basic fluid', 'iconRight'=>'right arrow'], ['r1c3'])
81+
->link('https://git.io/ad');
82+
\atk4\ui\Button::addTo($gl, ['More ATK Add-ons', 'primary basic fluid', 'iconRight'=>'right arrow'], ['r1c4'])
83+
->link('https://github.com/atk4/ui/#add-ons-and-integrations');
84+
85+
86+
\atk4\ui\View::addTo($this, ['ui'=>'divider']);
87+
88+
\atk4\ui\Message::addTo($this, ['Cool fact!', 'info', 'icon'=>'book'])->text
89+
->addParagraph('This entire demo is coded in Agile Toolkit and takes up less than 300 lines of very simple code code!');
90+
}
91+
}
92+
93+
94+
4895
$app = new \atk4\ui\App([
4996
'call_exit' => isset($_GET['APP_CALL_EXIT']) && $_GET['APP_CALL_EXIT'] == 0 ? false : true,
5097
'catch_exceptions' => isset($_GET['APP_CATCH_EXCEPTIONS']) && $_GET['APP_CATCH_EXCEPTIONS'] == 0 ? false : true,

demos/loader.php

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
require_once __DIR__ . '/init.php';
4+
require_once '../tests/ViewTester.php';
45

56
\atk4\ui\Button::addTo($app, ['Loader Examples - Page 2', 'small right floated basic blue', 'iconRight' => 'right arrow'])
67
->link(['loader2']);

demos/tutorial-actions.php

+213
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
<?php
2+
3+
require 'init.php';
4+
require 'database.php';
5+
6+
/** @var \atk4\ui\View $wizard */
7+
$wizard = $app->add('Wizard');
8+
$app->stickyGet($wizard->name);
9+
10+
$wizard->addStep('Define User Action', function ($page) {
11+
/** @var \atk4\ui\Text $t */
12+
13+
\atk4\ui\Header::addTo($page, ['What are Actions?']);
14+
15+
$t = $page->add('Text');
16+
$t->addParagraph(
17+
<<< 'EOF'
18+
Since the early version ATK UI was about building generic UI capable of automatically read information about
19+
model Fields and visualising them correctly. Version 2.0 introduces support for "Actions" which can be declared
20+
in Data layer and can use generic UI for visualising and triggering. Models of Agile Data has always supported 3
21+
basic actions: "save" (for new and existing records) and "delete". Historically any other interaction required
22+
tinkering with UI layer. Now ATK implements a generic support for arbitrary actions and then re-implements
23+
"save", "delete" and "add" on top.
24+
EOF
25+
);
26+
27+
$t->addParagraph(
28+
<<< 'EOF'
29+
This enables developer to easily add more actions in the Data layers and have the rest of ATK recognise
30+
and respect those actions. Actions can be added into the model just like you are adding fields:
31+
EOF
32+
);
33+
34+
$page->add(new Demo())->setCode(
35+
<<<'CODE'
36+
$country = new Country($app->app->db);
37+
38+
$country->addAction('send_message');
39+
CODE
40+
);
41+
42+
$t = $page->add('Text');
43+
$t->addParagraph(
44+
<<< 'EOF'
45+
Once defied - actions will be visualised in the Form, Grid, CRUD and CardDeck. Additionally add-ons will recognise
46+
your actions - for example 'Login' add-on introduces ACL system capable of enabling/disabling fields or actions
47+
on per-user basis.
48+
EOF
49+
);
50+
51+
$t->addParagraph(
52+
<<< 'EOF'
53+
Any actions you define will automatically appear in the UI. This is consistent with your field definitions. You can
54+
also "disable" or mark actions as "system". When action is executed, the response will appear to the user as a
55+
toast message, but this can also be customised.
56+
EOF
57+
);
58+
59+
$page->add(new Demo())->setCode(
60+
<<<'CODE'
61+
62+
$country = new Country($app->app->db);
63+
64+
$country->addAction('send_message', function() {
65+
return 'sent';
66+
});
67+
$country->tryLoadAny();
68+
69+
$card = $app->add('Card');
70+
$card->setModel($country, ['iso']);
71+
$card->addClickAction($country->getAction('send_message'));
72+
73+
CODE
74+
);
75+
});
76+
77+
$wizard->addStep('UI Integration', function ($page) {
78+
/** @var \atk4\ui\Text $t */
79+
$t = $page->add('Text');
80+
$t->addParagraph(
81+
<<< 'EOF'
82+
Agile UI introduces a new set of views called "Action Executors". Their job is to recognise all that meta-information
83+
that you have specified for the action and requesting it from the user. "edit" action is defined for models by default
84+
and you can trigger it on button-click with a very simple code:
85+
EOF
86+
);
87+
88+
$page->add(new Demo())->setCode(
89+
<<<'CODE'
90+
$country = new Country($app->app->db);
91+
$country->loadAny();
92+
93+
$app->add(['Button', 'Edit some country'])
94+
->on('click', $country->getAction('edit'));
95+
CODE
96+
);
97+
98+
$t = $page->add('Text');
99+
$t->addParagraph(
100+
<<< 'EOF'
101+
It is not only the button, but any view can have "Action" passed as a second step of the on() call. Here the action
102+
is executed when you click on "World" menu item:
103+
EOF
104+
);
105+
106+
$page->add(new Demo())->setCode(
107+
<<<'CODE'
108+
$country = new Country($app->app->db);
109+
$country->loadAny();
110+
111+
$menu = $app->add('Menu');
112+
$menu->addItem('Hello');
113+
$menu->addItem('World', $country->getAction('edit'));
114+
CODE
115+
);
116+
});
117+
118+
$wizard->addStep('Arguments', function ($page) {
119+
$t = $page->add('Text');
120+
$t->addParagraph(
121+
<<< 'EOF'
122+
Next demo defines an action that requires arguments. You can specify action when the action is invoked, but if not
123+
defined - user will be asked to supply an argument. Action will automatically validate argument types and it uses
124+
same type system as fields.
125+
EOF
126+
);
127+
128+
$page->add(new Demo())->setCode(
129+
<<<'CODE'
130+
$model = new \atk4\data\Model($app->db, 'test');
131+
$model->addAction('greet', [
132+
'scope' => \atk4\data\UserAction\Generic::NO_RECORDS,
133+
'args'=> [
134+
'age'=>[
135+
'type'=>'integer',
136+
'required' => true
137+
]
138+
],
139+
'callback'=>function ($m, $age) {
140+
return 'Age is '.$age;
141+
}
142+
]);
143+
144+
$app->add(new \atk4\ui\FormField\Line([
145+
// TODO - how to specify watermark here?
146+
'action' => $model->getAction('greet'),
147+
]));
148+
149+
$app->add(['ui'=>'divider']);
150+
151+
$app->add(['Button', 'Greet without Age argument'])
152+
->on('click', $model->getAction('greet'));
153+
CODE
154+
);
155+
});
156+
157+
/*
158+
$wizard->addStep('More Ways', function ($page) {
159+
$page->add(new Demo(['left_width'=>5, 'right_width'=>11]))->setCode(
160+
<<<'CODE'
161+
$m = new Stat($app->db);
162+
$m->addAction('mail', [
163+
'fields' => ['currency_field'],
164+
'scope' => \atk4\data\UserAction\Generic::SINGLE_RECORD,
165+
'callback' => function() { return 'testing'; },
166+
'description' => 'Email testing',
167+
]);
168+
$app->add('CardDeck')
169+
->setModel(
170+
$m,
171+
['description']
172+
);
173+
CODE
174+
);
175+
});
176+
*/
177+
178+
179+
180+
$wizard->addStep('CRUD integration', function ($page) {
181+
$t = $page->add('Text');
182+
$t->addParagraph(
183+
<<< 'EOF'
184+
Compared to 1.x versions CRUD implementation has became much more lightweight, however you retain all the same
185+
functionality and more. Next example shows how you can disable action (add) entirely, or on per-row basis (delete)
186+
and how you could add your own action with a custom trigger button and even a preview.
187+
EOF
188+
);
189+
190+
191+
$page->add(new Demo())->setCode(
192+
<<<'CODE'
193+
$country = new Country($app->app->db);
194+
$country->getAction('add')->enabled = false;
195+
$country->getAction('delete')->enabled = function() { return rand(1,2)>1; };
196+
$country->addAction('mail', [
197+
'scope' => \atk4\data\UserAction\Generic::SINGLE_RECORD,
198+
'preview' => function($m) { return 'here is email preview for '.$m['name']; },
199+
'callback' => function($m) { return 'email sent to '.$m['name']; },
200+
'description' => 'Email testing',
201+
'ui' => ['icon'=>'mail', 'button'=>[null, 'icon'=>'green mail']],
202+
]);
203+
$crud = $app->add(['CRUD', 'ipp'=>5]);
204+
$crud->setModel($country, ['name','iso']);
205+
CODE
206+
);
207+
});
208+
209+
$wizard->addFinish(function ($page) use ($wizard) {
210+
PromotionText::addTo($page);
211+
\atk4\ui\Button::addTo($wizard, ['Exit demo', 'primary', 'icon'=>'left arrow'], ['Left'])
212+
->link(['begin'=>false, 'layout'=>false]);
213+
});

0 commit comments

Comments
 (0)