Browse Source

Merge branch 'master' of bitbucket.org:ikflowdat/ftth

iksop 7 years ago
parent
commit
226050b3bf

+ 54 - 0
app/Resources/SonataAdminBundle/views/CRUD/delete.html.twig

@@ -0,0 +1,54 @@
+{#
+
+This file is part of the Sonata package.
+
+(c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
+
+For the full copyright and license information, please view the LICENSE
+file that was distributed with this source code.
+
+#}
+
+{% extends base_template %}
+
+{%- block actions -%}
+    {% include 'SonataAdminBundle:CRUD:action_buttons.html.twig' %}
+{%- endblock -%}
+
+{% block tab_menu %}{{ knp_menu_render(admin.sidemenu(action), {'currentClass' : 'active', 'template': sonata_admin.adminPool.getTemplate('tab_menu_template')}, 'twig') }}{% endblock %}
+
+{% block content %}
+    <div class="sonata-ba-delete">
+
+        <div class="box box-danger">
+            <div class="box-header">
+                <h3 class="box-title">{{ 'title_delete'|trans({}, 'SonataAdminBundle') }}</h3>
+            </div>
+            <div class="box-body">
+                {{ 'message_delete_confirmation'|trans({'%object%': admin.toString(object)}, 'SonataAdminBundle') }}
+
+                {# Muestro mensaje con las entidades relacionadas a eliminar #}
+                {% set pre_remove_entities_message = pre_remove_entities_message(object) %}
+                {% if pre_remove_entities_message != '' %}
+                <br /><br />{{ pre_remove_entities_message|raw }}
+                {% endif %}
+
+            </div>
+            <div class="box-footer clearfix">
+                <form method="POST" action="{{ admin.generateObjectUrl('delete', object) }}">
+                    <input type="hidden" name="_method" value="DELETE">
+                    <input type="hidden" name="_sonata_csrf_token" value="{{ csrf_token }}">
+
+                    <button type="submit" class="btn btn-danger"><i class="fa fa-trash" aria-hidden="true"></i> {{ 'btn_delete'|trans({}, 'SonataAdminBundle') }}</button>
+
+                    {% if admin.hasRoute('edit') and admin.hasAccess('edit', object) %}
+                        {{ 'delete_or'|trans({}, 'SonataAdminBundle') }}
+                        <a class="btn btn-success" href="{{ admin.generateObjectUrl('edit', object) }}">
+                            <i class="fa fa-pencil" aria-hidden="true"></i>
+                            {{ 'link_action_edit'|trans({}, 'SonataAdminBundle') }}</a>
+                    {% endif %}
+                </form>
+            </div>
+        </div>
+    </div>
+{% endblock %}

+ 6 - 6
composer.lock

@@ -1464,7 +1464,7 @@
             "source": {
                 "type": "git",
                 "url": "ssh://git@200.50.168.30:222/VendorSoftwareFlowdat3/BaseAdmin.git",
-                "reference": "9d644224c89b99d8f911af12f91b3a5ca9c349e6"
+                "reference": "45403b2910820c70f7f20047bb7601d89bb2fc54"
             },
             "type": "library",
             "autoload": {
@@ -1479,7 +1479,7 @@
                 "bootstrap",
                 "sonata"
             ],
-            "time": "2018-01-05T14:07:02+00:00"
+            "time": "2018-01-11T13:38:16+00:00"
         },
         {
             "name": "ik/device-bundle",
@@ -1487,7 +1487,7 @@
             "source": {
                 "type": "git",
                 "url": "ssh://git@gogs.infra.flowdat.com:222/VendorSoftwareFlowdat3/DeviceBundle.git",
-                "reference": "e53cfbcc9620f776428490e9ab92b151eab007bc"
+                "reference": "5ff7b53da7f48f39276c507e9b162f3e87b1bae3"
             },
             "type": "library",
             "autoload": {
@@ -1502,7 +1502,7 @@
                 "bundle",
                 "validators"
             ],
-            "time": "2018-01-04T14:56:46+00:00"
+            "time": "2018-01-11T11:36:46+00:00"
         },
         {
             "name": "ik/extra-data-bundle",
@@ -1697,7 +1697,7 @@
             "source": {
                 "type": "git",
                 "url": "ssh://git@200.50.168.30:222/VendorSoftwareFlowdat3/WorkflowBundle.git",
-                "reference": "e830889b31d990f9f56e90f840117f2e8f0df362"
+                "reference": "006416bda248fff8844520888096140b8f59ab45"
             },
             "require": {
                 "php-amqplib/rabbitmq-bundle": "^1.12"
@@ -1727,7 +1727,7 @@
                 "bundle",
                 "workflow"
             ],
-            "time": "2018-01-05T15:29:31+00:00"
+            "time": "2018-01-10T12:25:25+00:00"
         },
         {
             "name": "incenteev/composer-parameter-handler",

+ 1 - 3
src/FTTHBundle/Entity/NAP.php

@@ -66,9 +66,7 @@ class NAP implements TenancyIdTraitInterface, LocationInterface
     private $container;
 
     /**
-     * @ORM\ManyToOne(targetEntity="OLT", inversedBy="onus", fetch="EXTRA_LAZY")
-     *
-     * @Assert\NotNull
+     * @ORM\ManyToOne(targetEntity="OLT", inversedBy="naps", fetch="EXTRA_LAZY")
      *
      * @JMS\MaxDepth(1)
      */

+ 72 - 2
src/FTTHBundle/Entity/OLT.php

@@ -2,6 +2,7 @@
 
 namespace FTTHBundle\Entity;
 
+use Base\AdminBundle\Interfaces\PreRemoveInterface;
 use Base\AdminBundle\Traits\TenancyIdTrait;
 use Base\AdminBundle\Traits\TenancyIdTraitInterface;
 use Doctrine\ORM\Mapping as ORM;
@@ -16,20 +17,25 @@ use MapBundle\Entity\Interfaces\LocationInterface;
 use MapBundle\Entity\Traits\LocationTrait;
 use WorkflowBundle\Entity\Interfaces\WorkflowInterface;
 use WorkflowBundle\Entity\Traits\WorkflowTrait;
+use Gedmo\SoftDeleteable\Traits\SoftDeleteableEntity as SoftDeleteable;
+use Gedmo\Mapping\Annotation as Gedmo;
+use Base\AdminBundle\Interfaces\SoftDeleteInterface;
 
 /**
  * @ORM\Entity
  * @UniqueEntity("ip")
+ * @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=true)
  *
  * @ValidatorAssert\Device
  */
-class OLT implements DeviceInterface, TenancyIdTraitInterface, LocationInterface, WorkflowInterface
+class OLT implements DeviceInterface, TenancyIdTraitInterface, LocationInterface, WorkflowInterface, PreRemoveInterface, SoftDeleteInterface
 {
 
     use ExtraDataTrait;
     use TenancyIdTrait;
     use LocationTrait;
     use WorkflowTrait;
+    use SoftDeleteable;
 
     /**
      * @var bigint $id
@@ -93,12 +99,19 @@ class OLT implements DeviceInterface, TenancyIdTraitInterface, LocationInterface
     protected $model;
 
     /**
-     * @ORM\OneToMany(targetEntity="ONU", mappedBy="olt", fetch="EXTRA_LAZY")
+     * @ORM\OneToMany(targetEntity="ONU", mappedBy="olt", fetch="EXTRA_LAZY", cascade={"remove"})
      *
      * @JMS\MaxDepth(2)
      */
     protected $onus;
 
+    /**
+     * @ORM\OneToMany(targetEntity="NAP", mappedBy="olt", fetch="EXTRA_LAZY", cascade={"remove"})
+     *
+     * @JMS\MaxDepth(2)
+     */
+    protected $naps;
+
     /**
      * @ORM\Column(type="string", nullable=true)
      */
@@ -289,6 +302,38 @@ class OLT implements DeviceInterface, TenancyIdTraitInterface, LocationInterface
         return $this->onus;
     }
 
+    /**
+     * @param NAP $nap
+     *
+     * @return OLT
+     */
+    public function addNap(NAP $nap)
+    {
+        $this->naps[] = $nap;
+
+        return $this;
+    }
+
+    /**
+     * @param NAP $nap
+     *
+     * @return OLT
+     */
+    public function removeNap(NAP $nap)
+    {
+        $this->naps->removeElement($nap);
+
+        return $this;
+    }
+
+    /**
+     * @return Doctrine\Common\Collections\Collection
+     */
+    public function getNaps()
+    {
+        return $this->naps;
+    }
+
     /**
      * @return OLTModel
      */
@@ -488,5 +533,30 @@ class OLT implements DeviceInterface, TenancyIdTraitInterface, LocationInterface
     {
         return $this->libraryVersion;
     }
+    
+    /**
+    * @return array
+    */
+    public function getSoftDeleteCriteria() 
+    {
+        return array('ip' => $this->ip);
+    }
+
+    /**
+     * @return array
+     */
+    public function getEntitiesForRemove()
+    {
+        $entities = [];
+        if ($this->onus->count() != 0) {
+            $entities['onus'] = $this->onus;
+        }
+
+        if ($this->naps->count() != 0) {
+            $entities['naps'] = $this->naps;
+        }
+
+        return $entities;
+    }
 
 }

+ 14 - 3
src/FTTHBundle/Entity/ONU.php

@@ -18,6 +18,7 @@ use WorkflowBundle\Entity\Interfaces\WorkflowInterface;
 use WorkflowBundle\Entity\Traits\WorkflowTrait;
 use Gedmo\SoftDeleteable\Traits\SoftDeleteableEntity as SoftDeleteable;
 use Gedmo\Mapping\Annotation as Gedmo;
+use Base\AdminBundle\Interfaces\SoftDeleteInterface;
 
 /**
  * ONU
@@ -29,7 +30,7 @@ use Gedmo\Mapping\Annotation as Gedmo;
  *
  * @ValidatorAssert\Device
  */
-class ONU implements DeviceInterface, TenancyIdTraitInterface, LocationInterface, WorkflowInterface
+class ONU implements DeviceInterface, TenancyIdTraitInterface, LocationInterface, WorkflowInterface, SoftDeleteInterface
 {
 
     use ExtraDataTrait;
@@ -113,6 +114,8 @@ class ONU implements DeviceInterface, TenancyIdTraitInterface, LocationInterface
 
     /**
      * @ORM\ManyToOne(targetEntity="OLT", inversedBy="onus", fetch="EXTRA_LAZY")
+     * @ORM\JoinColumn(onDelete="SET NULL")
+     *
      * @JMS\MaxDepth(1)
      */
     protected $olt;
@@ -126,15 +129,15 @@ class ONU implements DeviceInterface, TenancyIdTraitInterface, LocationInterface
 
     /**
      * @ORM\ManyToOne(targetEntity="NAP", inversedBy="onus", fetch="EXTRA_LAZY")
+     * @ORM\JoinColumn(onDelete="SET NULL")
      *
      * @JMS\MaxDepth(1)
-     *
-     * @Assert\NotNull
      */
     protected $nap;
 
     /**
      * @ORM\ManyToOne(targetEntity="Profile", inversedBy="onus", fetch="EXTRA_LAZY")
+     * @ORM\JoinColumn(name="profile_id", referencedColumnName="id", onDelete="SET NULL")
      * @JMS\MaxDepth(1)
      */
     protected $profile;
@@ -562,4 +565,12 @@ class ONU implements DeviceInterface, TenancyIdTraitInterface, LocationInterface
         return $deviceData;
     }
 
+    /**
+     * @return array
+     */
+    public function getSoftDeleteCriteria() 
+    {
+        return array('ponSerialNumber' => $this->ponSerialNumber);
+    }
+
 }

+ 0 - 31
src/FTTHBundle/EventListener/ONUSoftDeleteListener.php

@@ -1,31 +0,0 @@
-<?php
-
-namespace FTTHBundle\EventListener;
-
-use Base\AdminBundle\EventListener\SoftDeleteListener;
-use FTTHBundle\Entity\ONU;
-
-class ONUSoftDeleteListener extends SoftDeleteListener
-{
-
-    /**
-    * @return boolean
-    */
-    public function checkInstanceOf($entity)
-    {
-        return $entity instanceof ONU;
-    }
-
-    /**
-    * @param Object $entity
-
-    * @return Object
-    */
-    public function getEntity($entity)
-    {
-        return $this->em->getRepository(ONU::class)->findOneBy([
-            'ponSerialNumber' => $entity->getPonSerialNumber()
-        ]);
-    }
-
-}

+ 0 - 5
src/FTTHBundle/Resources/config/services.yml

@@ -67,11 +67,6 @@ services:
             - { name: kernel.event_listener, event: sonata.admin.event.configure.datagrid, method: configureDatagridFilters }
         arguments: ["@service_container"]
 
-    ftth.onu_soft_delete.listener:
-        class: FTTHBundle\EventListener\ONUSoftDeleteListener
-        tags:
-            - { name: doctrine.event_listener, event: prePersist }
-
     ftth.nap.subscriber:
         class: FTTHBundle\EventListener\NAPAddressSubscriber
         tags:

+ 1 - 1
src/FTTHBundle/Resources/translations/FTTHBundle.es.yml

@@ -190,7 +190,7 @@ show:
 helps:
     check_address: Verifique la dirección para el cálculo de distancias.
 error:
-    address_not_found: Dirección no encontrada.
+    address_not_found: La dirección "%client_address%" no fue encontrada en los servicios de google.
 Distance: Distancia
 Free Port: Puertos Libres
 Incorrect State: Estado erróneo

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

@@ -65,13 +65,13 @@
                 if (res != undefined && res.status == google.maps.GeocoderStatus.OK) {
                     drawMap(res.results[0].geometry.location.lat, res.results[0].geometry.location.lng);
                 } else {
-                    console.log(res.status);
-                    alert("{{ 'error.address_not_found'|trans({}, 'FTTHBundle') }}");
+                    // direccion no encontrada por google
+                    var msg = "{{ 'error.address_not_found'|trans({}, 'FTTHBundle') }}";
+                    showError(msg.replace('%client_address%', address));
                 }
             }).error(function (res) {
-                console.log("ERROR: ");
-                console.log(res);
-                alert("{{ 'error.address_not_found'|trans({}, 'FTTHBundle') }}");
+                // direccion no encontrada por google, esto se puede deber a la cantidad de consultas que se
+                // realizan al webservice de google
             });
         }
 

