Browse Source

Added possibility to change style

Manuel Gall 3 years ago
parent
commit
6ece79b91e
5 changed files with 92 additions and 153 deletions
  1. 28 84
      frames
  2. 13 14
      frames.xml
  3. 1 1
      template/css/frames.css
  4. 50 29
      template/js/ui.js
  5. 0 25
      template/template.html

+ 28 - 84
frames

@@ -51,19 +51,15 @@ class Put < Riddl::Implementation
       File.write(File.join('data',@r.last,'style.url'),@p[0].value)
       File.write(File.join('data',@r.last,'style.url'),@p[0].value)
     end
     end
     
     
-    
-    
-    File.write(File.join('data',@r.last,'document.xml'),@p[1].value)
-    
     File.write(File.join('data',@r.last,'frames.json'),JSON.dump(JSON.parse('{"data":[]}')))
     File.write(File.join('data',@r.last,'frames.json'),JSON.dump(JSON.parse('{"data":[]}')))
     
     
+    #for handler
     File.write(File.join('data',@r.last,'dataelements.json'),JSON.dump(JSON.parse('{"data":[]}')))
     File.write(File.join('data',@r.last,'dataelements.json'),JSON.dump(JSON.parse('{"data":[]}')))
     
     
-    
     File.write(File.join('data',@r.last,'info.json'),JSON.dump(JSON.parse('{"x_amount":' + @p[2].value + ', "y_amount":' + @p[3].value + ', "lang":"' + @p[4].value  + '", "langs":["' + @p[4].value +  '"]}')))
     File.write(File.join('data',@r.last,'info.json'),JSON.dump(JSON.parse('{"x_amount":' + @p[2].value + ', "y_amount":' + @p[3].value + ', "lang":"' + @p[4].value  + '", "langs":["' + @p[4].value +  '"]}')))
 
 
-
     File.write(File.join('data',@r.last,'callback'),@h['CPEE_CALLBACK'])
     File.write(File.join('data',@r.last,'callback'),@h['CPEE_CALLBACK'])
+    File.write(File.join('data',@r.last,'cpeeinstance.url'),@h['CPEE_INSTANCE_URL'])
 
 
     @a[0].send('new')
     @a[0].send('new')
     nil
     nil
@@ -77,6 +73,7 @@ end
 
 
 
 
 #https://coderwall.com/p/atyfyq/ruby-string-to-boolean
 #https://coderwall.com/p/atyfyq/ruby-string-to-boolean
+#showbutton
 class String
 class String
   def to_bool
   def to_bool
     return true if self == true || self =~ (/(true|t|yes|y|1)$/i)
     return true if self == true || self =~ (/(true|t|yes|y|1)$/i)
@@ -92,23 +89,13 @@ class NewFrame < Riddl::Implementation
     file = File.read(path)
     file = File.read(path)
     data_hash = JSON::parse(file)
     data_hash = JSON::parse(file)
     
     
+    #check if new frame overlaps others if it does, delete overlapped frames
     data_hash["data"].each do | c |
     data_hash["data"].each do | c |
       if doOverlap(c['lx'], c['ly'], c['rx'], c['ry'], @p[0].value.to_i, @p[1].value.to_i, (@p[0].value.to_i + @p[2].value.to_i - 1), (@p[1].value.to_i + @p[3].value.to_i - 1))
       if doOverlap(c['lx'], c['ly'], c['rx'], c['ry'], @p[0].value.to_i, @p[1].value.to_i, (@p[0].value.to_i + @p[2].value.to_i - 1), (@p[1].value.to_i + @p[3].value.to_i - 1))
         data_hash["data"].delete(c)
         data_hash["data"].delete(c)
       end
       end
     end
     end
     
     
-#    example
-#    myObj = {
-#      "lx":3,
-#      "ly":3,
-#      "rx":3,
-#      "ry":3,
-#      "url": {
-#        "de-at":"xyz.at",
-#        "en-us":"xyz.com"
-#      }
-#     }
     urls = JSON::parse(@p[4].value);
     urls = JSON::parse(@p[4].value);
     
     
     hash = {lx: @p[0].value.to_i, ly: @p[1].value.to_i, rx: (@p[0].value.to_i + @p[2].value.to_i - 1), ry: (@p[1].value.to_i + @p[3].value.to_i - 1), url: urls, showbutton: @p[5].value.to_bool};
     hash = {lx: @p[0].value.to_i, ly: @p[1].value.to_i, rx: (@p[0].value.to_i + @p[2].value.to_i - 1), ry: (@p[1].value.to_i + @p[3].value.to_i - 1), url: urls, showbutton: @p[5].value.to_bool};
@@ -134,6 +121,7 @@ class NewFramePut < Riddl::Implementation
     file = File.read(path)
     file = File.read(path)
     data_hash = JSON::parse(file)
     data_hash = JSON::parse(file)
     
     
+    #check if new frame overlaps others if it does, delete overlapped frames
     data_hash["data"].each do | c |
     data_hash["data"].each do | c |
       if doOverlap(c['lx'], c['ly'], c['rx'], c['ry'], @p[0].value.to_i, @p[1].value.to_i, (@p[0].value.to_i + @p[2].value.to_i - 1), (@p[1].value.to_i + @p[3].value.to_i - 1))
       if doOverlap(c['lx'], c['ly'], c['rx'], c['ry'], @p[0].value.to_i, @p[1].value.to_i, (@p[0].value.to_i + @p[2].value.to_i - 1), (@p[1].value.to_i + @p[3].value.to_i - 1))
         data_hash["data"].delete(c)
         data_hash["data"].delete(c)
@@ -142,7 +130,7 @@ class NewFramePut < Riddl::Implementation
     
     
     urls = JSON::parse(@p[4].value);
     urls = JSON::parse(@p[4].value);
     
     
-  hash = {lx: @p[0].value.to_i, ly: @p[1].value.to_i, rx: (@p[0].value.to_i + @p[2].value.to_i - 1), ry: (@p[1].value.to_i + @p[3].value.to_i - 1), url: urls, showbutton: @p[5].value.to_bool, callback: @h['CPEE_CALLBACK']};
+    hash = {lx: @p[0].value.to_i, ly: @p[1].value.to_i, rx: (@p[0].value.to_i + @p[2].value.to_i - 1), ry: (@p[1].value.to_i + @p[3].value.to_i - 1), url: urls, showbutton: @p[5].value.to_bool, callback: @h['CPEE_CALLBACK']};
     data_hash["data"].push(hash)
     data_hash["data"].push(hash)
     File.write(path, JSON.dump(data_hash))
     File.write(path, JSON.dump(data_hash))
     
     
@@ -164,8 +152,6 @@ end
 
 
 class DeleteFrame < Riddl::Implementation
 class DeleteFrame < Riddl::Implementation
   def response    
   def response    
-    puts "deleting"
-    
     path = File.join('data',@r.last,'frames.json')
     path = File.join('data',@r.last,'frames.json')
     file = File.read(path)
     file = File.read(path)
     data_hash = JSON::parse(file)
     data_hash = JSON::parse(file)
@@ -206,6 +192,7 @@ class Delete < Riddl::Implementation
     end
     end
 
 
     File.unlink(File.join('data',@r.last,'callback')) rescue nil
     File.unlink(File.join('data',@r.last,'callback')) rescue nil
+    File.unlink(File.join('data',@r.last,'cpeeinstance.url')) rescue nil
     File.unlink(File.join('data',@r.last,'style.url')) rescue nil
     File.unlink(File.join('data',@r.last,'style.url')) rescue nil
     File.unlink(File.join('data',@r.last,'document.xml')) rescue nil
     File.unlink(File.join('data',@r.last,'document.xml')) rescue nil
     File.unlink(File.join('data',@r.last,'info.json')) rescue nil
     File.unlink(File.join('data',@r.last,'info.json')) rescue nil
@@ -250,9 +237,6 @@ class GetDataElements < Riddl::Implementation #{{{
 end #}}}
 end #}}}
 
 
 
 
-
-
-
 class GetInfo < Riddl::Implementation #{{{
 class GetInfo < Riddl::Implementation #{{{
   def response
   def response
     fname = File.join('data',@r[-2],'info.json')
     fname = File.join('data',@r[-2],'info.json')
