Browse Source

Updated search for new DB-Structure

Manuel Gall 3 years ago
parent
commit
690cfee9da
2 changed files with 32 additions and 148 deletions
  1. 32 143
      server/was.rb
  2. 0 5
      ui/index.html

+ 32 - 143
server/was.rb

@@ -634,89 +634,29 @@ end
 
 class SearchImages < Riddl::Implementation
   def response
-  
-    
     #https://centurio.work/customers/evva/was/ui/TransformProductCode.php?ProductCode=E.A.PZ.DZ-S.31.31.MP.SEP
-    
-    #path = File.join(File.dirname(__FILE__), + '../ui/')
-    #args = ['arg1', 'arg2']
-    #puts `php -f #{ path + 'TransformProductCode.php'}`
-
   
     pattern = JSON.parse(Net::HTTP.get URI("https://centurio.work/customers/evva/was/ui/TransformProductCode.php?ProductCode=" + @p[0].value))
-    puts pattern.keys[0]
 
     
-    
-    #iter = @p[0].value.split(".")
-    count = 0
-    
-    #search = K.*.9.*
-    
-    #match: = K.5.9.7
-      #match: = K.5.9.*
-    #match: = K.*.*.*
-    
-    #no match: = K.*.8.*
-    #puts iter;
-    
-    
-    
-    
-    #$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)"
-    
-    #Get first key dynamicly
-    searchstring = "SELECT " + pattern.keys[0] + ".internalID AS ID From"
-    
-    pattern.each  do |key, val|
-      puts key
-      
-      #searchstring = searchstring + "pattern " + key
-    end
-    
-    #Search for pattern
-    searchstring = "SELECT A.internalID AS ID, A.value AS Pb, B.value AS Sy, C.value AS Pk, D.value AS BA, E.value AS ZA
-    FROM pattern A, pattern B, pattern C, pattern D, pattern E
-    WHERE A.internalID == B.internalID AND A.internalID == C.internalID AND A.internalID == D.internalID AND A.internalID == E.internalID
-    AND A.type == 'Pb' AND (A.value == '#{pattern["Pb"]}' or A.value == '*')
-    AND B.type == 'Sy' AND (B.value == '#{pattern["Sy"]}' or B.value == '*')
-    AND C.type == 'Pk' AND (C.value == '#{pattern["Pk"]}' or C.value == '*')
-    AND D.type == 'Ba' AND (D.value == '#{pattern["Ba"]}' or D.value == '*')
-    AND E.type == 'Za' AND (E.value == '#{pattern["Za"]}' or E.value == '*');"
-    
+    #Get first key dynamicly and then build sql query
+    searchstring = "SELECT " + pattern.keys[0] + ".internalID AS ID"
+    searchstring = searchstring + " FROM " + pattern.map{ |key, val| "pattern " + key}.join(', ')
+    searchstring = searchstring + " WHERE " + pattern.map{ |key, val| pattern.keys[0] + ".internalID == " + key + ".internalID"}.join(' AND ')
+    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;
     
-    if result.length > 0
-    
-      result.each do |item|
-        puts "ID: " +item[0].to_s + " Pattern:" + item[1]   + "." + item[2]+ "." + item[3]+ "." + item[4] + "." + item[5]
-      end
-    
-    end
-    #iter.each do |item|
-    #  if !item.nil?
-    #    if item.to_s != "*"
-    #      item.to_s.gsub! '_empty_', '/'
-    #      searchstring = searchstring + " and (P" + count.to_s + "='*' or P" + count.to_s + " = '" + item.to_s + "')"
-    #      else
-    #      searchstring = searchstring + " and (P" + count.to_s + "!=''" + ")"
-    #    end
-    #    count += 1
-    #  end
-    #end
-    
-    #result = $db.execute "SELECT patternID FROM station WHERE station = " + @r[0] + searchstring
     
     #Search for images with one or multiple found patternIDs
     ret = []
-    #if result.length > 0
-    #  result.each do |item|
-    #    result2 = $db.execute "SELECT DISTINCT station, patternID, imageID FROM image WHERE station = #{@r[0]} and patternID = #{item[0]}"
-    #    result2.each do |item2|
-    #      ret << item2[0].to_s + "/" + item2[1].to_s + "/" + item2[2].to_s
-    #    end
-    #  end
-    #end
+    if result.length > 0
+      result.each do |item| 
+        result2 = $db.execute "SELECT DISTINCT internalID, imageID FROM image WHERE internalID = #{item[0]} ORDER BY imageID ASC"
+        result2.each do |item2|
+          ret << @r[0] + "/" + item2[0].to_s + "/" + item2[1].to_s
+        end
+      end
+    end
     
     Riddl::Parameter::Complex.new('list','application/json',JSON::pretty_generate(ret))
   end
@@ -725,51 +665,29 @@ end
 
 class SearchImagesSingle < Riddl::Implementation
   def response
