浏览代码

FD3-754 se agrega client-classes en kea config. css dhcp options

Guillermo Espinoza 6 年之前
父节点
当前提交
6d82449e72

+ 10 - 9
src/HostBundle/EventListener/AdminDHCPOption.php

@@ -13,13 +13,13 @@ use Symfony\Component\Form\FormEvents;
 
 class AdminDHCPOption
 {
-    
+
     /**
      * @var HostService
      */
     private $hostService;
-    
-    
+
+
     /**
      * @param HostService $hostService
      */
@@ -41,6 +41,7 @@ class AdminDHCPOption
             }
             $options = array(
                 'translation_domain' => 'HostBundle',
+                'class' => 'dhcp-option-tab',
             );
             $mapper->tab('DHCP Option', $options)
                 ->with('DHCP Option', $options);
@@ -48,9 +49,9 @@ class AdminDHCPOption
                 'required' => false,
             ];
             foreach (DHCPOptions::getConstants() as $opt) {
-                
+
                 if ($opt == 'fixed_address') {
-                    $hostType = method_exists($subject, 'getHostType') 
+                    $hostType = method_exists($subject, 'getHostType')
                                 ? $subject->getHostType() : null;
                     $freeIP = $this->hostService->getFreeFixedIP($hostType);
                     $fixedAddress = $subject->getFixedAddress();
@@ -62,19 +63,19 @@ class AdminDHCPOption
                     $fieldOptions['choice_translation_domain'] = false;
                     $mapper->add($opt, ChoiceType::class, $fieldOptions);
                     unset($fieldOptions['choices'], $fieldOptions['choice_translation_domain']);
-                    
+
                     continue;
                 }
-                
+
                 $mapper->add($opt, TextType::class, $fieldOptions);
             }
             $mapper->end()->end();
-            
+
             // fix seteo de fixed IP al editar el tipo de Host
             $mapper->getFormBuilder()->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) {
                 $data = $event->getData();
                 $form = $event->getForm();
-                
+
                 if (isset($data['fixed_address'])) {
                     $form->add('fixed_address', null, [
                         'data' => $data['fixed_address'],

+ 19 - 11
src/HostBundle/Resources/views/CRUD/edit.html.twig

@@ -1,5 +1,13 @@
 {% extends "@SonataAdmin/CRUD/edit.html.twig" %}
 
+{% block stylesheets %}
+
+{{ parent() }}
+
+{% include "HostBundle::dhcp_options_style.html.twig" %}
+
+{% endblock stylesheets %}
+
 {% block javascripts %}
 
 {{ parent() }}
@@ -13,15 +21,15 @@ $(document).ready(function() {
     {% if object.getFixedAddress() is not null or object.getFixedAddress() != "" %}
         $fixedIP = "{{object.getFixedAddress()}}";
     {% endif %}
-    
+
     {% if object.getHostType() is not null %}
         $initHostTypeId = {{object.getHostType().getId()}};
     {% endif %}
-    
+
     showHostField();
 
     $("select[id$='hostType']").on('change', showHostField);
-    
+
 });
 
 // Al seleccionar tipo Cablemodem oculto el campo Host
@@ -32,13 +40,13 @@ function showHostField()
     var $hostTypeField = $("select[id$='hostType'] :selected");
     var $hostField = $("div.form-group[id$='host']");
     var $hostSelect = $("select[id$='host']");
-    
+
     if ($hostTypeField.html() === 'Cablemodem') {
         if ($hostSelect.find("option[value='']").length == 0) {
             $hostSelect.prepend('<option value=""></option>');
         }
         $hostSelect.val(null).trigger('change');
-        
+
         $hostField.hide();
     } else {
         if ($hostSelect.find("option[value='']").length) {
@@ -46,10 +54,10 @@ function showHostField()
         }
         var val = $hostSelect.find("option").first().attr('value');
         $hostSelect.val(val).trigger('change');
-        
+
         $hostField.show();
     }
-    
+
     updateFixedIPs();
 
     return false;
@@ -59,9 +67,9 @@ function updateFixedIPs()
 {
     var $hostTypeField = $("select[id$='hostType'] :selected");
     var $hostTypeId = $hostTypeField.val();
-    
+
     var option = '<option value=""></option>';
-    
+
     if (($hostTypeId == $initHostTypeId) && $fixedIP != false) {
         option = `<option value="${$fixedIP}" selected>${$fixedIP}</option>`;
         $("div[id$='_fixed_address'] a span.select2-chosen").html($fixedIP);
@@ -74,14 +82,14 @@ function updateFixedIPs()
         type: 'POST',
         data: {id: $hostTypeId},
         success: function(data) {
-            
+
             $('select[id$="_fixed_address"]').html(option);
             if (data.ips) {
                 $.each(data.ips, function (index, value) {
                     $('select[id$="_fixed_address"]').append('<option value="' + value + '">' + value + '</option>');
                 });
             }
-            
+
             return false;
         }
     });

+ 7 - 0
src/HostBundle/Resources/views/dhcp_options_style.html.twig

@@ -0,0 +1,7 @@
+<style>
+.dhcp-option-tab .form-group {
+    width: 48%;
+    float: left;
+    margin-right: 15px;
+}
+</style>

+ 1 - 0
src/IPv4Bundle/Resources/config/services.yml

@@ -25,6 +25,7 @@ services:
             - { name: sonata.admin, manager_type: orm, group: IPv4, label: SubNet, label_catalogue: IPv4Bundle, label_translator_strategy: sonata.admin.label.strategy.underscore }
         calls:
             - [setTranslationDomain, [IPv4Bundle]]
+            - [setTemplate, [edit, "IPv4Bundle:CRUD:subnet_edit.html.twig"]]
         public: true
 
     pool_ipv4_service:

+ 9 - 0
src/IPv4Bundle/Resources/views/CRUD/subnet_edit.html.twig

@@ -0,0 +1,9 @@
+{% extends "@SonataAdmin/CRUD/edit.html.twig" %}
+
+{% block stylesheets %}
+
+{{ parent() }}
+
+{% include "HostBundle::dhcp_options_style.html.twig" %}
+
+{% endblock stylesheets %}

+ 6 - 0
src/KeaBundle/Services/BaseKea.php

@@ -61,6 +61,8 @@ class BaseKea implements KeaConfigInterface
         ],
     ];
 
+    private $client_classes = [];
+
 
     /**
      * @param array $data
@@ -87,6 +89,7 @@ class BaseKea implements KeaConfigInterface
                         'control-socket' => $this->controlSocketConfig(),
                         'lease-database' => $this->leaseDatabaseConfig($data),
                         'hosts-database' => $this->leaseDatabaseConfig($data),
+                        'client-classes' => $this->client_classes,
                         'subnet4' => $this->subnet4,
                         'hooks-libraries' => $this->hooks_libraries,
                         'interfaces-config' => $this->getInterfacesConfig(),
@@ -141,6 +144,9 @@ class BaseKea implements KeaConfigInterface
 
             if ($client_class != '') {
                 $subnetConf['client-class'] = $client_class;
+                $this->client_classes [] = [
+                    'name' => $client_class,
+                ];
             }
 
             $netgroup = $subnet->getNetGroup();