Forráskód Böngészése

Added Assignments to image creation

Manuel Gall 3 éve
szülő
commit
6315109ddd
7 módosított fájl, 513 hozzáadás és 97 törlés
  1. 156 12
      server/was.rb
  2. 14 0
      server/was.xml
  3. 19 3
      ui/imageReplacement.php
  4. 119 64
      ui/index.html
  5. 190 0
      ui/js/assignment.js
  6. 13 11
      ui/js/design.js
  7. 2 7
      ui/js/imageSlicer.js

+ 156 - 12
server/was.rb

@@ -620,7 +620,6 @@ end
 
 class ListSearch < Riddl::Implementation
   def response
-    
     ret = {
       :imagesWIZAll => "/imagesWIZ?pattern=...",
       :imagesWIZSingle => "/imagesWIZ/0..*/?pattern=...",
@@ -693,7 +692,6 @@ class SearchImagesSingle < Riddl::Implementation
                     if index != 0
                       uri += "&" + item.name.to_s + "=" + item.value.to_s
                     end
-                    
                   end
                 
                   xml.variant(:lang => item3[2].to_s, :label => item3[3].to_s){
@@ -726,7 +724,6 @@ class SearchErrors < Riddl::Implementation
     searchstring = searchstring + " AND " + pattern.map{ |key, val| key + ".type == '" + key + "' AND (" + key + ".value == '"+ val +"' or " + key + ".value == '*')"}.join(' AND ') + " ORDER BY ID ASC" 
     result = $db.execute searchstring;
 
-    
     ret = []
     if result.length > 0
       result.each do |item|
@@ -738,8 +735,6 @@ class SearchErrors < Riddl::Implementation
     end
     
     ret = ret.uniq
-    
-    
     builder = Nokogiri::XML::Builder.new do |xml|
       xml.reason{
         if result.length > 0
@@ -756,6 +751,145 @@ class SearchErrors < Riddl::Implementation
   end
 end
 
+
+
+class GetAssignments < Riddl::Implementation
+  def response
+    ret = {}
+    resultstation = $db.execute "SELECT * FROM assignments"
+    resultstation.each do |row|
+      ret[row[0]] = row[1]
+    end
+    Riddl::Parameter::Complex.new('list','application/json',JSON::pretty_generate(ret))
+  end
+end
+
+class SaveNewAssignment < Riddl::Implementation
+  def response
+    form = JSON.parse(@p[0].value.read);
+    result = $db.execute "SELECT MAX(ID) FROM assignments"
+    if(result[0][0] == nil)
+      id = 0 
+    else
+      id = result[0][0] +1
+    end
+
+    checkimage = $db.execute "SELECT * FROM assignments WHERE image = '#{form["img"]}'"
+    #if image not stored create new assignment with pattern, otherwise only add pattern
+    if(checkimage[0] == nil)    
+      $db.execute("INSERT INTO assignments (ID, image) VALUES (?,?)", [id, form["img"]])
+      form["parts"].each{ |key,val|
+          $db.execute("INSERT INTO patternassignments (ID, AssID, type, value) VALUES (?,?,?,?)", [id, 0, key, val])
+      }
+      $db.execute("INSERT INTO patternassignments (ID, AssID, type, value) VALUES (?,?,?,?)", [id, 0, "STATION", form["station"]])
+      $db.execute("INSERT INTO patternassignments (ID, AssID, type, value) VALUES (?,?,?,?)", [id, 0, "TEXT", form["assignmentText"]])
+    else
+      maxID = $db.execute "SELECT MAX(AssID) FROM patternassignments WHERE ID ='#{checkimage[0][0]}'"
+      
+      if(maxID[0][0] == nil)
+        maxID = 0 
+      else
+        maxID = maxID[0][0] +1
+      end
+      
+      form["parts"].each{ |key,val|
+          $db.execute("INSERT INTO patternassignments (ID, AssID, type, value) VALUES (?,?,?,?)", [checkimage[0][0], maxID, key, val])
+      }
+      $db.execute("INSERT INTO patternassignments (ID, AssID, type, value) VALUES (?,?,?,?)", [checkimage[0][0], maxID, "STATION", form["station"]])
+      $db.execute("INSERT INTO patternassignments (ID, AssID, type, value) VALUES (?,?,?,?)", [checkimage[0][0], maxID, "TEXT", form["assignmentText"]])
+    end
+  end
+end
+
+
+
+class GetAssignment < Riddl::Implementation
+  def response
+    ret = {}
+    allAssIds = $db.execute "SELECT DISTINCT AssID FROM patternassignments WHERE ID = #{@r[1]}"
+    
+    allAssIds.each do |row|
+      
+      
+      station = $db.execute "SELECT value FROM patternassignments WHERE ID = #{@r[1]} AND AssID = #{row[0]} AND type == 'STATION'"
+      stationvalue = Integer(station[0][0])
+      
+      singleItem = $db.execute "SELECT value FROM patternassignments WHERE ID = #{@r[1]} AND AssID = #{row[0]} AND type != 'STATION'"
+      
+      if(ret[stationvalue] == nil)
+        ret[stationvalue] = Hash.new()
+      end
+      ret[stationvalue][row[0]] = singleItem.join('.')
+      
+    
+    
+    end
+    Riddl::Parameter::Complex.new('list','application/json',JSON::pretty_generate(ret))
+  end
+end
+
+class DeleteAssignment < Riddl::Implementation
+  def response
+    $db.execute("DELETE FROM assignments WHERE ID = ?", [@r[1]])
+  end
+end
+
+class DeleteSingleAssignment < Riddl::Implementation
+  def response
+    $db.execute("DELETE FROM patternassignments WHERE AssID = ? AND ID = ?", [@r[2], @r[1]])
+  end
+end
+
+class ListAssignmentSearch < Riddl::Implementation
+  def response
+  
+    #https://centurio.work/customers/evva/was/ui/TransformProductCode.php?ProductCode=E.A.PZ.DZ-S.31.31.MP.SEP
+  
+    pattern = JSON.parse(Net::HTTP.get URI("https://centurio.work/customers/evva/was/ui/TransformProductCode.php?ProductCode=" + @p[0].value))
+
+    puts  @p[1].value + @p[2].value
+#$db.execute "CREATE TABLE IF NOT EXISTS patternassignments(ID INT, AssID INT, type CHARACTER(20), value CHARACTER(20), FOREIGN KEY(ID) REFERENCES assignments(ID) ON DELETE CASCADE)"
+
+    #Get first key dynamicly and then build sql query
+    searchstring = "SELECT " + pattern.keys[0] + ".ID AS ID"
+    searchstring = searchstring + " FROM " + pattern.map{ |key, val| "patternassignments " + key}.join(', ')
+    searchstring = searchstring + " , patternassignments STATION , patternassignments ValText"    
+    searchstring = searchstring + " WHERE " + pattern.map{ |key, val| pattern.keys[0] + ".AssID == " + key + ".AssID"}.join(' AND ') + " AND ";
+    searchstring = searchstring + pattern.map{ |key, val| pattern.keys[0] + ".ID == " + key + ".ID"}.join(' AND ')
+    
+    searchstring = searchstring + " AND " + pattern.keys[0] + ".AssID == STATION.AssID"   
+    searchstring = searchstring + " AND " + pattern.keys[0] + ".AssID == ValText.AssID"   
+    searchstring = searchstring + " AND " + pattern.keys[0] + ".ID == STATION.ID"   
+    searchstring = searchstring + " AND " + pattern.keys[0] + ".ID == ValText.ID"   
+    
+    
+    searchstring = searchstring + " AND STATION.type == 'STATION'" + " AND STATION.value == '" + @p[1].value + "'"
+    searchstring = searchstring + " AND ValText.type == 'TEXT'"  + " AND ValText.value == '" + @p[2].value + "'"
+    
+    searchstring = searchstring + " AND " + pattern.map{ |key, val| key + ".type == '" + key + "' AND (" + key + ".value == '"+ val +"' or " + key + ".value == '*')"}.join(' AND ') + " ORDER BY ID ASC" 
+    
+    #puts searchstring;
+    
+    result = $db.execute searchstring;
+    
+    
+    #Search for images with one or multiple found patternIDs
+    ret = []
+    if result.length > 0
+      result.each do |item|
+        result2 = $db.execute "SELECT DISTINCT image FROM assignments WHERE ID = #{item[0]}"
+        result2.each do |item2|
+          ret << item2[0]
+        end
+      end
+    end
+    
+    Riddl::Parameter::Complex.new('list','application/json',JSON::pretty_generate(ret))
+  end
+end
+
+
+
 def createDB(opts)
   $db.execute("PRAGMA foreign_keys=ON");
   
@@ -767,17 +901,10 @@ def createDB(opts)
   
   #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 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 stationpattern(station INT, internalID INT, description TEXT, date TEXT, PRIMARY KEY(internalID), UNIQUE(internalID))"
@@ -786,6 +913,9 @@ def createDB(opts)
   $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)"
   
+  $db.execute "CREATE TABLE IF NOT EXISTS assignments(ID INT, image TEXT, PRIMARY KEY(ID) UNIQUE (ID))"
+  $db.execute "CREATE TABLE IF NOT EXISTS patternassignments(ID INT, AssID INT, type CHARACTER(20), value CHARACTER(20), FOREIGN KEY(ID) REFERENCES assignments(ID) ON DELETE CASCADE)"
+  
 end
 
 server = Riddl::Server.new(File.join(__dir__,'/was.xml'), :host => 'localhost') do |opts|
@@ -866,5 +996,19 @@ server = Riddl::Server.new(File.join(__dir__,'/was.xml'), :host => 'localhost')
         end
       end
     end
+    on resource 'assignments' do
+      run GetAssignments if get
+      run SaveNewAssignment if post 'list'
+      on resource 'search' do
+        run ListAssignmentSearch if get
+      end
+      on resource '\d+' do
+        run GetAssignment if get
+        run DeleteAssignment if delete
+        on resource '\d+' do
+          run DeleteSingleAssignment if delete
+        end
+      end
+    end
   end
 end.loop!

+ 14 - 0
server/was.xml

@@ -160,5 +160,19 @@
         </resource>
       </resource>
 
+    <resource relative="assignments">
+      <get out="list"/> 
+      <post in="list"/>
+      <resource relative="search">
+        <get out="list"/>
+      </resource>
+      <resource relative="\d+">
+        <get out="list"/>
+        <delete/>
+        <resource relative="\d+">
+          <delete/>
+        </resource>
+      </resource>
+    </resource>
   </resource>
 </description>

+ 19 - 3
ui/imageReplacement.php

@@ -17,7 +17,6 @@
     $len = strpos($string,$end,$ini) - $ini;
     return substr($string,$ini,$len);
   }
-
   
   //header('Content-type: image/svg+xml'); //does not play video
   
@@ -91,18 +90,18 @@
   $curstation = $_GET["Station"];
   //Einzelbilder vom Universal Storage laden
   foreach ($keyValueStore as $key => $value) {
-  
     $keyorig = $key;
   
     $key = substr($key, 1); 
     $keyarray = str_split($key, 2);
     
     $fullfilename = "";
-    
+    $textentry = "";
     foreach($keyarray as $keypart){
       //only if all keyparts (Pb Sy Pk Of) can be found within the asociative array (Pb -> E, Sy -> X) the file can be linked otherwise there is a problem.
       if($keypart == "ID"){
         $fullfilename = $fullfilename . "_ID;" . substr($keyorig, strrpos($keyorig, "ID:") + 3);
+        $textentry = substr($keyorig, strrpos($keyorig, "ID:") + 3);
         break;
         
       }
@@ -116,6 +115,23 @@
     }
     $fullfilename = substr($fullfilename, 1); 
     $fullfilename = "https://centurio.work/customers/evva/universal-storage/storage/Stationsbilder/Einzelbilder/Station" . $curstation . "/Station". $curstation.     "_" . $fullfilename . ".jpg";
+    
+    if (!file_exists($fullfilename)) {
+      $fullfilename = "https://centurio.work/customers/evva/was/server/assignments/search?pattern=". $_GET["ProductCode"] ."&station=". $curstation ."&Text=" .  $textentry;
+      $json = json_decode(file_get_contents($fullfilename));
+      
+      if (isset($json[0])) {
+        $fullfilename = $json[0];
+      }
+      else{
+        continue;
+      }
+
+      
+      
+    }
+
+
     //echo $fullfilename . "<br>";
   
     

+ 119 - 64
ui/index.html

@@ -55,6 +55,7 @@
     
     <script type="text/javascript" src="js/design.js"></script>
     <script type="text/javascript" src="js/imageSlicer.js"></script>
+    <script type="text/javascript" src="js/assignment.js"></script>
     <script type="text/javascript" src="js/settings.js"></script>
     
     
@@ -324,12 +325,12 @@
       
       
       <div>
-        <a href="#" onclick="overlayOn($(this), true);">🔍</a>
+        <a href="#" onclick="overlayOn($(this), 'image');">🔍</a>
       </div>
       
       
       <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="" />
+       <img class="image" id="sliceImg" src="" alt="" />
        
       
       <!--
@@ -367,10 +368,6 @@
       
       <ui-area data-belongs-to-tab="cutter" id="detailcolumn2" class="inactive">
         <div class='x-ui-layout' style="padding: 10px">
-          <div class="wasGroup">
-            <div class="wasLeft">Status:</div>
-            <div class="wasRight"><b>Work in Progress</b></div>
-          </div>
           
           
           
@@ -579,14 +576,7 @@
       <!--<ui-resizehandle data-belongs-to-tab="cutter" data-label="drag to resize" ></ui-resizehandle>-->
       
     <ui-area data-belongs-to-tab="settings" id="detailcolumn3" class="inactive">
-        <div class='x-ui-layout' style="padding: 10px">        
-          <div class="wasGroup">
-            <div class="wasLeft">Status:</div>
-            <div class="wasRight"><b>Work in Progress</b></div>
-          </div>
-          
-          
-          
+        <div class='x-ui-layout' style="padding: 10px">
           <div class="wasGroup">
             <form id="jsonfileform">
               <textarea id="jsonfiletxtarea" rows="30" cols="50"></textarea>
@@ -602,64 +592,129 @@
     
     
     <ui-area data-belongs-to-tab="assignment" class="inactive">
-      Once its Functional will be moved before Settings.
       List of all Images
       
+      <template id="assignmentitem">
+        <tr >
+          <td > </td>
+          <td data-class='item'><a href=''></a></td>
+          <!--<td data-class='duplicate' class="stationAction"><a href=''>⎘</a></td>-->
+          <td data-class='delete' class="assignmentAction"><a href=''>[⨯]</a></td>
+        </tr>
+      </template>
+      <br>
+      <a href="javascript:createAssignmentForm();">Create Assignment</a>
+      <table id="assignmentslist">
+      </table>
+          
     </ui-area>
       
       <!--<ui-resizehandle data-belongs-to-tab="cutter" data-label="drag to resize" ></ui-resizehandle>-->
       
     <ui-area data-belongs-to-tab="assignment" id="detailcolumn4" class="inactive">
+      <div id="assignment_details" class="x-ui-layout" style="display: none; padding: 10px">
+        <!--
+        Create new Link (die spalten werden aus dem namen aufgebaut das zb. nur System und Bauart ausgewählt werden können)
+        <table>
+          <tr>
+            <th>Station</th>
+            <th>Produktbereich</th>
+            <th>System</th>
+            <th>Produktkategorie</th>
+            <th>Bauart</th>
+            <th>Zylinderlänge außen</th>
+            <th>...</th>
+          </tr>
+          <tr>
+            <td>[ ] Station1</td>
+            <td>[ ] E</td>
+            <td>[ ] X</td>
+            <td>[ ] PZ</td>
+            <td>[ ] KZ-S</td>
+            <td>[ ] 31</td>
+            <td>...</td>
+          </tr>
+          <tr>
+            <td>[ ] Station2</td>
+            <td></td>
+            <td></td>
+            <td></td>
+            <td>[ ] RKZ-S</td>
+            <td>[ ] 36</td>
+            <td>...</td>
+          </tr>
+          <tr>
+            <td>[ ] Station3</td>
+            <td></td>
+            <td></td>
+            <td></td>
+            <td>[ ] HZ-S</td>
+            <td>[ ] 41</td>
+            <td>...</td>
+          </tr>
+          <tr>
+            <td>[ ] Station4</td>
+            <td></td>
+            <td></td>
+            <td></td>
+            <td>[ ] RHZ-S</td>
+            <td>[ ] 46</td>
+            <td>...</td>
+          </tr>
+        </table>
+        -->
+        
+        
+        <h1>Assignments</h1>
+        <div id="storedassignments">
+        
+          <template id="singleassignment">
+            <tr >
+              <td > </td>
+              <td data-class='station'></td>
+              <td data-class='item'></td>
+              <!--<td data-class='duplicate' class="stationAction"><a href=''>⎘</a></td>-->
+              <td data-class='delete' class="assignmentAction"><a href=''>[⨯]</a></td>
+            </tr>
+          </template>
+          
+          <table id="assignmentdetaillist">
+          </table>
       
-      Create new Link (die spalten werden aus dem namen aufgebaut das zb. nur System und Bauart ausgewählt werden können)
-      <table>
-        <tr>
-          <th>Station</th>
-          <th>Produktbereich</th>
-          <th>System</th>
-          <th>Produktkategorie</th>
-          <th>Bauart</th>
-          <th>Zylinderlänge außen</th>
-          <th>...</th>
-        </tr>
-        <tr>
-          <td>[ ] Station1</td>
-          <td>[ ] E</td>
-          <td>[ ] X</td>
-          <td>[ ] PZ</td>
-          <td>[ ] KZ-S</td>
-          <td>[ ] 31</td>
-          <td>...</td>
-        </tr>
-        <tr>
-          <td>[ ] Station2</td>
-          <td></td>
-          <td></td>
-          <td></td>
-          <td>[ ] RKZ-S</td>
-          <td>[ ] 36</td>
-          <td>...</td>
-        </tr>
-        <tr>
-          <td>[ ] Station3</td>
-          <td></td>
-          <td></td>
-          <td></td>
-          <td>[ ] HZ-S</td>
-          <td>[ ] 41</td>
-          <td>...</td>
-        </tr>
-        <tr>
-          <td>[ ] Station4</td>
-          <td></td>
-          <td></td>
-          <td></td>
-          <td>[ ] RHZ-S</td>
-          <td>[ ] 46</td>
-          <td>...</td>
-        </tr>
-      </table>
-      
+        </div>
+        
+        
+        <h1>New Assignment</h1>
+        <form id="assignmentform" onsubmit="submitAssignment()">
+          <input type="text" class="abbreviationInput width100 url" name="externalImage" id="addExternalImageAssignment">
+          <a href="#" id="assignmentLupe" onclick="overlayOn($(this), 'assigment');">🔍</a>
+          <div class="wasGroup" data-class="mainDiv">
+            <div data-class="description" class="wasLeft">
+              <span data-class="Name">Station</span>
+            </div>
+            <div class="wasRight">
+              <select name="station" id="assignmentstation"></select>
+            </div>
+          </div>
+          
+          
+          <div id="FormPatternAssignment">
+            
+          </div>
+          
+          
+          <div class="wasGroup" data-class="mainDiv">
+            <div data-class="description" class="wasLeft">
+              <span data-class="Name">Text</span>
+            </div>
+            <div class="wasRight">
+              <input data-class="input" id="assignmentText" type="text" maxlength="4" size="4" value="">
+            </div>
+          </div>
+          
+          <input class="width100" type="submit" value="Save Assignment">
+        </form>
+      </div>
     </ui-area>
     
     

+ 190 - 0
ui/js/assignment.js

@@ -0,0 +1,190 @@
+
+
+function createAssignmentForm(assID, url){
+  
+  $('#assignmentdetaillist').text("");
+  
+	$.ajax({
+    type: "GET",
+    url: "../server/",
+	  dataType: "xml",
+    success: function(xml) {
+      $(xml).find('station').each(function(index){
+          $('#assignmentstation').append('<option value="' + $(this).attr('id') +'">' + $(this).attr('id') +'</option>');
+      });
+    }
+  });
+  
+  if (assID == null){
+    $('#storedassignments').css("display", "none");
+    $('#assignmentLupe').css("display", "block"); 
+    $('#addExternalImageAssignment').removeAttr('disabled');
+    $('#addExternalImageAssignment').val("");
+    
+  
+  }
+  else{
+    $('#storedassignments').css("display", "block");
+    $('#assignmentLupe').css("display", "none");    
+    $('#addExternalImageAssignment').attr('disabled','disabled');
+    $('#addExternalImageAssignment').val(url);
+    
+    
+    
+    //Show Assignments
+    
+    $.getJSON( "../server/assignments/" + assID, function( data ) {
+      
+      
+      console.log(data);
+    
+      $.each( data, function(i, alldata){
+        
+        var clonePattern = document.importNode(document.querySelector('#singleassignment').content,true);
+        $('[data-class=station]',clonePattern).text("Station " + i);
+        
+        $('#assignmentdetaillist').append(clonePattern);
+      
+        $.each( alldata, function(i, item){
+          var clonePattern = document.importNode(document.querySelector('#singleassignment').content,true);
+          $('[data-class=item]',clonePattern).text(item);
+          $('[data-class=delete] a',clonePattern).attr('href','javascript:deleteSingleAssignment(' + assID +', ' + i + ');');
+          
+          $('#assignmentdetaillist').append(clonePattern);
+        });
+      });
+    });
+    
+  }
+  
+  
+  
+  $('#assignment_details').css("display", "block");
+}
+
+
+//called when new image is selected
+function getImgText(imgtext){
+  var result = /[^;]*$/.exec(imgtext)[0];
+  if(result != imgtext){
+    $('#assignmentText').val(result.replace(/\.[^/.]+$/, ""))
+  }
+}
+
+function submitAssignment(){
+  var obj = new Object();
+  obj.img = $('#addExternalImageAssignment').val();
+  obj.station = $('#assignmentstation option:selected').text();
+  obj.parts = {};  
+  abk.forEach(function(item){
+    if(typeof $("#FormPatternAssignment_Form_" + item).val() !== 'undefined' && typeof $("#FormPatternAssignment_Form_" + item).val() !== 'undefined'){
+      if($("#FormPatternAssignment_Form_" + item).find(":selected").text() != ""){
+        obj.parts[item] = $("#FormPatternAssignment_Form_" + item).find(":selected").text();
+      }
+    }
+  });
+  obj.assignmentText = $('#assignmentText').val();
+  $.ajax({
+    type: "Post",
+		data: JSON.stringify(obj),
+		headers: {"content-id": "list"},
+    contentType: "application/json",
+    url: "../server/assignments/",
+    success: function(res) {
+    },
+    error: function (request, status, error) {
+      alert(request.responseText + status + error);
+    }
+  });
+  
+  
+  
+}
+
+function deleteAssignment(assignmentID) { //Delete From DB
+  if (confirm('Are you really, really, REALLY sure!')) {
+    $.ajax({
+      type: "DELETE",
+      url: "../server/assignments/" + assignmentID,
+      success: function(res) { 
+        location.reload();
+      }
+    });
+  }
+}
+
+function deleteSingleAssignment(assignmentID, patternID) { //Delete From DB
+  if (confirm('Are you really, really, REALLY sure!')) {
+    $.ajax({
+      type: "DELETE",
+      url: "../server/assignments/" + assignmentID + "/" + patternID,
+      success: function(res) { 
+        location.reload();
+      }
+    });
+  }
+}
+
+function initAssignment(){
+  $.getJSON( "../server/assignments/", function( data ) {
+    $.each( data, function(i, item){
+      console.log("ID " + i + " image " + item)      
+          var clonePattern = document.importNode(document.querySelector('#assignmentitem').content,true);
+          $('[data-class=item] a',clonePattern).text(item);
+          $('[data-class=item] a',clonePattern).attr('href','javascript:createAssignmentForm(' + i + ',"' + item + '");');
+          //$('[data-class=duplicate] a',clonePattern).attr('href','javascript:duplicatePattern(' + curstation + ','+ $(this).attr('id') + ');');
+          $('[data-class=delete] a',clonePattern).attr('href','javascript:deleteAssignment(' + i + ');');
+          
+          $('#assignmentslist').append(clonePattern);
+      });
+  });
+}
+
+
+
+
+$(document).ready(function() {
+  initAssignment();
+  
+  $(document).on('submit', '#assignmentform', function() { //prevent page reload on form submit
+    return false;
+  });
+  
+  /*
+  loadStationsForm();
+  getAllFolders();
+  //press enter to fill out patternform
+  $("#slicerpatterninput").bind("keypress", {}, fillpatternForm);
+
+
+  
+  $.getJSON( "../server/json/SlicerConfig.json", function( data ) {
+    if(!data["SlicerRectForm"]){
+      $("#addRectanglesGroup").hide();
+      $("#imgRectangles").hide();
+      $("#Json2ClipboardGroup").hide();
+    }
+  });
+  
+  
+  
+  $("#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()});
+  $("#pattern2").append(clone);
+  
+  
+  //handle zoom event in order to fix rectangle position
+  window.addEventListener("resize", resizeAllRect, false); 
+  */
+  
+});

+ 13 - 11
ui/js/design.js

@@ -10,14 +10,14 @@
 var pictureWidth = 1280;
 var pictureHeight = 720;
 
-function overlayOn(value, showimage=false) {
+function overlayOn(value, special="") {
   
-      if(showimage){
-  url = "https://centurio.work/customers/evva/universal-storage/ui/?iframe&path=Stationsbilder/Gesamtbilder/Station3"
-      }
-      else{
-  url = "https://centurio.work/customers/evva/universal-storage/ui/?iframe"
-        }
+  if(special == "image" || special == "assigment"){
+    url = "https://centurio.work/customers/evva/universal-storage/ui/?iframe&path=Stationsbilder/Gesamtbilder/Station3"
+  }
+  else{
+    url = "https://centurio.work/customers/evva/universal-storage/ui/?iframe"
+  }
   document.getElementById("overlay").style.display = "block";
   
   var iframe = $('#overlaycontentsize').append("<iframe id='overlaycontent' src='" + url + "' width='1800' height='800'></iframe>");
@@ -32,13 +32,15 @@ function overlayOn(value, showimage=false) {
       overlayOff();
       
       //fill input with url
-      if(!showimage){
+      if(special == ""){
         $(data.xyz).parent().parent().find(".abbreviationInput").val(extra1.url)
       }
-      else{
-        
+      else if (special == "assigment"){
+        $(data.xyz).parent().parent().find(".abbreviationInput").val(extra1.url)
+        getImgText(extra1.url)
+      }
+      else if (special == "image"){
         clearForm();
-        
         //hide current image
         var newSrc = extra1.url + "?rand=" + Math.random();
         image = new Image();    

+ 2 - 7
ui/js/imageSlicer.js

@@ -129,14 +129,11 @@ function addRectangle1(id,x,y,w,h,pattern,idtext){
   });
 }
 
-
-
 function createPatternForm(){
   /* Load pattern config */
   //Create form for WAS/Stations/Pattern and WAS/Slicer
-  var populate = ["FormPattern","FormPattern2"]
+  var populate = ["FormPattern","FormPattern2","FormPatternAssignment"]
   
- 
   var first = true;
   populate.forEach(function(populate2){
     $.getJSON( "../server/json/ProductCode.json", function( data ) {
@@ -158,7 +155,6 @@ function createPatternForm(){
     });
   });
   abk.length = 0;
-  console.log(abk);
   
   //get Save locations
   $.getJSON( "../server/json/SlicerConfig.json", function( data ) {
@@ -185,12 +181,11 @@ function createRectForm(station){
         });
       }
     });
-    });
+  });
 }
 
 
 function loadStationsForm(){
-  
   $.getJSON( "../server/json/Rectangle.json", function( data ) {
     $.each( data["Configs"], function(i, item){
       $("#loadconfig").append('<option value="' + item["name"] +'">' + item["name"] +'</option>');