Browse Source

Added the possibility to add collumns after creating the tables

Manuel Gall 6 months ago
parent
commit
66cf5e290c
4 changed files with 137 additions and 1 deletions
  1. 62 0
      addCollumnToJson.rb
  2. 58 0
      dashboard
  3. 16 0
      dashboard.xml
  4. 1 1
      template/index.html

+ 62 - 0
addCollumnToJson.rb

@@ -0,0 +1,62 @@
+#!/usr/bin/ruby
+  #
+  # This file is part of centurio.work/was.
+  #
+  # centurio.work/ing/commands is free software: you can redistribute it and/or
+  # modify it under the terms of the GNU General Public License as published by
+  # the Free Software Foundation, either version 3 of the License, or (at your
+  # option) any later version.
+  #
+  # centurio.work/ing/commands is distributed in the hope that it will be useful,
+  # but WITHOUT ANY WARRANTY; without even the implied warranty of
+  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
+  # Public License for more details.
+  #
+  # You should have received a copy of the GNU General Public License along with
+  # centurio.work/ing/commands (file COPYING in the main directory). If not, see
+# <http://www.gnu.org/licenses/>.
+
+require 'rubygems'
+require 'json'
+require 'riddl/server'
+require 'riddl/client'
+require 'fileutils'
+require 'nokogiri'
+require 'sqlite3'
+require 'net/http'
+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;
+
+result.each do |item|
+  key = item[0]
+  newalldata = item[1]
+  
+  pp key
+  pp newalldata
+  
+  thaData = JSON.parse(newalldata)
+  thaData["DZ-M"] = 0;
+  thaData["RDZ-M"] = 0;
+
+  
+  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"]
+ 
+  newalldata = {}
+  sort_order.each{|k| newalldata[k] = thaData[k.to_s] }
+ 
+  #pp newalldata.to_json
+  
+  $db.execute("UPDATE Entries SET alldata = ? WHERE __orderID__ = ?", newalldata.to_json, key )
+  
+end
+
+
+
+

+ 58 - 0
dashboard

@@ -87,6 +87,59 @@ class GetAllData < Riddl::Implementation
 end
 
 
+class AddColumn < Riddl::Implementation
+  def response
+  
+    colname = @p[0].value
+    colvalue = @p[1].value
+    
+    fname = File.join('data',@r[-2],'data.db')
+    db = SQLite3::Database.open fname
+    
+    searchstring = "SELECT DISTINCT	__orderID__, alldata FROM Entries"
+    result = db.execute searchstring;
+
+    result.each do |item|
+      key = item[0]
+      newalldata = item[1]
+      
+      thaData = JSON.parse(newalldata)
+      thaData[colname] = colvalue;
+      
+      db.execute("UPDATE Entries SET alldata = ? WHERE __orderID__ = ?", thaData.to_json, key )
+    end   
+    
+    Riddl::Parameter::Complex.new('value','application/json',JSON.dump({status: "looks good?"}))
+  end
+end
+
+
+class DeleteColumn < Riddl::Implementation
+  def response
+    colname = @p[0].value
+    
+    fname = File.join('data',@r[-2],'data.db')
+    db = SQLite3::Database.open fname
+    
+    searchstring = "SELECT DISTINCT	__orderID__, alldata FROM Entries"
+    result = db.execute searchstring;
+
+    result.each do |item|
+      key = item[0]
+      newalldata = item[1]
+      
+      thaData = JSON.parse(newalldata)
+      thaData.delete(colname)
+      
+      db.execute("UPDATE Entries SET alldata = ? WHERE __orderID__ = ?", thaData.to_json, key )
+    end   
+    
+    
+    Riddl::Parameter::Complex.new('value','application/json',JSON.dump({status: "looks good?"}))
+  end
+end        
+
+
 class GetNData < Riddl::Implementation
   def response    
     fname = File.join('data',@r[-2],'data.db')
@@ -613,6 +666,11 @@ server = Riddl::Server.new(File.join(__dir__,'/dashboard.xml'), :host => 'localh
         run GetAllData if get
       end
       
+      on resource 'Column' do
+        run AddColumn if post 'addColumn'
+        run DeleteColumn if post 'removeColumn'
+      end
+      
       on resource 'htmlform' do
         run PostHtmlVals, opts[:signals][idx] if post
       end

+ 16 - 0
dashboard.xml

@@ -26,6 +26,16 @@
       </optional>
     </optional>
   </message>
+  
+  <message name="addColumn">
+    <parameter name="colname" type="string"/>
+    <parameter name="colvalue" type="string"/>
+  </message>
+  
+  <message name="removeColumn">
+    <parameter name="colname" type="string"/>
+  </message>
+  
   <message name="inputprio">
     <parameter name="inputprio" type="string"/>
     <optional>
@@ -132,6 +142,12 @@
       </resource>
       
       
+      <resource relative='Column'>
+        <post in="addColumn" out="json"/>
+        <post in="removeColumn" out="json"/>
+      </resource>
+      
+      
       <resource relative='htmlform'>
         <post out="ui"/>
       </resource>

+ 1 - 1
template/index.html

@@ -54,7 +54,7 @@
      <h1>Configurations</h1>
      
      <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><br>
         
         
      <h2>"Menu"</h2>