+ 5 - 0
src/RadiusBundle/Admin/NASModelAdmin.php

@@ -16,6 +16,7 @@ class NASModelAdmin extends BaseAdmin
     protected function configureDatagridFilters(DatagridMapper $datagridMapper)
     {
         $datagridMapper
+            ->add('library')
             ->add('name');
     }
 
@@ -26,6 +27,7 @@ class NASModelAdmin extends BaseAdmin
     {
         $listMapper
             ->add('name')
+            ->add('library')
             ->add('extraData')
             ->add('_action', null, array(
                 'actions' => array(
@@ -41,8 +43,10 @@ class NASModelAdmin extends BaseAdmin
      */
     protected function configureFormFields(FormMapper $formMapper)
     {
+        $libraries = ['OIDSBase' => 'OIDSBase'];
         $formMapper
             ->add('name')
+            ->add('library', 'choice', array('required'=>true, 'choices' => $libraries))
             ->add('extraData');
     }
 
@@ -53,6 +57,7 @@ class NASModelAdmin extends BaseAdmin
     {
         $showMapper
             ->add('name')
+            ->add('library')
             ->add('extraData');
     }
 

+ 24 - 17
src/RadiusBundle/Entity/NAS.php

@@ -261,23 +261,30 @@ class NAS implements TenancyIdTraitInterface, DeviceInterface, LocationInterface
      */
     public function getDeviceData()
     {
-        $deviceExtraData = [
-            'description' => $this->description,
-            'host' => $this->host,
-            'snmpComunity' => $this->snmpComunity,
-            'snmpVersion' => $this->snmpVersion,
-            'radiusPassword' => $this->radiusPassword,
-            'model' => $this->model ? $this->model->getId() : $this->model,
-            'acctEnabled' => $this->acctEnabled,
-        ];
-
-        return [
-            'deviceType' => get_class($this),
-            'deviceId' => $this->id,
-            'ip' => null,
-            'tenancy' => $this->tenancyId,
-            'extraData' => json_encode($deviceExtraData),
-        ];
+
+        $deviceData = array();
+        $deviceData['deviceType'] = get_class($this);
+        $deviceData['deviceId'] = $this->id;
+        $deviceData['ip'] = $this->host;
+        $deviceData['tenancy'] = $this->tenancyId;
+
+        $deviceExtraData = array('snmpCommunity' => $this->snmpCommunity, 'snmpVersion' => $this->snmpVersion, 'radiusPassword' => $this->radiusPassword,
+            'acctEnabled' => $this->acctEnabled, 'description' => $this->description);
+
+        if ($this->model) {
+            $model = $this->getModel();
+            $deviceExtraData['modelId'] = $model->getId();
+            $deviceExtraData['library'] = $model->getLibrary();
+        } else {
+            $deviceExtraData['modelId'] = null;
+            $deviceExtraData['library'] = null;
+        }
+
+
+        $deviceData['extraData'] = json_encode($deviceExtraData);
+
+        return $deviceData;
+
     }
 
 }

+ 27 - 0
src/RadiusBundle/Entity/NASModel.php

@@ -41,6 +41,13 @@ class NASModel implements TenancyIdTraitInterface
      */
     protected $nass;
 
+    /**
+     * @var string $library
+     *
+     * @ORM\Column(type="string", length=255, nullable=true)
+     */
+    protected $library;
+
     /**
      * @return string
      */
@@ -89,4 +96,24 @@ class NASModel implements TenancyIdTraitInterface
         return $this;
     }
 
+    /**
+     * @param string $library
+     *
+     * @return OLTModel
+     */
+    public function setLibrary($library)
+    {
+        $this->library = $library;
+
+        return $this;
+    }
+
+    /**
+     * @return string
+     */
+    public function getLibrary()
+    {
+        return $this->library;
+    }
+
 }

+ 4 - 0
src/RadiusBundle/Resources/translations/RadiusBundle.es.yml

@@ -25,6 +25,7 @@ filter:
     label_radius_password: Contraseña
     label_model: Modelo
     label_acct_enabled: Cuenta Habilitada
+    label_library: Librería
 
 breadcrumb:
     link_profile_list: Listado Perfiles
@@ -59,6 +60,7 @@ form:
     label_model: Modelo
     label_acct_enabled: Cuenta Habilitada
     label_extra_data: Extra Data
+    label_library: Librería
 
 list:
     label__action: Acciones
@@ -79,6 +81,7 @@ list:
     label_model: Modelo
     label_acct_enabled: Cuenta Habilitada
     label_extra_data: Extra Data
+    label_library: Librería
 
 show:
     label__action: Acciones
@@ -99,6 +102,7 @@ show:
     label_model: Modelo
     label_acct_enabled: Cuenta Habilitada
     label_extra_data: Extra Data
+    label_library: Librería
 
 error:
     address_not_found: Dirección no encontrada.