Parcourir la source

En el ONUAdmin se agruparon los naps por olt, se oculto el select de olt y se corrijieron los scripts de carga.

Se modifico el show de ONUAdmin para agregar los valores del OLT

Se agregarón traducciones

Se quito del ONUTemplate la relacion con la olt porque esta relacion se hace por nap
gabriel il y a 6 ans
Parent
commit
24329b2500

+ 92 - 22
src/FTTHBundle/Admin/ONUAdmin.php

@@ -4,6 +4,7 @@ namespace FTTHBundle\Admin;
 
 use Buzz\Message\RequestInterface as HttpRequestInterface;
 use Doctrine\ORM\EntityRepository;
+use FTTHBundle\Entity\NAP;
 use Sonata\DoctrineORMAdminBundle\Datagrid\ProxyQuery;
 use Sonata\AdminBundle\Datagrid\DatagridMapper;
 use Sonata\AdminBundle\Datagrid\ListMapper;
@@ -45,7 +46,7 @@ class ONUAdmin extends WorkflowBaseAdmin
                                     {$alias}.ponSerialNumber LIKE :id OR
                                     {$alias}.ponSerialNumberAux LIKE :id")
                         ->setParameter('id', "%{$data['value']}%");
-                        
+
                     return true;
                 },), null, [
                     'attr' => [
@@ -108,7 +109,7 @@ class ONUAdmin extends WorkflowBaseAdmin
     {
         $subject = $this->getSubject();
         $em = $this->get("doctrine.orm.entity_manager");
-        
+
         // busco el ONU template si se pasa como parámetro
         $template = null;
         $onuTemplateId = $this->getRequest()->query->get('onu_template');
@@ -135,13 +136,8 @@ class ONUAdmin extends WorkflowBaseAdmin
 
         // Editando la ONU o hay template base o pasado como parámetro
         if ($subject->getId() || $template) {
-            $olt = null;
-            if ($subject->getOlt()) {
-                $olt = $subject->getOlt();
-            } elseif ($template) {
-                $olt = $template->getOlt();
-            }
-            
+            $olt = $subject->getOlt();
+
             // Según el modelo de OLT se muestran algunos campos específicos
             if ($olt && $olt->getModel()) {
                 $oltModel = $olt->getModel();
@@ -165,7 +161,7 @@ class ONUAdmin extends WorkflowBaseAdmin
         $formMapper
             ->tab('default')
                 ->with('');
-        
+
         // Se agrega ONUTemplate solo en el create
         if ($this->isCurrentRoute('create')) {
             $formMapper->add('onuTemplate', 'entity', [
@@ -176,7 +172,7 @@ class ONUAdmin extends WorkflowBaseAdmin
                 'data' => $template,
             ]);
         }
-        
+
         $formMapper
                     ->add('clientId')
                     ->add('ponSerialNumber', null, array(
@@ -186,9 +182,25 @@ class ONUAdmin extends WorkflowBaseAdmin
         if ($this->hasParameter('show.onu.activationCode') && $this->getParameter('show.onu.activationCode') == true) {
             $formMapper->add('activationCode');
         }
+
+        $naps = $em->getRepository(NAP::class)->findAll(['enable' => 1]);
         $formMapper
                     ->add('profile')
-                    ->add('nap')
+                    ->add('nap', ChoiceType::class,
+                            array(
+                                'choices' => $naps,
+                                'multiple' => false,
+                                'required' => true,
+                                'choice_value' => function ( $entity = null) {
+                                    return $entity ? $entity->getId() : '';
+                                },
+                                'choice_label' => function ($choiceValue, $key, $value) {
+                                    return $choiceValue->getName();
+                                },
+                                'group_by' => function($value, $key, $index) {
+                                    return $value->getOlt()->getName();
+                                },
+                            ))
                     ->add('model')
                     ->add('comments')
                 ->end()
@@ -203,7 +215,7 @@ class ONUAdmin extends WorkflowBaseAdmin
                         'attr' => array(
                             'style' => 'text-transform: uppercase;'
                         )))
-                    ->add('olt')
+                    ->add('olt','hidden', array('attr' => array("hidden" => true)))
                     ->add('position')
                     ->add('ip')
                 ->end()
@@ -351,7 +363,7 @@ class ONUAdmin extends WorkflowBaseAdmin
                             ->setParameter('id', $olt);
 
                     $form->add('olt', 'entity', array(
-                        'class' => 'FTTHBundle:OLT', 
+                        'class' => 'FTTHBundle:OLT',
                         'query_builder' => $query_olt
                     ));
                 }
@@ -379,7 +391,43 @@ class ONUAdmin extends WorkflowBaseAdmin
         if ($this->hasParameter('show.onu.activationCode') && $this->getParameter('show.onu.activationCode') == true) {
             $showMapper->add('activationCode');
         }
-        
+
+        $subject = $this->getSubject();
+        $em = $this->get("doctrine.orm.entity_manager");
+        $marks = OLTModelMark::getChoices();
+        foreach ($marks as $m) {
+            $hidden[$m] = 'hidden';
+        }
+
+        // Por defecto se esconden los campos en ZTE v4
+        $optionsZTEV4 = [
+            'label_attr' => [
+                'class' => 'zte_v4 hidden',
+            ],
+            'attr' => [
+                'class' => 'zte_v4 hidden',
+            ],
+        ];
+
+        // Editando la ONU o hay template base o pasado como parámetro
+        if ($subject->getId()) {
+            $olt = $subject->getOlt();
+
+            // Según el modelo de OLT se muestran algunos campos específicos
+            if ($olt && $olt->getModel()) {
+                $oltModel = $olt->getModel();
+                $mark = $oltModel->getMark();
+                $hidden[$mark] = '';
+
+                // Chequeo si el modelo de OLT es ZTE v4
+                $name = $oltModel->getName();
+                if (strpos($name, 'ZTE') !== false && strpos($name, 'V4') !== false) {
+                    $optionsZTEV4['label_attr']['class'] = 'zte_v4';
+                    $optionsZTEV4['attr']['class'] = 'zte_v4';
+                }
+            }
+        }
+
         $showMapper->add('profile')
                     ->add('nap')
                     ->add('model')
@@ -394,7 +442,31 @@ class ONUAdmin extends WorkflowBaseAdmin
                     ->add('olt')
                     ->add('currentState')
                     ->add('position')
-                    ->add('ip');
+                    ->add('ip')
+                ->end()
+                ->with('Huawei', ['class' => "col-md-12 {$hidden['Huawei']} olt_mark Huawei"])
+                    ->add('servicePorts', CollectionType::class, array(
+                        'entry_type' => "FTTHBundle\\Form\\ServicePortType",
+                        'allow_add' => true,
+                        'allow_delete' => true,
+                        'required' => false,
+                        'by_reference' => false,
+                    ))
+                ->end()
+                ->with('ZTE', ['class' => "col-md-12 {$hidden['ZTE']} olt_mark ZTE"])
+                    ->add('vlan')
+                    ->add('vlanProfile', null, $optionsZTEV4)
+                    ->add('onuProfile', null, $optionsZTEV4)
+                    ->add('trafficProfileIn')
+                    ->add('trafficProfileOut')
+                    ->add('tcontprofile')
+                    ->add('catv')
+                ->end()
+                ->with('FiberLink', ['class' => "col-md-12 {$hidden['FiberLink']} olt_mark FiberLink"])
+                    ->add('vlans', null, array(
+                        'required' => false,
+                        'multiple' => true,
+                    ));
         // Consulto en stats la url del detalle de onu
         $onuShowUrl = $this->getStatsShowOnuUrl();
         if ($onuShowUrl != '') {
@@ -500,7 +572,7 @@ class ONUAdmin extends WorkflowBaseAdmin
                 ->end();
         }
     }
-    
+
     /**
      * @return string
      */
@@ -518,7 +590,7 @@ class ONUAdmin extends WorkflowBaseAdmin
             $json_decode = json_decode($response, true);
             $onuShowUrl = isset($json_decode['url']) ? $json_decode['url'] : '';
         }
-        
+
         return $onuShowUrl;
     }
 
@@ -547,6 +619,7 @@ class ONUAdmin extends WorkflowBaseAdmin
 
     public function preUpdate($onu)
     {
+        $onu->setOlt($onu->getNap()->getOlt());
         $this->correctSerialNumber($onu);
 
         if((boolean) $this->getForm()->get('tr069_exist')->getData()) {
@@ -576,6 +649,7 @@ class ONUAdmin extends WorkflowBaseAdmin
 
     public function prePersist($onu)
     {
+        $onu->setOlt($onu->getNap()->getOlt());
         $this->correctSerialNumber($onu);
     }
 
@@ -664,10 +738,6 @@ class ONUAdmin extends WorkflowBaseAdmin
             $form->add('profile', null, array('data' => $profile));
         }
 
-        if($olt = $template->getOlt()) {
-            $form->add('olt', null, array('data' => $olt));
-        }
-
         if($model = $template->getModel()) {
             $form->add('model', null, array('data' => $model));
         }

+ 1 - 5
src/FTTHBundle/Admin/ONUTemplateAdmin.php

@@ -31,8 +31,7 @@ class ONUTemplateAdmin extends BaseAdmin
     {
         $datagridMapper
             ->add('profile')
-            ->add('model')
-            ->add('olt');
+            ->add('model');
     }
 
     /**
@@ -43,7 +42,6 @@ class ONUTemplateAdmin extends BaseAdmin
         $listMapper
             ->add('model')
             ->add('profile')
-            ->add('olt')
             ->add('vlan')
             ->add('vlanProfile')
             ->add('onuProfile')
@@ -71,7 +69,6 @@ class ONUTemplateAdmin extends BaseAdmin
                 ->with('')
                     ->add('model')
                     ->add('profile')
-                    ->add('olt')
                     ->add('vlans', null, array(
                         'required' => false,
                         'multiple' => true,
@@ -100,7 +97,6 @@ class ONUTemplateAdmin extends BaseAdmin
                 ->with('')
                     ->add('model')
                     ->add('profile')
-                    ->add('olt')
                     ->add('vlans')
                     ->add('vlan')
                     ->add('vlanProfile')

+ 21 - 3
src/FTTHBundle/Controller/ONUController.php

@@ -278,7 +278,7 @@ class ONUController extends Controller
         }
         return ($a < $b) ? -1 : 1;
     }
-    
+
     /**
      * chequea la position si esta libre, según nap
      * @param Request $request
@@ -303,8 +303,26 @@ class ONUController extends Controller
                 }
             }
         }
-        
+
+        return new JsonResponse(compact('result'));
+    }
+
+    /**
+     * Obtiene el id de la olt segun el nap.
+     * @param Request $request
+     *
+     * @return JsonResponse
+     */
+    public function getNapOltAction(Request $request)
+    {
+        $napId = $request->get('id');
+        $em = $this->getDoctrine()->getManager();
+        $nap = $em->getRepository(NAP::class)->find($napId);
+        if ($nap) {
+            $result = $nap->getOlt()->getId();
+        } else {
+            $result = 0;
+        }
         return new JsonResponse(compact('result'));
     }
-    
 }

+ 1 - 28
src/FTTHBundle/Entity/ONUTemplate.php

@@ -49,13 +49,6 @@ class ONUTemplate implements TenancyIdTraitInterface
      */
     protected $updated;
 
-    /**
-     * @ORM\ManyToOne(targetEntity="OLT", fetch="EXTRA_LAZY")
-     * @ORM\JoinColumn(onDelete="SET NULL")
-     *
-     */
-    protected $olt;
-
     /**
      * @ORM\ManyToOne(targetEntity="ONUModel", fetch="EXTRA_LAZY")
      * @ORM\JoinColumn(onDelete="SET NULL")
@@ -148,7 +141,7 @@ class ONUTemplate implements TenancyIdTraitInterface
      */
     public function __toString()
     {
-        return sprintf("ID: %s MODELO: %s PERFIL: %s OLT: %s ", $this->id, $this->model, $this->profile, $this->olt);
+        return sprintf("ID: %s MODELO: %s PERFIL: %s", $this->id, $this->model, $this->profile);
     }
 
     /**
@@ -220,26 +213,6 @@ class ONUTemplate implements TenancyIdTraitInterface
         return $this;
     }
 
-    /**
-     * @return OLT
-     */
-    public function getOlt()
-    {
-        return $this->olt;
-    }
-
-    /**
-     * @param OLT $olt
-     *
-     * @return $this
-     */
-    public function setOlt($olt)
-    {
-        $this->olt = $olt;
-
-        return $this;
-    }
-
     /**
      * @return ONUModel
      */

+ 5 - 1
src/FTTHBundle/Resources/config/routing.yml

@@ -1,7 +1,11 @@
 ajax_distance_nap_onu:
     path:      /ajax_distance_nap_onu
     defaults:  { _controller: FTTHBundle:ONU:getDistanceNapOnu }
-    
+
+ajax_nap_olt:
+    path:      /ajax_nap_olt
+    defaults:  { _controller: FTTHBundle:ONU:getNapOlt }
+
 ajax_check_position:
     path:      /ajax_check_position
     defaults:  { _controller: FTTHBundle:ONU:ajaxCheckPosition }

+ 6 - 0
src/FTTHBundle/Resources/translations/FTTHBundle.es.yml

@@ -303,6 +303,11 @@ show:
     label_enable_pass: Enable Password
     label_ssh_port: SSH Port
     label_ssh_connect: Conexión por SSH
+    label_position: Posición dentro del puerto
+    label_vlan: VLAN ID
+    label_traffic_profile_in: Perfil de Tráfico In
+    label_traffic_profile_out: Perfil de Tráfico Out
+    label_tcontprofile: Perfil tcont
 
 helps:
     check_address: Verifique la dirección para el cálculo de distancias.
@@ -319,6 +324,7 @@ helps:
     ip_static: Ip estática
 error:
     address_not_found: La dirección "%client_address%" no fue encontrada en los servicios de google.
+    nap_relation_olt_not_found: No se encontró la relación entre el nap y la olt.
 Distance: Distancia
 Free Port: Puertos Libres
 Incorrect State: Estado erróneo

+ 29 - 2
src/FTTHBundle/Resources/views/ONU/form.html.twig

@@ -71,8 +71,8 @@
             });
         }
         
