An opinionated extension package for Laravel Orchid to extend its table handling capabilities, and some further useful helper methods.

Overview

OrchidTables

Latest Version on Packagist Total Downloads Build Status StyleCI PHP Composer

An opinionated extension package for Laravel Orchid to extend its table handling capabilities, and some further useful helper methods.

Installation

Via Composer

$ composer require lintaba/orchid-tables

Usage

This package adds the following new shiny things:

Screen\TdChecklist

Checklist with select-all support. Can select range by pressing shift.

Usage:

use Lintaba\OrchidTables\Screen\TDChecklist;

class UserTable extends Table {
//...
    public function columns(): array
    {
        return [
            TDChecklist::make(),
            //...
            TD::make('id'),
        ];
    }
}

TDChecklist::make($name = 'checkbox')

->checkboxSet(key,value)

and almost everything available thats available on TD.

Without further configuration it sends the following:

checkbox[] = 1

The provided collection's items must have a getKey():int|string method, which provides the value for the checkbox.

By default the checklist belongs to the main form, which is linked to most of the action buttons, therefore having a Button within Screen@commandBar() will send the selection list too. However the modals are having their own forms, so it will not be included there. Currently only one form is supported. (Feel free to open a ticket if you need support for multiple forms/modals.)

Changing the form of the list to a modal:

class UserTable extends Table {
//...
    public function commandBar(): array {
        return [
            ModalToggle::make("my modal")->modal('myModal'),
        ];
    }
    public function columns(): array {
        return [
            TD::Checklist::make()->checkboxSet('form','screen-modal-form-myModal'),
        ];
    }

Redirecting back with error/success can keep the current selection:

class UserScreen extends Screen {
//...
    public function activateUsers(Request $request){
        Alert::message('Selected item count is still ' . count($request->get('checkbox', []) ) );
        $request->flash();
    }

Can mixins:

These are mixed into most of the orchid's makeable and visible things.

  • TD
  • Field
  • LayoutFactory

can(string[] $permissions...)

Hides the field if the current user has none of the listed permissions.

Shows only if a previous canSee didn't hide it, and if any of the listed permissions are given to the user.

canAll(string[] $permissions...)

Hides the field if the current user has none of the listed permissions.

Shows only if a previous canSee didn't hide it, and if all of the listed permissions are given to the user.

Both can and canAll internally usese canSee, so chaining another canSee after a can will invalidate the permission check.

Using a non-existing permission throws an easily fixable exception during development mode, to help avoid bugs.

Layout mixins:

html

html(string|callable $content): self

Makes a Layout component, that renders the provided html string (or the value of it, when its a closure.)

Cell mixins:

date

date(bool $withHumanReadable = true, string $format = null): self

Formats a date string or carbon date to human readable. Format defaults to config('orchid-tables.date_format'), config('app.date_format'), or Y?-m-d H:i. (omits year if its the current year.)

num

num(int $decimals = 0,
        string $suffix = null,
        string $decimalSeparator = ',',
        string $thousandsSeparator = DataHelpers::NBSP): self

Formats a numeric value to a more readable / convinient format.

  • Sets the decimals
  • May add a suffix, delimitered with a non-breakable space (nbsp), which guaranteed not to be broken to multiple lines.

example:

TD::make('size')->num(2,'m²')

limit

limit(int $max = 100, string $end = '...')

Keeps the text under the given maximum character count. If its longer, replaces the end with ... (or anything specified in end).

bool()

Shows a green tick, or a red cross, depending on if the column's value has a truthy or falsy value.

Truthy Falsy

keyValues()

keyValues(int $maxDepth = 3)

Shows a key-value structure (using dl/dt/dd) of a complex object / array / json entry.

Limits max depth, by default to 3.

link($href, $segments = null)

Makes a link/button to the target location. Both $href and $segments can be a closure, or a value.

Example:

// article: { user: { id: 42, first: "John", last: "Doe", __toString:"John Doe" } }
TD::make('user')->link(function(User $user){return route('user.show',$user->id)}),
//<a href="/users/show/42">John Doe</a>

TD::make('user')->link('user.create',['last','first'])
//<a href="/users/show/42">Doe<br> John</a>

renderable()

Tries to render a model, using one of the following:

  • its value, when its a scalar or null
  • as a Personable Persona
  • ->presenter() to get a Personable Persona
  • value from ->display()
  • its name, slug, or class@id as last resort.

Formatted exportable cells

These helper methods are useful with formatted excel exports. By default its not activated, as it adds an extra overhead, which is usually not being used. To activate, you can either set it up in the configuration:

# config/orchid-tables.php
        'cell'   => Mixins\CellExportFormattableMixin::class,

or call the following:

\Lintaba\OrchidTables\Facades\OrchidTables::mixinTdExportFormattables();

Augmented methods:

  • date
    • Formatted as date
  • num
    • Formatted as the provided number format, but stored as a number.
  • keyValues
    • Stored as json in the output

Furthermore the following helper methods are available:

####notExportable($notExportable = true): self Sets a column to be non-exported.

Its advised to set it on ie. action buttons.

####setStyle($style): self

A callback that formats the given row, or the actual formatting. Can be called multiple times, and the result will be merged. Callback can either return with a phpexcel formatted array, or one (or multiple merged together) from the followings:

  • ExportStyles::FORMAT_NONE

  • ExportStyles::FORMAT_TEXT

  • ExportStyles::FORMAT_HUF

  • ExportStyles::FORMAT_USD

  • ExportStyles::FORMAT_EUR

  • ExportStyles::FORMAT_PCS

  • ExportStyles::FORMAT_DATE

  • ExportStyles::FORMAT_DATETIME

  • ExportStyles::FORMAT_TIME

  • ExportStyles::FORMAT_BOLD

  • ExportStyles::FORMAT_ITALIC

  • ExportStyles::FORMAT_UNDERLINED

  • ExportStyles::FORMAT_LEFT

  • ExportStyles::FORMAT_RIGHT

  • ExportStyles::FORMAT_CENTER

  • ExportStyles::FORMAT_TOP

  • ExportStyles::FORMAT_MIDDLE

  • ExportStyles::FORMAT_BOTTOM

  • ExportStyles::FORMAT_RED

  • ExportStyles::FORMAT_GREEN

  • ExportStyles::FORMAT_YELLOW

  • ExportStyles::FORMAT_BLUE

  • ExportStyles::FORMAT_BLACK

####exportRender(callable $callback): self

Sets the renderer method for excel. Input is the field's value. Must return with a string or stringable.

Example:

TD::make('name')->exportRender(function(string $value, User $entry, int $rowNum){
    return Str::upper($value).' #'.$entry->id.' (row-'.$rowNum.')';
})

QuickExport

Using Lintaba\OrchidTables\Exports\QuickExport its possible to set up data exports quickly, without creating extra classes, just by building on an already existing table.

Quick export example:

use Lintaba\OrchidTables\Exports\QuickExport;
use Orchid\Screen\Actions\Button;
use Orchid\Screen\Screen;

class UsersTableScreen extends Screen
{

    public function commandBar(): array
    {
        return [
            Button::make('export')->method('export')->rawClick(),
        ];
    }

    public function export(){
        $query = User::filters()->defaultSort('id', 'desc');
        return (new QuickExport($query, UserTable::class))->download('userExport.xlsx');
    }
//...

TableAdvanced

The extended table layout, \Lintaba\OrchidTables\Screen\TableAdvanced adds the following functionality:

rowClass($row)

Calculates classlist based on a row. Useful for coloring a whole row.

rowLink($row)

Makes a row clickable.

Example:

use Lintaba\OrchidTables\Screen\TableAdvanced

class UserTable extends TableAdvanced
{

    public function rowClass(User $row)
    {
        return $row->active ? 'bg-success' : 'bg-danger';
    }

    public function rowLink(User $row)
    {
        return route('admin.users.show',$row);
    }
//...

Customization

Run the following command to publish the configuration:

php artisan vendor:publish --tag="orchid-tables.config"
# /config/orchid-tables.php
use Lintaba\OrchidTables\Mixins;

return [
    'mixins' => [
        'can'    => Mixins\CanMixin::class,
        'cell'   => Mixins\CellMixin::class,
        'layout' => Mixins\LayoutMixin::class,
    ],

    'date_format' => null,
];

Extend or create your overwrites, based on the existing mixins, like \Lintaba\OrchidTables\CellMixin. You can turn on or off any of these mixins by setting their key to null.

Change log

Please see the changelog for more information on what has changed recently.

Testing

$ composer test

Contributing

Please see contributing.md and open tickets for details and a todolist.

Credits

License

MIT. Please see the license file for more information.

Comments
  • After installing the package (executing the composer require lintaba/orchid-tables command), errors appeared in the console