-    iter = @p[0].value.split(".")
-    searchstring = ""
-    count = 0
-    
-    iter.each do |item|
-      if !item.nil?
-        if item.to_s != "*"
-          searchstring = searchstring + " and (P" + count.to_s + "='*' or P" + count.to_s + " = '" + item.to_s + "')"
-          else
-          searchstring = searchstring + " and (P" + count.to_s + "!=''" + ")"
-        end
-        count += 1
-      end
-    end
-    
-    result = $db.execute "SELECT patternID FROM station WHERE station = " + @r[0] + searchstring
+    pattern = JSON.parse(Net::HTTP.get URI("https://centurio.work/customers/evva/was/ui/TransformProductCode.php?ProductCode=" + @p[0].value))
+
+    searchstring = "SELECT " + pattern.keys[0] + ".internalID AS ID"
+    searchstring = searchstring + " FROM " + pattern.map{ |key, val| "pattern " + key}.join(', ')
+    searchstring = searchstring + " WHERE " + pattern.map{ |key, val| pattern.keys[0] + ".internalID == " + key + ".internalID"}.join(' AND ')
+    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;
     
     count = 0
     pattern = 0
     image = 0
     
-    
-    
-    
-    
-    
     builder = Nokogiri::XML::Builder.new do |xml|
       xml.image(:id => @r[3].to_s){
         if result.length > 0
           result.each do |item|
-            result2 = $db.execute "SELECT DISTINCT station, patternID, imageID FROM image WHERE station = #{@r[0]} and patternID = #{item[0]}"
+            result2 = $db.execute "SELECT DISTINCT internalID, imageID FROM image WHERE internalID = #{item[0]} ORDER BY imageID ASC"
             result2.each do |item2|
               if(count == @r[3].to_i)
-                
-                  
-                result3 = $db.execute "SELECT DISTINCT station, patternID, imageID, language, label FROM image WHERE station = #{@r[0]} and patternID = #{item[0]} and imageID =#{item2[2]}"
-                
-                
-                
-                
-                
-                
+                result3 = $db.execute "SELECT DISTINCT internalID, imageID, language, label FROM image WHERE internalID = #{item[0]} and imageID =#{item2[1]}"
                 
                 result3.each do |item3|                
-                  uri = "https://centurio.work/customers/evva/was/ui/imageReplacement.php?___image___=" +  @r[0].to_s + "/" + item3[1].to_s + "/" + item3[2].to_s + "/" + item3[3].to_s + ".svg"
+                  uri = "https://centurio.work/customers/evva/was/ui/imageReplacement.php?___image___=" +  @r[0].to_s + "/" + item3[0].to_s + "/" + item3[1].to_s + "/" + item3[2].to_s + ".svg"
                   
                   @p.each_with_index do |item, index|
                     if index != 0
@@ -778,7 +696,7 @@ class SearchImagesSingle < Riddl::Implementation
                     
                   end
                 
-                  xml.variant(:lang => item3[3].to_s, :label => item3[4].to_s){
+                  xml.variant(:lang => item3[2].to_s, :label => item3[3].to_s){
                     xml.text(uri)
                   }
                 end
@@ -791,57 +709,28 @@ class SearchImagesSingle < Riddl::Implementation
     end
     
     #https://centurio.work/customers/evva/was/ui/imageReplacement.php?___image___=8/23/0/de-at.svg
-    
-    
-    
-          
-    
-    
 
-    
     #puts builder.to_xml
     Riddl::Parameter::Complex.new('image','application/xml',builder.to_xml)
-    
-    
-    
-    
-    
   end
 end
 
 
 class SearchErrors < Riddl::Implementation
   def response
-    iter = @p[0].value.split(".")
-    searchstring = ""
-    count = 0
-    
-    #search = K.*.9.*
-    
-    #match: = K.5.9.7
-      #match: = K.5.9.*
-    #match: = K.*.*.*
-    
-    #no match: = K.*.8.*
-    
-    iter.each do |item|
-      if !item.nil?
-        if item.to_s != "*"
-          searchstring = searchstring + " and (P" + count.to_s + "='*' or P" + count.to_s + " = '" + item.to_s + "')"
-          else
-          searchstring = searchstring + " and (P" + count.to_s + "!=''" + ")"
-        end
-        count += 1
-      end
-    end
-    
-    result = $db.execute "SELECT patternID FROM station WHERE station = " + @r[0] + searchstring
+    pattern = JSON.parse(Net::HTTP.get URI("https://centurio.work/customers/evva/was/ui/TransformProductCode.php?ProductCode=" + @p[0].value))
+
+    searchstring = "SELECT " + pattern.keys[0] + ".internalID AS ID"
+    searchstring = searchstring + " FROM " + pattern.map{ |key, val| "pattern " + key}.join(', ')
+    searchstring = searchstring + " WHERE " + pattern.map{ |key, val| pattern.keys[0] + ".internalID == " + key + ".internalID"}.join(' AND ')
+    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|
-        result2 = $db.execute "SELECT DISTINCT error FROM error WHERE station = #{@r[0]} and patternID = #{item[0]}"
+        result2 = $db.execute "SELECT DISTINCT error FROM error WHERE internalID = #{item[0]} ORDER BY internalID ASC"
         result2.each do |item2|
           ret << item2[0].to_s
         end

+ 0 - 5
ui/index.html

@@ -144,11 +144,6 @@
             
             
             <div style="background-color: #efefef; padding-bottom: 1em; margin-top:1em">
-            <div class="wasGroup">
-              <div class="wasLeft">Status:</div>
-              <div class="wasRight"><b>Work in Progress</b></div>
-            </div>
-            
             <div id="FormPattern">
             
             </div>