demency/pulse-field

A Laravel Nova field for Trend indexing.

Installs: 203

Dependents: 0

Suggesters: 0

Security: 0

Stars: 2

Watchers: 2

Forks: 2

Open Issues: 3

Language:JavaScript

1.3.0 2020-06-29 16:37 UTC

This package is auto-updated.

Last update: 2020-09-30 14:38:52 UTC


README

This field allows you to add a trend metric to the index and details of a resource.

Example

Example

Requirements

This package requires:

  • PHP ^7.3.
  • Laravel Nova ^2.6.1.

Installation

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

composer require demency/pulse-field

Usage

Add the following code in your own resource implementation:

<?php

...

class YourResource extends Resource {

    ...

    public function fields(NovaRequest $request)
    {
        // Replace this variable with your own trend.
        $trend = (new YourOwnTrendClass());

        return [
            ...

            // Are you ready?
            // --------------
            // 1. Add field implementation.
            // 2. Set trend instance as meta.
            // 3. Use first range or specify directly the range.
            // 4. Add title for pulse unit, default is "Times"
            Pulse::make(__('Pulse'), 'id')
                ->withMeta([
                    "trend" => $trend,
                    "range" => array_key_first($trend->ranges()),
                    "title" => __("Executions")
                ]),
        ];
    }

Translations

The following strings are available for translation:

String Description
Times If you dont set title meta data, this will fallback using "Times" string as pulse unit.
Waiting for data If trend calculation returns a list with zero values, the component will be rendered using "Waiting for data" text.

Example JSON

// Add this line on your own i18n file... 
// in my case /resources/lang/vendor/nova/es.json
{
    "Waiting for data": "Esperando información",
    "Times": "Veces"
}

To-do

  • Add details view implementation.

Changelog

1.1.0

  • Now this package support details view.

1.0.0

  • Recently published, currently this package can be used only for indexing purpose.

Disclaimer

This package isn't tested. Feel free to make PR with improvements.