added Validation support
authorunknown <p1@.(none)>
Wed, 13 May 2009 22:52:53 +0000 (00:52 +0200)
committerunknown <p1@.(none)>
Wed, 13 May 2009 22:52:53 +0000 (00:52 +0200)
src/validate.exe [new file with mode: 0644]
web/cgi/validate.exe [new file with mode: 0644]
web/cgi/validateTest.php [new file with mode: 0644]
web/js/communication.js
web/php/communication.php
web/php/page/createplant.pg

diff --git a/src/validate.exe b/src/validate.exe
new file mode 100644 (file)
index 0000000..876f2c4
Binary files /dev/null and b/src/validate.exe differ
diff --git a/web/cgi/validate.exe b/web/cgi/validate.exe
new file mode 100644 (file)
index 0000000..876f2c4
Binary files /dev/null and b/web/cgi/validate.exe differ
diff --git a/web/cgi/validateTest.php b/web/cgi/validateTest.php
new file mode 100644 (file)
index 0000000..74ebae7
--- /dev/null
@@ -0,0 +1,52 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+
+<html>
+       <head>
+               <title>ValidateTest</title>
+               
+               <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+       </head>
+       <body>
+
+<?php 
+       function ValidateRuleSet($ruleset) {
+               $result = "{valid: false, line: 0, column: 0, msg: 'Internal Server Error'}";
+               
+               $descriptorspec = array(
+                  0 => array("pipe", "r"),  // STDIN ist eine Pipe, von der das Child liest
+                  1 => array("pipe", "w"),  // STDOUT ist eine Pipe, in die das Child schreibt
+                  2 => array("pipe", "w")   // STDERR
+               );
+
+               $cwd = realpath(".");
+
+
+               $process = proc_open('validate.exe', $descriptorspec, $pipes, $cwd, array());
+
+               if (is_resource($process)) {
+                       // $pipes sieht nun so aus:
+                       // 0 => Schreibhandle, das auf das Child STDIN verbunden ist
+                       // 1 => Lesehandle, das auf das Child STDOUT verbunden ist
+                       // Jedwede Fehlerausgaben werden an /tmp/error-output.txt angefügt
+
+                       fwrite($pipes[0], $ruleset);
+                       fclose($pipes[0]);
+
+                       $result = stream_get_contents($pipes[1]);
+                       fclose($pipes[1]);
+
+                       //echo stream_get_contents($pipes[2]);
+                       fclose($pipes[2]);
+
+                       $return_value = proc_close($process);
+               }
+               
+               return $result;
+       }
+       
+       echo ValidateRuleSet("RyULE MyRule GROW BY 1");
+
+?>
+       </body>
+</html>
\ No newline at end of file
index 27f7504..584be1f 100644 (file)
@@ -462,6 +462,7 @@ Lseed.Communication = function() {
                
                this.AddCallback("SavePlant", editor.SaveCallback.createDelegate(editor));
                this.AddCallback("DeletePlant", editor.DeleteCallback.createDelegate(editor));
+               this.AddCallback("ValidatePlant", editor.CheckSyntaxCallback.createDelegate(editor));
                
                this.sendMessage(Lseed.MessageCommands.RPC, {func: 'IsLoggedIn'});
        };
