Browse Source

Dashboards können nun über die url Search mit den paramtern colname und searchvalue durchsucht werden, das ganze ist aufgrund der struktur (es wrden json gespeichert) aber recht ineffizient, besser läuft das beim dashboard_evva_db

Manuel Gall 1 week ago
parent
commit
1449ea4a76
4 changed files with 100 additions and 11 deletions
  1. 14 4
      addCollumnToJson.rb
  2. 72 6
      dashboard
  3. 6 0
      dashboard.xml
  4. 8 1
      template/index.html

+ 14 - 4
addCollumnToJson.rb

@@ -30,10 +30,10 @@ require 'uri'
 $db = SQLite3::Database.open 'data.db'
 
 
-#ADD ST entry to all entries
 searchstring = "SELECT DISTINCT	__orderID__, alldata FROM Entries"
 result = $db.execute searchstring;
 
+#every result in the table is updated here:
 result.each do |item|
   key = item[0]
   newalldata = item[1]
@@ -42,11 +42,21 @@ result.each do |item|
   pp newalldata
   
   thaData = JSON.parse(newalldata)
-  thaData["DZ-M"] = 0;
-  thaData["RDZ-M"] = 0;
+  
+  #Adding new key with 0 value
+  #thaData["DZ-M"] = 0;
+  #thaData["RDZ-M"] = 0;
+  
+  #Renaming Key
+  thaData["AZ37-SEC"] = thaData.delete("AZ37")
+  thaData["IZ37-SEC"] = thaData.delete("IZ37")
+  thaData["AZ38-NOR"] = thaData.delete("AZ38")
+  thaData["IZ38-NOR"] = thaData.delete("IZ38")
+  
+  
 
   
-  sort_order = [:"gesamt", :"KZ-S", :"RKZ-S", :"HZ-S", :"RHZ-S", :"DZ-S", :"DZ-M", :"RDZ-S", :"RDZ-M", :"HM24-S", :"MB19", :"MB22", :"MB23CH", :"MB27", :"SKA", :"A0V", :"AZ25-FP", :"AZ37", :"IZ37", :"AZ38", :"IZ38", :"AZ29-RC1"]
+  sort_order = [:"gesamt", :"KZ-S", :"RKZ-S", :"HZ-S", :"RHZ-S", :"DZ-S", :"DZ-M", :"RDZ-S", :"RDZ-M", :"HM24-S", :"MB19", :"MB22", :"MB23CH", :"MB27", :"SKA", :"A0V", :"AZ25-FP", :"AZ37-SEC", :"IZ37-SEC", :"AZ38-NOR", :"IZ38-NOR", :"AZ29-RC1"]
  
   newalldata = {}
   sort_order.each{|k| newalldata[k] = thaData[k.to_s] }

+ 72 - 6
dashboard

@@ -195,13 +195,7 @@ class AddEntry < Riddl::Implementation
       db.execute("INSERT OR REPLACE INTO Entries (alldata, cpeeInstance) VALUES (?,?)",JSON.dump(newEntry["alldata"]), "Direkt")
       hash = {__orderID__: db.execute("select last_insert_rowid()")[0], alldata: JSON.dump(newEntry["alldata"]), cpeeInstance: "Direkt"};
     end
-    
-    
-    
     @a[0].send("reset")
- 
- 
- 
     nil
     
   end
@@ -526,6 +520,77 @@ class SearchPK < Riddl::Implementation
   end
 end
 
+def sqlite_json_path(*segments)
+  raise ArgumentError, "at least one segment required" if segments.empty?
+
+  segments.map! { |s| s.to_s }
+  # Escape " and \ inside a quoted segment
+  esc = ->(s) { s.gsub(/["\\]/) { |c| "\\#{c}" } }
+
+  out = "$"
+  segments.each do |seg|
+    if seg =~ /\A\d+\z/
+      # pure array index
+      out << "[#{seg}]"
+    elsif seg =~ /\A[A-Za-z_][A-Za-z0-9_]*\z/
+      # simple identifier -> dot notation
+      out << ".#{seg}"
+    else
+      # needs quoting -> bracket notation
+      out << %Q{["#{esc.call(seg)}"]}
+    end
+  end
+  out
+end
+
+
+class SearchField < Riddl::Implementation
+  def response
+    
+    fname = File.join('data',@r[-2],'data.db')
+    db = SQLite3::Database.open fname
+    
+    
+    colname = @p[0].value
+    colvalue = @p[1].value
+    
+    
+    
+    
+    if !db.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='Entries';").empty?
+      db.results_as_hash = true
+      alldata = {};
+      
+      sql_case_b = <<~SQL
+        SELECT e.*
+        FROM Entries AS e
+        JOIN json_each(json_extract(e.alldata, '$')) AS j
+          ON j.key = ?
+        WHERE j.value = ?
+      SQL
+      
+      rows = db.execute(sql_case_b, [colname, colvalue])
+
+      
+      #rows.each do |row|
+      #  puts "#{row['alldata']}"
+      #end
+            
+      
+      
+      
+      #alldata["data"] = (db.execute "Select * from Entries WHERE " + colname + " = '" + colvalue + "'")
+      
+      
+      
+      
+      Riddl::Parameter::Complex.new('value','application/json',JSON.dump(rows))
+    else 
+      Riddl::Parameter::Complex.new('value','application/json',JSON.dump({}))
+    end
+  end
+end
+
 
 class GetNext < Riddl::Implementation
   def response
@@ -676,6 +741,7 @@ server = Riddl::Server.new(File.join(__dir__,'/dashboard.xml'), :host => 'localh
       end
       
       on resource 'search' do
+        run SearchField if get 'searchColumn'
         on resource 'PK' do
           on resource '.*' do
             run SearchPK if get

+ 6 - 0
dashboard.xml

@@ -27,6 +27,11 @@
     </optional>
   </message>
   
+  <message name="searchColumn">
+    <parameter name="colname" type="string"/>
+    <parameter name="searchvalue" type="string"/>
+  </message>
+  
   <message name="addColumn">
     <parameter name="colname" type="string"/>
     <parameter name="colvalue" type="string"/>
@@ -154,6 +159,7 @@
       
       
       <resource relative='search'>
+        <get in="searchColumn" out="json"/>
         <resource relative='PK'>
           <resource relative=".*">
             <get out="json"/>

+ 8 - 1
template/index.html

@@ -53,9 +53,16 @@
         
      <h1>Configurations</h1>
      
+     <h2>Examples</h2>
+     https://centurio.evva.com/dashboard/austaktenLog/?showfilter=true&display=empty&hideAdd=true/
+     
+     
      <h2>Button Filtering</h2>
-        &display=aktivieren,aktivierenPrio,stornieren,moveTop,moveX,move,move2,edit<br><br>
+        &display=aktivieren,aktivierenPrio,stornieren,moveTop,moveX,move,move2,edit<br>
+        &display=empty<br>
         
+     <h2>Hide Add Button and Row</h2>
+        &hideAdd=true
         
      <h2>"Menu"</h2>
         ?menu=Buttonname,link/<br>