|
@@ -792,7 +792,13 @@ class SaveNewAssignment < Riddl::Implementation
|
|
id = result[0][0] +1
|
|
id = result[0][0] +1
|
|
end
|
|
end
|
|
|
|
|
|
- #puts form
|
|
|
|
|
|
+ #bring given pattern into correct string (initially pattern could be in different order than required)
|
|
|
|
+ pattern = [];
|
|
|
|
+ fullcode = JSON.parse( File.read(File.join(File.dirname(__dir__),"server/json/ProductCode.json")))
|
|
|
|
+ fullcode["pattern"].each do |child|
|
|
|
|
+ pattern.push(form["parts"][child["abk"]])
|
|
|
|
+ end
|
|
|
|
+
|
|
|
|
|
|
checkimage = $db.execute "SELECT * FROM assignments WHERE image = '#{form["img"]}'"
|
|
checkimage = $db.execute "SELECT * FROM assignments WHERE image = '#{form["img"]}'"
|
|
#if image not stored create new assignment with pattern, otherwise only add pattern
|
|
#if image not stored create new assignment with pattern, otherwise only add pattern
|
|
@@ -815,13 +821,17 @@ class SaveNewAssignment < Riddl::Implementation
|
|
maxID = maxID[0][0] +1
|
|
maxID = maxID[0][0] +1
|
|
end
|
|
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"]])
|
|
|
|
-
|
|
|
|
- ret = {:id => checkimage[0][0]}
|
|
|
|
|
|
+ #Search 4 assignment if none found add assignment
|
|
|
|
+ #pp ListAssignmentSearch::prepare(@a[0][:appconf]["wasurl"], pattern.join('.'), form["station"], form["assignmentText"])
|
|
|
|
+ if (!ListAssignmentSearch::prepare(@a[0][:appconf]["wasurl"], pattern.join('.'), form["station"], form["assignmentText"]).any?)
|
|
|
|
+ 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"]])
|
|
|
|
+
|
|
|
|
+ ret = {:id => checkimage[0][0]}
|
|
|
|
+ end
|
|
Riddl::Parameter::Complex.new('list','application/json',JSON::pretty_generate(ret))
|
|
Riddl::Parameter::Complex.new('list','application/json',JSON::pretty_generate(ret))
|
|
end
|
|
end
|
|
end
|
|
end
|
|
@@ -878,10 +888,11 @@ class DeleteSingleAssignment < Riddl::Implementation
|
|
end
|
|
end
|
|
|
|
|
|
class ListAssignmentSearch < Riddl::Implementation
|
|
class ListAssignmentSearch < Riddl::Implementation
|
|
- def response
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
+ def self::prepare(appconf, pat, pat_station, pat_value)
|
|
#https://centurio.work/customers/evva/was/ui/TransformProductCode.php?ProductCode=E.A.PZ.DZ-S.31.31.MP.SEP
|
|
#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))
|
|
|
|
|
|
+ pattern = JSON.parse(Net::HTTP.get URI(appconf + "ui/TransformProductCode.php?ProductCode=" + pat))
|
|
|
|
|
|
#remove empty entries from pattern
|
|
#remove empty entries from pattern
|
|
pattern.each do |key, value|
|
|
pattern.each do |key, value|
|
|
@@ -931,21 +942,26 @@ class ListAssignmentSearch < Riddl::Implementation
|
|
searchstring = searchstring + " AND " + pattern.keys[0] + ".ID == ValText.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 STATION.type == 'STATION'" + " AND STATION.value == '" + pat_station + "'"
|
|
|
|
+ searchstring = searchstring + " AND ValText.type == 'TEXT'" + " AND ValText.value == '" + pat_value + "'"
|
|
|
|
|
|
|
|
|
|
- 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"
|
|
|
|
|
|
+ searchstring = searchstring + " AND " + pattern.map{ |key, val|
|
|
|
|
+ #In case a value has the option "KeineAngabe" empty values are allowed
|
|
|
|
+ if(val.start_with?("KeineAngabe"))
|
|
|
|
+ key + ".type == '" + key + "' AND (" + key + ".value == '"+ val +"' or " + key + ".value == '*' or " + key + ".value == '')"
|
|
|
|
+ else
|
|
|
|
+ key + ".type == '" + key + "' AND (" + key + ".value == '"+ val +"' or " + key + ".value == '*')"
|
|
|
|
+ end
|
|
|
|
+ }.join(' AND ') + " ORDER BY ID ASC"
|
|
|
|
|
|
#puts searchstring;
|
|
#puts searchstring;
|
|
else
|
|
else
|
|
searchstring = "SELECT * FROM "
|
|
searchstring = "SELECT * FROM "
|
|
searchstring = searchstring + "patternassignments STATION , patternassignments ValText"
|
|
searchstring = searchstring + "patternassignments STATION , patternassignments ValText"
|
|
searchstring = searchstring + " WHERE"
|
|
searchstring = searchstring + " WHERE"
|
|
- searchstring = searchstring + " STATION.type == 'STATION'" + " AND STATION.value == '" + @p[1].value + "'"
|
|
|
|
- searchstring = searchstring + " AND ValText.type == 'TEXT'" + " AND ValText.value == '" + @p[2].value + "'"
|
|
|
|
|
|
+ searchstring = searchstring + " STATION.type == 'STATION'" + " AND STATION.value == '" + pat_station + "'"
|
|
|
|
+ searchstring = searchstring + " AND ValText.type == 'TEXT'" + " AND ValText.value == '" + pat_value + "'"
|
|
searchstring = searchstring + " AND ValText.AssID == STATION.AssID"
|
|
searchstring = searchstring + " AND ValText.AssID == STATION.AssID"
|
|
searchstring = searchstring + " ORDER BY ID ASC"
|
|
searchstring = searchstring + " ORDER BY ID ASC"
|
|
end
|
|
end
|
|
@@ -965,7 +981,12 @@ class ListAssignmentSearch < Riddl::Implementation
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
-
|
|
|
|
|
|
+ return ret
|
|
|
|
+
|
|
|
|
+ end
|
|
|
|
+
|
|
|
|
+ def response
|
|
|
|
+ ret = ListAssignmentSearch::prepare(@a[0][:appconf]["wasurl"], @p[0].value, @p[1].value, @p[2].value)
|
|
Riddl::Parameter::Complex.new('list','application/json',JSON::pretty_generate(ret))
|
|
Riddl::Parameter::Complex.new('list','application/json',JSON::pretty_generate(ret))
|
|
end
|
|
end
|
|
end
|
|
end
|
|
@@ -1080,7 +1101,7 @@ server = Riddl::Server.new(File.join(__dir__,'/was.xml'), :host => 'localhost')
|
|
end
|
|
end
|
|
on resource 'assignments' do
|
|
on resource 'assignments' do
|
|
run GetAssignments if get
|
|
run GetAssignments if get
|
|
- run SaveNewAssignment if post 'list'
|
|
|
|
|
|
+ run SaveNewAssignment, opts if post 'list'
|
|
on resource 'search' do
|
|
on resource 'search' do
|
|
run ListAssignmentSearch, opts if get
|
|
run ListAssignmentSearch, opts if get
|
|
end
|
|
end
|