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

Fix #629, also add new Callback for custom HTML #643

Merged
merged 8 commits into from Jun 21, 2019
Merged

Fix #629, also add new Callback for custom HTML #643

merged 8 commits into from Jun 21, 2019

Conversation

PhilippGrashoff
Copy link
Collaborator

Adds property renderRowFunction, which can be used to pass custom html options to renderView for each option.
If not defined, only needed title_field and id_field are used. (and system fields, they are also loaded when using only_fields()).

Adds property renderRowFunction, which can be used to pass custom html options to renderView for each option.
If not defined, only needed title_field and id_field are used
@PhilippGrashoff
Copy link
Collaborator Author

Some thoughts about this:

  1. I only tested locally,. Need to read more into atk tests to write a test which complies with other tests sensibly.
  2. could make sense to also use this function when values are set instead of model, what do you think?

@codecov
Copy link

codecov bot commented Feb 1, 2019

Codecov Report

Merging #643 into develop will decrease coverage by 0.01%.
The diff coverage is 77.77%.

Impacted file tree graph

@@             Coverage Diff              @@
##             develop    #643      +/-   ##
============================================
- Coverage      69.81%   69.8%   -0.02%     
  Complexity      1853    1853              
============================================
  Files            100     100              
  Lines           4377    4382       +5     
============================================
+ Hits            3056    3059       +3     
- Misses          1321    1323       +2
Impacted Files Coverage Δ Complexity Δ
src/FormField/DropDown.php 86.66% <77.77%> (-2.43%) 30 <0> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d466e9e...0df3dea. Read the comment docs.

@codecov
Copy link

codecov bot commented Feb 1, 2019

Codecov Report

Merging #643 into develop will decrease coverage by 0.03%.
The diff coverage is 92.68%.

Impacted file tree graph

@@              Coverage Diff              @@
##             develop     #643      +/-   ##
=============================================
- Coverage      66.05%   66.02%   -0.04%     
- Complexity      2223     2233      +10     
=============================================
  Files            118      118              
  Lines           5235     5262      +27     
=============================================
+ Hits            3458     3474      +16     
- Misses          1777     1788      +11
Impacted Files Coverage Δ Complexity Δ
src/FormField/DropDown.php 88.09% <92.68%> (-3.14%) 41 <15> (+10)
src/App.php 69.84% <0%> (-2.39%) 117% <0%> (ø)
src/Card.php 62.61% <0%> (ø) 51% <0%> (ø) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6565b7c...8d5af3b. Read the comment docs.

//record to callback
if (is_callable($this->renderRowFunction)) {
foreach ($this->model as $key => $row) {
$options[] = call_user_func($this->renderRowFunction, $row);
Copy link
Member

Choose a reason for hiding this comment

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

could use

array_merge(
    ['div', 'class' => 'item', 'data-value' => (string) $key, [$row->getTitle()]],
    call_user_func(...)
)

here so you don't have to always set all parameters in callback - just overwrite the ones you need.

Copy link
Member

Choose a reason for hiding this comment

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

Also it would be good to add same callback function support below if model is not set ($this->values is).
In this line https://github.com/atk4/ui/pull/643/files#diff-4b67e9492f67665780c2571ad53ebb68R225

@PhilippGrashoff
Copy link
Collaborator Author

Both things sound very sensible. Just don't get how to change files in my pull request... You gotta show me someday how to sensibly create atk4 pr s

@romaninsh
Copy link
Member

Missing documentation and examples..

Copy link
Member

@romaninsh romaninsh left a comment

Choose a reason for hiding this comment

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

need documentation and examples..

otherwise i like the idea.

@DarkSide666
Copy link
Member

DarkSide666 commented Feb 8, 2019

@PhilippGrashoff if you're mostly Windows guy like me or Mac and don't like to type every single command from command line then you can use free SmartGit program. It works very well. I use it for a few years - makes all git stuff a lot simpler and with nice UI.

P.S. I can't add changes in branch in your github account, so you'll have to make them yourself.
Otherwise I can just copy your changes and make new branch myself and tweak it.

@PhilippGrashoff
Copy link
Collaborator Author

PhilippGrashoff commented Feb 9, 2019

@DarkSide666 maybe have a short Skype conversation sometime. I think my whole approach to creating PRs for atk is crap :)

p.s: I'm a Linux guy and using Gitkraken.

@gowrav-vishwakarma
Copy link
Collaborator

Gitkraken

If this is the case, I am also in line. One 30 minutes session can help, a bunch of bad "pull requesters" like me in action ;)

@romaninsh
Copy link
Member

How about we have a weekly on-line session where we discuss all hot issues and also help contributors? I would certainly attend, but I'd prefer someone else to do the admin stuff (announce, etc)

@PhilippGrashoff
Copy link
Collaborator Author

Sounds good. I'd just need some push in the right direction for creating prs from git software. At the moment I edit the file on github.com by copy pasting the changes :) didn't get any atk4 pr to work in another way yet

@abbadon1334
Copy link
Collaborator

i'm the king of PR messing :D in the last week i start thinking about start streaming on twitch out of working time while i'm coding/debug things just to do something and see what would happen.

I think a project like atk4 need more help to grow and make it better, we started an app for a client 3 weeks ago and we are near releasing alpha and considering time for debugging some atk4 things, it's unreal

@gowrav-vishwakarma
Copy link
Collaborator

