olivier.massot 8 年之前
父節點
當前提交
56620c03ea

+ 4 - 4
MobiParc/Controllers/MobiparcController.cs

@@ -24,13 +24,13 @@ namespace mobiparc.Controllers
         }
 
         // POST: api/mobiparc
-        public int Post([FromBody]string value)
+        public bool Post([FromBody]string value)
         {
-           var data =  System.Web.HttpContext.Current.Request["data"];
-           var f= File.CreateText(System.Web.HttpContext.Current.Server.MapPath(@"~/data/" + Guid.NewGuid() +".json"));
+            var data =  System.Web.HttpContext.Current.Request["data"];
+            var f= File.CreateText(System.Web.HttpContext.Current.Server.MapPath(@"~/data/" + Guid.NewGuid() +".json"));
             f.Write(data);
             f.Close();
-            return 0;
+            return true;
         }
 
         // PUT: api/mobiparc/5

+ 1 - 6
MobiParc/MobiParc.csproj

@@ -92,12 +92,6 @@
     <Content Include="bin\fr\System.Web.Http.resources.dll" />
     <Content Include="bin\fr\System.Web.Http.WebHost.resources.dll" />
     <Content Include="packages.config" />
-    <Content Include="data\530e3b26-5b66-4aa0-af9b-446980d322fa.json" />
-    <Content Include="data\5eee9fc9-68e0-447f-8e9e-98cfc91f220d.json" />
-    <Content Include="data\anomalies.json" />
-    <Content Include="data\contacts.json" />
-    <Content Include="data\releves.json" />
-    <Content Include="data\users.json" />
     <Content Include="obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache" />
     <Content Include="obj\Debug\MobiParc.csprojResolveAssemblyReference.cache" />
     <Content Include="bin\MobiParc.dll.config" />
@@ -156,6 +150,7 @@
     <Compile Include="Properties\AssemblyInfo.cs" />
   </ItemGroup>
   <ItemGroup>
+    <Folder Include="data\" />
     <Folder Include="obj\Debug\TempPE\" />
   </ItemGroup>
   <PropertyGroup>

文件差異過大導致無法顯示
+ 0 - 0
MobiParc/data/530e3b26-5b66-4aa0-af9b-446980d322fa.json


+ 0 - 1
MobiParc/data/5eee9fc9-68e0-447f-8e9e-98cfc91f220d.json

@@ -1 +0,0 @@
-{"type":"1","desc":"dggfgdf","tstamp":1513677457704,"user":"2","model":"anomaly"}

+ 0 - 7
MobiParc/data/anomalies.json

@@ -1,7 +0,0 @@
-{"type":[
-{"id":1,"name":"Obstacle à l'écoulement"},
-{"id":2,"name":"Obstacle au passage sur le domaine"},
-{"id":3,"name":"Dégradation ouvrage"},
-{"id":4,"name":"Dégradation hors ouvrage"},
-{"id":5,"name":"Occupation illicite du Domaine"},
-{"id":6,"name":"Autre"}]}

+ 0 - 26
MobiParc/data/contacts.json

@@ -1,26 +0,0 @@
-{
-  "contact": [
-    {
-      "id": 2,
-      "name": "TIRARD",
-      "firstname": "Luc",
-      "email": "luc.tirard@bas-rhin.fr",
-      "phone": "0672193941",
-      "mobile" : "0672193941"
-    },
-    {
-      "id": 3,
-      "name": "PAUTRAT",
-      "firstname": "Hervé",
-      "email": "herve.pautrat@bas-rhin.fr",
-      "phone": "0688346306",
-      "mobile": "0688346306"
-    },
-    {
-      "id": 4,
-      "name": "Accueil du service",
-      "firstname": "",
-      "phone": "0388766341"
-    }
-  ]
-}

+ 0 - 19
MobiParc/data/releves.json

