m-a-k-o/nova-custom-table-card 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

m-a-k-o/nova-custom-table-card

Composer 安装命令:

composer require m-a-k-o/nova-custom-table-card

包简介

Nova custom table card. Show your latest data (orders, posts,...) as card or data you prefer.

关键字:

README 文档

README

Simple Nova Card for Custom Tables

Simple card table with data of you choice.

It can be useful as latest order list or latest posts, ...

Nova Custom Table Card

This docs are only for v. > 2.*

In version 2 added: refresh (reload), possiblity to add id and classes to cells

In version 3: REMOVED refresh, fixed problem with multiple dashboards

Version 4: Add compatibility for Nova v. 4

Installation

You can install the package in to a Laravel app that uses Nova via composer:

composer require m-a-k-o/nova-custom-table-card

You must register the card with NovaServiceProvider.

// in app/Providers/NovaServiceProvder.php

// ...
public function cards()
{
    return [
        // ...

        // all the parameters are required excelpt title
        new \Mako\CustomTableCard\CustomTableCard(
            array $header, array $data, string $title, array $viewAll
        ),
    ];
}

Example of use:

// ...
public function cards()
{
    return [
        // ...

        // all the parameters are required
        new \Mako\CustomTableCard\CustomTableCard(
            [
                new \Mako\CustomTableCard\Table\Cell('Order Number'),
                // Set sortable to true in a header Cell to allow its column's sorting
                (new \Mako\CustomTableCard\Table\Cell('Price'))->sortable(true)->class('text-right'),
            ], // header
            [
                (new \Mako\CustomTableCard\Table\Row(
                    new \Mako\CustomTableCard\Table\Cell('2018091001'),
                    (new \Mako\CustomTableCard\Table\Cell('20.50'))->class('text-right')->id('price-2')
                ))->viewLink('/resources/orders/1'),
                (new \Mako\CustomTableCard\Table\Row(
                    new \Mako\CustomTableCard\Table\Cell('2018091002'),
                    (new \Mako\CustomTableCard\Table\Cell('201.25'))->class('text-right')->id('price-2')
                )),
            ], // data
            'Orders', // title
            ['label' => 'View All', 'link' => '/resources/orders'], // View All
        ),
    ];
}

or:

// ...
public function cards()
{
    return [
        // ...

        // all the parameters are required except title
        (new \Mako\CustomTableCard\CustomTableCard)
            ->header([
                new \Mako\CustomTableCard\Table\Cell('Order Number'),
                // Set sortable to true in a header Cell to allow its column's sorting
                (new \Mako\CustomTableCard\Table\Cell('Price'))->sortable(true)->class('text-right'),
            ])
            ->data([
                (new \Mako\CustomTableCard\Table\Row(
                    new \Mako\CustomTableCard\Table\Cell('2018091001'),
                    (new \Mako\CustomTableCard\Table\Cell('20.50'))->class('text-right')->id('price-2')
                ))->viewLink('/resources/orders/1'),
                (new \Mako\CustomTableCard\Table\Row(
                    new \Mako\CustomTableCard\Table\Cell('2018091002'),
                    (new \Mako\CustomTableCard\Table\Cell('201.25'))->class('text-right')->id('price-2')
                )),
            ])
            ->title('Orders')
            ->viewAll(['label' => 'View All', 'link' => '/resources/orders']),
    ];
}

or:

You can create your own class which will extend \Mako\CustomTableCard\CustomTableCard in Nova/Cards directory on example.

In this separate class you are able to fetch data from models in nice clean way.

<?php

namespace App\Nova\Cards;

use App\Models\Order;

class LatestOrders extends \Mako\CustomTableCard\CustomTableCard
{
    public function __construct()
    {
        $header = collect(['Date', 'Order Number', 'Status', 'Price', 'Name']);

        $this->title('Latest Orders');
        $this->viewAll(['label' => 'View All', 'link' => '/resources/orders']);

        // $orders = Order::all();
        // Data from you model
        $orders = collect([
            ['date' => '2018-12-01', 'order_number' => '2018120101', 'status' => 'Ordered', 'price' => '20.55', 'name' => 'John Doe'],
            ['date' => '2018-12-01', 'order_number' => '2018120101', 'status' => 'Ordered', 'price' => '20.55', 'name' => 'John Doe'],
            ['date' => '2018-12-01', 'order_number' => '2018120101', 'status' => 'Ordered', 'price' => '20.55', 'name' => 'John Doe'],
            ['date' => '2018-12-01', 'order_number' => '2018120101', 'status' => 'Ordered', 'price' => '20.55', 'name' => 'John Doe'],
            ['date' => '2018-12-01', 'order_number' => '2018120101', 'status' => 'Ordered', 'price' => '20.55', 'name' => 'John Doe'],
            ['date' => '2018-12-01', 'order_number' => '2018120101', 'status' => 'Ordered', 'price' => '20.55', 'name' => 'John Doe'],
        ]);

        $this->header($header->map(function($value) {
            // Make the Status column sortable
            return ($value === 'Status') ?
                (new \Mako\CustomTableCard\Table\Cell($value))->sortable(true) :
                new \Mako\CustomTableCard\Table\Cell($value);
        })->toArray());

        $this->data($orders->map(function($order) {
            return new \Mako\CustomTableCard\Table\Row(
                new \Mako\CustomTableCard\Table\Cell($order['date']),
                new \Mako\CustomTableCard\Table\Cell($order['order_number']),
                // Instead of alphabetically ordering the status, set a sortableData value for better representation
                (new \Mako\CustomTableCard\Table\Cell($order['status'])->sortableData($this->getStatusSortableData($order['status']))),
                new \Mako\CustomTableCard\Table\Cell($order['price']),
                new \Mako\CustomTableCard\Table\Cell($order['name'])
            );
        })->toArray());
    }

    private function getStatusSortableData (string $status) : int
    {
        switch ($status) {
            case 'Ordered':
                return 1;            
            default:
                return 0.
        } 
    }
}

Then register your custom class inside cards in NovaServiceProvider.php

protected function cards()
{
    return [
        ......
        new \App\Nova\Cards\LatestOrders,
     ];
 }

Note: If you don't specify view or view all, show icon will not be visible.

Table Style Customization

To show more data on your table, you can use the "tight" table style option designed to increase the visual density of your table rows.

protected function cards()
{
    return [
        ...
        \Mako\CustomTableCard\CustomTableCard::make(
            ...
        )->style('tight'),
     ];
 }

Or override the $style property on your custom class:

public $style = 'tight';

m-a-k-o/nova-custom-table-card 适用场景与选型建议

m-a-k-o/nova-custom-table-card 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 450.61k 次下载、GitHub Stars 达 45, 最近一次更新时间为 2018 年 08 月 26 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「nova」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 m-a-k-o/nova-custom-table-card 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 m-a-k-o/nova-custom-table-card 我们能提供哪些服务?
定制开发 / 二次开发

基于 m-a-k-o/nova-custom-table-card 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 450.61k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 46
  • 点击次数: 21
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 45
  • Watchers: 1
  • Forks: 31
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-08-26