    After installing the package (executing the composer require lintaba/orchid-tables command), errors appeared in the console

    Expected Behavior

    Actual Behavior

    Steps to Reproduce the Problem

    1. installing the package executing the composer require lintaba/orchid-tables command, errors appeared in the console
    2. And now I can't execute any command in the console, even php artisan -v

    Screenshots (if applicable)

    image

    Specifications

    • ORCHID Platform Version: 12.3.0
    • Laravel Version: 9.8.1
    • PHP Version: 8.1
    • Database Version: 8.0.27

    Other Notes

    It's a very strange situation, composer itself is also the latest version, I always update everything. Help solve the problem.

    bug good first issue 
    opened by EduardRe 6
  • widened builder compatibility

    widened builder compatibility

    Fixes #

    Proposed Changes

    • QuickExport supports collections as input, besides querybuilders
    • Moved some cell mixins to cell level: getName, getTitle, isExportable, notExportable, exportGetValue, exportRender are always available on TD.
    opened by lintaba 0
  • Fix some incompatibilities, and pending check from the original author

    Fix some incompatibilities, and pending check from the original author

    Fixes #

    Proposed Changes

    • Change requirement of Orchid version from 12 to 13 in the composer.json file
    • Change phpunit version from ~9 to ^9
    • Add some section at readme file to explain that Orchid 13 don't support anymore jQuery and how to keep working with it redirecting to Orchid Upgrade Guide documentation
    opened by cryptodev4 0
  • Control multiple modals with one Checkbox

    Control multiple modals with one Checkbox

    Expected Behavior

    Control multiple modals with 1 checkbox-list

    Actual Behavior

    The same documentation says: "Orchid Tables only supports one modal at time, feel free to open ticket to control multiple modals"

    Steps to Reproduce the Problem

    1. Add modal 1
    2. Add modal 2
    3. Add 1 checkbox to control both modals

    Screenshots (if applicable)

    image

    Specifications

    • ORCHID Platform Version: 12.6
    • Laravel Version: 9
    • PHP Version: 8
    • Database Version: MariaDB 10.2

    Other Notes

    good first issue hacktoberfest 
    opened by cryptodev4 0
  • Orchid 13 support

    Orchid 13 support

    Expected Behavior

    Hi I want to install Orchid-Tables on Orchid 13

    Actual Behavior

    I was trying to add Orchid-Tables by Lintaba on Orchid latest version (13) but I have a dependency error, does Orchid-Tables will support Orchid 13 version?

    Steps to Reproduce the Problem

    1. Create a project with Laravel 9
    2. Install Orchid 13
    3. Try to install Orchid-Tables 1.1.1

    Screenshots (if applicable)

    image

    Specifications

    • ORCHID Platform Version: 13
    • Laravel Version: 9
    • PHP Version: 8.1
    • Database Version: MariaDB 10.2

    Other Notes

    hacktoberfest 
    opened by cryptodev4 10
Releases(1.1.1)
  • 1.0.3(Apr 25, 2022)

    Full Changelog: https://github.com/lintaba/orchid-tables/compare/1.0.2...1.0.3

    Restored orchid dependencies. This minor will stick with orchid/platform:^10.0, and a new minor may have support for 11+.

    Source code(tar.gz)
    Source code(zip)
  • 1.0.2(Apr 24, 2022)

  • 1.0.1(Feb 1, 2022)

    What's Changed

    • widened builder compatibility by @lintaba in https://github.com/lintaba/orchid-tables/pull/2

    Full Changelog: https://github.com/lintaba/orchid-tables/compare/1.0.0...1.0.1

    Source code(tar.gz)
    Source code(zip)
  • 1.0.0(Jan 28, 2022)

    Initial release

    What's Changed

    • Apply fixes from StyleCI by @lintaba in https://github.com/lintaba/orchid-tables/pull/1

    New Contributors

    • @lintaba made their first contribution in https://github.com/lintaba/orchid-tables/pull/1

    Full Changelog: https://github.com/lintaba/orchid-tables/commits/1.0.0