@@ -1,19 +0,0 @@
-{"pr":[
-{"id":"ECH_S1","name":"Station n°1 - Bief n°1"},
-{"id":"ECH_BA1","name":"Echelle ouvrage AD"},
-{"id":"ECH_BA2","name":"Echelle ouvrage AS"},
-{"id":"ECH_PA1","name":"Echelle ouvrage PA1"},
-{"id":"ECH_E1","name":"Echelle écluse n°1"},
-{"id":"ECH_E2","name":"Echelle écluse n°2"},
-{"id":"ECH_E7","name":"Echelle écluse n°7"},
-{"id":"ECH_S2","name":"Station n°2 - Bief n°8"},
-{"id":"ECH_E8","name":"Echelle écluse n°8"},
-{"id":"ECH_RD222","name":"Echelle pont RD 222"},
-{"id":"ECH_S3","name":"Station n°3 - Bief n°9"},
-{"id":"ECH_S4","name":"Station n°4 - Bief n°11"},
-{"id":"ECH_E4","name":"Echelle écluse n°4"},
-{"id":"ECH_PF","name":"Echelle pont SNCF Bief 11"},
-{"id":"ECH_D6","name":"Echelle déversoir D6"},
-{"id":"ECH_D11AM","name":"Echelle amont D11"},
-{"id":"ECH_D11AV","name":"Echelle aval D11"}
-]}

+ 0 - 5
MobiParc/data/users.json

@@ -1,5 +0,0 @@
-{"user":[
-{"id":2,"name":"Clément VIX","mail":"clement.vix@bas-rhin.fr"},
-{"id":4,"name":"Luc TIRARD","mail":"luc.tirard@bas-rhin.fr"},
-{"id":6,"name":"Freddy SITTLER","mail":"freddy.sittler@bas-rhin.fr"}]
-}

+ 22 - 15
MobiParc/js/mobiparc.js

@@ -33,7 +33,10 @@ Handlebars.registerHelper('if_eq', function (a, opts) {
 
 //### Initialisation
 
+var db_name = "MobiParc"
 var db_version = "3"
+var indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB || window.shimIndexedDB;
+var request;
 
 // Installe le service worker
 if ('serviceWorker' in navigator) {
@@ -59,8 +62,8 @@ var load = function () {
         var template = Handlebars.compile(section.html());
 
         // Charge la base de données, et le stockage courant
-        var indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB || window.shimIndexedDB;
-        var request = indexedDB.open("MobiParc", db_version);
+        //var indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB || window.shimIndexedDB;
+        request = indexedDB.open(db_name, db_version);
         var db;
         var txs;
         var store;
@@ -210,26 +213,32 @@ $("#main").selectable({
 
 $(".data-sync").on("click", function () {
 
-    var db = open.result;
-    var txs = db.transaction("activite", "readonly");
-    var stores = txs.objectStore("activite");
-    console.log("post all : ");
+    if (!request) {
+        request = indexedDB.open(db_name, db_version);
+        request.onerror = function () {
+            console.log("Error while accessing the db");
+            alert("Erreur: impossible d'accéder à la base de données locale.");
+            return;
+        };
+    }
+
+    var db = request.result;
+    var txs = db.transaction("activites", "readonly");
+    var stores = txs.objectStore("activites");
+    console.log("post all");
     stores.openCursor().onsuccess = function (event) {
-        //var data =  { data: event.target.result };
         var cursor = event.target.result;
         if (cursor) {
-            //cursor.model = "anomaly";
-
-            cursor.value.model = "activite";
+            cursor.value.model = "activites";
             var id = cursor.value.tstamp;
             var posting = $.post("/api/mobiparc", { data: JSON.stringify(cursor.value) });
 
             // Put the results in a div
             posting.done(function (data) {
-                if (data == 'ole') {
+                if (data == true) {
 
-                    var tx = db.transaction("activite", "readwrite");
-                    var store = tx.objectStore("activite");
+                    var tx = db.transaction("activites", "readwrite");
+                    var store = tx.objectStore("activites");
                     store.delete(id).onsuccess = function (evt) {
                         $('.sync-result').append("Sync ok activite : " + id + "<br>");
                     };
@@ -244,8 +253,6 @@ $(".data-sync").on("click", function () {
     };
 })
 
-
-
 //###### TOOLBOX  ######
 
 function createGuid() {

部分文件因文件數量過多而無法顯示