Browse Source

Various improvements

boutils 10 years ago
parent
commit
3825c93bcf
3 changed files with 86 additions and 27 deletions
  1. 4 4
      ajax/oracle.php
  2. 5 0
      index.html
  3. 77 23
      js/app.js

+ 4 - 4
ajax/oracle.php

@@ -13,10 +13,10 @@
           )";
 
 
-  // if(!isset(oci_connect)) {
-  //   echo json_encode({error: 'No oci_connect'});
-  //   return;
-  // }
+  if(!isset(oci_connect)) {
+    echo json_encode({error: 'No oci_connect'});
+    return;
+  }
 
   // Connexion au service
   $conn = oci_connect('ELIGIBILITE_R', 'H6nmb0KCwR', $db);

+ 5 - 0
index.html

@@ -296,6 +296,11 @@
                   ng-bind-html = "formatDateFTTH(results.ftth.date)">
                 </div>
 
+                <div ng-if = "!results.ftth.date">
+
+                  Déploiement prévu ultérieurement.
+                </div>
+
                 <div
                   class = "box-description-more"
                   ng-if = "!results.ftth._advanced"

+ 77 - 23
js/app.js

@@ -120,11 +120,11 @@ app.controller('mainController', function($scope, $detection, $http, $mdSidenav,
 
   var catAccord = [
     {
-      "name": "J’ai l’intention de souscrire à une offre Très Haut Débit après \r\n le pré-raccordement",
+      "name": "J’ai l’intention de souscrire à une offre Très Haut Débit après le pré-raccordement",
       "id"  : "avec_souscription"
     },
     {
-      "name": "Je n’ai pas l’intention de souscrire à une offre Très Haut Débit après<br> le pré-raccordement",
+      "name": "Je n’ai pas l’intention de souscrire à une offre Très Haut Débit après le pré-raccordement",
       "id"  : "sans_souscription"
     }
   ];
@@ -424,8 +424,10 @@ app.controller('mainController', function($scope, $detection, $http, $mdSidenav,
 
     currentMarker.bindPopup("L'adresse que vous nous avez fournie est localisée sur la carte. Il se peut que la position réelle de votre logement soit un peu différente. Dans ce cas, merci de déplacer le pointeur sur la carte pour le positionner à l'emplacement de votre logement.").openPopup();
 
-     if(withReverse) {
-       reverseLocation($scope.geoCode, null, function(address) {
+    if(withReverse) {
+      $scope.magicKey = null;
+
+      reverseLocation($scope.geoCode, null, function(address) {
         $scope.address = address;
       });
     }
@@ -434,6 +436,8 @@ app.controller('mainController', function($scope, $detection, $http, $mdSidenav,
       var p = currentMarker.getLatLng();
       //console.log('dragend', p);
 
+      $scope.magicKey = null;
+
       $scope.geoCode = {
         x: p.lng,
         y: p.lat
@@ -455,10 +459,13 @@ app.controller('mainController', function($scope, $detection, $http, $mdSidenav,
       return;
     }
 
-    // Compute Date
-    var momentDate = moment($scope.results.ftth.DATE_FIN_TRAV_PREV, 'DD/MM/YY');
-    momentDate.add(nbJoursFTTH, 'days');
-    $scope.results.ftth.date = momentDate.format('DD/MM/YYYY');
+    else if($scope.results.ftth.DATE_FIN_TRAV_PREV) {
+
+      // Compute Date
+      var momentDate = moment($scope.results.ftth.DATE_FIN_TRAV_PREV, 'DD/MM/YY');
+      momentDate.add(nbJoursFTTH, 'days');
+      $scope.results.ftth.date = momentDate.format('DD/MM/YYYY');
+    }
   };
 
   var computeFullAdress = function() {
@@ -469,6 +476,45 @@ app.controller('mainController', function($scope, $detection, $http, $mdSidenav,
     return moment(value.toString().substr(0,4) + '-' + value.toString().substr(4,2) + '-' + value.toString().substr(6,2)).locale("fr");
   };
 
+  var getFullAddress = function(callback) {
+
+    if($scope.magicKey) {
+      var findURL  = 'http://api-adresse.data.gouv.fr/search/?';
+      var url      = findURL + "q=" + $scope.address;
+
+      $.get(
+      url,
+      function(data, status) {
+
+        var next = function(record) {
+
+          reverseLocation($scope.geoCode, null, function(string, address) {
+            if(record) {
+              address.StreetNumber = record.housenumber;
+              address.Match_addr   = $scope.address;
+            }
+
+            callback(null, address);
+          });
+        };
+
+        if(data && data.features && data.features[0] && data.features[0].properties) {
+
+          next(data.features[0].properties);
+        }
+        else {
+          next();
+        }
+      });
+    }
+    else {
+
+      reverseLocation($scope.geoCode, null, function(string, address) {
+        callback(null, address);
+      });
+    }
+  };
+
   var getRecordsFor = function(identifier, coordinates) {
     var records = [];
     _.each($scope.data[identifier], function(record) {
@@ -513,8 +559,9 @@ app.controller('mainController', function($scope, $detection, $http, $mdSidenav,
     .error(function(err) {
       console.error('Oracle issue', err);
 
+      //[{"ID_ZAPM_PARTIELLE":"119CP0","DATE_OUV_SERVICE_REEL":null,"DATE_OUV_SERVICE_PREV":null,"DATE_FIN_TRAV_PREV":null}]
       // Debug without Oracle access
-      onResults('{"x":-1.1060984089996,"y":49.119046582,"ftth":[{"ID_ZAPM_PARTIELLE":"203AP0","DATE_OUV_SERVICE_REEL":null,"DATE_OUV_SERVICE_PREV":null,"DATE_FIN_TRAV_PREV":"02\/05\/16"}],"adsl":[{"ID_FT_ADSL":"656","LEGENDE":"TV sur ADSL","NATURE":"0 - 37"}],"mimo":null}');
+      onResults('{"x":-1.1060984089996,"y":49.119046582,"ftth":[{"ID_ZAPM_PARTIELLE":"203AP0","DATE_OUV_SERVICE_REEL":null,"DATE_OUV_SERVICE_PREV":null,"DATE_FIN_TRAV_PREV":"04\/05\/16"}],"adsl":[{"ID_FT_ADSL":"656","LEGENDE":"TV sur ADSL","NATURE":"0 - 37"}],"mimo":null}');
     })
     .done(function( msg ) {
       onResults(msg);
@@ -539,7 +586,7 @@ app.controller('mainController', function($scope, $detection, $http, $mdSidenav,
         $scope.hideResultPane();
       }
 
-      console.log('$scope.results', results, '=>', $scope.results);
+      //console.log('$scope.results', results, '=>', $scope.results);
       $scope.$apply();
     };
 
@@ -855,7 +902,7 @@ app.controller('mainController', function($scope, $detection, $http, $mdSidenav,
   };
 
   $scope.formatDateFTTH = function(date) {
-    if(!date) {return;}
+    if(!date || date === "Invalid date") {return;}
     var momentDate = moment(date, 'DD/MM/YYYY');
 
     var result =  '<div class="popup-line"><div class="box-eligibilite-title">Date prévisionnelle abonnement FTTH</div><div style="font-weight: bold;" class="popup-value">' + momentDate.locale("fr").format('ddd, LL') + '</div><div class="popup-small-date">' + momentDate.locale("fr").fromNow() + '</div></div>';
@@ -888,15 +935,15 @@ app.controller('mainController', function($scope, $detection, $http, $mdSidenav,
            data.locations[0].extent.xmin > searchExtent.xmax) {
 
           getGeoCodeInProgress = false;
-          console.debug('getGeoCode', address, magicKey, '=>', data);
+          //console.debug('getGeoCode', address, magicKey, '=>', data);
           return callback(null, data);
         }
         getGeoCodeInProgress = false;
-        console.debug('getGeoCode', address, magicKey, '=>', 'No result');
+        //console.debug('getGeoCode', address, magicKey, '=>', 'No result');
         callback('No result for ' + address);
       } else {
         getGeoCodeInProgress = false;
-        console.debug('getGeoCode', address, magicKey, '=>', 'No result');
+        //console.debug('getGeoCode', address, magicKey, '=>', 'No result');
 
         callback(status !== 'success' ? status : 'No result for ' + address);
       }
@@ -958,7 +1005,10 @@ app.controller('mainController', function($scope, $detection, $http, $mdSidenav,
   $scope.initPopup = function() {
     //console.log('initPopup', $scope.geoCode);
     $scope.postForm = null;
-    reverseLocation($scope.geoCode, null, function(string, address) {
+
+    getFullAddress(function(err, address) {
+      if(err) {console.error(err);}
+
       //console.log('add', address);
       $scope.result = {eligibilite: {}, autres: {}};
 
@@ -1175,14 +1225,18 @@ app.controller('mainController', function($scope, $detection, $http, $mdSidenav,
 
         //console.log('$scope.result', $scope.result);
 
-        body += '</table></div><br>';
-
-        body += 'Conformément à la loi "informatique et libertés" du 6 janvier 1978 modifiée, vous bénéficiez d’un droit d’accès, de rectification aux informations qui vous concernent, d’opposition au traitement de vos données personnelles. Si vous souhaitez exercer ce droit et obtenir communication des informations vous concernant, merci de nous contacter :' + '<br>' +
-                '<div style="">' +
-                ' Email: ' + siteEmail + '<br>' +
-                ' Adresse: ' + siteAddresse + '<br>' +
-                ' Tel: ' + siteTel + '<br>' +
-                '</div><br><br>';
+        body += '</table></div><br><br>';
+
+        body += 'Conformément à la loi "informatique et libertés" du 6 janvier 1978 modifiée, vous bénéficiez d’un droit d’accès, de rectification aux informations qui vous concernent, d’opposition au traitement de vos données personnelles. Si vous souhaitez exercer ce droit et obtenir la communication des informations vous concernant, merci de nous contacter :' + '<br>' +
+                '<table style="">' +
+                '  <tr>' +
+                ' <th style="text-align: left;white-space: nowrap;height: 30px;color: #666;">Email</th><td>' + siteEmail + '</td>' +
+                '  </tr><tr>' +
+                ' <th style="text-align: left;white-space: nowrap;height: 30px;color: #666;">Adresse</th><td>' + siteAddresse + '</td>' +
+                '  </tr><tr>' +
+                ' <th style="text-align: left;white-space: nowrap;height: 30px;color: #666;">Tel</th><td>' + siteTel + '</td>' +
+                '  </tr>' +
+                '</table><br><br>';
 
         body += 'A bientôt sur:  <a href="' + siteUrl + '">' + siteName + '</a>';