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

Implement "Multiformat" column decorator for table #408

Merged
merged 10 commits into from Mar 22, 2018

Conversation

Projects
None yet
2 participants
@romaninsh
Copy link
Member

romaninsh commented Mar 21, 2018

Implementation of Multiformat column for the table. It allows to use different formatters depending on cell value. Simple use:

    $table->addColumn('amount', ['Multiformat', 'callback'=>function($a, $b) {

        if($a['is_invoiced'] > 0) {
            return ['Link', 'invoice', ['invoice_id'=>'id']];
        } elseif (abs($a['is_refunded']) < 50) {
            return ['Template', 'Amount was <b>refunded</b>'];
        }

        return ['Money'];
    }]);

Screenshot does not really correspond to example above, but demonstrates 3 different decorators for a same column, including Link+Money, Money and Template.

screen shot 2018-03-21 at 17 00 16

  • Documentation: docs/table.rst
  • Demo: demos/table2.php
@codecov

This comment has been minimized.

Copy link

codecov bot commented Mar 21, 2018

Codecov Report

Merging #408 into develop will increase coverage by 0.24%.
The diff coverage is 90%.

Impacted file tree graph

@@              Coverage Diff              @@
##             develop     #408      +/-   ##
=============================================
+ Coverage      68.98%   69.23%   +0.24%     
- Complexity      1363     1376      +13     
=============================================
  Files             73       74       +1     
  Lines           3215     3254      +39     
=============================================
+ Hits            2218     2253      +35     
- Misses           997     1001       +4
Impacted Files Coverage Δ Complexity Δ
src/Grid.php 75.58% <100%> (ø) 36 <0> (ø) ⬇️
src/Template.php 69.72% <50%> (-0.19%) 83 <0> (+1)
src/TableColumn/Multiformat.php 91.89% <91.89%> (ø) 12 <12> (?)

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 a835ac7...d906e4f. Read the comment docs.

@romaninsh romaninsh requested a review from DarkSide666 Mar 21, 2018

@@ -3,33 +3,70 @@
date_default_timezone_set('UTC');
include 'init.php';
$app->add(['Header', 'Table with various headers', 'subHeader'=>'Demonstrates how you can add subheaders, footnotes and other insertions into your data table', 'icon'=>'table']);

This comment has been minimized.

@DarkSide666

DarkSide666 Mar 22, 2018

Member

table2 demo page is not included in left side menu.

This comment has been minimized.

@DarkSide666

DarkSide666 Mar 22, 2018

Member

also opening that demo page throws exception

Error: Class '\atk4\data\Field\Callback' not found (in C:\wamp64\www\git\atk\ui\vendor\atk4\core\src\FactoryTrait.php:153)
#0 C:\wamp64\www\git\atk\ui\vendor\atk4\data\src\Model.php(373): atk4\data\Model->factory(Array, Array, '\\atk4\\data\\Fiel...')
#1 C:\wamp64\www\git\atk\ui\demos\table2.php(49): atk4\data\Model->addField('amount_copy', Array)
#2 {main}

If it doesn't do that on your environment, then try running composer update

This comment has been minimized.

@romaninsh

romaninsh Mar 22, 2018

Member

fixed both.

@@ -0,0 +1,80 @@
<?php

This comment has been minimized.

@DarkSide666

DarkSide666 Mar 22, 2018

Member

Please add at least some type-hint comments for properties and methods :)

This comment has been minimized.

@romaninsh

romaninsh Mar 22, 2018

Member

adding..

romaninsh added some commits Mar 22, 2018

@romaninsh romaninsh merged commit b8085cc into develop Mar 22, 2018

9 checks passed

codeclimate All good!
Details
codeclimate/diff-coverage 89% (80% threshold)
Details
codeclimate/total-coverage 69% (0.2% change)
Details
codecov/patch 90% of diff hit (target 68.98%)
Details
codecov/project 69.23% (+0.24%) compared to a835ac7
Details
continuous-integration/styleci/pr The StyleCI analysis has passed
Details
continuous-integration/styleci/push The StyleCI analysis has passed
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details

@romaninsh romaninsh deleted the feature/add-multiformat-column branch Mar 22, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment