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

Big addColumn, addField and Seed refactor (PART1) #179

Merged
merged 35 commits into from
Sep 14, 2017

Conversation

romaninsh
Copy link
Member

@romaninsh romaninsh commented Jun 19, 2017

Refactor to have a consistent addField / addColumn mechanics implementing #188 and #187 as well as incorporating atk4/core#50.

  • addColumn, addField and addColumnDecorator arguments should be consistent
  • new Seed should be respected
  • addColumn may not be called twice on same column
  • adding addDecorator (instead of Formatter) because formatting is done in UI Persistence
  • add consistent arguments (, <form field/table column> = null, = null)
  • significantly improve docs

Things to do:

  • create a good testSutie for all addColumn addDecorator and addField scenarios
  • reflect in the code
  • reflect in the docs

@romaninsh romaninsh mentioned this pull request Jun 19, 2017
8 tasks
@romaninsh romaninsh self-assigned this Jun 20, 2017
@romaninsh romaninsh added this to the 1.2 - Next Major Branch milestone Jun 20, 2017
@romaninsh romaninsh changed the title Feature/refactor columns fields Big addColumn, addField and Seed refactor Jul 28, 2017
@romaninsh
Copy link
Member Author

Updating to version 1.3 of Agile Core..

@romaninsh romaninsh changed the title Big addColumn, addField and Seed refactor Big addColumn, addField and Seed refactor (PART1) Sep 4, 2017
@romaninsh
Copy link
Member Author

Given a huge scope of this commit, I propose that it would be split up into 3 stages:

  • First - this PR. It won't pass the tests, but the Form at least will work OK
  • Second PR will deal with addColumn()
  • Third PR will resolve all other problems with test suite.

It would be easier to review all PRs individually then merge them all simultaneously.

Also - the current 'develop' branch is broken because it's not compatible with core/develop.

@romaninsh
Copy link
Member Author

With the recent addition of documentation the Form should now be a first rate citizen of Agile UI.

I have used approach similar to basic elements where I start explaining it from the very basics and then gradually look at various use-cases while laying documentation against the classes, methods and properties.

}

return $this->_add($field, ['name'=>$field->short_name]);
if (is_string($decorator)) {
$decorator = $this->form->decoratorFactory($field, ['caption'=>$decorator]);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am myself unsure about this code. IIRC, Decorator should indicate type and third argument may contain caption.

$sub->setAttr('data-tab', $item->name);

//# TODO: refactor this ugly hack
$item->setPath(str_replace('.php.', '.', $this->app->url($url)).'#');
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ibelar this is a nasty hack, can you see if that can be improved?

@romaninsh romaninsh changed the base branch from develop to epic/atk-core-refactor September 11, 2017 12:28
Copy link
Member

@DarkSide666 DarkSide666 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are some comments, but also some changes required.

@@ -0,0 +1,75 @@
<?php
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No link to this demo page in menu.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be OK for now, i suppose we will be re-making the demo suite anyways.

$f->addField('five', new \atk4\ui\FormField\Checkbox());

// can add field that does not exist in a model
$f->addField('nine', new \atk4\ui\FormField\Checkbox(['caption'=>'Caption3']));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really good option. Previously in toolkit I have had issues with this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and i think it will change again, now it's new Checkbox('Caption 4')

will include "sorting" icons or any other controls that go in the header of the table.

The output of this field will automatically encode any values (such as caption), shorten them
if necessary and localize them.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

really??

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

confused by that text, so i deleted.


.. php:method:: getTotalsCellHTML(\atk4\data\Field $f, $value)

Provided with the field and the value, format the cell for the footer "totals" column. Table
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... footer "totals" row not column.

show it without masking just for the admin? Change type in-line for the model field::

$m = new User($app->db);
$m->getElement('password')->type = 'string';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will password save normally in this case? will it still use encoding?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't think there is password encoding anywhere yet, but in this case, no , it won't use encodyngi.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added note.

return $this->success('Form data has been saved');
} else {
return new jsExpression('console.log([])', ['Form submission is not handled']);
try {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need 3 inherited try blocks?
We can use

try {
    ...
} catch (\atk4\data\ValidationException $val) {
    ...
} catch (\Error $e) {
    ...
} catch (\Exception $e) {
    ...
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I leave this to you to refactor later, can you do it? I am not sure if php 5.6 supports multiple catch blocks, but 7.1 certainly good by adding https://wiki.php.net/rfc/multiple-catch.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't mean multiple-catch like catch (\Error $1 || \Exception $e2) syntax. I mean not nesting try/catch blocks.

@@ -40,6 +40,8 @@ class Input extends Generic

public $actionLeft = null;

public $width = null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

description of possible options and data type ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added.

} elseif (is_array($args) && isset($args[0])) {
$args['caption'] = $args[0];
unset($args[0]);
if (!is_string($name)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's already defined in function definition addField(string $name, ... so isit really necessary to check that here too?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, since user can call $layout->addField too.

$existingField->setDefaults($field);
$field = $existingField;
} elseif (is_object($field)) {
throw new Exception(['Duplicate field', 'name'=>$name]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in what case $field can be object?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i feel this code still needs cleanup after latest changes to seed.

src/Grid.php Outdated
* an.
*
* @param string $name New or existing column name
* @param [type] $columnDef [description]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

incorrect @param

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually must be refactored to match Table

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

@romaninsh romaninsh merged commit 41cc057 into epic/atk-core-refactor Sep 14, 2017
@DarkSide666 DarkSide666 deleted the feature/refactor-columns-fields branch September 14, 2017 21:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants