Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Lock demo Models #1725

Merged
merged 4 commits into from
Jan 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion demos/_includes/DemoActionsUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class DemoActionsUtil
{
public static function setupDemoActions(CountryLock $country): void
public static function setupDemoActions(Country $country): void
{
$country->addUserAction(
'callback',
Expand Down
15 changes: 6 additions & 9 deletions demos/_includes/DemoLookup.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,17 @@ protected function initQuickNewRecord()
$form->setModel($entity, $this->plus['fields'] ?? null);

$form->onSubmit(function (\Atk4\Ui\Form $form) {
// Prevent from saving
// $form->model->save();
$form->model->save();

$ret = [
new \Atk4\Ui\JsToast('Form submit!. Demo cannot saved data.'),
new \Atk4\Ui\JsToast('Form submit!. Data are not save in demo mode.'),
(new \Atk4\Ui\Jquery('.atk-modal'))->modal('hide'),
];

if ($row = $this->renderRow($form->model)) {
$chain = new \Atk4\Ui\Jquery('#' . $this->name . '-ac');
$chain->dropdown('set value', $row['value'])->dropdown('set text', $row['title']);

$ret[] = $chain;
}
$row = $this->renderRow($form->model);
$chain = new \Atk4\Ui\Jquery('#' . $this->name . '-ac');
$chain->dropdown('set value', $row['value'])->dropdown('set text', $row['title']);
$ret[] = $chain;

return $ret;
});
Expand Down
2 changes: 1 addition & 1 deletion demos/_unit-test/callback-nested.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';

$m = (new CountryLock($app->db))->setLimit(5);
$m = (new Country($app->db))->setLimit(5);
$app->getExecutorFactory()->registerTrigger(
ExecutorFactory::TABLE_BUTTON,
[Button::class, 'ui' => 'atk-test button', 'icon' => 'pencil'],
Expand Down
2 changes: 1 addition & 1 deletion demos/_unit-test/callback.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';

$m = (new CountryLock($app->db))->setLimit(5);
$m = (new Country($app->db))->setLimit(5);

$vp = \Atk4\Ui\VirtualPage::addTo($app);
$vp->cb->triggerOnReload = false;
Expand Down
2 changes: 1 addition & 1 deletion demos/_unit-test/crud.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// reset to default button
$app->getExecutorFactory()->useTriggerDefault(ExecutorFactory::TABLE_BUTTON);

$model = new CountryLock($app->db);
$model = new Country($app->db);
$crud = \Atk4\Ui\Crud::addTo($app, ['ipp' => 10, 'menu' => ['class' => ['atk-grid-menu']]]);
$crud->setModel($model);

Expand Down
2 changes: 1 addition & 1 deletion demos/_unit-test/lookup-virtual-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';

$product = new ProductLock($app->db);
$product = new Product($app->db);

$vp = VirtualPage::addTo($app);

Expand Down
2 changes: 1 addition & 1 deletion demos/_unit-test/lookup.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';

$model = new ProductLock($app->db);
$model = new Product($app->db);
$model->addCondition($model->fieldName()->name, '=', 'Mustard');

// use default.
Expand Down
2 changes: 1 addition & 1 deletion demos/basic/breadcrumb.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

$crumb->addCrumb('Countries', []);

$model = new CountryLock($app->db);
$model = new Country($app->db);
$model->setLimit(15);

if ($id = $app->stickyGet('country_id')) {
Expand Down
15 changes: 4 additions & 11 deletions demos/collection/crud.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';

$model = new CountryLock($app->db);
$model = new Country($app->db);

$crud = \Atk4\Ui\Crud::addTo($app, ['ipp' => 10]);

Expand All @@ -24,13 +24,6 @@
$form->js(true, $form->getControl($model->fieldName()->name)->jsInput()->attr('readonly', true));
});

// callback for both model action edit and add.
$crud->onFormAddEdit(function (Form $form, $ex) {
$form->onSubmit(function (Form $form) use ($ex) {
return [$ex->hide(), new \Atk4\Ui\JsToast('Submit all right! This demo does not saved data.')];
});
});

$crud->setModel($model);

$crud->addDecorator($model->title_field, [\Atk4\Ui\Table\Column\Link::class, ['test' => false, 'path' => 'interfaces/page'], ['_id' => 'id']]);
Expand All @@ -51,7 +44,7 @@
'table' => ['class' => ['red inverted']],
]);
// Condition on the model can be applied on a model
$model = new CountryLock($app->db);
$model = new Country($app->db);
$model->addCondition($model->fieldName()->numcode, '<', 200);
$model->onHook(\Atk4\Data\Model::HOOK_VALIDATE, function (Country $model, $intent) {
$err = [];
Expand All @@ -65,7 +58,7 @@

// Because Crud inherits Grid, you can also define custom actions
$crud->addModalAction(['icon' => [\Atk4\Ui\Icon::class, 'cogs']], 'Details', function ($p, $id) use ($crud) {
$model = CountryLock::assertInstanceOf($crud->model);
$model = Country::assertInstanceOf($crud->model);
\Atk4\Ui\Message::addTo($p, ['Details for: ' . $model->load($id)->name . ' (id: ' . $id . ')']);
});

Expand Down Expand Up @@ -93,7 +86,7 @@ public function addFormTo(\Atk4\Ui\View $view): Form
}
});

