Browse Source

started with database structue change

Manuel Gall 3 years ago
parent
commit
0933079705

BIN
server/database/stations.db


+ 144 - 0
server/json/ProductCode.json

@@ -0,0 +1,144 @@
+{
+  "pattern": [
+    {
+      "name": "Produktbereich",
+      "abk": "Pb",
+      "types": [
+        "E"
+      ]
+    },
+    {
+      "name": "System",
+      "abk": "Sy",
+      "types": [
+        "X",
+        "A"
+      ]
+    },
+    {
+      "name": "Produktkategorie",
+      "abk": "Pk",
+      "types": [
+        "PZ"
+      ]
+    },
+    {
+      "name": "Bauart",
+      "abk": "Ba",
+      "types": [
+        "*",
+        "KZ-S",
+        "RKZ-S",
+        "HZ-S",
+        "RHZ-S",
+        "DZ-S",
+        "RDZ-S"
+      ]
+    },
+    {
+      "name": "Zylinderlänge außen",
+      "abk": "Za",
+      "types": [
+        "*",
+        "31",
+        "36",
+        "41",
+        "46",
+        "51",
+        "56",
+        "61"
+      ]
+    },
+    {
+      "name": "Zylinderlänge Innen",
+      "abk": "Zi",
+      "types": [
+        "*",
+        "31",
+        "36",
+        "41",
+        "46",
+        "51",
+        "56",
+        "61",
+        "K31",
+        "K36",
+        "K41",
+        "K46",
+        "K51",
+        "K56",
+        "K61"
+      ]
+    },
+    {
+      "name": "Oberfläche",
+      "abk": "Of",
+      "types": [
+        "",
+        "*",
+        "NI",
+        "NP",
+        "MP",
+        "PB",
+        "PS"
+      ]
+    },
+    {
+      "name": "Knaufform",
+      "abk": "Kf",
+      "types": [
+        "",
+        "*",
+        "X1K",
+        "ATA",
+        "Blind",
+        "2GW4"
+      ]
+    },
+    {
+      "name": "Panikfunktion",
+      "abk": "Pf",
+      "types": [
+        "",
+        "*",
+        "FZG",
+        "FAP",
+        "FLU",
+        "FSR"
+      ]
+    },
+    {
+      "name": "Verlängerte Außenachse",
+      "abk": "Va",
+      "types": [
+        "",
+        "*",
+        "AV05",
+        "AV10",
+        "AV15"
+      ]
+    },
+    {
+      "name": "Schließnase",
+      "abk": "Sn",
+      "types": [
+        "",
+        "*",
+        "SEP",
+        "SRP",
+        "BIF",
+        "Z10",
+        "Z18"
+      ]
+    },
+    {
+      "name": "Zusatzzertifikat",
+      "abk": "Zs",
+      "types": [
+        "",
+        "*",
+        "SKG"
+      ]
+    }
+  ]
+}

+ 757 - 0
server/json/Rectangle.json

@@ -0,0 +1,757 @@
+{
+  "Configs": [
+    {
+      "name": "Station1",
+      "rects": [
+        {
+          "id": "0",
+          "X": 0,
+          "Y": 0,
+          "W": 200,
+          "H": 200,
+          "pattern": {
+            "Pb": true,
+            "Sy": true,
+            "Pk": true,
+            "Ba": true,
+            "Kf": true
+          }
+        },
+        {
+          "id": "1",
+          "X": 500,
+          "Y": 500,
+          "W": 200,
+          "H": 200,
+          "pattern": {
+            "Pb": true,
+            "Sy": true,
+            "Pk": true
+          }
+        }
+      ]
+    },
+    {
+      "name": "Station2",
+      "rects": [
+        {
+          "id": "0",
+          "X": 1000,
+          "Y": 1000,
+          "W": 200,
+          "H": 200,
+          "pattern": {
+            "Pb": true,
+            "Sy": true
+          }
+        }
+      ]
+    },
+    {
+      "name": "StationTest",
+      "rects": [
+        {
+          "id": "0",
+          "X": "20",
+          "Y": "75",
+          "W": "580",
+          "H": "160",
+          "pattern": {
+            "Pb": true,
+            "Sy": true,
+            "Pk": true,
+            "Ba": true,
+            "Zs": true
+          },
+          "idtext": ""
+        },
+        {
+          "id": "1",
+          "X": "20",
+          "Y": "235",
+          "W": "340",
+          "H": "500",
+          "pattern": {
+            "Pb": true,
+            "Sy": true,
+            "Pk": true,
+            "Ba": true,
+            "Sn": true
+          },
+          "idtext": ""
+        },
+        {
+          "id": "2",
+          "X": "360",
+          "Y": "235",
+          "W": "220",
+          "H": "190",
+          "pattern": {
+            "Pb": true,
+            "Sy": true,
+            "Pk": true,
+            "Ba": true,
+            "Kf": true
+          },
+          "idtext": ""
+        },
+        {
+          "id": "3",
+          "X": "360",
+          "Y": "425",
+          "W": "220",
+          "H": "80",
+          "pattern": {
+            "Pb": true,
+            "Sy": true,
+            "Pk": true,
+            "Ba": true,
+            "Pf": true
+          },
+          "idtext": ""
+        },
+        {
+          "id": "4",
+          "X": "580",
+          "Y": "235",
+          "W": "500",
+          "H": "200",
+          "pattern": {
+            "Pb": true,
+            "Sy": true,
+            "Pk": true,
+            "Ba": true,
+            "Za": true,
+            "Zi": true
+          },
+          "idtext": ""
+        },
+        {
+          "id": "5",
+          "X": "360",
+          "Y": "505",
+          "W": "220",
+          "H": "230",
+          "pattern": {
+            "Pb": true,
+            "Sy": true,
+            "Pk": true,
+            "Ba": true,
+            "Va": true
+          },
+          "idtext": "cc"
+        },
+        {
+          "id": "6",
+          "X": "600",
+          "Y": "75",
+          "W": "480",
+          "H": "160",
+          "pattern": {
+            "Pb": true,
+            "Sy": true,
+            "Pk": true,
+            "Of": true
+          },
+          "idtext": "bb"
+        },
+        {
+          "id": "7",
+          "X": "580",
+          "Y": "435",
+          "W": "500",
+          "H": "300",
+          "pattern": {
+            "Pb": true,
+            "Sy": true,
+            "Pk": true,
+            "Of": true,
+            "Kf": true
+          },
+          "idtext": "aa"
+        }
+      ]
+    },
+    {
+      "name": "Station3_SEP",
+      "rects": [
+        {
+          "id": "0",
+          "X": "535",
+          "Y": "100",
+          "W": "410",
+          "H": "180",
+          "pattern": {
+            "Ba": true,
+            "Za": true,
+            "Zi": false,
+            "Of": true,
+            "Kf": false,
+            "Pf": true,
+            "Va": true,
+            "Sn": false
+          },
+          "idtext": ""
+        },
+        {
+          "id": "1",
+          "X": "945",
+          "Y": "100",
+          "W": "109",
+          "H": "180",
+          "pattern": {
+            "Ba": true,
+            "Za": false,
+            "Zi": false,
+            "Of": false,
+            "Kf": false,
+            "Pf": false,
+            "Va": false,
+            "Sn": true
+          },
+          "idtext": ""
+        },
+        {
+          "id": "2",
+          "X": "1054",
+          "Y": "100",
+          "W": "411",
+          "H": "180",
+          "pattern": {
+            "Ba": true,
+            "Za": false,
+            "Zi": true,
+            "Of": true,
+            "Kf": true,
+            "Pf": true,
+            "Va": false,
+            "Sn": false
+          },
+          "idtext": ""
+        },
+        {
+          "id": "3",
+          "X": "535",
+          "Y": "280",
+          "W": "449",
+          "H": "200",
+          "pattern": {
+            "Ba": true,
+            "Za": true,
+            "Zi": false,
+            "Of": true,
+            "Kf": false,
+            "Pf": true,
+            "Va": true,
+            "Sn": false
+          },
+          "idtext": "SEP"
+        },
+        {
+          "id": "4",
+          "X": "984",
+          "Y": "280",
+          "W": "42",
+          "H": "200",
+          "pattern": {
+            "Ba": true,
+            "Za": false,
+            "Zi": false,
+            "Of": false,
+            "Kf": false,
+            "Pf": false,
+            "Va": false,
+            "Sn": true
+          },
+          "idtext": "SEP"
+        },
+        {
+          "id": "5",
+          "X": "1024",
+          "Y": "280",
+          "W": "440",
+          "H": "200",
+          "pattern": {
+            "Ba": true,
+            "Za": false,
+            "Zi": true,
+            "Of": true,
+            "Kf": true,
+            "Pf": true,
+            "Va": false,
+            "Sn": false
+          },
+          "idtext": "SEP"
+        },
+        {
+          "id": "6",
+          "X": "535",
+          "Y": "480",
+          "W": "260",
+          "H": "550",
+          "pattern": {
+            "Ba": false,
+            "Za": false,
+            "Zi": false,
+            "Of": false,
+            "Kf": false,
+            "Pf": false,
+            "Va": false,
+            "Sn": false
+          },
+          "idtext": "Le6"
+        },
+        {
+          "id": "7",
+          "X": "795",
+          "Y": "480",
+          "W": "170",
+          "H": "265",
+          "pattern": {
+            "Ba": false,
+            "Za": false,
+            "Zi": false,
+            "Of": false,
+            "Kf": false,
+            "Pf": false,
+            "Va": false,
+            "Sn": false
+          },
+          "idtext": "4Bat"
+        },
+        {
+          "id": "8",
+          "X": "965",
+          "Y": "480",
+          "W": "500",
+          "H": "265",
+          "pattern": {
+            "Ba": false,
+            "Za": false,
+            "Zi": false,
+            "Of": false,
+            "Kf": false,
+            "Pf": false,
+            "Va": false,
+            "Sn": false
+          },
+          "idtext": "Le8"
+        },
+        {
+          "id": "9",
+          "X": "795",
+          "Y": "745",
+          "W": "180",
+          "H": "90",
+          "pattern": {
+            "Ba": false,
+            "Za": false,
+            "Zi": false,
+            "Of": false,
+            "Kf": false,
+            "Pf": true,
+            "Va": false,
+            "Sn": false
+          },
+          "idtext": ""
+        },
+        {
+          "id": "10",
+          "X": "795",
+          "Y": "835",
+          "W": "180",
+          "H": "195",
+          "pattern": {
+            "Ba": false,
+            "Za": false,
+            "Zi": false,
+            "Of": true,
+            "Kf": false,
+            "Pf": false,
+            "Va": false,
+            "Sn": false
+          },
+          "idtext": ""
+        },
+        {
+          "id": "11",
+          "X": "975",
+          "Y": "745",
+          "W": "190",
+          "H": "90",
+          "pattern": {
+            "Ba": true,
+            "Za": false,
+            "Zi": false,
+            "Of": false,
+            "Kf": false,
+            "Pf": true,
+            "Va": false,
+            "Sn": false
+          },
+          "idtext": ""
+        },
+        {
+          "id": "12",
+          "X": "975",
+          "Y": "835",
+          "W": "190",
+          "H": "195",
+          "pattern": {
+            "Ba": true,
+            "Za": false,
+            "Zi": false,
+            "Of": true,
+            "Kf": false,
+            "Pf": false,
+            "Va": false,
+            "Sn": false
+          },
+          "idtext": ""
+        },
+        {
+          "id": "13",
+          "X": "1165",
+          "Y": "745",
+          "W": "120",
+          "H": "285",
+          "pattern": {
+            "Ba": false,
+            "Za": false,
+            "Zi": false,
+            "Of": false,
+            "Kf": false,
+            "Pf": false,
+            "Va": false,
+            "Sn": false
+          },
+          "idtext": "Le13"
+        },
+        {
+          "id": "14",
+          "X": "1285",
+          "Y": "745",
+          "W": "180",
+          "H": "285",
+          "pattern": {
+            "Ba": false,
+            "Za": false,
+            "Zi": false,
+            "Of": false,
+            "Kf": false,
+            "Pf": false,
+            "Va": false,
+            "Sn": false
+          },
+          "idtext": "Le14"
+        }
+      ]
+    },
+    {
+      "name": "Station98",
+      "rects": [
+        {
+          "id": "0",
+          "X": "535",
+          "Y": "100",
+          "W": "410",
+          "H": "180",
+          "pattern": {
+            "Ba": false,
+            "Za": false,
+            "Zi": false,
+            "Of": false,
+            "Kf": false,
+            "Pf": false,
+            "Va": false,
+            "Sn": false
+          },
+          "idtext": ""
+        },
+        {
+          "id": "13",
+          "X": "945",
+          "Y": "100",
+          "W": "109",
+          "H": "180",
+          "pattern": {
+            "Ba": false,
+            "Za": false,
+            "Zi": false,
+            "Of": false,
+            "Kf": false,
+            "Pf": false,
+            "Va": false,
+            "Sn": false
+          },
+          "idtext": ""
+        },
+        {
+          "id": "14",
+          "X": "1054",
+          "Y": "100",
+          "W": "411",
+          "H": "180",
+          "pattern": {
+            "Ba": false,
+            "Za": false,
+            "Zi": false,
+            "Of": false,
+            "Kf": false,
+            "Pf": false,
+            "Va": false,
+            "Sn": false
+          },
+          "idtext": ""
+        },
+        {
+          "id": "1",
+          "X": "535",
+          "Y": "280",
+          "W": "449",
+          "H": "200",
+          "pattern": {
+            "Ba": false,
+            "Za": false,
+            "Zi": false,
+            "Of": false,
+            "Kf": false,
+            "Pf": false,
+            "Va": false,
+            "Sn": false
+          },
+          "idtext": ""
+        },
+        {
+          "id": "2",
+          "X": "984",
+          "Y": "280",
+          "W": "42",
+          "H": "200",
+          "pattern": {
+            "Ba": false,
+            "Za": false,
+            "Zi": false,
+            "Of": false,
+            "Kf": false,
+            "Pf": false,
+            "Va": false,
+            "Sn": false
+          },
+          "idtext": ""
+        },
+        {
+          "id": "3",
+          "X": "1024",
+          "Y": "280",
+          "W": "440",
+          "H": "200",
+          "pattern": {
+            "Ba": false,
+            "Za": false,
+            "Zi": false,
+            "Of": false,
+            "Kf": false,
+            "Pf": false,
+            "Va": false,
+            "Sn": false
+          },
+          "idtext": ""
+        },
+        {
+          "id": "4",
+          "X": "535",
+          "Y": "480",
+          "W": "260",
+          "H": "550",
+          "pattern": {
+            "Ba": false,
+            "Za": false,
+            "Zi": false,
+            "Of": false,
+            "Kf": false,
+            "Pf": false,
+            "Va": false,
+            "Sn": false
+          },
+          "idtext": ""
+        },
+        {
+          "id": "5",
+          "X": "795",
+          "Y": "480",
+          "W": "170",
+          "H": "265",
+          "pattern": {
+            "Ba": false,
+            "Za": false,
+            "Zi": false,
+            "Of": false,
+            "Kf": false,
+            "Pf": false,
+            "Va": false,
+            "Sn": false
+          },
+          "idtext": ""
+        },
+        {
+          "id": "6",
+          "X": "965",
+          "Y": "480",
+          "W": "500",
+          "H": "265",
+          "pattern": {
+            "Ba": false,
+            "Za": false,
+            "Zi": false,
+            "Of": false,
+            "Kf": false,
+            "Pf": false,
+            "Va": false,
+            "Sn": false
+          },
+          "idtext": ""
+        },
+        {
+          "id": "7",
+          "X": "795",
+          "Y": "745",
+          "W": "180",
+          "H": "90",
+          "pattern": {
+            "Ba": false,
+            "Za": false,
+            "Zi": false,
+            "Of": false,
+            "Kf": false,
+            "Pf": false,
+            "Va": false,
+            "Sn": false
+          },
+          "idtext": ""
+        },
+        {
+          "id": "8",
+          "X": "795",
+          "Y": "835",
+          "W": "180",
+          "H": "195",
+          "pattern": {
+            "Ba": false,
+            "Za": false,
+            "Zi": false,
+            "Of": false,
+            "Kf": false,
+            "Pf": false,
+            "Va": false,
+            "Sn": false
+          },
+          "idtext": ""
+        },
+        {
+          "id": "9",
+          "X": "975",
+          "Y": "745",
+          "W": "190",
+          "H": "90",
+          "pattern": {
+            "Ba": false,
+            "Za": false,
+            "Zi": false,
+            "Of": false,
+            "Kf": false,
+            "Pf": false,
+            "Va": false,
+            "Sn": false
+          },
+          "idtext": ""
+        },
+        {
+          "id": "10",
+          "X": "975",
+          "Y": "835",
+          "W": "190",
+          "H": "195",
+          "pattern": {
+            "Ba": false,
+            "Za": false,
+            "Zi": false,
+            "Of": false,
+            "Kf": false,
+            "Pf": false,
+            "Va": false,
+            "Sn": false
+          },
+          "idtext": ""
+        },
+        {
+          "id": "11",
+          "X": "1165",
+          "Y": "745",
+          "W": "120",
+          "H": "285",
+          "pattern": {
+            "Ba": false,
+            "Za": false,
+            "Zi": false,
+            "Of": false,
+            "Kf": false,
+            "Pf": false,
+            "Va": false,
+            "Sn": false
+          },
+          "idtext": ""
+        },
+        {
+          "id": "12",
+          "X": "1285",
+          "Y": "745",
+          "W": "180",
+          "H": "285",
+          "pattern": {
+            "Ba": false,
+            "Za": false,
+            "Zi": false,
+            "Of": false,
+            "Kf": false,
+            "Pf": false,
+            "Va": false,
+            "Sn": false
+          },
+          "idtext": ""
+        }
+      ]
+    },
+    {
+      "name": "Station99",
+      "rects": [
+        {
+          "id": "0",
+          "X": 0,
+          "Y": 0,
+          "W": 200,
+          "H": 200,
+          "pattern": {
+            "Pb": true,
+            "Sy": true,
+            "Pk": true,
+            "Ba": true,
+            "Kf": true
+          }
+        },
+        {
+          "id": "1",
+          "X": 500,
+          "Y": 500,
+          "W": 200,
+          "H": 200,
+          "pattern": {
+            "Pb": true,
+            "Sy": true,
+            "Pk": true
+          }
+        }
+      ]
+    }
+  ]
+}

+ 7 - 0
server/json/SlicerConfig.json

@@ -0,0 +1,7 @@
+{
+  "saveLocation": [
+    "../../universal-storage/storage/Stationsbilder/Einzelbilder/Station3/",
+    "../../universal-storage/storage/Stationsbilder/Einzelbilder/Station99/"
+  ],
+  "SlicerRectForm": true
+}

+ 8 - 2
server/rngs/pattern.rng

@@ -4,10 +4,16 @@
   <define name="pattern">
     <element name="pattern">
       <attribute name="id"><data type="nonNegativeInteger"/></attribute>
-      <attribute name="value"><text/></attribute>
       <attribute name="description"><text/></attribute>
       <attribute name="changed"><data type="dateTime"/></attribute>
-	  
+      <element name="parts">
+        <zeroOrMore>
+          <element>
+            <anyName/>
+            <text/>
+          </element>
+        </zeroOrMore>
+      </element>
       <zeroOrMore>
         <ref name="images"/>
       </zeroOrMore>

+ 1 - 1
server/was.conf

@@ -1,4 +1,4 @@
 :port: 9323
 :appconf:
   wizurl: https://centurio.work/wiz/wiztest/
-  stations: [ 1, 2, 3, 8 ]
+  stations: [ 1, 2, 3, 8, 99]

+ 163 - 73
server/was.rb

@@ -30,15 +30,35 @@ $db = SQLite3::Database.open 'database/stations.db'
 
 
 
+class GetJsonFiles < Riddl::Implementation
+  def response
+    Dir.chdir( __dir__  + '/json')
+    ret = [];
+    Dir.glob('*').select{ |e| 
+      ret.append(e)
+    }
+    Riddl::Parameter::Complex.new('list','application/json',JSON::pretty_generate(ret))
+  end
+end
+
 
-class CutImage < Riddl::Implementation
+class GetJson < Riddl::Implementation
   def response
-    puts "Cutting"
-    "Cutting"
+    Dir.chdir( __dir__  + '/json')
+    Riddl::Parameter::Complex.new('list','application/json',File.open(@r[1]).read) rescue Riddl::Parameter::Complex.new('list','application/json', '{"error":"No such file"}')
   end
 end
 
 
+class SaveJson < Riddl::Implementation
+  def response
+    Dir.chdir( __dir__  + '/json')
+    File.write(@r.last,(@p[0].value.read))
+    end
+end
+
+
+
 class GetStations < Riddl::Implementation
   def response
     result = $db.execute "SELECT * FROM stations"