    Source code(tar.gz)
    Source code(zip)
Owner
null
Magento 2 Blog Extension is a better blog extension for Magento 2 platform. These include all useful features of Wordpress CMS

Magento 2 Blog extension FREE Magento 2 Better Blog by Mageplaza is integrated right into the Magento backend so you can manage your blog and your e-c

Mageplaza 113 Dec 14, 2022
The plugin generates posts/pages. Useful to generate millions of records in wp_posts table

KAGG Generator The plugin generates posts/pages. Useful to generate millions of records in wp_posts table. In WordPress development, sometimes it is n

Igor at KAGG Design 16 Jan 1, 2023
Simple opinionated PHP 8.1 enum helper for Laravel

Laravel Enum Helper This is an extension of the datomatic/enum-helper package based on Laravel Framework. The package consists on a LaravelEnumHelper

Datomatic 17 Jan 1, 2023
Smart File System - Use SmartFileInfo with useful methods that you need everyday

Smart File System - Use SmartFileInfo with useful methods that you need everyday

null 78 Dec 22, 2022
Simple opinionated framework agnostic PHP 8.1 enum helper

Enum Helper A simple and opinionated collections of PHP 8.1 enum helpers inspired by archtechx/enums and BenSampo/laravel-enum. This package is framew

Datomatic 52 Jan 1, 2023
Some useful hooks desigend by DMIT for WHMCS

whmcs-hooks Some useful hooks desigend by DMIT for WHMCS CancelSubscription.php Cancel Subscriptions (like PayPal) when perform refund/cancel/change g

DMIT, Inc. 6 Dec 14, 2022
Display some useful information in the reports module.

Useful information in the reports module : xclass, ajax, cliKeys, eID, general status of the system (encoding, DB, php vars...), hooks, compare local and TER extension (diff), used content type, used plugins, ExtDirect... It can really help you during migration or new existing project (to have a global reports of the system).

CERDAN Yohann 12 Aug 8, 2022
This is a simple Wrapper around the ZipArchive methods with some handy functions

Note I haven't updated this package in a long time except merging PRs. The last time I was using this package was with PHP5. I archived the repository

Nils Plaschke 845 Dec 13, 2022
This is a simple Wrapper around the ZipArchive methods with some handy functions

Note I haven't updated this package in a long time except merging PRs. The last time I was using this package was with PHP5. I archived the repository

Nils Plaschke 836 Jan 26, 2022
Immutable value object for IPv4 and IPv6 addresses, including helper methods and Doctrine support.

IP is an immutable value object for (both version 4 and 6) IP addresses. Several helper methods are provided for ranges, broadcast and network address

Darsyn 224 Dec 28, 2022
This extension links MediaWiki to phpBB's user table for authentication, and disallows the creation of new accounts in MediaWiki.

This extension links MediaWiki to phpBB's user table for authentication, and disallows the creation of new accounts in MediaWiki. Users must then log in to the wiki with their phpBB account.

Digitalroot Technologies 22 Feb 8, 2022
salah eddine bendyab 18 Aug 17, 2021
Allow multiple options for Magento 2 checkout layout. Provides capabilities to AB test checkout changes and more.

Aimes_CheckoutDesigns Features Please note: This module is currently still considered a proof of concept. This module provides the ability to change c

Rob Aimes 30 Aug 8, 2022
Magento 2 Module to add simple image resizing capabilities in all blocks and .phtml templates

Magento 2 Image Resizer Magento 2 Module to add simple image resizing capabilities in all blocks and .phtml templates Installation $ composer require

Stämpfli AG 88 Apr 18, 2022
The FileLocator library was created to provide file locating capabilities to a larger project

File Locator A simple file locator library. Summary The FileLocator library was created to provide file locating capabilities to a larger project. It

KHerGe - Archived Projects 20 Dec 22, 2021
Laravel Pint is an opinionated PHP code style fixer for minimalists.

Laravel Pint is an opinionated PHP code style fixer for minimalists. Pint is built on top of PHP-CS-Fixer and makes it simple to ensure that your code style stays clean and consistent.

The Laravel Framework 2.2k Jan 5, 2023
Generally, a graceful shutdown is preferable in the case of any OS that saves its state

Graceful Shutdown with PHP Generally, a graceful shutdown is preferable in the case of any OS that saves its state.

Leonardo Carmo 17 Oct 14, 2022
This project has reached its end-of-life (EOL).

EOL Notice This project has reached its end-of-life (EOL). README Requirements The supported Magento version is 1.9.x Features ajax navigation using h

Catalin Ciobanu 136 Apr 2, 2022