@@ -266,14 +250,10 @@ end #}}}
 
 
 class GetLangs < Riddl::Implementation #{{{
 class GetLangs < Riddl::Implementation #{{{
   def response
   def response
-    fname = File.join('data',@r[-2],'document.xml')
+    fname = File.join('data',@r[-2],'info.json')
     if File.exists? fname
     if File.exists? fname
-      doc = XML::Smart.open_unprotected(fname)
-      ndoc = XML::Smart.string('<languages/>')
-      doc.find('//@lang').each do |e|
-        ndoc.root.add('language',e.value)
-      end
-      Riddl::Parameter::Complex.new('value','text/xml',ndoc.to_s)
+      infojson = JSON::parse(File.read(fname))
+      Riddl::Parameter::Complex.new('value','application/json',infojson["langs"])
     else
     else
       @status = 404
       @status = 404
     end
     end
@@ -315,42 +295,23 @@ class GetStyle < Riddl::Implementation #{{{
     end
     end
   end
   end
 end #}}}
 end #}}}
-class GetDocument < Riddl::Implementation #{{{
+
+class GetCpeeInstance < Riddl::Implementation #{{{
   def response
   def response
-    fname = File.join('data',@r[-3],'document.xml')
+    fname = File.join('data',@r[-2],'cpeeinstance.url')
     if File.exists? fname
     if File.exists? fname
-      doc = XML::Smart.open_unprotected(fname)
-      val = nil
-      doc.find("//variant[@lang='#{@r[-1]}']").each do |e|
-        val = e.text
-      end
-      if val
-        Riddl::Parameter::Complex.new('url','text/plain',val.strip)
-      else
-        @status = 404
-      end
+      Riddl::Parameter::Complex.new('url','text/plain',File.read(fname).strip)
     else
     else
       @status = 404
       @status = 404
     end
     end
   end
   end
 end #}}}
 end #}}}
-class GetButton < Riddl::Implementation #{{{
+
+
+
+class OutputTest < Riddl::Implementation #{{{
   def response
   def response
-    fname = File.join('data',@r[-3],'document.xml')
-    if File.exists? fname
-      doc = XML::Smart.open_unprotected(fname)
-      val = nil
-      doc.find("//variant[@lang='#{@r[-1]}']").each do |e|
-        val = e.attributes['button']
-      end
-      if val
-        Riddl::Parameter::Complex.new('url','text/plain',val.strip)
-      else
-        @status = 404
-      end
-    else
-      @status = 404
-    end
+    puts "Test"
   end
   end
 end #}}}
 end #}}}
 
 
@@ -358,8 +319,6 @@ end #}}}
 
 
 
 
 
 
-
-
 class Handler < Riddl::Implementation
 class Handler < Riddl::Implementation
   def response    
   def response    
     puts "handler"
     puts "handler"
@@ -377,6 +336,7 @@ class Handler < Riddl::Implementation
   
   
       #puts instancenr
       #puts instancenr
       #puts activity
       #puts activity
+      puts content['values']
       
       
       
       
       if content['values']&.any?
       if content['values']&.any?
@@ -385,17 +345,6 @@ class Handler < Riddl::Implementation
         path = File.join('data',@r[0],'dataelements.json')
         path = File.join('data',@r[0],'dataelements.json')
         File.write(path, JSON.dump(content['values']))
         File.write(path, JSON.dump(content['values']))
       end
       end
-      
-      
-      
-      
-      
-      
-      
-      
-      
-      
-      
   
   
       @a[0].send(@r[0])
       @a[0].send(@r[0])
       nil
       nil