@@ -47,9 +67,22 @@ class GetStations < Riddl::Implementation
       xml.stations {
         result.each do |row|
           xml.station(:id => row[0]){
-            resultstation = $db.execute "SELECT * FROM station WHERE station = #{row[0]}"
+            resultstation = $db.execute "SELECT * FROM stationpattern WHERE station = #{row[0]}"
             resultstation.each do |row|
-              xml.pattern(:id => row[1], :value => row[2], :description => row[3], :changed => row[4])
+              xml.pattern(:id => row[1], :description => row[2], :changed => row[3]){
+              xml.parts{
+                resultpattern = $db.execute "SELECT * FROM pattern WHERE internalID = #{row[1]}"
+                resultpattern.each do |row2|
+                  xml.send(row2[1], row2[2])
+                end
+
+
+
+  #$db.execute "CREATE TABLE IF NOT EXISTS pattern(internalID INT, type CHARACTER(20), value CHARACTER(20), FOREIGN KEY(internalID) REFERENCES stationpattern(internalID) ON DELETE CASCADE)"
+  
+  
+              }
+              }
             end
           }
         end
@@ -83,14 +116,24 @@ end
 
 class GetStation < Riddl::Implementation
   def self::prepare(id)
-    result = $db.execute "SELECT * FROM station WHERE station = #{id}"
+  
+    resultstation = $db.execute "SELECT * FROM stationpattern WHERE station = #{id}"
+    
     Nokogiri::XML::Builder.new do |xml|
       xml.station(:id => id){
-        result.each do |row|
-          xml.pattern(:id => row[1], :value => row[2], :description => row[3], :changed => row[4])
+        resultstation.each do |row|
+          xml.pattern(:id => row[1], :description => row[2], :changed => row[3]){
+            xml.parts{
+              resultpattern = $db.execute "SELECT * FROM pattern WHERE internalID = #{row[1]}"
+              resultpattern.each do |row2|
+                xml.send(row2[1], row2[2])
+              end
+            }
+          }
         end
       }
     end
+
   end
   
   def response
@@ -101,17 +144,22 @@ end
 
 class CreatePattern < Riddl::Implementation
   def response
-
     doc = Nokogiri::XML(@p[0].value)
-    result = $db.execute "SELECT MAX(patternID) FROM station"
+    result = $db.execute "SELECT MAX(internalID) FROM stationpattern"
     if(result[0][0] == nil)
       id = 0
       else
       id = result[0][0] +1
     end
     
-    values = doc.xpath("/*/@value")[0].value.split(".")
-    $db.execute("INSERT INTO station (station, patternID, pattern, description, date, P0, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", [@r.last, id, doc.xpath("/*/@value")[0].value, doc.xpath("/*/@description")[0].value, doc.xpath("/*/@changed")[0].value, values[0], values[1], values[2], values[3], values[4], values[5], values[6], values[7], values[8], values[9], values[10]])
+    
+    $db.execute("INSERT INTO stationpattern (station, internalID, description, date) VALUES (?,?,?,?)", [@r.last, id, doc.xpath("/*/@description")[0].value, doc.xpath("/*/@changed")[0].value])
+    
+    doc.xpath(".//parts/*").each do |node|
+      if(node.text != "")
+        $db.execute("INSERT INTO pattern (internalID, type, value) VALUES (?,?,?)", [id, node.name, node.text])
+      end
+    end
     
     
     ret = {:id => id}
@@ -124,9 +172,18 @@ end
 
 class GetPattern < Riddl::Implementation
   def response
-    result = $db.execute "SELECT * FROM station WHERE station = #{@r[0]} and patternID = #{@r[1]}"
+    resultstation = $db.execute "SELECT * FROM stationpattern WHERE station = #{@r[0]} AND internalID = #{@r[1]}"
     builder = Nokogiri::XML::Builder.new do |xml|
-      xml.pattern(:id => result[0][1], :value => result[0][2], :description => result[0][3], :changed => result[0][4])
+      resultstation.each do |row|
+      xml.pattern(:id => row[1], :description => row[2], :changed => row[3]){
+          xml.parts{
+            resultpattern = $db.execute "SELECT * FROM pattern WHERE internalID = #{row[1]}"
+            resultpattern.each do |row2|
+              xml.send(row2[1], row2[2])
+            end
+          }
+        }
+      end
     end
     Riddl::Parameter::Complex.new('pattern','application/xml',builder.to_xml)
   end
@@ -134,28 +191,22 @@ end
 
 class UpdatePattern < Riddl::Implementation
   def response
-    
     doc = Nokogiri::XML(@p[0].value)
-    #puts "UPdate Pattern" + @r[0] + @r[1] + " value " + doc.xpath("/*/@value")[0].value
-    #$db.execute("DELETE FROM station WHERE  station = ? AND patternID = ?", [@r[0], @r[1]])
-    
-    
-    values = doc.xpath("/*/@value")[0].value.split(".")    
-    #$db.execute("INSERT INTO station (station, patternID, pattern, description, date, P0, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", [@r[0], @r[1], doc.xpath("/*/@value")[0].value, doc.xpath("/*/@description")[0].value, doc.xpath("/*/@changed")[0].value, values[0], values[1], values[2], values[3], values[4], values[5], values[6], values[7], values[8], values[9], values[10]])
-    
-    #$db.execute("UPDATE image SET imageID = ? WHERE  station = ? AND patternID = ? AND imageID = ? AND language = ?", [999999, @r[0], @r[1], i, @r[4]])
+    $db.execute("Update stationpattern SET description = ?, date = ? WHERE internalID = ?", [doc.xpath("/*/@description")[0].value, doc.xpath("/*/@changed")[0].value, @r[1]])
     
-    $db.execute("Update station SET  pattern = ?, description = ?, date = ?, P0 = ?, P1 = ?, P2 = ?, P3 = ?, P4 = ?, P5 = ?, P6 = ?, P7 = ?, P8 = ?, P9 = ?, P10 = ? WHERE station = ? AND patternID = ?", [doc.xpath("/*/@value")[0].value, doc.xpath("/*/@description")[0].value, doc.xpath("/*/@changed")[0].value, values[0], values[1], values[2], values[3], values[4], values[5], values[6], values[7], values[8], values[9], values[10], @r[0], @r[1]])
-    
-    #$db.execute("INSERT INTO station (station, patternID, pattern, description, date) VALUES (?,?,?,?,?)", [@r[0], @r[1]], doc.xpath("/*/@value")[0].value, doc.xpath("/*/@description")[0].value, doc.xpath("/*/@changed")[0].value)
-    
-    #$db.execute("UPDATE station SET pattern = ? and description = ? and date = ? WHERE station = ? and patternID = ?", [doc.xpath("/*/@value")[0].value, doc.xpath("/*/@description")[0].value, doc.xpath("/*/@changed")[0].value, @r[0], @r[1]])
+    $db.execute("DELETE FROM pattern WHERE  internalID = ?", [@r[1]])
+
+    doc.xpath(".//parts/*").each do |node|
+      if(node.text != "")
+        $db.execute("INSERT INTO pattern (internalID, type, value) VALUES (?,?,?)", [@r[1], node.name, node.text])
+      end
+    end
   end
 end
 
 class DeletePattern < Riddl::Implementation
   def response
-    $db.execute("DELETE FROM station WHERE  station = ? AND patternID = ?", [@r[0], @r[1]])
+    $db.execute("DELETE FROM stationpattern WHERE internalID = ?", [@r[1]])
   end
 end
 
@@ -164,27 +215,41 @@ class DuplicatePattern < Riddl::Implementation
     
     
     #duplicate db etwas mühsam da der eintrag kopiert werden muss und dabei die unique ID verändert werden muss daher geht insert into select nicht so ganz.
-    result = $db.execute "SELECT MAX(patternID) FROM station"
+    result = $db.execute "SELECT MAX(internalID) FROM stationpattern"
     if(result[0][0] == nil)
       id = 0
       else
       id = result[0][0] +1
     end
     
-    result = $db.execute "SELECT * FROM station WHERE station = #{@r[0]} and patternID = #{@r[1]}"
+    result = $db.execute "SELECT * FROM stationpattern WHERE internalID = #{@r[1]}"
     result[0][1] = id;
-    questionmarks = ""
-    result[0].length().times{questionmarks = questionmarks + ",?"}
-    questionmarks[0] = ""
+    $db.execute( "INSERT INTO stationpattern values (?,?,?,?)", result[0])
+    
+    
+    
+    result = $db.execute "SELECT * FROM pattern WHERE internalID = #{@r[1]}"
+    result.each do |row|
+      row[0] = id;
+      $db.execute( "INSERT INTO pattern values (?,?,?)", row)
+    end
+    
+
+
+
+    
+
     
     
-    $db.execute( "INSERT INTO station values (#{questionmarks})", result[0])
     #duplicate error
-    result = $db.execute "SELECT * FROM error WHERE station = #{@r[0]} and patternID = #{@r[1]}"
+    
+    #$db.execute "CREATE TABLE IF NOT EXISTS error(internalID INT, error TEXT, FOREIGN KEY(internalID) REFERENCES stationpattern(internalID) ON DELETE CASCADE)"
+    
+    result = $db.execute "SELECT * FROM error WHERE internalID = #{@r[1]}"
     
     if(result[0] != nil)
       result.each do |row|
-        row[1] = id;
+        row[0] = id;
         questionmarks = ""
         row.length().times{questionmarks = questionmarks + ",?"}
         questionmarks[0] = ""
@@ -193,10 +258,13 @@ class DuplicatePattern < Riddl::Implementation
     end
     
     #duplicate image db
-    result = $db.execute "SELECT * FROM image WHERE station = #{@r[0]} and patternID = #{@r[1]}"
+    
+    #$db.execute "CREATE TABLE IF NOT EXISTS image(internalID INT, imageID INT, language CHARACTER(20), label TEXT, FOREIGN KEY(internalID) REFERENCES stationpattern(internalID) ON DELETE CASCADE)"
+    
+    result = $db.execute "SELECT * FROM image WHERE internalID = #{@r[1]}"
     if(result[0] != nil)
       result.each do |row|
-        row[1] = id;
+        row[0] = id;
         questionmarks = ""
         row.length().times{questionmarks = questionmarks + ",?"}
         questionmarks[0] = ""
@@ -207,15 +275,18 @@ class DuplicatePattern < Riddl::Implementation
     #duplicate images
     pathorigin = File.join(File.dirname(__dir__),'images/uploads', @r[0], @r[1])
     pathdestination = File.join(File.dirname(__dir__),'images/uploads', @r[0], id.to_s)
-    FileUtils.mkdir_p(pathdestination)
-    
-    FileUtils.copy_entry pathorigin, pathdestination
+    if (Dir.exist?(pathorigin))
+      FileUtils.mkdir_p(pathdestination)
+      FileUtils.copy_entry pathorigin, pathdestination
+    end
     
     #duplicate Replacement db
-    result = $db.execute "SELECT * FROM replacements WHERE station = #{@r[0]} and patternID = #{@r[1]}"
+    
+    #$db.execute "CREATE TABLE IF NOT EXISTS replacements(internalID INT, abbreviation TEXT, url TEXT, ordering INT, FOREIGN KEY(internalID) REFERENCES stationpattern(internalID) ON DELETE CASCADE)"
+    result = $db.execute "SELECT * FROM replacements WHERE internalID = #{@r[1]}"
     if(result[0] != nil)
       result.each do |row|
-        row[1] = id;
+        row[0] = id;
         questionmarks = ""
         row.length().times{questionmarks = questionmarks + ",?"}
         questionmarks[0] = ""
@@ -232,27 +303,27 @@ end
 
 class SaveError < Riddl::Implementation
   def response
-    $db.execute "CREATE TABLE IF NOT EXISTS error(station INT, patternID INT, error TEXT, FOREIGN KEY(station) REFERENCES station(station), FOREIGN KEY(patternID) REFERENCES station(patternID))"
-    
+  
+    $db.execute "CREATE TABLE IF NOT EXISTS error(internalID INT, error TEXT, FOREIGN KEY(internalID) REFERENCES stationpattern(internalID) ON DELETE CASCADE)"
+
+  
     #Delete all, afterwards insert
-    $db.execute("DELETE FROM error WHERE  station = ? AND patternID = ?", [@r[0], @r[1]])
+    $db.execute("DELETE FROM error WHERE  internalID = ?", [@r[1]])
     
     doc = Nokogiri::XML(@p[0].value)
     doc.xpath(".//reason").each do |node|
-      $db.execute("INSERT INTO error (station, patternID, error) VALUES (?,?,?)", [@r[0], @r[1], node.text])
+      $db.execute("INSERT INTO error (internalID, error) VALUES (?,?)", [@r[1], node.text])
     end
   end
 end
 
 class GetError < Riddl::Implementation
-  def response
-    $db.execute "CREATE TABLE IF NOT EXISTS error(station INT, patternID INT, error TEXT, FOREIGN KEY(station) REFERENCES station(station), FOREIGN KEY(patternID) REFERENCES station(patternID))"
-    
-    result = $db.execute "SELECT * FROM error WHERE station = #{@r[0]} and patternID = #{@r[1]}"
+  def response 
+    result = $db.execute "SELECT * FROM error WHERE internalID = #{@r[1]}"
     builder = Nokogiri::XML::Builder.new do |xml|
       xml.error(){
         result.each do |row|
-          xml.reason row[2]
+          xml.reason row[1]
         end
       }
     end
@@ -263,30 +334,33 @@ end
 
 
 class SaveReplacement < Riddl::Implementation
-  def response  
+  def response 
+  
+  #  $db.execute "CREATE TABLE IF NOT EXISTS replacements(internalID INT, abbreviation TEXT, url TEXT, ordering INT, FOREIGN KEY(internalID) REFERENCES stationpattern(internalID) ON DELETE CASCADE)"
+  
     #Delete all, afterwards insert
-    $db.execute("DELETE FROM replacements WHERE  station = ? AND patternID = ?", [@r[0], @r[1]])
+    $db.execute("DELETE FROM replacements WHERE  internalID = ?", [@r[1]])
     
     order = 0;
     
     doc = Nokogiri::XML(@p[0].value)
     doc.xpath(".//item").each do |node|
-      $db.execute("INSERT INTO replacements (station, patternID, abbreviation, url, ordering) VALUES (?,?,?,?,?)", [@r[0], @r[1], node.xpath(".//abbreviation").text, node.xpath(".//url").text, order])
+      $db.execute("INSERT INTO replacements (internalID, abbreviation, url, ordering) VALUES (?,?,?,?)", [@r[1], node.xpath(".//abbreviation").text, node.xpath(".//url").text, order])
       order += 1
     end
   end
 end
 
 class GetReplacement < Riddl::Implementation
-  def response
-    result = $db.execute "SELECT * FROM replacements WHERE station = #{@r[0]} and patternID = #{@r[1]} ORDER BY ordering ASC"
+  def response  
+    result = $db.execute "SELECT * FROM replacements WHERE internalID = #{@r[1]} ORDER BY ordering ASC"
     
     builder = Nokogiri::XML::Builder.new do |xml|
       xml.replacement(){
         result.each do |row|
           xml.item(){
-            xml.abbreviation row[2]
-            xml.url row[3]
+            xml.abbreviation row[1]
+            xml.url row[2]
           }
         end
       }
@@ -304,11 +378,16 @@ class GetImages < Riddl::Implementation
     formatted_no_decl = Nokogiri::XML::Node::SaveOptions::FORMAT +
     Nokogiri::XML::Node::SaveOptions::NO_DECLARATION
     
-    result = $db.execute "SELECT DISTINCT station, patternID, imageID FROM image WHERE station = #{@r[0]} and patternID = #{@r[1]}"
+    
+#$db.execute "CREATE TABLE IF NOT EXISTS image(internalID INT, imageID INT, language CHARACTER(20), label TEXT, FOREIGN KEY(internalID) REFERENCES stationpattern(internalID) ON DELETE CASCADE)"
+    
+    
+    
+    result = $db.execute "SELECT DISTINCT imageID FROM image WHERE internalID = #{@r[1]}"
     builder = Nokogiri::XML::Builder.new do |xml|
       xml.images(){
         result.each do |row|
-          xml<< GetImage::prepare(@r[0], @r[1], row[2]).to_xml( save_with:formatted_no_decl )
+          xml<< GetImage::prepare(@r[0], @r[1], row[0]).to_xml( save_with:formatted_no_decl )
         end
       }
     end
@@ -1003,24 +1082,26 @@ def createDB(opts)
     CreateStation::createDB(n)
   }
   
-  #  Unique pattern
-  #  $db.execute "CREATE TABLE IF NOT EXISTS station(station INT, patternID INT, pattern CHARACTER(20), description TEXT, date TEXT, P0 VARCHAR(2), P1 VARCHAR(2), P2 VARCHAR(2), P3 VARCHAR(2), P4 VARCHAR(2), P5 VARCHAR(2), P6 VARCHAR(2), P7 VARCHAR(2), P8 VARCHAR(2), P9 VARCHAR(2), P10 VARCHAR(2), PRIMARY KEY(station,patternID), UNIQUE(station, pattern))"
-  $db.execute "CREATE TABLE IF NOT EXISTS station(station INT, patternID INT, pattern CHARACTER(256), description TEXT, date TEXT, P0 VARCHAR(10), P1 VARCHAR(10), P2 VARCHAR(10), P3 VARCHAR(10), P4 VARCHAR(10), P5 VARCHAR(10), P6 VARCHAR(10), P7 VARCHAR(10), P8 VARCHAR(10), P9 VARCHAR(10), P10 VARCHAR(10), PRIMARY KEY(station,patternID), UNIQUE(station, patternID))"
-  
-  
+  #vor DB struktur umstellung
+  #$db.execute "CREATE TABLE IF NOT EXISTS station(station INT, patternID INT, pattern CHARACTER(256), description TEXT, date TEXT, P0 VARCHAR(10), P1 VARCHAR(10), P2 VARCHAR(10), P3 VARCHAR(10), P4 VARCHAR(10), P5 VARCHAR(10), P6 VARCHAR(10), P7 VARCHAR(10), P8 VARCHAR(10), P9 VARCHAR(10), P10 VARCHAR(10), PRIMARY KEY(station,patternID), UNIQUE(station, patternID))"
   
