浏览代码

Se crea admin y controller para Kea

Maxi Schvindt 7 年之前
父节点
当前提交
c751de7de7

+ 6 - 0
app/config/roles.yml

@@ -52,6 +52,12 @@ security:
         ROLE_SONATA_TEMPLATE_EDITOR: [ROLE_SONATA_TEMPLATE_READER, ROLE_SONATA_ADMIN_TEMPLATE_CREATE, ROLE_SONATA_ADMIN_TEMPLATE_EDIT]
         ROLE_SONATA_TEMPLATE_ADMIN: [ROLE_SONATA_TEMPLATE_EDITOR, ROLE_SONATA_ADMIN_TEMPLATE_DELETE, ROLE_SONATA_ADMIN_TEMPLATE_EXPORT]
 
+        # KEA
+        ROLE_SONATA_KEA_CONFIG_READER: [ROLE_ADMIN, ROLE_SONATA_ADMIN_KEA_CONFIG_LIST, ROLE_SONATA_ADMIN_KEA_CONFIG_VIEW]
+        ROLE_SONATA_KEA_CONFIG_EDITOR: [ROLE_SONATA_KEA_CONFIG_READER, ROLE_SONATA_ADMIN_KEA_CONFIG_CREATE, ROLE_SONATA_ADMIN_KEA_CONFIG_EDIT]
+        ROLE_SONATA_KEA_CONFIG_ADMIN: [ROLE_SONATA_KEA_CONFIG_EDITOR, ROLE_SONATA_ADMIN_KEA_CONFIG_DELETE, ROLE_SONATA_ADMIN_KEA_CONFIG_EXPORT]
+
         ROLE_ADMIN_TENANCIES: ROLE_ADMIN_TENANCIES
         ROLE_ADMIN: [ROLE_USER, ROLE_SONATA_ADMIN]
         ROLE_SUPER_ADMIN: [ROLE_ADMIN, ROLE_USER_CREATE, ROLE_ADMIN_TENANCIES, ROLE_ALLOWED_TO_SWITCH]
+

+ 5 - 0
app/config/routing.yml

@@ -13,6 +13,10 @@ dhcp:
     type:     annotation
     prefix:   /
 
+KeaBundle:
+    resource: "@KeaBundle/Resources/config/routing/admin.xml"
+    prefix: /
+
 i_pv4_sub_net_api:
     resource: "@IPv4Bundle/Controller/REST/SubNetRESTController.php"
     type:   rest
@@ -97,3 +101,4 @@ _sonata:
 admin_tenancy_change_tenancy_global_ajax:
     path: changeTenancyAjaxAction
     defaults: { _controller: BaseAdminBundle:RedirectionAjax:changeTenancyAjax }
+

+ 69 - 0
src/KeaBundle/Admin/ConfigAdmin.php

@@ -0,0 +1,69 @@
+<?php
+
+namespace KeaBundle\Admin;
+
+use Base\AdminBundle\Admin\BaseAdmin;
+use Sonata\AdminBundle\Datagrid\DatagridMapper;
+use Sonata\AdminBundle\Datagrid\ListMapper;
+use Sonata\AdminBundle\Form\FormMapper;
+use Sonata\AdminBundle\Show\ShowMapper;
+
+class ConfigAdmin extends BaseAdmin
+{
+    /**
+     * @param DatagridMapper $datagridMapper
+     */
+    protected function configureDatagridFilters(DatagridMapper $datagridMapper)
+    {
+        $datagridMapper
+            ->add('description')
+            ->add('dhcp')
+            ->add('template')
+        ;
+    }
+
+    /**
+     * @param ListMapper $listMapper
+     */
+    protected function configureListFields(ListMapper $listMapper)
+    {
+        $listMapper
+            ->add('id')
+            ->add('dhcp')
+            ->add('template')
+            ->add('created')
+            ->add('_action', null, array(
+                'actions' => array(
+                    'show' => array(),
+                    'edit' => array(),
+                    'delete' => array(),
+                ),
+            ))
+        ;
+    }
+
+    /**
+     * @param FormMapper $formMapper
+     */
+    protected function configureFormFields(FormMapper $formMapper)
+    {
+        $formMapper
+            ->add('dhcp')
+            ->add('description')
+            ->add('template')
+        ;
+    }
+
+    /**
+     * @param ShowMapper $showMapper
+     */
+    protected function configureShowFields(ShowMapper $showMapper)
+    {
+        $showMapper
+            ->add('dhcp')
+            ->add('description')
+            ->add('created')
+            ->add('template')
+        ;
+    }
+}

+ 42 - 0
src/KeaBundle/Controller/ConfigController.php

@@ -0,0 +1,42 @@
+<?php
+
+namespace KeaBundle\Controller;
+
+use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
+use Symfony\Bundle\FrameworkBundle\Controller\Controller;
+use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\HttpFoundation\JsonResponse;
+use Symfony\Component\HttpFoundation\Response;
+
+use DHCPBundle\Entity\DHCP;
+use KeaBundle\Entity\Config;
+
+use Symfony\Component\Form\Extension\Core\Type\TextType;
+use Symfony\Component\Form\Extension\Core\Type\DateType;
+use Symfony\Component\Form\Extension\Core\Type\SubmitType;
+use WebserviceBundle\Form\Type\RemoteClientType;
+use FOS\RestBundle\Controller\Annotations\RouteResource;
+
+/**
+ * Config controller.
+ * @RouteResource("Kea")
+ */
+class ConfigController extends Controller
+{
+
+    public function getAction() 
+    {
+        print_r("getAction");
+        die;
+    }
+
+    public function setAction() 
+    {
+        print_r("setAction");
+        die;
+    }
+
+    
+
+    
+}