@@ -498,11 +499,26 @@ Lseed.Editor = function() {
        this.TestCallback = function() {
        };
        
+       this.CheckSyntaxCallback = null;
        this.CheckSyntax = function(plant, callback) {
-               communication.showMessage("Diese Funktion ist leider momentan nicht verfügbar", "error");
+               this.CheckSyntaxCallback = callback;
+               
+               communication.sendMessage(Lseed.MessageCommands.RPC, { 
+                       func: 'ValidatePlant'
+                       ,code: plant.data.Code
+               });
        };
        
-       this.CheckSyntaxCallback = function() {
+       this.CheckSyntaxCallback = function(data) {
+               if (!data.valid) {
+                       if (this.CheckSyntaxCallback != null) {
+                               this.CheckSyntaxCallback(data);
+                       } else {
+                               console.error("Lseed.Editor.CheckSyntaxCallback: no Callback given.");
+                       }
+               } else {
+                       console.info("Syntax is Valid.");
+               }
        };
        
        this.Delete = function(plant) {
@@ -518,6 +534,22 @@ Lseed.Editor = function() {
                }
                communication.GetPlantList();
        };
+       
+       this.GetStartFromField = function(field, row, column) {
+               var result = 0;
+               var content = field.getValue();
+               var lines = content.split("\n");
+               if (lines.length >= row) {
+                       for (var i=0; i<row; i++) {
+                               result += lines[i].length + 1;
+                       }
+               }
+               result += column;
+               
+               console.info("error in row: " + row + " column: " + column + " at: " + result);
+               
+               return result;
+       };
 };
 
 Lseed.Plant = Ext.data.Record.create([{
index e367d00..381341d 100644 (file)
                return $result;
        }
        
-       function DeletePlant($id) {
-               $result = "{ success: false }";
-
+       function GetPlantById($id) {
+               $result = null;
+               
                $userid = GetUser($_SESSION['user'])->ID;
                $list = GetPlantsForUser($userid);
-               
-               $plantToBeDeleted = null;
+
                foreach ($list as $plant) {
                        if ($plant->ID == $id) {
-                               $plantToBeDeleted = $plant;
+                               $result = $plant;
                                break;
                        }
                }
+               
+               return $result;
+       }
+       
+       function DeletePlant($id) {
+               $result = "{ success: false }";
+
+               $plantToBeDeleted = GetPlantById($id);
                if ($plantToBeDeleted != null) {
                        if (DropPlant($plantToBeDeleted)) {
                                $result = "{ success: true }";
 
                return $result;
        }
+       
+       function ValidatePlant($id) {
+               $plantToBeValidated = GetPlantById($id);
+               
+               return ValidatePlantCode($plantToBeValidated->Code);
+       }
+       
+       function ValidatePlantCode($code) {
+               $result = "{valid: false, line: 0, column: 0, msg: 'Internal Server Error'}";
+               
+               $descriptorspec = array(
+                  0 => array("pipe", "r"),  // STDIN ist eine Pipe, von der das Child liest
+                  1 => array("pipe", "w"),  // STDOUT ist eine Pipe, in die das Child schreibt
+                  2 => array("pipe", "w")   // STDERR
+               );
+
+               $cwd = realpath("..\\cgi");
+
+
+               $process = proc_open('validate.exe', $descriptorspec, $pipes, $cwd, array());
+
+               if (is_resource($process)) {
+                       // $pipes sieht nun so aus:
+                       // 0 => Schreibhandle, das auf das Child STDIN verbunden ist
+                       // 1 => Lesehandle, das auf das Child STDOUT verbunden ist
+                       // Jedwede Fehlerausgaben werden an /tmp/error-output.txt angefügt
+
+                       fwrite($pipes[0], $code);
+                       fclose($pipes[0]);
+
+                       $output = stream_get_contents($pipes[1]);
+                       fclose($pipes[1]);
+
+                       //echo stream_get_contents($pipes[2]);
+                       fclose($pipes[2]);
+
+                       $return_value = proc_close($process);
+                       
+                       //echo $return_value;
+                       if ($return_value == 0) {
+                               $result = $output;
+                       }
+               }
+
+               return $result;
+       }
 
        //Communication
 
 
                                case "TestPlant":
                                        break;
+
+                               case "ValidatePlant":
+                                       $res = null;
+                                       if (isset($_POST["id"])) {
+                                               $res = ValidatePlant($_POST["id"]);
+                                       } else {
+                                               $res = ValidatePlantCode($_POST["code"]);
+                                       }
+                                       RPCAnswer($_POST["func"], $res);
+                                       break;
                        }
                        break;
 
index 8e29d8c..db528de 100644 (file)
                text: "CheckSyntax"
                ,icon: 'img/icons/accept.png'
                ,cls: 'x-btn-text-icon'
-               ,handler: editor.CheckSyntax.createDelegate(editor)
+               ,handler: function() { 
+                       var pdEditor = Ext.getCmp("plantdefinitioneditor");
+                       if (pdEditor) {
+                               var code = pdEditor.getValue();
+                               editor.CheckSyntax({data:{Code:code}}, function(data) {
+                                       var pdEditor = Ext.getCmp("plantdefinitioneditor");
+                                       if (pdEditor) {
+                                               //TODO: mark error in code
+                                               
+                                               Ext.MessageBox.show({
+                                                       title:'Fehler'
+                                                       ,msg: data.msg
+                                                       ,buttons: Ext.Msg.OK
+                                                       ,fn: function() {
+                                                               var index = editor.GetStartFromField(pdEditor, data.line-1, data.column);
+                                                               if (index != -1) {
+                                                                       pdEditor.selectText(index-1, index);
+                                                               }
+                                                       }
+                                                       ,icon: Ext.MessageBox.ERROR
+                                               });
+                                       } else {
+                                               console.error("Lseed.Editor.CheckSyntaxCallback_Callback: 'plantdefinitioneditor' Could not be found.");
+                                       }
+                               }); 
+                       } else {
+                               console.error("Lseed.Editor.CheckSyntaxCallback_Callback: 'plantdefinitioneditor' Could not be found.");
+                       }
+               }.createDelegate(editor)
        }]
        ,items: [{
                id: "plantdefinitionnamefield"
@@ -48,7 +76,6 @@
                ,anchor:'100%'
                ,enableKeyEvents: true
                ,listeners: {
-                       keyup: editor.NameChanged.createDelegate(editor)
                }
        },{
                id: "plantdefinitioneditor"
@@ -58,7 +85,6 @@
                ,anchor:'100% -50'
                ,enableKeyEvents: true
                ,listeners: {
-                       keyup: editor.DefinitionChanged.createDelegate(editor)
                }
                ,value: 'RULE "MyRule"\nGROW BY 1'
        }]