@@ -474,9 +423,6 @@ server = Riddl::Server.new(File.join(__dir__,'/frames.xml'), :host => 'localhost
       opts[:signals].each do |k,v|
       opts[:signals].each do |k,v|
         v.send('keepalive')
         v.send('keepalive')
       end
       end
-      sleep 5
-    end
-    loop do
       opts[:signals2].each do |k,v|
       opts[:signals2].each do |k,v|
         v.send('keepalive')
         v.send('keepalive')
       end
       end
@@ -484,6 +430,7 @@ server = Riddl::Server.new(File.join(__dir__,'/frames.xml'), :host => 'localhost
     end
     end
   end
   end
 
 
+
   on resource do
   on resource do
     on resource do |r|
     on resource do |r|
       idx = r[:r][0]
       idx = r[:r][0]
@@ -521,27 +468,24 @@ server = Riddl::Server.new(File.join(__dir__,'/frames.xml'), :host => 'localhost
       on resource 'style.url' do
       on resource 'style.url' do
         run GetStyle if get
         run GetStyle if get
       end
       end
+      on resource 'cpeeinstance.url' do
+        run GetCpeeInstance if get
+      end
       on resource 'info.json' do
       on resource 'info.json' do
         run GetInfo if get
         run GetInfo if get
       end
       end
       on resource 'frames.json' do
       on resource 'frames.json' do
         run GetFrames if get
         run GetFrames if get
       end
       end
+      on resource 'test' do
+        run OutputTest if put
+      end
       
       
       on resource 'dataelements.json' do
       on resource 'dataelements.json' do
         run GetDataElements if get
         run GetDataElements if get
       end
       end
       
       
-      on resource 'buttons' do
-        on resource '[a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*' do
-          run GetButton if get
-        end
-      end
-      on resource 'documents' do
-        on resource '[a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*' do
-          run GetDocument if get
-        end
-      end
+      
     end
     end
   end
   end
 end.loop!
 end.loop!

+ 13 - 14
frames.xml

@@ -45,11 +45,6 @@
   <message name="url">
   <message name="url">
     <parameter name="url" mimetype="text/plain"/>
     <parameter name="url" mimetype="text/plain"/>
   </message>
   </message>
-  <message name="langs">
-    <parameter name="langs" mimetype="*/xml">
-      <xi:include href="rngs/langs.rng"/>
-    </parameter>
-  </message>
   <message name="lang">
   <message name="lang">
     <parameter name="lang" type="string"/>
     <parameter name="lang" type="string"/>
   </message>
   </message>
@@ -64,6 +59,10 @@
   <message name="json">
   <message name="json">
     <parameter name="value" mimetype="application/json"/>
     <parameter name="value" mimetype="application/json"/>
   </message>
   </message>
+  
+  <message name="string"> <!--{{{-->
+    <parameter name="value" type="string"/>
+  </message> <!--}}}-->
 
 
   <resource>
   <resource>
     <resource>
     <resource>
@@ -77,26 +76,20 @@
       
       
       
       
       
       
-      
-      
-      
-      
       <delete in='opa'/>
       <delete in='opa'/>
       <delete in='opb'/>
       <delete in='opb'/>
       <resource relative='sse'>
       <resource relative='sse'>
         <sse/>
         <sse/>
       </resource>
       </resource>
       <resource relative="languages">
       <resource relative="languages">
-        <get out="langs"/>
+        <get out="json"/>
         <post in='lang'/>
         <post in='lang'/>
       </resource>
       </resource>
       <resource relative="style.url">
       <resource relative="style.url">
         <get out="url"/>
         <get out="url"/>
       </resource>
       </resource>
-      <resource relative="documents">
-        <resource relative="[a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*">
-            <get out="url"/>
-        </resource>
+      <resource relative="cpeeinstance.url">
+        <get out="url"/>
       </resource>
       </resource>
       <resource relative="info.json">
       <resource relative="info.json">
         <get out="json"/>
         <get out="json"/>
@@ -108,6 +101,12 @@
         <get out="json"/>
         <get out="json"/>
       </resource>
       </resource>
       
       
+      
+      <resource relative="test">
+        <put in="string"/>
+      </resource>
+        
+      
       <resource relative='handler'>
       <resource relative='handler'>
         <post />
         <post />
         
         

+ 1 - 1
template/css/frames.css

@@ -22,7 +22,7 @@
 
 
 .grid-item {
 .grid-item {
   border: none;
   border: none;
-  background-color: #ddd;
+  background-color: #fff;
   text-align: center;
   text-align: center;
 }
 }
 
 

+ 50 - 29
template/js/ui.js

@@ -16,7 +16,6 @@ function doOverlap(l1x, l1y, r1x, r1y, l2x, l2y, r2x, r2y) {
 
 
 
 
 function makeFrame(lx, ly, rx, ry, content = "", id = "", showbutton=false) {
 function makeFrame(lx, ly, rx, ry, content = "", id = "", showbutton=false) {
-  
   //check if rects overlap if they do remove old ones
   //check if rects overlap if they do remove old ones
   for (i = 0; i < window.storage.length; i++) {
   for (i = 0; i < window.storage.length; i++) {
     if(doOverlap(window.storage[i].lx, window.storage[i].ly, window.storage[i].rx, window.storage[i].ry, lx, ly, rx, ry)){
     if(doOverlap(window.storage[i].lx, window.storage[i].ly, window.storage[i].rx, window.storage[i].ry, lx, ly, rx, ry)){
@@ -30,8 +29,6 @@ function makeFrame(lx, ly, rx, ry, content = "", id = "", showbutton=false) {
   //add new ellement to storage
   //add new ellement to storage
   window.storage.push({lx:lx, ly:ly, rx:rx, ry: ry})
   window.storage.push({lx:lx, ly:ly, rx:rx, ry: ry})
   
   
-  
-  
   const container = document.getElementById("container");
   const container = document.getElementById("container");
   let cell = document.createElement("div");
   let cell = document.createElement("div");
   cell.classList.add("grid-item");
   cell.classList.add("grid-item");
@@ -53,60 +50,55 @@ function makeFrame(lx, ly, rx, ry, content = "", id = "", showbutton=false) {
   jQuery.cssNumber.gridRowStart = true;
   jQuery.cssNumber.gridRowStart = true;
   jQuery.cssNumber.gridRowEnd = true;
   jQuery.cssNumber.gridRowEnd = true;
   
   
-  $(cell).css({"display": "block", "border-style": "solid", "border-color": "blue", "grid-column": (lx+1) + spancol,  "grid-row": ly+1 + spanrow});
-  
+  $(cell).css({"grid-column": (lx+1) + spancol,  "grid-row": ly+1 + spanrow});
   
   
   container.appendChild(cell);
   container.appendChild(cell);
-    
   //Create new element with width, heigth and content
   //Create new element with width, heigth and content
   //$(".item" + lx + "-" + ly).css({"display": "block", "border-style": "solid", "border-color": "blue", "grid-column": (lx+1) + " / span " + (rx-lx+1),  "grid-row": ly+1 + " / span " + (ry-ly+1)});
   //$(".item" + lx + "-" + ly).css({"display": "block", "border-style": "solid", "border-color": "blue", "grid-column": (lx+1) + " / span " + (rx-lx+1),  "grid-row": ly+1 + " / span " + (ry-ly+1)});
   
   
   if(content != null && content != ""){
   if(content != null && content != ""){
-    $(".item" + lx + "-" + ly).html("<iframe width=100% height=100% name='" + id +"' id='" + id +"' src='" + content + "' title=''></iframe>");
+    $(".item" + lx + "-" + ly).html("<iframe width=100% height=100% name='" + id +"' id='" + id +"' src='" + content + "' title='' frameBorder='0' ></iframe>");
             
             
-    if(showbutton && content.startsWith("https://centurio.work/out/forms")){
-      $(".item" + lx + "-" + ly).append('<button class="formbutton" type="button" onclick="sendForm(\'' + '.item' + lx + '-' + ly +'\', \'' + encodeURIComponent(id) + '\', \'' + lx  + '\', \'' + ly  + '\')">Send Form</button>')    
+    if(showbutton){
+      $(".item" + lx + "-" + ly).append('<button class="formbutton" type="button" onclick="sendForm(\'' + '.item' + lx + '-' + ly +'\', \'' + encodeURIComponent(id) + '\', \'' + lx  + '\', \'' + ly  + '\')">Submit</button>')
     }
     }
     
     
     //hideRectangel(lx, ly, rx, ry)
     //hideRectangel(lx, ly, rx, ry)
   }
   }
   else{
   else{
     $(".item" + lx + "-" + ly).html("No language available.<br> Nicht in der Sprache verfügbar.");
     $(".item" + lx + "-" + ly).html("No language available.<br> Nicht in der Sprache verfügbar.");
-    //hideRectangel(lx, ly, rx, ry)
   }
   }
   
   
 }
 }
 
 
-function getFormData($form){
-    var unindexed_array = $form.serializeArray();
-    var indexed_array = {};
-
-    $.map(unindexed_array, function(n, i){
-        indexed_array[n['name']] = n['value'];
-    });
-
-    return indexed_array;
-}
-
-
-
 function sendForm(menuitem, cpeecallback,lx,ly){
 function sendForm(menuitem, cpeecallback,lx,ly){
-  //Call iframe function that button has been pressed iframe decides what to do
+  //Call iframe function that button has been pressed iframe should send json back
   //document.getElementById(decodeURIComponent(cpeecallback)).contentWindow.buttonPressed(cpeecallback);
   //document.getElementById(decodeURIComponent(cpeecallback)).contentWindow.buttonPressed(cpeecallback);
   
   
+  
+  var formdata;
+ if (typeof document.getElementById(decodeURIComponent(cpeecallback)).contentWindow.buttonPressed !== 'undefined' && $.isFunction(document.getElementById(decodeURIComponent(cpeecallback)).contentWindow.buttonPressed)) {
+    var formdata = document.getElementById(decodeURIComponent(cpeecallback)).contentWindow.buttonPressed();
+  }
+
+
+  
   $.ajax({
   $.ajax({
     type: "PUT",
     type: "PUT",
     url: decodeURIComponent(cpeecallback),
     url: decodeURIComponent(cpeecallback),
     contentType: "application/json",
     contentType: "application/json",
-    data: document.getElementById(decodeURIComponent(cpeecallback)).contentWindow.buttonPressed(),
+    data: JSON.stringify(formdata),
     success: function (data) {
     success: function (data) {
     }
     }
   });
   });
   
   
   
   
-  //close form
+  
+  
+  //Its a design question if removing the frame should be done within centurio, do have more controll, or automatic within code?
+  //close frame
   $(menuitem).remove();
   $(menuitem).remove();
-  //remove form from Server
+  //remove frame from Server
   $.ajax({
   $.ajax({
     type: "Post",
     type: "Post",
     url: "",
     url: "",
@@ -117,6 +109,37 @@ function sendForm(menuitem, cpeecallback,lx,ly){
   });
   });
 }
 }
 
 
+function sendData(dataelement, datavalue){
+  
+  $.ajax({
+    type: "Get",
+    url: 'cpeeinstance.url',
+    success: function(ret) {
+      $.ajax({
+        type: "Put",
+        url: ret + "/properties/dataelements/" + dataelement,
+        data: {value: datavalue},
+        success: function (data) {     
+          alert("Data Sent")
+        }
+      });
+    }
+  });
+  
+}
+
+function sendCallback(callbackUrl, jsonToSend){
+  
+  $.ajax({
+    type: "PUT",
+    url: callbackUrl,
+    contentType: "application/json",
+    data: jsonToSend,
+    success: function (data) {
+      
+    }
+  });
+}
 
 
 function showDocument() {
 function showDocument() {
   
   
@@ -271,8 +294,6 @@ function init() {
         catch (e) {
         catch (e) {
         }
         }
       }
       }
-      
-        
     }
     }
   };
   };
   es.onerror = function() {
   es.onerror = function() {

+ 0 - 25
template/template.html

@@ -55,30 +55,5 @@
   <body is="x-ui">
   <body is="x-ui">
     <div id="container">
     <div id="container">
     </div>
     </div>
-<!--
-    <div id="languages" class="hidden"></div>
-
-    <div id="nav" class="hidden">
-      <template>
-        <span class="item"/>
-      </template>
-    </div>
-
-    <div id="content">
-      <div id="nope">
-        <div onclick="document.location.reload()">🚫</div>
-        <div id="reason"></div>
-      </div>
-      <template>
-        <div/>
-      </template>
-    </div>
-
-    <div id="control">
-      <template>
-        <div><button name="" class="center"/></div>
-      </template>
-    </div>
--->
   </body>
   </body>
 </html>
 </html>