gowrav-vishwakarma commented Feb 21, 2019 via email

@romaninsh
Copy link
Member

romaninsh commented Mar 20, 2019

note: inconsistent with https://github.com/atk4/ui/blob/develop/src/Table.php#L504.

Then again - i think that dropdown does not implement hook trait.

@PhilippGrashoff
Copy link
Collaborator Author

Hi,

  1. the idea with array_merge is nice, but as the array is only partly indexed, it wont work, at least not in a sensible way.

  2. In general I am not happy with the solution I added. Would you mind if I split up renderView() a bit, introducing a method which is called _renderLines() which takes care of rendering the Dropdown elements?
    That would make renderView() smaller and Dropdown would be easier to extend, e.g. if someone wants to just change the way the dropdown options are displayed (exceeding what a callback could do?)?

Best regards

@romaninsh
Copy link
Member

@PhilippGrashoff if you are willing to improve your PR, - sure by all means, close this one and create a new on!

And thanks again for contributing.

- use Subtemplate for row rendering instead of $app->getTag(). Makes customization easier if needed (e.g. display complex HTML per row)
- implement renderRowFunction which can be used to easily customize dropdown row rendering
@PhilippGrashoff
Copy link
Collaborator Author

HI there,

I refactored renderView quite a bit and used a subtemplate for row's HTML instead of $app->getTag(). Why?

  1. Makes introduction of complex HTML easier, just set defaultTemplate to your own (thinking about this, maybe make $_tItem public to have the possibility to just overwrite this?)
  2. move HTML from PHP file to Template file

Now the renderRowFunction works nicely IMHO, have a look at this:

        $this->mainForm->fields['tour_type_id']->renderRowFunction = function($row) {
            return [
                'value' => $row->id,
                'title' => strtoupper($row->getTitle()).' ('.$row->get('activity_id').')',
                'icon'  => 'calendar',
            ];
        };

ddrefactor1

   $this->mainForm->addField('test', [
            'DropDown',
            'values' => [
                1 => 'BLa',
                2 => 'dfdfd',
            ],
            'renderRowFunction' => function($value, $key) {
                 return [
                    'value' => $key,
                    'title' => strtoupper($value),
                    'icon'  => strpos('BLa', $value) !== false ? 'calendar' : 'money',
                ];
            },
        ]);

ddrefactor2

I didnt write any tests or documentation yet as I am not sure if what I did is the ATK way. I like it like this. Please give me some feedback and if you think this is fine I will provide documentation.

@romaninsh romaninsh added the Documentation 📚 Undocumented features label May 21, 2019
@romaninsh
Copy link
Member

Sorry for not mentioning it right away - some examples in demo/ would be also nice.

Here is a spot for docs: https://github.com/atk4/ui/blob/develop/docs/field.rst#dropdown

(although it's really sparse there)

Finally - didn't we switch from "DropDown" to "Lookup" as a default dropdown implementation?

@PhilippGrashoff
Copy link
Collaborator Author

HI Romans,
yes, for hasOne() relations the standard UI has be switched to Lookup. But I guess 'normal' DropDown' will continue to be there? :)

@romaninsh
Copy link
Member

@PhilippGrashoff actually, me and @ibelar made Lookup to be a copy of Dropdown then enhanced it.

The idea was to remove DropDown but then we forgot 😢

@romaninsh
Copy link
Member

#637
#551

@romaninsh
Copy link
Member

We can probably move one of those two into an add-on.

@romaninsh romaninsh added the hangout agenda 🔈 Will discuss on next hangout label May 21, 2019
@PhilippGrashoff
Copy link
Collaborator Author

After a quick read of Lookup code:

  1. seems like a new version of AutoComplete, always working with a Query to the server, right?
  2. seems to only work with a model, not with values property as Dropdown?

To me it looks more as if Lookup was to replace AutoComplete, not Dropdown.

@PhilippGrashoff
Copy link
Collaborator Author

+1 for keeping dropdown, as

  1. it renders all items right away without an additional request to the server
  2. custom values can be defined using $values properties

@ibelar
Copy link
Contributor

ibelar commented May 22, 2019

@PhilippGrashoff is right. New Lookup was for replacing Autocomplete. We should keep Dropdown.

@romaninsh
Copy link
Member

Sorry, i was confused, we're obsoleting AutoComplete, not Dropdown.

Copy link
Member

@romaninsh romaninsh left a comment

Choose a reason for hiding this comment

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

good!

@romaninsh romaninsh removed the hangout agenda 🔈 Will discuss on next hangout label May 23, 2019
Copy link
Collaborator

@gowrav-vishwakarma gowrav-vishwakarma left a comment

Choose a reason for hiding this comment

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

Looks okay, just need documentation and demos

@PhilippGrashoff
Copy link
Collaborator Author

Added Docs, but am too stupid to get the markup right. Will read into it.

dropdown-plus.php existed, but was not linked in demo menu
@PhilippGrashoff
Copy link
Collaborator Author

Hi, I also added Demos, but didnt test them yet as I am not sure how to do this best. Also, the formatting of the docs aint correct in some places.

@DarkSide666 DarkSide666 self-requested a review May 27, 2019 16:58
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.

Tests fail:
PHP Fatal error: Cannot use empty array elements in arrays in /home/travis/build/atk4/ui/demos/dropdown-plus.php on line 35

@romaninsh romaninsh merged commit ec078d9 into atk4:develop Jun 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants