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

Feature2/integrate actions #741

Merged
merged 17 commits into from
Jun 12, 2019
Merged

Feature2/integrate actions #741

merged 17 commits into from
Jun 12, 2019

Conversation

romaninsh
Copy link
Member

REMERGE of #701

Implements support for ATK Data Actions in ATK UI through Generic UI:

Implicit use in CRUD

$files->addAction(
    'import_files',
    [
        'args'=>['path'=>['type'=>'string','required'=>true]],
        'scope'=>atk4\data\UserAction\Action::NO_RECORDS
    ]
);

$files->addAction('download', function($m){ 
  file_get_contents($m['path']);
  $m->app->terminate(); 
} );

$crud->setModel($files);  // "Download" button will be next to each file

image

Explicit executor use

$app->add($executor = new \atk4\ui\ActionExecutor\ArgumentForm());

$executor->setAction($model->getAction('import_files'));

// optionally we can augment return handling
$executor->addHook(
  'afterExecute', 
  function($x, $ret) { return new \atk4\ui\jsToast('Files imported: '. $ret); }
);

image

TODO

  • CRUD should show actions with scope=NO_RECORDS and scope=ALL_RECORDS in menu. Clickable.
  • CRUD should enable "selectable" at least one action with scope=MULTIPLE_RECORDS exist. If clicked before items are selected, should show error.
  • CRUD should include actions automatically along with "edit" and "delete" with scope=SINGLE_RECORD
  • CRUD should support ability to specify which actions must be presented
  • We need some View that would display and execute single-item records.
  • Must support warning if action is dangerous
  • Must support output from the action
  • Support for default executor (will display form for missing arguments, then console with output)
  • Must support custom action executors
  • Support use of custom model for defining arguments
  • Respect action permissions. If action is not permitted for the user hide(or disable) control
  • Support for model-type arguments (single-record)

Explanation

Various UI elements will become aware of Model actions and will provide UI to invoke a corresponding PHP method. The "UserAction" class will provide meta-information on how the method should be called.

Use Cases

I'm collecting some of the potential use-cases here which can be solved by this PR:

Emailing Invoice

User has a CRUD of Invoices. He can click "Email Invoice" button on any client. Modal window will appear showing a Preview of a specific invoice. Two buttons below "Confirm" and "Cancel". Preview is generated by non-ui $action->preview callback. Actual emailing happens by invoking nun-ui $action->callback. Arguments for both are identical and in this case - empty.

Executor = Preview\HTML

Generate VAT report

User have to supply START and END date as arguments to a non-ui callback "generateVATReport". Arguments must be supplied by a user. No preview. When submitted, callback return model "VatReport" that was just generated.

We can use Hook of the executor, to properly redirect the user:

Executor = ArgumentForm

Big Red Button

This is a executor which displays a message along with a big red button. Will use name and description of the action. If button is clicked, action is executed.

Executor = Confirmation

@codecov
Copy link

codecov bot commented Jun 12, 2019

Codecov Report

Merging #741 into develop2 will decrease coverage by 1.12%.
The diff coverage is 1.21%.

Impacted file tree graph

@@              Coverage Diff               @@
##             develop2     #741      +/-   ##
==============================================
- Coverage        68.6%   67.48%   -1.13%     
- Complexity       2058     2092      +34     
==============================================
  Files             106      109       +3     
  Lines            4839     4921      +82     
==============================================
+ Hits             3320     3321       +1     
- Misses           1519     1600      +81
Impacted Files Coverage Δ Complexity Δ
src/App.php 72.8% <ø> (ø) 117 <0> (ø) ⬇️
src/ActionExecutor/ArgumentForm.php 0% <0%> (ø) 5 <5> (?)
src/ActionExecutor/Preview.php 0% <0%> (ø) 9 <9> (?)
src/Grid.php 69.87% <0%> (-3.54%) 66 <2> (+2)
src/ActionExecutor/Basic.php 0% <0%> (ø) 17 <17> (?)
src/CRUD.php 47.43% <50%> (+0.06%) 55 <0> (+1) ⬆️

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 809a39d...5dc36e6. Read the comment docs.

1 similar comment
@codecov
Copy link

codecov bot commented Jun 12, 2019

Codecov Report

Merging #741 into develop2 will decrease coverage by 1.12%.
The diff coverage is 1.21%.

Impacted file tree graph

@@              Coverage Diff               @@
##             develop2     #741      +/-   ##
==============================================
- Coverage        68.6%   67.48%   -1.13%     
- Complexity       2058     2092      +34     
==============================================
  Files             106      109       +3     
  Lines            4839     4921      +82     
==============================================
+ Hits             3320     3321       +1     
- Misses           1519     1600      +81
Impacted Files Coverage Δ Complexity Δ
src/App.php 72.8% <ø> (ø) 117 <0> (ø) ⬇️
src/ActionExecutor/ArgumentForm.php 0% <0%> (ø) 5 <5> (?)
src/ActionExecutor/Preview.php 0% <0%> (ø) 9 <9> (?)
src/Grid.php 69.87% <0%> (-3.54%) 66 <2> (+2)
src/ActionExecutor/Basic.php 0% <0%> (ø) 17 <17> (?)
src/CRUD.php 47.43% <50%> (+0.06%) 55 <0> (+1) ⬆️

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 809a39d...5dc36e6. Read the comment docs.

@romaninsh romaninsh merged commit 5dc36e6 into develop2 Jun 12, 2019
@mvorisek mvorisek deleted the feature2/integrate-actions branch May 11, 2021 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant