Просмотр исходного кода

Updated assignment creation and search.

Manuel Gall лет назад: 3
Родитель
Сommit
4cd51a79ca
9 измененных файлов с 223 добавлено и 785 удалено
  1. 1 757
      server/json/Rectangle.json
  2. 1 1
      server/was.conf
  3. 48 6
      server/was.rb
  4. 1 1
      server/was.xml
  5. 3 3
      ui/config.php
  6. 1 0
      ui/css/imageSlicer.css
  7. 21 4
      ui/index.html
  8. 143 11
      ui/js/imageSlicer.js
  9. 4 2
      ui/js/settings.js

Разница между файлами не показана из-за своего большого размера
+ 1 - 757
server/json/Rectangle.json


+ 1 - 1
server/was.conf

@@ -1,5 +1,5 @@
 :port: 9323
 :appconf:
   wizurl: https://centurio.evva.com/wiz/wiztest/
-  wasurl: https://centurio.evva.com/departments/emontage/WAS/
+  wasurl: https://centurio.work/customers/evva/was/
   stations: [ 1, 2, 3, 8, 99]

+ 48 - 6
server/was.rb

@@ -791,6 +791,8 @@ class SaveNewAssignment < Riddl::Implementation
     else
       id = result[0][0] +1
     end
+     
+    #puts form
 
     checkimage = $db.execute "SELECT * FROM assignments WHERE image = '#{form["img"]}'"
     #if image not stored create new assignment with pattern, otherwise only add pattern
@@ -801,6 +803,9 @@ class SaveNewAssignment < Riddl::Implementation
       }
       $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"]])
+      
+      ret = {:id => id}
+      Riddl::Parameter::Complex.new('list','application/json',JSON::pretty_generate(ret))
     else
       maxID = $db.execute "SELECT MAX(AssID) FROM patternassignments WHERE ID ='#{checkimage[0][0]}'"
       
@@ -815,6 +820,9 @@ class SaveNewAssignment < Riddl::Implementation
       }
       $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"]])
+      
+      ret = {:id => checkimage[0][0]}
+      Riddl::Parameter::Complex.new('list','application/json',JSON::pretty_generate(ret))
     end
   end
 end
@@ -874,16 +882,48 @@ class ListAssignmentSearch < Riddl::Implementation
   
     #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(@a[0][:appconf]["wasurl"] + "ui/TransformProductCode.php?ProductCode=" + @p[0].value))
+    
+    #remove empty entries from pattern
+    pattern.each do |key, value|
+      if(value == "")
+        if(key == "Zi")
+        elsif (key == "Kf")
+        else
+          pattern.delete(key)
+        end
+      end
+    end
+    
+    
+    emptypatternparts = []
+    #fullcode = JSON.parse( File.read(File.join("json" , "ProductCode.json")))
+    puts File.join(File.dirname(__dir__),"server/json/ProductCode.json")
+    fullcode = JSON.parse( File.read(File.join(File.dirname(__dir__),"server/json/ProductCode.json")))
+    
+    fullcode["pattern"].each do |key|
+      if(!pattern.has_key?(key["abk"]) )
+        emptypatternparts.push(key["abk"])
+      end
+    end
+    
 
-  #$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)"
+    #$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
     if(pattern.keys[0] != nil)
       searchstring = "SELECT " + pattern.keys[0] + ".ID AS ID"
       searchstring = searchstring + " FROM " + pattern.map{ |key, val| "patternassignments " + key}.join(', ')
+      searchstring = searchstring + ", " + emptypatternparts.map{ |key| "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 + " WHERE " + pattern.map{ |key, val| pattern.keys[0] + ".AssID == " + key + ".AssID"}.join(' AND ');
+      searchstring = searchstring + " AND " + pattern.map{ |key, val| pattern.keys[0] + ".ID == " + key + ".ID"}.join(' AND ')
+      
+      
+      searchstring = searchstring + " AND " + emptypatternparts.map{ |key| pattern.keys[0] + ".AssID == " + key + ".AssID"}.join(' AND ')
+      searchstring = searchstring + " AND " + emptypatternparts.map{ |key| pattern.keys[0] + ".ID == " + key + ".ID"}.join(' AND ')
+      searchstring = searchstring + " AND " + emptypatternparts.map{ |key| key + ".type == '" + key + "' AND " + key + ".value == ''" }.join(' AND ')
       
       searchstring = searchstring + " AND " + pattern.keys[0] + ".AssID == STATION.AssID"   
       searchstring = searchstring + " AND " + pattern.keys[0] + ".AssID == ValText.AssID"   
@@ -894,7 +934,10 @@ class ListAssignmentSearch < Riddl::Implementation
       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" 
+ 
+      
+      
+      searchstring = searchstring + " AND " + pattern.map{ |key, val| key + ".type == '" + key + "' AND (" + key + ".value == '"+ val +"' or " + key + ".value == '*' or " + key + ".value == '')"}.join(' AND ') + " ORDER BY ID ASC" 
       
       #puts searchstring;
     else
@@ -905,11 +948,10 @@ class ListAssignmentSearch < Riddl::Implementation
       searchstring = searchstring + " AND ValText.type == 'TEXT'"  + " AND ValText.value == '" + @p[2].value + "'"
       searchstring = searchstring + " AND ValText.AssID == STATION.AssID"
       searchstring = searchstring + " ORDER BY ID ASC"
-
-    
     end
     
     
+    
     result = $db.execute searchstring;
     
     

+ 1 - 1
server/was.xml

@@ -162,7 +162,7 @@
 
     <resource relative="assignments">
       <get out="list"/> 
-      <post in="list"/>
+      <post in="list" out="list"/>
       <resource relative="search">
         <get out="list"/>
       </resource>

+ 3 - 3
ui/config.php

@@ -1,5 +1,5 @@
 <?php
-  $wasUrl ="https://centurio.evva.com/departments/emontage/WAS/";
-  $transformCodeUrl ="https://centurio.evva.com/departments/emontage/WAS/";
-  $universalStorageEinzelbilder = "https://centurio.evva.com/departments/emontage/universal-storage/storage/Stationsbilder/Einzelbilder/";
+  $wasUrl ="https://centurio.work/customers/evva/was/";
+  $transformCodeUrl ="https://centurio.work/customers/evva/was/";
+  $universalStorageEinzelbilder = "https://centurio.work/customers/evva/universal-storage/storage/Stationsbilder/Einzelbilder/";
 ?>

+ 1 - 0
ui/css/imageSlicer.css

@@ -17,6 +17,7 @@
   text-align: center;
   border-style: dotted;
   transform-origin: left top;
+  font-size: 20px;
 }
 
 .patternpartcheckbox{

+ 21 - 4
ui/index.html

@@ -82,7 +82,7 @@
       <ui-before                                  ><a class="logo" href="/customers/evva"></a></ui-before>
       <ui-tab class=""         data-tab="station"           >Stations</ui-tab>
       <ui-tab class="inactive" data-tab="cutter"            >Slicer</ui-tab>
-      <ui-tab class="inactive" data-tab="assignment"        >Assignment</ui-tab>
+      <ui-tab class="inactive" data-tab="assignment" onclick="initAssignment()"        >Assignment</ui-tab>
       <ui-tab class="inactive" data-tab="settings"          >Settings</ui-tab>
       <!-- <ui-tab class="inactive" data-tab="patternAlignment"  >Alignment</ui-tab> -->
       <ui-behind                                  ></ui-behind>
@@ -140,7 +140,7 @@
             <div class="wasGroup">
               <div class="wasLeft">Preview</div>
               <div class="wasRight">
-                <a href="https://centurio.evva.com/out/frames/WAS_Test/">WIZ-Preview</a>
+                <a href="https://centurio.work/out/frames/WAS_Test/">WIZ-Preview</a>
               </div>
             </div>
             
@@ -437,17 +437,22 @@
             <template id="RectanglesAssignmentValue">
               <span>
                 <a data-class='AssignmentDelete' style="padding-left: 2em;"> - </a>
-                <span data-class='AssignmentText' class="RectanglesAssignmentValue" style="width: 4em;">
+                <span data-class='AssignmentText' class="RectanglesAssignmentValue" style="width: 2em; display:inline-block;">
                 </span>
               </span>
             </template>
             
+                        
             <template id="RectanglesAssignment">
               <div data-class='Assignment'>
                 <span data-class='AssignmentAbk' style="display: inline-block; width: 3em;"></span>
                 <select data-class='AssignmentOptionen' name="" style="width: 7em"></select>
                 <a data-class='AssignmentAdd'> + </a>
-                <span data-class='AllAssignments'></span>
+                <span data-class='AllAssignments'>
+                  <span>
+                    <span data-class='AssignmentDefaultValue' class="RectanglesAssignmentDefaultValue" style="width: 4em; color: green; padding-left: 2em; display:inline-block;"></span>
+                  </span>
+                </span>
               </div>
             </template>
                 
@@ -458,6 +463,12 @@
                   RectID: 
                   <span data-class='RectID' class="RectID"></span>
                   <div class="handle3">⇅</div>
+                  <div>
+                    Inactive: <input data-class='setinactive' class="" type="checkbox" name="setinactive">
+                  </div>
+                  <div>
+                    <a data-class='removeRect' href="#">Remove Rectangle</a>
+                  </div>
                 </div>
                 <div class="wasRight">
                   <div class="patternPart2">
@@ -481,6 +492,9 @@
                   </div>
                   <a href="#" onclick="togglenext($(this));">Assignments</a>
                   <div style="display: none">
+                    <div style="margin-left: 13.3em; color: green;">
+                    Default Values
+                    </div>
                     <div data-class='RectangleAssignmentStation' class="RectangleAssignmentStation">
                     </div>
                     <div data-class='RectangleAssignment' class="RectangleAssignment">
@@ -566,6 +580,9 @@
             <div id="Json2ClipboardGroup" class="wasGroup">
               <button  class="width100" type="button" id="showJson">Json2Clipboard</button>
             </div>
+            <div id="Json2ClipboardGroup" class="wasGroup">
+              <button  class="width100" type="button" id="overrideRect">OverrideRectangle</button>
+            </div>
             <div class="wasGroup">
               <input class="width100" type="submit" value="startCutting">
             </div>

+ 143 - 11
ui/js/imageSlicer.js

@@ -70,6 +70,16 @@ function addRectangle1(id,x,y,w,h,pattern,idtext,assignmentsstation,assignments)
     changeRectPosition(localID, "height", this.value );
   });
   