-  $db.execute "CREATE TABLE IF NOT EXISTS error(station INT, patternID INT, error TEXT, FOREIGN KEY(station, patternID) REFERENCES station(station, patternID) ON DELETE CASCADE)"
+   
+  #$db.execute "CREATE TABLE IF NOT EXISTS error(station INT, patternID INT, error TEXT, FOREIGN KEY(station, patternID) REFERENCES station(station, patternID) ON DELETE CASCADE)"
   
   
-  $db.execute "CREATE TABLE IF NOT EXISTS replacements(station INT, patternID INT, abbreviation TEXT, url TEXT, ordering INT, FOREIGN KEY(station, patternID) REFERENCES station(station, patternID) ON DELETE CASCADE)"
-  
-  $db.execute "CREATE TABLE IF NOT EXISTS image(station INT, patternID INT, imageID INT, language CHARACTER(20), label TEXT, FOREIGN KEY(station, patternID) REFERENCES station(station, patternID) ON DELETE CASCADE,PRIMARY KEY(station,patternID,imageID,language))"
+  #$db.execute "CREATE TABLE IF NOT EXISTS replacements(station INT, patternID INT, abbreviation TEXT, url TEXT, ordering INT, FOREIGN KEY(station, patternID) REFERENCES station(station, patternID) ON DELETE CASCADE)"
+
+  #$db.execute "CREATE TABLE IF NOT EXISTS image(station INT, patternID INT, imageID INT, language CHARACTER(20), label TEXT, FOREIGN KEY(station, patternID) REFERENCES station(station, patternID) ON DELETE CASCADE,PRIMARY KEY(station,patternID,imageID,language))"
   
-  #  $db.execute "CREATE TABLE IF NOT EXISTS error(station INT, patternID INT, error TEXT, FOREIGN KEY(station) REFERENCES station(station), FOREIGN KEY(patternID) REFERENCES station(patternID) ON DELETE CASCADE)"
+
   
-  #  $db.execute "CREATE TABLE IF NOT EXISTS image(station INT, patternID INT, imageID INT, language CHARACTER(20), label TEXT, FOREIGN KEY(station) REFERENCES station(station), FOREIGN KEY(patternID) REFERENCES station(patternID) ON DELETE CASCADE,PRIMARY KEY(station,patternID,imageID,language))"
   
   
+  $db.execute "CREATE TABLE IF NOT EXISTS stationpattern(station INT, internalID INT, description TEXT, date TEXT, PRIMARY KEY(internalID), UNIQUE(internalID))"
+  $db.execute "CREATE TABLE IF NOT EXISTS pattern(internalID INT, type CHARACTER(20), value CHARACTER(20), FOREIGN KEY(internalID) REFERENCES stationpattern(internalID) ON DELETE CASCADE)"
+  $db.execute "CREATE TABLE IF NOT EXISTS error(internalID INT, error TEXT, FOREIGN KEY(internalID) REFERENCES stationpattern(internalID) ON DELETE CASCADE)"
+  $db.execute "CREATE TABLE IF NOT EXISTS replacements(internalID INT, abbreviation TEXT, url TEXT, ordering INT, FOREIGN KEY(internalID) REFERENCES stationpattern(internalID) ON DELETE CASCADE)"
+  $db.execute "CREATE TABLE IF NOT EXISTS image(internalID INT, imageID INT, language CHARACTER(20), label TEXT, FOREIGN KEY(internalID) REFERENCES stationpattern(internalID) ON DELETE CASCADE)"
   
 end
 
@@ -1041,6 +1122,15 @@ server = Riddl::Server.new(File.join(__dir__,'/was.xml'), :host => 'localhost')
       #should add deleteReplacement
     end
     
+    on resource 'json' do
+      run GetJsonFiles if get
+      on resource '.*' do
+        run SaveJson if put 'list'
+        run GetJson if get
+      end
+      #should add deleteReplacement
+    end
+    
     on resource '\d+' do
       run GetStation if get
       run CreatePattern if post 'pattern'

+ 7 - 0
server/was.xml

@@ -102,6 +102,13 @@
       <resource relative="cutimage">
         <get/>
       </resource>
+      <resource relative="json">
+        <get out="list"/>
+        <resource relative=".*">
+          <put in="list"/>
+          <get out="list"/>
+        </resource>
+      </resource>
       <resource relative="\d+">
         <get out="station"/>
         <post in="pattern" out="list"/> 

+ 6 - 1
ui/css/design.css

@@ -205,15 +205,20 @@ td {
   z-index:5;
   overflow:hidden;
   border-radius: 10px;
+  width: 80%;
 }
 
+#overlaycontentsizeNotClickable{
+  width: auto;
+}
 #overlaycontentsizeNotClickable .noDeco:hover{
   text-decoration: none;
 }
 
 #overlaycontent{
   max-height: 100%;
-  max-width: 100%;  
+  max-width: 100%;
+  width: 100%;
 }
 
 

+ 1 - 1
ui/imageReplacement.php

@@ -115,7 +115,7 @@
       }
     }
     $fullfilename = substr($fullfilename, 1); 
-    $fullfilename = "https://centurio.work/customers/evva/universal-storage/storage/JohannesEinzelbilder/" . $curstation . "_" . $fullfilename . ".jpg";
+    $fullfilename = "https://centurio.work/customers/evva/universal-storage/storage/Stationsbilder/Einzelbilder/Station" . $curstation . "/Station". $curstation.     "_" . $fullfilename . ".jpg";
     //echo $fullfilename . "<br>";
   
     

+ 5 - 3
ui/imageSlicer.php

@@ -2,9 +2,8 @@
   ini_set('display_errors', 1);
   ini_set('display_startup_errors', 1);
   error_reporting(E_ALL);
-  
   header('Content-Type: application/json');
-  $asocarray = array();
+  
   
   $imgurl = htmlspecialchars($_POST["url"]);
   $alldata = json_decode($_POST["alldata"]);
@@ -12,10 +11,13 @@
   $savelocation = $_POST["savelocation"];
   //echo $savelocation;
   
+  $asocarray = array();
   if ( ! is_writable($savelocation)) {
     $asocarray["error"] = $savelocation . ' must be writable!!!';
-    //echo $savelocation . ' must be writable!!!';
+    echo json_encode($asocarray);
+    exit();
   }
