Browse Source

FD3-190 Se agrega método y lógica para visualizar mapas con
estadísticas, en este caso el de las ONUs. Se agrega librería para
realizar click en layer geoserver y traer la información del punto.

Maximiliano Schvindt 7 years ago
parent
commit
fda2b91fb0

+ 2 - 1
app/AppKernel.php

@@ -42,7 +42,8 @@ class AppKernel extends Kernel
             new RedisBundle\RedisBundle(),
             new FiberhomeBundle\FiberhomeBundle(),
             new StatsDBundle\StatsDBundle(),
-            new GeoserverBundle\GeoserverBundle()
+            new GeoserverBundle\GeoserverBundle(),
+            new LeafletBundle\LeafletBundle()
         ];
 
         if (in_array($this->getEnvironment(), ['dev', 'test'], true)) {

+ 10 - 2
src/StatsBundle/Admin/DeviceAdmin.php

@@ -9,6 +9,7 @@ use Sonata\AdminBundle\Form\FormMapper;
 use Sonata\AdminBundle\Show\ShowMapper;
 use DeviceBundle\Utils\DeviceTypes;
 use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
+use Sonata\AdminBundle\Route\RouteCollection;
 
 class DeviceAdmin extends BaseAdmin
 {
@@ -40,13 +41,13 @@ class DeviceAdmin extends BaseAdmin
                 ->add('ip')
                 ->add('extraData')
                 ->add('tenancyId')
-                ->add('_action', null, array(
+                /* ->add('_action', null, array(
                     'actions' => array(
                         'show' => array(),
                         'edit' => array(),
                         'delete' => array(),
                     )
-                ))
+                )) */
         ;
     }
 
@@ -98,4 +99,11 @@ class DeviceAdmin extends BaseAdmin
         return $actions;
     }
 
+    protected function configureRoutes(RouteCollection $collection)
+    {
+        $collection->remove('delete');
+        $collection->remove('create');
+        $collection->remove('edit');
+    }
+
 }

+ 24 - 4
src/StatsBundle/Admin/OnuAdmin.php

@@ -9,6 +9,7 @@ use Sonata\AdminBundle\Form\FormMapper;
 use Sonata\AdminBundle\Show\ShowMapper;
 use DeviceBundle\Utils\DeviceTypes;
 use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
+use Sonata\AdminBundle\Route\RouteCollection;
 
 class OnuAdmin extends BaseAdmin
 {
@@ -37,7 +38,8 @@ class OnuAdmin extends BaseAdmin
             ->add('deviceServer')
             ->add('oltDeviceId')
             ->add('tenancyId')
-            ->add('ponSerialNumber')
+            /* ->add('ponSerialNumber') */
+            ->addIdentifier('ponSerialNumber')
             ->add('ponPort')
             ->add('status')
             ->add('txPower', 'string', array('template' => 'StatsBundle:Onu:base_list_field_tx.html.twig'))
@@ -46,9 +48,9 @@ class OnuAdmin extends BaseAdmin
             ->add('temperature', 'string', array('template' => 'StatsBundle:Onu:base_list_field_temperature.html.twig'))
             ->add('uptime', 'string', array('template' => 'StatsBundle:Onu:base_list_field_uptime.html.twig'))
             ->add('updated')
-            //->add('_action', null, array(
-            //    'actions' => array('show' => array())
-            //    ))
+            /* ->add('_action', null, array(
+                'actions' => array('show' => array())
+                )) */
         ;
     }
 
@@ -64,6 +66,17 @@ class OnuAdmin extends BaseAdmin
      */
     protected function configureShowFields(ShowMapper $showMapper)
     {
+        $showMapper
+            ->add('oltDeviceId')
+            ->add('ponSerialNumber')
+            ->add('ponPort')
+            ->add('status')
+            ->add('txPower')
+            ->add('rxPower')
+            ->add('voltage')
+            ->add('temperature')
+            ->add('updated')
+        ;
     }
 
     /**
@@ -82,4 +95,11 @@ class OnuAdmin extends BaseAdmin
         return $actions;
     }
 
+    protected function configureRoutes(RouteCollection $collection)
+    {
+        $collection->remove('delete');
+        $collection->remove('create');
+        $collection->remove('edit');
+    }
+
 }

+ 97 - 0
src/StatsBundle/Controller/StatsController.php

@@ -7,6 +7,7 @@ use StatsBundle\Services\DeviceManager;
 use Symfony\Bundle\FrameworkBundle\Controller\Controller;
 use Symfony\Component\HttpFoundation\Request;
 use Symfony\Component\HttpFoundation\JsonResponse;
+use Symfony\Component\HttpFoundation\Response;
 
 class StatsController extends Controller
 {
@@ -109,4 +110,100 @@ class StatsController extends Controller
         ));
     }
 
+    /**
+     * @Route("/admin/stats/onu/stats/map", name="onu_stats_map")
+     * 
+     * @return string
+     */
+    public function showMapAction(Request $request)
+    {
+        
+        $map = array();
+        $map['zoom'] = 12;
+        $map['lng'] = -60.065884467624294;
+        $map['lat'] = -33.902661208376706;
+
+        $em = $this->get('doctrine')->getManager();
+        $adminPool = $this->get('sonata.admin.pool');
+
+        $api = $this->get('geoserver.api');
+        $data = $api->getLayerData("deviceServer_1", "onu_stats_tenancy_1");
+
+        $setLatLng = $setZoom = false;
+
+        if(!empty($data)) {
+            if(isset($data['featureType']['latLonBoundingBox'])) {
+                $setLatLng = $setZoom = true;
+                $srs = $data['featureType']['latLonBoundingBox'];
+            } elseif(isset($data['featureType']['nativeBoundingBox'])) {
+                $setLatLng = $setZoom = true;
+                $srs = $data['featureType']['nativeBoundingBox'];
+            }
+        }
+
+        if($setLatLng) {
+            $lng = $srs['minx'] + ($srs['maxx'] - $srs['minx']) / 2;
+            $lat = $srs['miny'] + ($srs['maxy'] - $srs['miny']) / 2;
+        }
+
+        if($setZoom) {
+            $lngDiff = $srs['maxx'] - $srs['minx'];
+            $latDiff = $srs['maxy'] - $srs['miny'];
+            $maxDiff = ($lngDiff > $latDiff) ? $lngDiff : $latDiff;
+            if ($maxDiff < 360 / pow(2, 20)) {
+                $zoom = 21;
+            } else {
+                $zoom = (-1*( (log($maxDiff)/log(2)) - (log(360)/log(2)))) + 1;
+                if ($zoom < 1) $zoom = 1;
+            }
+        }
+
+        $map = array('lat' => $lat, 'lng' => $lng, 'zoom' => $zoom);
+
+        /* print_r("<pre>");
+        print_r($data);
+        die; */
+
+        return $this->render('StatsBundle:Stats:onu_map.html.twig', array(
+            'base_template' => $adminPool->getTemplate('layout'),
+            'admin_pool' => $adminPool,
+            'admin' => $adminPool->getAdminByClass("StatsBundle\Entity\Onu"),
+            'map'   => $map
+        ));
+    }
+
+    /**
+     * @Route("/admin/stats/onu/stats/api_feature_json", name="api_feature_json")
+     * 
+     * @return string
+     */
+    public function apiFeatureJsonAction(Request $request) 
+    {
+        $params = $request->query->all();
+        $data = explode(":",$params['LAYERS']);
+        
+        $workspace = $data[0];
+
+        $api = $this->get('geoserver.api');
+        $return = $api->getFeature($workspace, $params);
+
+        
+        $data = json_decode($return,true);
+        
+        $return = array();
+        
+        if(isset($data['features'])) {
+            $return = json_encode($data['features'][0]['properties']);
+        }
+
+        $response = new Response(
+            $return,
+            Response::HTTP_OK,
+            array('content-type' => 'application/json')
+        );
+
+        return $response;
+
+    }
+
 }

+ 1 - 1
src/StatsBundle/Entity/Onu.php

@@ -129,7 +129,7 @@ class Onu
      */
     public function __toString()
     {
-        return sprintf('%s %s', $this->deviceType, $this->ip);
+        return sprintf('%s %s', $this->ponSerialNumber, $this->ip);
     }
 
     /**

+ 191 - 0
src/StatsBundle/Resources/views/Stats/onu_map.html.twig

@@ -0,0 +1,191 @@
+{% extends 'SonataAdminBundle:CRUD:base_list.html.twig' %}
+
+{% block stylesheets %}
+{{ parent() }}
+
+<style>
+
+.vakata-context {
+    z-index: 10000;
+}
+
+.content-header,.content {
+    padding-top: 0px;
+    padding-left: 0px;
+    padding-right: 0px;
+    padding-bottom: 0px;
+}
+
+.no_checkbox>i.jstree-checkbox
+{
+    display:none
+}
+
+.toolbar {
+    margin: 4px;
+}
+
+.statusBar {
+    display: block;
+    color: white;
+    margin-left: 10px;
+    /*margin-top: -10px;*/
+}
+
+.modal-xl { width: 90%; }
+
+.modal {
+  text-align: center;
+}
+
+@media screen and (min-width: 768px) {
+  .modal:before {
+    display: inline-block;
+    vertical-align: middle;
+    content: " ";
+    height: 100%;
+  }
+}
+
+.modal-dialog {
+  display: inline-block;
+  text-align: left;
+  vertical-align: middle;
+}
+
+#objectTree {
+    padding-top: 20px;
+    height: calc(100vh - 120px);
+    overflow-y: scroll;
+    overflow-x: hidden;
+}
+
+#objectTree.jstree-proton .jstree-anchor{
+    color: lightGray;
+}
+
+#map {
+    width: 100%;
+    height: calc(100vh - 157px);
+    border-top: 2px;
+    border-bottom: 0px;
+    border-left: 0px;
+    border-right: 0px;
+    border-style: solid;
+    border-color: gray;
+    z-index: 0;
+    cursor:default;
+}
+
+footer {
+    z-index: 1100;
+}
+
+</style>
+{% endblock %}
+
+{% block actions %}
+{% endblock %}
+
+{% block tab_menu %}
+{#{{ knp_menu_render(admin.sidemenu(action), {'currentClass' : 'active', 'template': sonata_admin.adminPool.getTemplate('tab_menu_template')}, 'twig') }}#}
+{% endblock %}
+
+{% block list_filters_actions %}
+{% endblock %}
+
+{% block list_filters %}
+{% endblock %}
+
+{% block list_table %}
+{% endblock %}
+
+{% block sonata_wrapper %}
+{{ parent() }}
+<footer class="footer">
+    <span id="statusBar" class="statusBar">Listo.</span>
+</footer>
+{% endblock %}
+
+{% block content %}
+
+<div id='wrapper'>
+    <div id='page-content-wrapper'>
+        <div class="cms-block cms-block-element" >
+            <div id="map"></div>
+        </div>
+    </div>
+</div>
+
+
+<!-- Page JS -->
+{% include 'LeafletBundle:Leaflet:resources.html.twig' %}
+
+<!-- twig para reemplazar url por crossbrowser de feature geoserver -->
+{% include 'LeafletBundle:Leaflet:leaflet_wms.html.twig' %}
+
+<script>
+
+window.SONATA_CONFIG.USE_ICHECK = false;
+
+
+/* --------------------- PROGRAMA PRINCIPAL ------------------------- */
+initializeMap();
+/* ------------------- FIN PROGRAMA PRINCIPAL ----------------------- */
+
+
+/* --------------------- Funciones ------------------------- */
+function initializeMap() {
+
+    window.map = new L.Map('map', { center: new L.LatLng({{map['lat']}}, {{map['lng']}}), zoom: {{map['zoom']}} });
+
+    var osmUrl = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
+    var osmAttrib = '&copy; OpenStreetMap';
+    var osm = L.tileLayer(osmUrl, { maxZoom: 18, attribution: osmAttrib });
+
+    var controlLayers = L.control.layers({
+        'OSM': osm.addTo(window.map),
+        "Google": L.tileLayer('http://www.google.cn/maps/vt?lyrs=s@189&gl=cn&x={x}&y={y}&z={z}', {zIndex:1, attribution: '&copy; Google'})
+    }, {}, { position: 'topleft', collapsed: false });
+
+    
+
+    layerGeoRx = L.tileLayer.betterWms('http://200.50.168.118:8081/geoserver/deviceServer_1/wms', {
+	    layers: 'deviceServer_1:onu_stats_tenancy_1',
+		transparent:true,
+		format: 'image/png',
+        zIndex: 99,
+		maxZoom: 24,
+        styles: 'onuRxPower'
+	});
+    layerGeoTx = L.tileLayer.betterWms('http://200.50.168.118:8081/geoserver/deviceServer_1/wms', {
+	    layers: 'deviceServer_1:onu_stats_tenancy_1',
+		transparent:true,
+		format: 'image/png',
+        zIndex: 99,
+		maxZoom: 24,
+        styles: 'onuTxPower'
+	});
+    
+    layerGeoStatus = L.tileLayer.betterWms('http://200.50.168.118:8081/geoserver/deviceServer_1/wms', {
+	    layers: 'deviceServer_1:onu_stats_tenancy_1',
+		transparent:true,
+		format: 'image/png',
+        zIndex: 99,
+		maxZoom: 24,
+        styles: 'onuStatus'
+	});
+    
+    var extraLayers = L.control.layers({
+        "TX": layerGeoTx,
+        'RX': layerGeoRx,
+        "Status": layerGeoStatus
+    }, {}, { position: 'topleft', collapsed: false });
+
+    extraLayers.addTo(window.map);
+
+}
+
+/* --------------------- Funciones ------------------------- */
+</script>
+{% endblock %}