javer / influxdb-admin-bundle
Provides integration of InfluxDB ODM with SonataAdminBundle
Installs: 19 756
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 3
Forks: 1
Open Issues: 1
Type:symfony-bundle
Requires
- php: >=8.1
- javer/influxdb-odm: ^1.0.4
- javer/influxdb-odm-bundle: ^1.0
- sonata-project/admin-bundle: ^4.17
- sonata-project/form-extensions: ^1.15 || ^2.0
- symfony/config: ^5.4 || ^6.0 || ^7.0
- symfony/dependency-injection: ^5.4 || ^6.0 || ^7.0
- symfony/form: ^5.4 || ^6.0 || ^7.0
- symfony/http-kernel: ^5.4 || ^6.0 || ^7.0
- symfony/yaml: ^5.4 || ^6.0 || ^7.0
Requires (Dev)
- phpstan/phpstan: ^1.0
- squizlabs/php_codesniffer: 3.8.*
- swivl/php-coding-standard: ^1.4
Conflicts
- sonata-project/exporter: <2.8.0
README
This bundle integrates the InfluxDB Object Document Mapper (ODM) library into SonataAdminBundle so that you can persist and retrieve objects to and from InfluxDB.
Installation
Make sure Composer is installed globally, as explained in the installation chapter of the Composer documentation.
Applications that use Symfony Flex
Open a command console, enter your project directory and execute:
$ composer require javer/influxdb-admin-bundle
Applications that don't use Symfony Flex
Step 1: Download the Bundle
Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:
$ composer require javer/influxdb-admin-bundle
Step 2: Enable the Bundle
Then, enable the bundle by adding it to the list of registered bundles
in the config/bundles.php
file of your project:
// config/bundles.php return [ // ... Javer\InfluxDB\AdminBundle\JaverInfluxDBAdminBundle::class => ['all' => true], ];
Configuration
Full configuration options:
javer_influx_db_admin: templates: form: - '@SonataAdmin/Form/form_admin_fields.html.twig' filter: - '@SonataAdmin/Form/filter_admin_fields.html.twig' types: list: array: "@SonataAdmin/CRUD/list_array.html.twig" boolean: "@SonataAdmin/CRUD/list_boolean.html.twig" date: "@SonataAdmin/CRUD/list_date.html.twig" time: "@SonataAdmin/CRUD/list_time.html.twig" datetime: "@SonataAdmin/CRUD/list_datetime.html.twig" text: "@SonataAdmin/CRUD/base_list_field.html.twig" trans: "@SonataAdmin/CRUD/list_trans.html.twig" string: "@SonataAdmin/CRUD/base_list_field.html.twig" smallint: "@SonataAdmin/CRUD/base_list_field.html.twig" bigint: "@SonataAdmin/CRUD/base_list_field.html.twig" integer: "@SonataAdmin/CRUD/base_list_field.html.twig" decimal: "@SonataAdmin/CRUD/base_list_field.html.twig" identifier: "@SonataAdmin/CRUD/base_list_field.html.twig" show: array: "@SonataAdmin/CRUD/show_array.html.twig" boolean: "@SonataAdmin/CRUD/show_boolean.html.twig" date: "@SonataAdmin/CRUD/show_date.html.twig" time: "@SonataAdmin/CRUD/show_time.html.twig" datetime: "@SonataAdmin/CRUD/show_datetime.html.twig" text: "@SonataAdmin/CRUD/base_show_field.html.twig" trans: "@SonataAdmin/CRUD/show_trans.html.twig" string: "@SonataAdmin/CRUD/base_show_field.html.twig" smallint: "@SonataAdmin/CRUD/base_show_field.html.twig" bigint: "@SonataAdmin/CRUD/base_show_field.html.twig" integer: "@SonataAdmin/CRUD/base_show_field.html.twig" decimal: "@SonataAdmin/CRUD/base_show_field.html.twig"
Admin class definition
Example of CpuLoadAdmin
definition:
# config/services.yaml services: acme.admin.cpu_load: class: App\Admin\CpuLoadAdmin arguments: [ ~, App\Measurement\CpuLoad, ~ ] tags: - { name: sonata.admin, manager_type: influxdb, label: 'CPU Load', pager_type: simple }
Please note that you must use influxdb
as manager_type
to work with InfluxDB measurement class.
Pager pager_type
can be either default
or simple
.
Example of CpuLoad
measurement class:
// src/Measurement/CpuLoad.php namespace App\Measurement; use Javer\InfluxDB\ODM\Mapping\Annotations as InfluxDB; /** * @InfluxDB\Measurement(name="cpu_load") */ class CpuLoad { /** * @InfluxDB\Timestamp(precision="u") */ private ?\DateTime $time = null; /** * @InfluxDB\Tag(name="server_id", type="integer") */ private ?int $serverId = null; /** * @InfluxDB\Tag(name="core_number", type="integer") */ private ?int $coreNumber = null; /** * @InfluxDB\Field(name="load", type="float") */ private ?float $load = null; // ...getters and setters }
Example of CpuLoadAdmin
class:
namespace App\Admin; use Sonata\AdminBundle\Admin\AbstractAdmin; class CpuLoadAdmin extends AbstractAdmin { protected function generateBaseRouteName(bool $isChildAdmin = false): string { return 'cpu_load'; } protected function generateBaseRoutePattern(bool $isChildAdmin = false): string { return 'cpu_load'; } protected function configureListFields(ListMapper $list): void { // ... } protected function configureDatagridFilters(DatagridMapper $filter): void { // ... } protected function configureShowFields(ShowMapper $show): void { // ... } protected function configureFormFields(FormMapper $form): void { // ... } }
Please note that you must explicitly implement generateBaseRouteName()
and generateBaseRoutePattern()
because they results cannot detected automatically from the measurement class name.
List field definition
These fields are used to display the information inside the list table.
Example
namespace App\Admin; use Sonata\AdminBundle\Admin\AbstractAdmin; use Sonata\AdminBundle\Datagrid\ListMapper; use Sonata\AdminBundle\FieldDescription\FieldDescriptionInterface; class CpuLoadAdmin extends AbstractAdmin { protected function configureListFields(ListMapper $list): void { $list ->addIdentifier('time', FieldDescriptionInterface::TYPE_DATETIME, [ 'format' => 'Y-m-d H:i:s.u', ]) ->add('serverId') ->add('load') ->add(ListMapper::NAME_ACTIONS, ListMapper::TYPE_ACTIONS, [ 'actions' => [ 'show' => [], 'edit' => [], 'delete' => [], ], ]); } }
Available types
The most important option for each field is the type
. The available types include:
- datetime (
FieldDescriptionInterface::TYPE_DATETIME
) - boolean (
FieldDescriptionInterface::TYPE_BOOLEAN
) - integer (
FieldDescriptionInterface::TYPE_INTEGER
) - float (
FieldDescriptionInterface::TYPE_FLOAT
) - string (
FieldDescriptionInterface::TYPE_STRING
)
If no type is set, the Admin
class will use the type defined in the doctrine mapping definition.
Filter field definition
These fields are displayed inside the filter box. They allow you to filter the list of entities by a number of different methods.
Example
namespace App\Admin; use Javer\InfluxDB\AdminBundle\Filter\DateTimeRangeFilter; use Sonata\AdminBundle\Admin\AbstractAdmin; use Sonata\AdminBundle\Datagrid\DatagridMapper; class CpuLoadAdmin extends AbstractAdmin { protected function configureDatagridFilters(DatagridMapper $filter): void { $filter ->add('time', DateTimeRangeFilter::class) ->add('serverId'); } }
Available types
The most important option for each filter is the type
. The available types from namespace Javer\InfluxDB\AdminBundle\Filter
are:
- BooleanFilter
- NumberFilter
- StringFilter
- ChoiceFilter
- CallbackFilter
- DateFilter
- DateTimeFilter
- DateRangeFilter
- DateTimeRangeFilter
Form field definition
These fields are used to edit data on the edit page.
Example
namespace App\Admin; use Sonata\AdminBundle\Admin\AbstractAdmin; use Sonata\AdminBundle\Form\FormMapper; class CpuLoadAdmin extends AbstractAdmin { protected function configureFormFields(FormMapper $form): void { $form ->add('serverId') ->add('load'); } }
Available types
- checkbox
- integer
- text
- choice
- datetime
If no type is set, the Admin
class will use the one set in the doctrine mapping definition.
InfluxDB Proxy Query
The ProxyQuery
object is used to add missing features from the original Doctrine Query builder:
use Javer\InfluxDB\AdminBundle\Datagrid\ProxyQuery; $query = $this->measurementManager->createQuery(); $proxyQuery = new ProxyQuery($query); $proxyQuery->setSortBy('time'); $proxyQuery->setMaxResults(10); $results = $proxyQuery->execute();