+  
   else{
     $im = imagecreatefromjpeg($imgurl);
     $counter = 0;

+ 34 - 2
ui/index.html

@@ -123,6 +123,7 @@
               </div>
             </template>
             
+            <!--
             <div class="wasGroup">
               <div class="wasLeft">Pattern <a class="mouseOver" href="#" title="Press '.' or 'space' while editing to create a new pattern part."></a>
               </div>
@@ -133,6 +134,14 @@
                 <a href="#" onclick="addPatternPart(true, 'patternInput')">[+]</a>
               </div>
             </div>
+            -->
+            <div class="wasGroup">
+              <div class="wasLeft">Preview</div>
+              <div class="wasRight">
+                <a href="https://centurio.work/out/frames/WAS_Test/">WIZ-Preview</a>
+              </div>
+            </div>
+            
             
             <div style="background-color: #efefef; padding-bottom: 1em; margin-top:1em">
             <div class="wasGroup">
@@ -147,6 +156,7 @@
             
             </div>
             
+            
             <div class="wasGroup">
               <div class="wasLeft">Description</div>
               <div class="wasRight">
@@ -308,7 +318,6 @@
       </ui-area>
       
       <ui-area data-belongs-to-tab="cutter" class="inactive">
-      Todo: Load image from Universal Storage
       
       
       <template id="RectanglesImage">
@@ -325,7 +334,7 @@
       
       
       <div id="imgrect" class="image-with-rect">
-       <img class="image" id="sliceImg" src="https://centurio.work/customers/evva/universal-storage/storage/Einzelbilder/IMG_1876_klein.JPG" alt="Alt text" />
+       <img class="image" id="sliceImg" src="https://centurio.work/customers/evva/universal-storage/storage/Einzelbilder/IMG_1876_klein.JPG" alt="" />
        
       
       <!--
@@ -341,6 +350,22 @@
       </div>
       
       
+      <div id="imgurlFolder" style="padding-top: 50px;">
+        <span style="color: red"> Handle with Care: </span><br>
+        Select a Folder (all content will be used 4 cutting)<br>
+        Select a SaveLocation (in the form to the right)<br>
+        Select a RectangleConfig (in the form to the right)(ignore the rectangles)<br>
+        Press button Cut Folder (currently images will not be overwritten)<br>
+        Wait a bit<br>
+        
+          <select id="selectfolders" class="width100">
+          </select>
+          
+          <button class="width100" type="button" id="multiCut">Cut Folder</button>
+      
+      </div>
+      
+      
       </ui-area>
       
       <!--<ui-resizehandle data-belongs-to-tab="cutter" data-label="drag to resize" ></ui-resizehandle>-->
@@ -353,6 +378,8 @@
           </div>
           
           
+          
+          
           <div class="wasGroup">
             <div class="wasLeft">Fill From Name: <a class="mouseOver" href="#" title="Press 'enter' after editing to fill the form with the pattern."></a></div>
             <input type="text" id="slicerpatterninput" name="description">
@@ -408,6 +435,11 @@
                 </select>
               </div>
             </div>
+            
+            <div class="wasGroup" id="FormSubmitOben">
+              <input class="width100" type="submit" value="startCutting">
+            </div>
+
                 
                 
                 

+ 76 - 9
ui/js/design.js

@@ -20,7 +20,7 @@ function overlayOn(value, showimage=false) {
         }
   document.getElementById("overlay").style.display = "block";
   
-  var iframe = $('#overlaycontentsize').append("<iframe id='overlaycontent' src='" + url + "' width='900' height='600'></iframe>");
+  var iframe = $('#overlaycontentsize').append("<iframe id='overlaycontent' src='" + url + "' width='1800' height='800'></iframe>");
   
   iframe.find("#overlaycontent").bind('load',{"ka": value}, function(event){
     var ref = this.contentWindow.ref;
@@ -141,7 +141,10 @@ function getStations(stationID , patternID ){ //Get DB 2 HTML
         var curstation=$(this).attr('id');		  
         $(this).find('pattern').each(function(index){
           var clonePattern = document.importNode(document.querySelector('#line').content,true);
-          $('[data-class=pattern] a',clonePattern).text($(this).attr('value'));
+          
+                
+          
+          $('[data-class=pattern] a',clonePattern).text($(this).find('parts').children().map(function(i, element){return $(element).text()}).get().join("."));
           $('[data-class=pattern] a',clonePattern).attr('href','javascript:getPattern(' + curstation + ','+ $(this).attr('id') + ');');
           $('[data-class=date]',clonePattern).text($.format.date(Date.parse($(this).attr('changed')), 'yyyy/MM/dd HH:mm:ss'));
           $('[data-class=duplicate] a',clonePattern).attr('href','javascript:duplicatePattern(' + curstation + ','+ $(this).attr('id') + ');');
@@ -163,6 +166,14 @@ function newPattern(stationID) { //HTML
 
 function getPattern(stationID, patternID){ //Get DB 2 HTML
   getStations(stationID, patternID)
+  //rest Pattern
+  abk.forEach(function(item){
+      $("#FormPattern_Form_" + item).val();
+      
+      $("#FormPattern_Form_" + item).val($("#FormPattern_Form_" + item + " option:first").val());
+
+  });
+
   if (patternID == null){
     $('#patternform').attr('onsubmit', "savePattern("+stationID+")");
     $('#pattern_ID').text("");
@@ -189,7 +200,40 @@ function getPattern(stationID, patternID){ //Get DB 2 HTML
       url: "../server/"+stationID+ "/" + patternID,
       dataType: "xml",
       success: function(xml) {
-        $(xml).find('pattern').each(function(index){
+        $(xml).find('parts').children().each(function(index){
+          /*
+          
+          
+          
+          
+        $(this).find('pattern').each(function(index){
+          var clonePattern = document.importNode(document.querySelector('#line').content,true);
+          
+                
+          
+          $('[data-class=pattern] a',clonePattern).text($(this).find('parts').children().map(function(i, element){return $(element).text()}).get().join("."));
+          
+          
+          
+  abk.forEach(function(item){
+    if(typeof $("#FormPattern_Form_" + item).val() !== 'undefined' && typeof $("#FormPattern_Form_" + item).val() !== 'undefined'){
+      $(xmlDocument).find("parts").append("<"+item+">" +$("#FormPattern_Form_" + item).find(":selected").text()+"</"+item+">")
+    }
+  });
+  */
+           
+          
+          //console.log($(this).prop("tagName"));
+          //console.log($(this).text());
+          
+          $("#FormPattern_Form_" + $(this).prop("tagName")).val($(this).text());
+
+          
+          
+          
+          
+          
+          /*
           var pattern = $(this).attr('value').split(".")
           for(var i = 0; i < pattern.length; i++)
           {
@@ -208,6 +252,7 @@ function getPattern(stationID, patternID){ //Get DB 2 HTML
           }
           
           $('#pattern').val($(this).attr('value'));
+          */
           $('#pattern_description').val($(this).attr('description'));
         });
       }
@@ -266,11 +311,23 @@ function getPatternString(){ //Helper Function
 }
 
 function savePattern(stationID) { //Save 2 DB
-  var xmlDocument = $.parseXML("<pattern/>");
+  var xmlDocument = $.parseXML("<pattern><parts></parts></pattern>");
   $(xmlDocument).find("pattern").attr('id','0');
-  $(xmlDocument).find("pattern").attr('value',getPatternString());
+  
+  
+  // #FormPattern
+  abk.forEach(function(item){
+    if(typeof $("#FormPattern_Form_" + item).val() !== 'undefined' && typeof $("#FormPattern_Form_" + item).val() !== 'undefined'){
+      $(xmlDocument).find("parts").append("<"+item+">" +$("#FormPattern_Form_" + item).find(":selected").text()+"</"+item+">")
+    }
+  });
+  
   $(xmlDocument).find("pattern").attr('description',$('#pattern_description').val());
   $(xmlDocument).find("pattern").attr('changed',new Date().toISOString());
+  
+  console.log((new XMLSerializer()).serializeToString(xmlDocument));
+  
+  
   $.ajax({
     type: "POST",
 		headers: {"content-id": "pattern"},
@@ -278,18 +335,28 @@ function savePattern(stationID) { //Save 2 DB
     contentType: "application/xml; charset=utf-8",
     url: "../server/"+stationID,
     success: function(res) {
-		  getPattern(stationID, res.id)
+		  //getPattern(stationID, res.id)
     },
     error: function (request, status, error) {
-      alert(request.responseText + status + error);
+      //alert(request.responseText + status + error);
     }
   });
+  
 }
 
 function saveChangedPattern(stationID, patternID) { //Save 2 DB
-  var xmlDocument = $.parseXML("<pattern/>");
+  var xmlDocument = $.parseXML("<pattern><parts></parts></pattern>");
   $(xmlDocument).find("pattern").attr('id',$('#pattern_ID').text());
-  $(xmlDocument).find("pattern").attr('value',getPatternString());
+
+
+  // #FormPattern
+  abk.forEach(function(item){
+    if(typeof $("#FormPattern_Form_" + item).val() !== 'undefined' && typeof $("#FormPattern_Form_" + item).val() !== 'undefined'){
+      $(xmlDocument).find("parts").append("<"+item+">" +$("#FormPattern_Form_" + item).find(":selected").text()+"</"+item+">")
+    }
+  });
+
+
   $(xmlDocument).find("pattern").attr('description',$('#pattern_description').val());
   $(xmlDocument).find("pattern").attr('changed',new Date().toISOString());
   

+ 106 - 23
ui/js/imageSlicer.js

@@ -230,11 +230,17 @@ function createJsonCutting(){
   rects.rects.forEach(function(value) {
     pattern = value.pattern;
     abk.forEach(function(item){
-      if(typeof $("#FormPattern2_Form_" + item).val() !== 'undefined' && typeof $("#FormPattern2_Form_" + item).val() !== 'undefined' && $("#FormPattern2_Form_" + item).val() !== ''){
+      if(typeof $("#FormPattern2_Form_" + item).val() !== 'undefined' && typeof $("#FormPattern2_Form_" + item).val() !== 'undefined'){
         if(pattern[item]){
-          pattern[item] = $("#FormPattern2_Form_" + item).find(":selected").text();
+        
+          //if rectangle is checked but nothing has been selected
+          if($("#FormPattern2_Form_" + item).find(":selected").text() == ""){
+            pattern[item] = "NoSelection";
+          }
+          else{
+            pattern[item] = $("#FormPattern2_Form_" + item).find(":selected").text();
+          }
         }
-        //console.log($("#Form_" + item).val())
 
       }
     });
@@ -245,41 +251,58 @@ function createJsonCutting(){
   return rects;
 }
 
-function submitSlices(){
+function submitSlices(skip = false){
   //createJsonCutting();
   
-  //console.log(JSON.stringify(createJsonCutting()));
   
   //check if selected options are also selected in drop down menus
-  var checkedoptions = new Set();
-  $("#imgRectangles input[type=checkbox]:checked").each(function(index, data){
-    checkedoptions.add($(data).attr("name"))
-  });
-  var allskips = [];
+  
   var skippall = false;
-  checkedoptions.forEach(function(item){ 
-    if($("#FormPattern2_Form_" + item).find(":selected").text() == ""){
-      allskips.push(item);
+  if(!skip){
+    var checkedoptions = new Set();
+    $("#imgRectangles input[type=checkbox]:checked").each(function(index, data){
+      checkedoptions.add($(data).attr("name"))
+    });
+    var allskips = [];
+    checkedoptions.forEach(function(item){ 
+      if($("#FormPattern2_Form_" + item).find(":selected").text() == ""){
+        allskips.push(item);
+      }
+    });
+    
+    if (Array.isArray(allskips) && allskips.length) {
+      if(!confirm("Achtung: [" + allskips + "] nicht ausgefüllt, fortfahren?")){
+        skippall = true;
+      }
     }
-  });
-  
-  
-  if(!confirm("Achtung: [" + allskips + "] nicht ausgefüllt, fortfahren?")){
-    skippall = true;
   }
   
   if(!skippall){
   request = $.ajax({
         type: "POST",
         url: "imageSlicer.php",
+        async: false,
         data: { url: $("#sliceImg").attr("src"), savelocation: $("#savelocation").val(), alldata: JSON.stringify(createJsonCutting()) },
         success: function(data){
-          if ( data.length <= 4 ) {
+        
+        
+        
+          if ( JSON.stringify(data) === '[]') {
             //clearFormFull();
-            alert("Saved Images");
+            
+            if(!skip){
+              alert("Saved Images");
+            }
+          }
+          else if(data.hasOwnProperty('error')){
+            alert("Achtung Fehler: \n" + data.error)
+            console.log(data);
           }
           else{
-            overlayOnDupliImages(data);
+          
+            if(!skip){
+              overlayOnDupliImages(data);
+            }
             //clearFormFull();
           }
           
@@ -290,7 +313,6 @@ function submitSlices(){
         }
     });
   }
-  
 }
 
 
@@ -361,17 +383,72 @@ function fillpatternForm(e) {
 
 function fillslicerpattern(){
   clearForm();
+  /*
   $.getJSON( "TransformProductCode.php?ProductCode=" + $("#slicerpatterninput").val(), function( data ) {
     $.each( data, function(i, item){        
       $("#FormPattern2_Form_" + i).val(item);
     });
   });
+  */
+  
+  
+  jQuery.ajax({
+    url: "TransformProductCode.php?ProductCode=" + $("#slicerpatterninput").val(),
+    success: function (data) {
+      $.each( data, function(i, item){        
+        $("#FormPattern2_Form_" + i).val(item);
+      });
+    },
+    async: false
+  });
+}
+
+
+function getAllFolders(folder = ""){ //Get DB 2 HTML //has to be synchronus in order to update before loading the rest
+	$('#selectfolders').find('option').remove()
+  $('#selectfolders').append("<option></option>")
+  $.ajax({
+	  type: "GET",
+	  url: "../../universal-storage/server/allfolders/" + folder,
+    async: false,
+	  dataType: "json",
+	  success: function(data) {
+      $.each( data, function( key, value ) {
+        $('#selectfolders').append("<option>" + value.slice(0,-1) +"</option>")
+        
+      });
+    }
+  });
+}
+
+function getAllFiles(folder = ""){ //Get DB 2 HTML //has to be synchronus in order to update before loading the rest
+ $.ajax({
+	  type: "GET",
+	  url: "../../universal-storage/server/images/" + folder,
+	  dataType: "json",
+	  success: function(data) {
+      $.each( data, function( key, value ) {
+      
+      
+        console.log(value);
+        console.log("../../universal-storage/storage/" + folder + "/" + value);
+        $("#sliceImg").attr("src", "../../universal-storage/storage/" + folder + "/" + value)
+        fillFormName(value);
+        
+        submitSlices(true);
+        /*
+        $("#slicerpatterninput").val(value);
+        fillslicerpattern();
+        */
+      });
+    }
+ });
 }
 
 $(document).ready(function() {
   createPatternForm();
   loadStationsForm();
-  
+  getAllFolders();
   //press enter to fill out patternform
   $("#slicerpatterninput").bind("keypress", {}, fillpatternForm);
 
@@ -407,10 +484,16 @@ $('#sliceImg').on('load',function(){
   });
   
   
+  
   $("#showJson").click(function() {
     showJson();
   });
   
+  $("#multiCut").click(function() {
+    getAllFiles($('#selectfolders').val());
+    
+  });
+  
   $('#pattern2').text("");
   var clone = document.importNode(document.querySelector('#patternClone').content,true);
   $('[data-class=part]',clone).limitkeypress({rexp: keypressRegex()});