-        ajax_olt_model_mark();
-        $('[id="{{ admin.uniqid }}_olt"]').on('click', ajax_olt_model_mark);
+        // ajax_olt_model_mark();
+        {#$('[id="{{ admin.uniqid }}_olt"]').on('click', ajax_olt_model_mark);#}
         
         {# Se chequea la position si esta libre, según el nap seleccionado #}
         
@@ -267,6 +267,33 @@
             }
         }
         $('#{{ admin.uniqid  ~ "_onuTemplate" }}').on('change', onuTemplateReloadPage);
+
+        // Al seleccionar un NAP se selecciona la OLT y se debe cargar la configuracion avanzada
+        function ajax_nap_olt()
+        {
+            var nap = $('[id="{{ admin.uniqid }}_nap"]').val();
+            $.ajax({
+                url: '{{ path('ajax_nap_olt') }}',
+                dataType: 'json',
+                type: "GET",
+                data: {
+                    id: nap
+                },
+                success: function (result) {
+                    if(result && result.result > 0){
+                        $('[id="{{ admin.uniqid }}_olt"]').val(result.result);
+                        ajax_olt_model_mark();
+                    } else {
+                        var msg = "{{ 'error.nap_relation_olt_not_found'|trans({}, 'FTTHBundle') }}";
+                        showError(msg);
+                    }
+                }
+            });
+        }
+
+        $('[id="{{ admin.uniqid }}_nap"]').on('click', ajax_nap_olt);
+        ajax_nap_olt();
+        ajax_olt_model_mark();
     </script>
 
 {% endblock %}