$file = new FileLock($app->db);
$file = new File($app->db);
$app->getExecutorFactory()->registerExecutor($file->getUserAction('edit'), [$myExecutorClass]);

$crud = \Atk4\Ui\Crud::addTo($column, [
Expand Down
4 changes: 0 additions & 4 deletions demos/collection/crud3.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

/** @var \Atk4\Data\Model $modelClass */
$modelClass = AnonymousClassNameCache::get_class(fn () => new class() extends \Atk4\Data\Model {
use ModelLockTrait;

public $table = 'test';

public $caption = 'Country';
Expand All @@ -24,8 +22,6 @@ protected function init(): void
$this->addField('name');
$this->addField('code');
$this->addField('country');

$this->lock();
}
});

Expand Down
2 changes: 1 addition & 1 deletion demos/collection/grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
require_once __DIR__ . '/../init-app.php';

$grid = \Atk4\Ui\Grid::addTo($app);
$model = new CountryLock($app->db);
$model = new Country($app->db);
$model->addUserAction('test', function (Model $model) {
return 'test from ' . $model->getTitle() . ' was successful!';
});
Expand Down
2 changes: 1 addition & 1 deletion demos/collection/tablefilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// Important: menu class added for Behat testing.
$grid = \Atk4\Ui\Grid::addTo($view, ['menu' => ['class' => ['atk-grid-menu']]]);

$model = new CountryLock($app->db);
$model = new Country($app->db);
$model->addExpression('is_uk', $model->expr('case when [atk_fp_country__iso] = [country] THEN 1 ELSE 0 END', ['country' => 'GB']))->type = 'boolean';

$grid->setModel($model);
Expand Down
2 changes: 1 addition & 1 deletion demos/data-action/actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';

$files = new FileLock($app->db);
$files = new File($app->db);

// Actions can be added easily to the model via the Model::addUserAction($name, $properties) method.
$action = $files->addUserAction(
Expand Down
4 changes: 2 additions & 2 deletions demos/data-action/factory-view.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected function getCardButton($action, $type)

Header::addTo($app, ['Executor Factory set for this Card View only.']);

DemoActionsUtil::setupDemoActions($country = new CountryLock($app->db));
DemoActionsUtil::setupDemoActions($country = new Country($app->db));
$country = $country->loadAny();

$cardActions = Card::addTo($app, ['useLabel' => true, 'executorFactory' => new $myFactory()]);
Expand All @@ -64,7 +64,7 @@ protected function getCardButton($action, $type)

Header::addTo($app, ['Card View using global Executor Factory']);

$model = new CountryLock($app->db);
$model = new Country($app->db);
$model = $model->loadAny();

$card = Card::addTo($app, ['useLabel' => true]);
Expand Down
2 changes: 1 addition & 1 deletion demos/data-action/factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
// Set new executor factory globally.
$app->setExecutorFactory(new $myFactory());

$country = new CountryLock($app->db);
$country = new Country($app->db);

$crud = \Atk4\Ui\Crud::addTo($app, ['ipp' => 5]);
$crud->setModel($country);
Expand Down
2 changes: 1 addition & 1 deletion demos/data-action/jsactions2.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';

$country = new CountryLock($app->db);
$country = new Country($app->db);
$entity = $country->tryLoadAny();
$countryId = $entity->getId();

Expand Down
2 changes: 1 addition & 1 deletion demos/data-action/jsactionscrud.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

// Actions can be added easily to the model

$files = new FileLock($app->db);
$files = new File($app->db);

// This action must appear on top of the Crud
$files->addUserAction(
Expand Down
2 changes: 1 addition & 1 deletion demos/data-action/jsactionsgrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

// Demo for Model action in Grid

$country = new CountryLock($app->db);
$country = new Country($app->db);
// Model actions for this file are setup in DemoActionUtil.
DemoActionsUtil::setupDemoActions($country);

Expand Down
6 changes: 3 additions & 3 deletions demos/form-control/input2.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,20 @@

$group->addControl('Lookup_norm', [
DemoLookup::class,
'model' => new CountryLock($app->db),
'model' => new Country($app->db),
'plus' => true,
])->set($model->loadAny()->getId());

$group->addControl('Lookup_read', [
Form\Control\Lookup::class,
'model' => new CountryLock($app->db),
'model' => new Country($app->db),
'plus' => true,
'readonly' => true,
])->set($model->loadAny()->getId());

$group->addControl('Lookup_disb', [
Form\Control\Lookup::class,
'model' => new CountryLock($app->db),
'model' => new Country($app->db),
'plus' => true,
'disabled' => true,
])->set($model->loadAny()->getId());
Expand Down
15 changes: 8 additions & 7 deletions demos/form/form-section.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
->link(['form-section-accordion']);
\Atk4\Ui\View::addTo($app, ['ui' => 'ui clearing divider']);

$model = new CountryLock($app->db);
$model = new Country($app->db);
$model = $model->loadAny();

// Prevent form from saving
$noSave = function (Form $form) {
$saveAndDumpValues = function (Form $form) {
$form->model->save();

return new \Atk4\Ui\JsToast([
'title' => 'POSTed field values',
'message' => '<pre>' . $form->getApp()->encodeJson($form->model->get()) . '</pre>',
Expand Down Expand Up @@ -46,7 +47,7 @@

$form->addControl($model->fieldName()->phonecode);

$form->onSubmit($noSave);
$form->onSubmit($saveAndDumpValues);

\Atk4\Ui\View::addTo($app, ['ui' => 'divider']);

Expand All @@ -68,7 +69,7 @@
$a2 = $accordionLayout->addSection('Section 2');
$a2->setModel($model, [$model->fieldName()->numcode, $model->fieldName()->phonecode]);

$form->onSubmit($noSave);
$form->onSubmit($saveAndDumpValues);

\Atk4\Ui\View::addTo($app, ['ui' => 'divider']);

Expand All @@ -90,7 +91,7 @@
$tab2 = $tabsLayout->addTab('Tab 2');
$tab2->setModel($model, [$model->fieldName()->numcode, $model->fieldName()->phonecode]);

$form->onSubmit($noSave);
$form->onSubmit($saveAndDumpValues);

\Atk4\Ui\View::addTo($app, ['ui' => 'divider']);

Expand All @@ -115,6 +116,6 @@
$c2 = $colsLayout->addColumn();
$c2->setModel($model, [$model->fieldName()->numcode, $model->fieldName()->phonecode]);

$form->onSubmit($noSave);
$form->onSubmit($saveAndDumpValues);

\Atk4\Ui\View::addTo($app, ['ui' => 'divider']);
6 changes: 3 additions & 3 deletions demos/form/form2.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
//$form = Form::addTo($app, ['segment', 'buttonSave' => [null, 'Import', 'secondary', 'iconRight' => 'list']]);
\Atk4\Ui\Label::addTo($form, ['Input new country information here', 'top attached'], ['AboveControls']);

$form->setModel((new CountryLock($app->db))->createEntity(), []);
$form->setModel((new Country($app->db))->createEntity(), []);

// form basic field group
$formAddress = $form->addGroup('Basic Country Information');
$name = $formAddress->addControl(Country::hinting()->fieldName()->name, ['width' => 'sixteen']);
$name->addAction(['Check Duplicate', 'iconRight' => 'search'])->on('click', function ($jQuery, $name) use ($app, $form) {
if ((new CountryLock($app->db))->tryLoadBy(Country::hinting()->fieldName()->name, $name)->isLoaded()) {
if ((new Country($app->db))->tryLoadBy(Country::hinting()->fieldName()->name, $name)->isLoaded()) {
return $form->js()->form('add prompt', Country::hinting()->fieldName()->name, 'This country name is already added.');
}

Expand All @@ -50,7 +50,7 @@

// form on submit
$form->onSubmit(function (Form $form) {
$countryEntity = (new CountryLock($form->getApp()->db))->createEntity();
$countryEntity = (new Country($form->getApp()->db))->createEntity();
// Model will have some validation too
foreach ($form->model->getFields('editable') as $k => $field) {
if ($countryEntity->hasField($k)) {
Expand Down
2 changes: 1 addition & 1 deletion demos/form/html-layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
$tab = $tabs->addTab('Custom layout class');

$form = Form::addTo($tab, ['layout' => [Form\Layout\Custom::class, 'defaultTemplate' => __DIR__ . '/templates/form-custom-layout.html']]);
$form->setModel((new CountryLock($app->db))->loadAny());
$form->setModel((new Country($app->db))->loadAny());

$form->onSubmit(function (Form $form) {
return new \Atk4\Ui\JsToast('Saving is disabled');
Expand Down
Loading