+ 165 - 0
src/KeaBundle/Entity/Config.php

@@ -0,0 +1,165 @@
+<?php
+
+namespace KeaBundle\Entity;
+
+use Doctrine\ORM\Mapping as ORM;
+use JMS\Serializer\Annotation as JMS;
+use Symfony\Component\Validator\Constraints as Assert;
+use Gedmo\Mapping\Annotation as Gedmo;
+
+/**
+ * Config
+ *
+ * @ORM\Table
+ * @ORM\Entity
+ */
+class Config
+{
+
+    /**
+     * @var int
+     *
+     * @ORM\Column(name="id", type="integer")
+     * @ORM\Id
+     * @ORM\GeneratedValue(strategy="AUTO")
+     */
+    private $id;
+
+    /**
+     * @var string
+     *
+     * @ORM\Column(type="string", length=255)
+     */
+    private $description;
+
+    /**
+     * @ORM\ManyToOne(targetEntity="\DHCPBundle\Entity\DHCP", inversedBy="configs", fetch="EXTRA_LAZY")
+     * @ORM\JoinColumn(onDelete="SET NULL")
+     *
+     * @JMS\MaxDepth(1)
+     */
+    private $dhcp;
+
+    /**
+     * @var text
+     *
+     * @ORM\Column(type="text", nullable=false)
+     */
+    protected $template;
+    
+    /**
+     * @Gedmo\Timestampable(on="create")
+     * @ORM\Column(type="datetime")
+     */
+    protected $created;
+
+    /**
+    * @return string
+    */
+    public function __toString()
+    {
+        return "Config KEA";
+    }
+
+    /**
+     * Get id
+     *
+     * @return int
+     */
+    public function getId()
+    {
+        return $this->id;
+    }
+
+    /**
+     * Set description
+     *
+     * @param string $description
+     *
+     * @return Config
+     */
+    public function setDescription($description)
+    {
+        $this->description = $description;
+
+        return $this;
+    }
+
+    /**
+     * Get description
+     *
+     * @return string
+     */
+    public function getDescription()
+    {
+        return $this->description;
+    }
+
+    /**
+     * Set template
+     *
+     * @param text $template
+     *
+     * @return Config
+     */
+    public function setTemplate($template)
+    {
+        $this->template = $template;
+
+        return $this;
+    }
+
+    /**
+     * Get template
+     *
+     * @return text
+     */
+    public function getTemplate()
+    {
+        return $this->template;
+    }
+
+    /**
+     * @return DHCP
+     */
+    public function getDhcp()
+    {
+        return $this->dhcp;
+    }
+
+    /**
+     * @param DHCP $dhcp
+     *
+     * @return Config
+     */
+    public function setDhcp($dhcp)
+    {
+        $this->dhcp = $dhcp;
+
+        return $this;
+    }
+
+    /**
+     * Get created
+     *
+     * @return \DateTime
+     */
+    public function getCreated()
+    {
+        return $this->created;
+    }
+
+    /**
+     * Set created
+     *
+     * @param \DateTime
+     *
+     * @return Config
+     */
+    public function setCreated($d)
+    {
+        $this->created = $d;
+        return $this;
+    }
+
+}

+ 15 - 0
src/KeaBundle/Resources/config/routing/admin.xml

@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<routes xmlns="http://symfony.com/schema/routing"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
+
+    <route id="kea_get_config" path="/admin/kea/config/get">
+        <default key="_controller">KeaBundle:Config:get</default>
+    </route>
+    
+    <route id="kea_set_config" path="/admin/kea/config/set">
+        <default key="_controller">KeaBundle:Config:set</default>
+    </route>
+    
+</routes>

+ 12 - 3
src/KeaBundle/Resources/config/services.yml

@@ -1,4 +1,13 @@
 services:
-   kea.config:
-       class: KeaBundle\Services\KeaConfigService
-       arguments: ["@doctrine.orm.entity_manager"]
+    kea.config:
+        class: KeaBundle\Services\KeaConfigService
+        arguments: ["@doctrine.orm.entity_manager"]
+
+    sonata.admin.kea_config:
+        class: KeaBundle\Admin\ConfigAdmin
+        arguments: [~, KeaBundle\Entity\Config, BaseAdminBundle:CRUD]
+        tags:
+            - { name: sonata.admin, manager_type: orm, group: Kea, label: Config, label_catalogue: KeaBundle, label_translator_strategy: sonata.admin.label.strategy.underscore }
+        calls:
+            - [setTranslationDomain, [KeaBundle]]
+        public: true

+ 31 - 0
src/KeaBundle/Resources/translations/KeaBundle.es.yml

@@ -0,0 +1,31 @@
+Kea: Kea
+Config: Configuración
+
+form:
+    label_description: Descripción
+    label_dhcp: DHCP
+    label_created: Creado
+    label_template: Plantilla
+
+breadcrumb:
+    link_d_h_c_p_list: Listado Configuraciones
+    link_d_h_c_p_delete: Eliminar Configuración
+    
+list:
+    label_description: Descripción
+    label_dhcp: DHCP
+    label_created: Creado
+    label_template: Plantilla
+    label__action: Acciones
+
+show:
+    label_description: Descripción
+    label_dhcp: DHCP
+    label_created: Creado
+    label_template: Plantilla
+
+filter:
+    label_description: Descripción
+    label_dhcp: DHCP
+    label_created: Creado
+    label_template: Plantilla