Skip to content

Commit

Permalink
Add imports for commonly used classes (#1829)
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek authored Aug 21, 2022
1 parent 928f8f2 commit 7625082
Show file tree
Hide file tree
Showing 203 changed files with 2,272 additions and 1,955 deletions.
17 changes: 9 additions & 8 deletions demos/_includes/Counter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,22 @@

namespace Atk4\Ui\Demos;

/**
* Counter for certain demos file.
*/
class Counter extends \Atk4\Ui\Form\Control\Line
use Atk4\Ui\Button;
use Atk4\Ui\Form;
use Atk4\Ui\JsExpression;

class Counter extends Form\Control\Line
{
public $content = '20';

protected function init(): void
{
parent::init();

$this->actionLeft = new \Atk4\Ui\Button(['icon' => 'minus']);
$this->action = new \Atk4\Ui\Button(['icon' => 'plus']);
$this->actionLeft = new Button(['icon' => 'minus']);
$this->action = new Button(['icon' => 'plus']);

$this->actionLeft->js('click', $this->jsInput()->val(new \Atk4\Ui\JsExpression('parseInt([]) - 1', [$this->jsInput()->val()])));
$this->action->js('click', $this->jsInput()->val(new \Atk4\Ui\JsExpression('parseInt([]) + 1', [$this->jsInput()->val()])));
$this->actionLeft->js('click', $this->jsInput()->val(new JsExpression('parseInt([]) - 1', [$this->jsInput()->val()])));
$this->action->js('click', $this->jsInput()->val(new JsExpression('parseInt([]) + 1', [$this->jsInput()->val()])));
}
}
13 changes: 9 additions & 4 deletions demos/_includes/Demo.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@

namespace Atk4\Ui\Demos;

class Demo extends \Atk4\Ui\Columns
use Atk4\Ui\Columns;
use Atk4\Ui\Exception;
use Atk4\Ui\JsChain;
use Atk4\Ui\View;

class Demo extends Columns
{
public $left;
public $right;
Expand All @@ -29,7 +34,7 @@ protected function extractCodeFromClosure(\Closure $fx): string
{
$funcRefl = new \ReflectionFunction($fx);
if ($funcRefl->getEndLine() === $funcRefl->getStartLine()) {
throw new \Atk4\Ui\Exception('Closure body to extract must be on separate lines');
throw new Exception('Closure body to extract must be on separate lines');
}

$codeArr = array_slice(
Expand All @@ -52,7 +57,7 @@ public function setCodeAndCall(\Closure $fx, $lang = 'php')
$code = $this->extractCodeFromClosure($fx);

$this->highLightCode();
\Atk4\Ui\View::addTo(\Atk4\Ui\View::addTo($this->left, ['element' => 'pre']), ['element' => 'code'])->addClass($lang)->set($code);
View::addTo(View::addTo($this->left, ['element' => 'pre']), ['element' => 'code'])->addClass($lang)->set($code);

$fx($this->right);
}
Expand All @@ -62,7 +67,7 @@ public function highLightCode()
if (!self::$isInitialized) {
$this->getApp()->requireCss('https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.16.2/styles/' . $this->highlightDefaultStyle . '.min.css');
$this->getApp()->requireJs('https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.16.2/highlight.min.js');
$this->js(true, (new \Atk4\Ui\JsChain('hljs'))->initHighlighting());
$this->js(true, (new JsChain('hljs'))->initHighlighting());
self::$isInitialized = true;
}
}
Expand Down
244 changes: 109 additions & 135 deletions demos/_includes/DemoActionsUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,160 +6,134 @@

use Atk4\Data\Model;
use Atk4\Data\Model\UserAction;
use Atk4\Ui\Exception;
use Atk4\Ui\Form\Control\Dropdown;

class DemoActionsUtil
{
public static function setupDemoActions(Country $country): void
{
$country->addUserAction(
'callback',
[
'description' => 'Callback',
'callback' => function (Country $model) {
return 'callback execute using country ' . $model->getTitle();
},
]
);
$country->addUserAction('callback', [
'description' => 'Callback',
'callback' => function (Country $model) {
return 'callback execute using country ' . $model->getTitle();
},
]);

$country->addUserAction(
'preview',
[
'description' => 'Display Preview prior to run the action',
'preview' => function (Country $model) {
return 'Previewing country ' . $model->getTitle();
},
'callback' => function (Country $model) {
return 'Done previewing ' . $model->getTitle();
},
]
);
$country->addUserAction('preview', [
'description' => 'Display Preview prior to run the action',
'preview' => function (Country $model) {
return 'Previewing country ' . $model->getTitle();
},
'callback' => function (Country $model) {
return 'Done previewing ' . $model->getTitle();
},
]);

$country->addUserAction(
'disabled_action',
[
'description' => 'This action is disabled.',
'caption' => 'Disabled',
'enabled' => false,
'callback' => function () {
return 'ok';
},
]
);
$country->addUserAction('disabled_action', [
'description' => 'This action is disabled.',
'caption' => 'Disabled',
'enabled' => false,
'callback' => function () {
return 'ok';
},
]);

$country->addUserAction(
'edit_argument',
[
'caption' => 'Argument',
'description' => 'Ask for argument "Age" prior to execute the action.',
'args' => [
'age' => ['type' => 'integer', 'required' => true],
],
'callback' => function (Country $model, int $age) {
if ($age < 18) {
$text = 'Sorry not old enough to visit ' . $model->getTitle();
} else {
$text = $age . ' is old enough to visit ' . $model->getTitle();
}
$country->addUserAction('edit_argument', [
'caption' => 'Argument',
'description' => 'Ask for argument "Age" prior to execute the action.',
'args' => [
'age' => ['type' => 'integer', 'required' => true],
],
'callback' => function (Country $model, int $age) {
if ($age < 18) {
$text = 'Sorry not old enough to visit ' . $model->getTitle();
} else {
$text = $age . ' is old enough to visit ' . $model->getTitle();
}

return $text;
},
]
);
return $text;
},
]);

$country->addUserAction(
'edit_argument_prev',
[
'caption' => 'Argument/Preview',
'description' => 'Ask for argument "Age" and display preview prior to execute',
'args' => [
'age' => ['type' => 'integer', 'required' => true],
],
'preview' => function (Country $model, int $age) {
return 'You age is: ' . $age;
},
'callback' => function (Model $model, $age) {
return 'age = ' . $age;
},
]
);
$country->addUserAction('edit_argument_prev', [
'caption' => 'Argument/Preview',
'description' => 'Ask for argument "Age" and display preview prior to execute',
'args' => [
'age' => ['type' => 'integer', 'required' => true],
],
'preview' => function (Country $model, int $age) {
return 'You age is: ' . $age;
},
'callback' => function (Model $model, $age) {
return 'age = ' . $age;
},
]);

$country->addUserAction(
'edit_iso',
[
'caption' => 'Edit ISO3',
'description' => function (UserAction $action) {
return 'Edit ISO3 for country: ' /* TODO . $action->getEntity()->getTitle() */;
},
'fields' => [$country->fieldName()->iso3],
'callback' => function () {
return 'ok';
},
]
);
$country->addUserAction('edit_iso', [
'caption' => 'Edit ISO3',
'description' => function (UserAction $action) {
return 'Edit ISO3 for country: ' /* TODO . $action->getEntity()->getTitle() */;
},
'fields' => [$country->fieldName()->iso3],
'callback' => function () {
return 'ok';
},
]);

$country->addUserAction(
'Ouch',
[
'caption' => 'Exception',
'description' => 'Throw an exception when executing an action',
'args' => [
'age' => ['type' => 'integer'],
],
'preview' => function () {
return 'Be careful with this action.';
},
'callback' => function () {
throw new \Atk4\Ui\Exception('Told you, didn\'t I?');
},
]
);
$country->addUserAction('Ouch', [
'caption' => 'Exception',
'description' => 'Throw an exception when executing an action',
'args' => [
'age' => ['type' => 'integer'],
],
'preview' => function () {
return 'Be careful with this action.';
},
'callback' => function () {
throw new Exception('Told you, didn\'t I?');
},
]);

$country->addUserAction(
'confirm',
[
'caption' => 'User Confirmation',
'description' => 'Confirm the action using a ConfirmationExecutor',
'confirmation' => function (UserAction $a) {
$iso3 = $a->getEntity()->get(Country::hinting()->fieldName()->iso3);
$country->addUserAction('confirm', [
'caption' => 'User Confirmation',
'description' => 'Confirm the action using a ConfirmationExecutor',
'confirmation' => function (UserAction $a) {
$iso3 = $a->getEntity()->get(Country::hinting()->fieldName()->iso3);

return 'Are you sure you want to perform this action on: <b>' . $a->getEntity()->getTitle() . ' (' . $iso3 . ')</b>';
},
'callback' => function (Country $model) {
return 'Confirm country ' . $model->getTitle();
},
]
);
return 'Are you sure you want to perform this action on: <b>' . $a->getEntity()->getTitle() . ' (' . $iso3 . ')</b>';
},
'callback' => function (Country $model) {
return 'Confirm country ' . $model->getTitle();
},
]);

$country->addUserAction(
'multi_step',
[
'caption' => 'Multi Step',
'description' => 'Ask for Arguments and field and display preview prior to run the action',
'args' => [
'age' => ['type' => 'integer', 'required' => true],
'city' => [],
'gender' => [
'type' => 'string',
'required' => true,
'default' => 'm',
'ui' => [
'form' => [
Dropdown::class, 'values' => ['m' => 'Male', 'f' => 'Female'],
],
$country->addUserAction('multi_step', [
'caption' => 'Multi Step',
'description' => 'Ask for Arguments and field and display preview prior to run the action',
'args' => [
'age' => ['type' => 'integer', 'required' => true],
'city' => [],
'gender' => [
'type' => 'string',
'required' => true,
'default' => 'm',
'ui' => [
'form' => [
Dropdown::class, 'values' => ['m' => 'Male', 'f' => 'Female'],
],
],
],
'fields' => [$country->fieldName()->iso3],
'callback' => function (Country $model, int $age, string $city, string $gender) {
$n = $gender === 'm' ? 'Mr.' : 'Mrs.';
],
'fields' => [$country->fieldName()->iso3],
'callback' => function (Country $model, int $age, string $city, string $gender) {
$n = $gender === 'm' ? 'Mr.' : 'Mrs.';

return 'Thank you ' . $n . ' at age ' . $age;
},
'preview' => function (Country $model, int $age, string $city, string $gender) {
return 'Gender = ' . $gender . ' / Age = ' . $age;
},
]
);
return 'Thank you ' . $n . ' at age ' . $age;
},
'preview' => function (Country $model, int $age, string $city, string $gender) {
return 'Gender = ' . $gender . ' / Age = ' . $age;
},
]);
}
}
4 changes: 3 additions & 1 deletion demos/_includes/DemoInvoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

namespace Atk4\Ui\Demos;

use Atk4\Data\Model;

/**
* Invoice class for tutorial intro.
*/
class DemoInvoice extends \Atk4\Data\Model
class DemoInvoice extends Model
{
public $dateFormat;

Expand Down
Loading

0 comments on commit 7625082

Please sign in to comment.