+  //allow to disable rectangle
+  $('[data-class=setinactive]',clone).change(function() {
+    $(this).parent().parent().parent().toggleClass("singleRect");
+  });
+  
+  $('[data-class=removeRect]',clone).on('click', function(e) {
+    $(this).parent().parent().parent().remove();
+  
+  });
+  
   
   //Alle Abkürzungen einfügen und prüfen ob im pattern angegeben
   abk.forEach(function(item){
@@ -79,6 +89,9 @@ function addRectangle1(id,x,y,w,h,pattern,idtext,assignmentsstation,assignments)
     if(typeof pattern !== 'undefined' && pattern[item]){
         $('[data-class=input]',clonepattern).prop('checked', true);
     }
+    
+    
+    $('[data-class=input]',clonepattern).change(refreshassignments);
     $('[data-class=RectanglePattern',clone).append(clonepattern);
     
   });
@@ -131,7 +144,7 @@ function addRectangle1(id,x,y,w,h,pattern,idtext,assignmentsstation,assignments)
       });
       $('[data-class=AllAssignments]',clonepattern).append(clonepatternvalue)
     });
-  }  
+  }
   
   $('[data-class=RectangleAssignmentStation]',clone).append(clonepattern);
   
@@ -161,6 +174,11 @@ function addRectangle1(id,x,y,w,h,pattern,idtext,assignmentsstation,assignments)
       e.target.nextElementSibling.append(clonepatternvalue)
     });
     
+    //Default Assignment nur bei angekreuzten pattern ausfüllen
+    if(typeof pattern !== 'undefined' && pattern[item["abk"]]){
+        $('[data-class=AssignmentDefaultValue]',clonepattern).text($("#FormPattern2_Form_" + item["abk"]).find(":selected").text());
+    }
+    
     //Assignment Ausfüllen
     if(typeof assignments !== 'undefined' && assignments[item["abk"]]){
       $.each(assignments[item["abk"]], function(i, item){    
@@ -191,7 +209,22 @@ function addRectangle1(id,x,y,w,h,pattern,idtext,assignmentsstation,assignments)
   var clone = document.importNode(document.querySelector('#RectanglesImage').content,true);
   $('[data-class=RectID]',clone).attr("id","Rect" + localID);
   $('[data-class=RectID]',clone).attr("y",y);
-  $('[data-class=RectID]',clone).text("Rect" + localID);
+  
+  //Write text into img. such that this text shall equal the text on the slides
+  var recttext = "";
+  abk.forEach(function(item){
+    if(typeof pattern !== 'undefined' && pattern[item]){
+      recttext += item;
+    }
+    
+  });
+  if(typeof idtext !== 'undefined' && idtext != ""){
+      recttext += "ID:" + idtext;
+  }
+  
+  
+  $('[data-class=RectID]',clone).text(recttext);
+  
   
   $('[data-class=RectID]',clone).css("top", y * scalefactor() + "px");
   $('[data-class=RectID]',clone).css("left", x  * scalefactor() + "px");
@@ -229,6 +262,7 @@ function addRectangle1(id,x,y,w,h,pattern,idtext,assignmentsstation,assignments)
 function createPatternForm(){
   /* Load pattern config */
   //Create form for WAS/Stations/Pattern and WAS/Slicer
+
   var populate = ["FormPattern","FormPattern2","FormPatternAssignment"]
   
   var first = true;
@@ -241,6 +275,7 @@ function createPatternForm(){
         $('[data-class=Abkürzung]',clone).text(item["abk"]);
         if(first)
           abk.push(item["abk"])
+        $('[data-class=Optionen]',clone).attr("name",item["abk"])
         $.each( item["types"], function(i, item){        
           $('[data-class=Optionen]',clone).append('<option value="' + item +'">' + item +'</option>');
         });
@@ -250,6 +285,13 @@ function createPatternForm(){
       });
       //Add "Text" to abk to show it within rects
       first = false;
+      
+      //on Patternform2 change trigger assignment default reset
+      if(populate2 == "FormPattern2"){
+        abk.forEach(function(localabk){
+          $("#FormPattern2_Form_" + localabk).change(refreshassignments);
+        });
+      }
     });
   });
   abk.length = 0;
@@ -260,7 +302,6 @@ function createPatternForm(){
       $("#savelocation").append('<option value="' + item +'">' + item +'</option>');
     });
   });
-  
 }
 
 function updateSlicerPatternForm(){
@@ -384,11 +425,16 @@ function assignmentGetAllStatios(cur) {
 }
 
 //gets assignments for current rectangle
-function assignmentGetAllAssignments(cur) {
+function assignmentGetAllAssignments(cur, addDefaultValues = false) {
   var assignments = {};
   cur.find(".RectangleAssignment div").each(function() {
-    assname = cur.attr('name')
+    assname = $(this).attr('name')
     var allass = new Set();
+    
+    if(addDefaultValues && $(this).find(".RectanglesAssignmentDefaultValue").first().text() != ""){
+      allass.add($(this).find(".RectanglesAssignmentDefaultValue").first().text());
+    }
+    
     $(this).find(".RectanglesAssignmentValue").each(function() {
       allass.add($(this).text());
     });
@@ -399,6 +445,27 @@ function assignmentGetAllAssignments(cur) {
   return assignments;
 }
 
+function assignmentGetAllEmptyAssignments(cur){
+  var assignments = {};
+  cur.find(".RectangleAssignment div").each(function() {
+    assname = $(this).attr('name')
+    var allass = new Set();
+        
+    if($(this).find(".RectanglesAssignmentDefaultValue").first().text() != ""){
+      allass.add($(this).find(".RectanglesAssignmentDefaultValue").first().text());
+    }
+    
+    $(this).find(".RectanglesAssignmentValue").each(function() {
+      allass.add($(this).text());
+    });
+    if(!allass.size){
+      assignments[assname] = "";
+    }
+  });
+  return assignments;
+  
+  
+}
 
 function submitSlices(skip = false){
   //createJsonCutting();
@@ -409,7 +476,7 @@ function submitSlices(skip = false){
   var skippall = false;
   if(!skip){
     var checkedoptions = new Set();
-    $("#imgRectangles input[type=checkbox]:checked").each(function(index, data){
+    $("#imgRectangles wasRight input[type=checkbox]:checked").each(function(index, data){
       checkedoptions.add($(data).attr("name"))
     });
     var allskips = [];
@@ -435,8 +502,7 @@ function submitSlices(skip = false){
       success: function(data){
       
       
-        console.log(Object.keys(data).length);
-        if ( Object.keys(data).length == 1) {
+        if (!data.hasOwnProperty('override')) {
           //clearFormFull();
           if(!skip){
             alert("Saved Images");
@@ -448,7 +514,7 @@ function submitSlices(skip = false){
         }
         else{
           if(!skip){
-            overlayOnDupliImages(data);
+            overlayOnDupliImages(data.override);
           }
         }
       
@@ -466,24 +532,39 @@ function submitSlices(skip = false){
             var assignmentstation = assignmentGetAllStatios($(this));
             
             //get all assignments of current Rectangle
-            var assignments = assignmentGetAllAssignments($(this));
+            var assignments = assignmentGetAllAssignments($(this), true);
+            //in case no assignments are found do next rect
+            console.log(assignments);
+            if(Object.keys(assignments).length === 0){
+              ++counter;
+              return true;
+            }
+            
+            //get all empty assignments of current Rectangle
+            var emptyassignments = assignmentGetAllEmptyAssignments($(this));
 
             //get all combinations of assignments
             var result = recCombi(assignments, 0, [], {});
             
+            
             //Save assignments
+            
             $.each(assignmentstation, function(i, station) {
               $.each(result, function(i, item) {
                 var obj = new Object();
                 obj.img = data.url[counter];
                 obj.station = station;
+                
+                $.extend( item, emptyassignments );
+
                 obj.parts = item;
                 obj.assignmentText = txt;
-                
+                console.log(obj);
                 //use storage function from assignment.js
                 submitAssignment(obj);
               });
             });
+            
             ++counter;
           });
         }        
@@ -498,6 +579,8 @@ function submitSlices(skip = false){
 
 function overlayOnDupliImages(data) {
   
+  
+  
   document.getElementById("overlayNotClickable").style.display = "block";
   
   var clone = document.importNode(document.querySelector('#SlicerDupliOverlay').content,true);
@@ -524,6 +607,24 @@ function showJson(){
   copy2Clipboard(JSON.stringify(createJson()))
 }
 
+function overrideRect(){
+  
+  if (confirm('Please be carefull when overriding, are you sure?')) {
+    var curjson = createJson();
+    $.getJSON( "../server/json/Rectangle.json", function( data ) {
+      //Override Rects
+      $.each(data.Configs, function(i, item) {
+        if(curjson.name == item.name){
+          //data.Configs[i].rects = curjson.rects;
+          item.rects = curjson.rects;
+          console.log("Overriding")
+        }
+      });
+      submitJson("Rectangle.json", JSON.stringify(data));
+    });
+  }
+}
+
 
 function copy2Clipboard(datalink) {
   const el = document.createElement('textarea');
@@ -615,6 +716,29 @@ function togglenext(currelement){
     currelement.next().slideToggle();
 }
 
+
+function refreshassignments(){
+  $(".singleRect").each(function() {
+    var main = $(this);
+    $(this).find(".RectangleAssignment div").each(function() {
+      var curabk = $(this).attr('name');
+      var next = false;
+      main.find(".patternPart3 .patternPart3Input:checked ").each(function() {
+        if($(this).attr('name') == curabk){
+          next = true;
+        }
+      });
+      if(next){
+        $(this).find(".RectanglesAssignmentDefaultValue").first().text($("#FormPattern2_Form_" + curabk).find(":selected").text())
+      }
+      else{
+        $(this).find(".RectanglesAssignmentDefaultValue").first().text("")
+      }
+    });
+  });
+}
+
+
 $(document).ready(function() {
   createPatternForm();
   updateSlicerPatternForm();
@@ -624,6 +748,10 @@ $(document).ready(function() {
   $("#slicerpatterninput").bind("keypress", {}, fillpatternForm);
 
   
+  
+
+      
+  
   /*
 $("#sliceImg").bind('load', function() {
   
@@ -658,6 +786,10 @@ $('#sliceImg').on('load',function(){
     showJson();
   });
   
+  $("#overrideRect").click(function() {
+    overrideRect();
+  });
+  
   $("#multiCut").click(function() {
     getAllFiles($('#selectfolders').val());
   });

+ 4 - 2
ui/js/settings.js

@@ -12,8 +12,10 @@ function IsJsonString(str) {
     }
 }
 
-function submitJson(filename){
-  jsonstring = $('#jsonfiletxtarea').val();
+function submitJson(filename, jsonstring = ""){
+  if(jsonstring == ""){
+    jsonstring = $('#jsonfiletxtarea').val();
+  }
   if(IsJsonString(jsonstring)){
     $.ajax({
       type: "PUT",