Changeset 166 for Dev


Ignore:
Timestamp:
11/23/11 17:15:20 (13 years ago)
Author:
fpvanagthoven
Message:

Jos, nevermind. Mijn fout, ik heb die creator[0] in SessionConnector:117 weer teruggezet.

  • ToolBox?.php is overgezet naar javascript werking.
  • updateSequencer() werkt.
  • updateDividers() werkt.
  • t_setOutOfDate is in principe niet meer nodig, maar handig voor test purposes. Deze flagget de geselecteerde object voor een refresh.
  • saveSession() werkt! De pipeline editor is nu dus daadwerkelijk bruikbaar! [move/delete/clear/edit nog niet!]
  • Verkeerde calling code voor session->creator aangepast, login systeem werkt nu goed.
  • createObject.php werkt!
Location:
Dev/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • Dev/trunk/classes/pipelineSequencer.php

    r164 r166  
    11<?php
    2 
    32/*
    43 * To change this template, choose Tools | Templates
     
    2726        $stringPipelineUpdated = "";
    2827        $numberOfSteps = 0;
    29        
     28
    3029        if (is_array($this->loadedSession->pipeline)) {
    3130            foreach ($this->loadedSession->pipeline as $object) {
    3231                $stringPipeline .= "$object->uid,";
    33                 $stringPipelineType .= get_class($object).",";
     32                $stringPipelineType .= get_class($object) . ",";
    3433                $stringPipelineUpdated .= "1,";
    3534                $numberOfSteps++;
    36                
    3735            }
    38             $stringPipeline = rtrim($stringPipeline, ",");
    39             $stringPipelineType = rtrim($stringPipelineType, ",");
    40             $stringPipelineUpdated = rtrim($stringPipelineUpdated, ",");
    41            
    4236        } else {
    4337            $stringPipeline = $this->loadedSession->pipeline;
     
    6963                    <input type="hidden" name="pipelineUpDated" id="pipelineUpdatedField" value="<?php echo $stringPipelineUpdated; ?>" />
    7064                    <input type="hidden" name="numSteps" id="numSteps" value="<?php echo $numberOfSteps; ?>" />
     65                    <input type="hidden" name="session" id="sessionField" value="<?php echo $this->loadedSession->uid; ?>" />
    7166                </div>
    7267            </fieldset>
     
    108103        if (isset($_SESSION['updateNeeded'])) {    // user has performed an operation that flags session to be reloaded from DB, or is first load of page for that session
    109104            $sessionResults = $this->dbi->get("Session", array("uid" => $currentSession));
    110            
     105
    111106            if (count($sessionResults) > 0) {
    112107                $_SESSION['localSessionCopy'] = $sessionResults[0];
     
    116111            }
    117112        }
    118             //var_dump($_SESSION['localSessionCopy']);   
    119        
     113
    120114        if (isset($_SESSION['localSessionCopy']) && !empty($_SESSION['localSessionCopy'])) {
    121            
     115
    122116            $this->loadedSession = $_SESSION['localSessionCopy'];
    123117            unset($_SESSION['updateNeeded']);
    124118        }
    125        
    126119    }
    127120
     
    180173    }
    181174
    182 
    183175}
    184176?>
  • Dev/trunk/createObject.php

    r165 r166  
    88    }
    99    else {
    10         die ("Invalid arguments passed!");
     10        //die ("Invalid arguments passed!");
    1111    }
    1212}
    1313else {
    14     die ("No arguments passed!");
     14    //die ("No arguments passed!");
    1515}
    1616
     
    2121}
    2222else {
    23     die ("Invalid creator, make sure you are logged in!");
     23    //die ("Invalid creator, make sur0e you are logged in!");
    2424}
    2525
     
    4040        break;
    4141    default:
    42         die ("Variable \$otc: $otc does not match a compatible object type!");
     42        //die ("Variable \$otc: $otc does not match a compatible object type!");
    4343        break;
    4444}
  • Dev/trunk/js/sequencerScripts.js

    r165 r166  
    2525}
    2626
    27 /*
    28 function SubmitToolbox() {
    29     document.forms['toolbox'].submit();
    30 }
    31 */
     27function removeNL(s){
     28    return s.replace(/[\n\r\t]/g,"");
     29}
     30
    3231function SubmitToolbox(type) {
    3332    var c = "objectToCreate="+type;
     
    3938   
    4039    newAjaxRequest(c, u, function(result){
    41         var resultUid = result.responseText;
    42         console.log(resultUid);
    43         console.log("lol");
    44         console.log(resultUid);
    45         pipeline.value += ","+resultUid;
    46         pipelineType += ","+type;
    47         pipelineUpdated += ",0";
     40        var resultUid = removeNL(result.responseText);
     41        //resultUid.replace("\n","").replace("\r","");
     42       
     43        pipeline.value += resultUid+",";
     44        pipelineType.value += type+",";
     45        pipelineUpdated.value += "0,";
    4846        updateSequencer();
    4947    }, a);
     
    7472    var nodes = document.getElementById("seqContent").childNodes;
    7573    for (var i = 0; i < nodes.length; i++) {     //loop through childNodes. Skip first node (whitespace)
    76         //debugger;
    7774        if (hasClass(nodes[i], "displayStep")) {    //check if current childNode is a displayStep, not divider or text.
    7875            if (nodes[i].id == uid) {
     
    9693}
    9794                                                                           
    98                                                                            
    99 /*
    100  * This function allows for simple use of AJAX requests.
    101  * Calling format:
    102  *
    103  * var c[] = "uid=123";
    104  *  var c[] = "name=tschipper";
    105  *  var u = "getResult.php";
    106  *  newAjaxRequest(c, u, function(xml) {
    107  *      <!--Do something-->
    108  *  });
    109  * 
    110  *  It is of course also possible to refer to an external function instead of
    111  *  defining function(xml){} in the call itself, as below:
    112  * 
    113  *  newAjaxRequest(c, u, externalFunction(xml));
    114  */
    115 
    11695function newAjaxRequest(c, u, cb, async) {
    11796   
     
    145124        }
    146125    }
    147     else {                      // single parameter or string already formatted by calling function
     126    else { // single parameter or string already formatted by calling function
    148127        contentString = content;
    149128    }
    150129    // finally send the formatted request
    151     //alert(contentString);
    152130    xml.send(contentString);
    153131}
     
    183161    var pipeline = document.getElementById("pipelineStringField").value;
    184162    var pipelineTypes = document.getElementById("pipelineTypeField").value;
    185     pipeline = pipeline.replace(/,/g , ",divider,");    //regex search for commas, global (repeat), to represent them with visual dividers.
    186     pipelineTypes = pipelineTypes.replace(/,/g, ",divider,");
    187     ajaxStepRequest(pipeline, pipelineTypes);
     163    var numSteps = document.getElementById("numSteps").value;
     164    if (numSteps > 0) {
     165        pipeline = pipeline.replace(/,/g , ",divider,");    //regex search for commas, global (repeat), to represent them with visual dividers.
     166        pipelineTypes = pipelineTypes.replace(/,/g, ",divider,");
     167        ajaxStepRequest(pipeline, pipelineTypes);
     168    }
    188169}
    189170
     
    192173    var plTypeString = document.getElementById("pipelineTypeField").value;
    193174    var plUpdatedString = document.getElementById("pipelineUpdatedField").value;
    194        
    195     var pl = plString.split(",");
    196     var plType = plTypeString.split(",");
    197     var plUpdated = plUpdatedString.split(",");
    198     //console.log(plUpdated);
    199    
     175   
     176   
     177    var pl = stringToArray(plString, ",");   
     178    var plType = stringToArray(plTypeString, ",");   
     179    var plUpdated = stringToArray(plUpdatedString, ",");
     180   
     181    var count = pl.length;
     182   
     183    document.getElementById("numSteps").value = count;
    200184   
    201185    for (var i = 0; i < pl.length; i++) {   // loop through pipeline contents
     
    204188            var seqContent = document.getElementById("seqContent");
    205189            var element = document.getElementById(pl[i]);
    206             var nextElement = element.nextSibling;
     190            if (element == null) {
     191                element = document.createElement("div");
     192                element.name = "placeholder";
     193                seqContent.appendChild(element);
     194            }
     195            if (element.nextSibling) {
     196                var nextElement = element.nextSibling;
     197            }
     198            else {
     199                var nextElement = document.createElement("div");
     200                nextElement.name = "placeholderNext";
     201                seqContent.appendChild(nextElement);
     202            }
    207203           
    208204            // now request a new step representation and insert it after previousElement
    209205            var holderDiv = document.createElement("div");
    210206            var requestString = "uids="+pl[i];
    211             var resultText;
     207           
     208            if (plType[i]) {
     209                requestString += "&types="+plType[i];
     210            }
     211            // globally declare newDiv so it can be passed to the updateDividers function
     212            var newDiv;
     213           
    212214            newAjaxRequest(requestString, "returnStep.php", function(result) {
    213                 holderDiv.innerHTML = result.responseText;
     215                holderDiv.innerHTML = result.responseText;
     216                newDiv = holderDiv.childNodes[1];           
     217                seqContent.replaceChild(newDiv, element);
     218                if (nextElement.name == "placeholderNext") {
     219                    seqContent.removeChild(nextElement);
     220                }
     221                plUpdated[i] = "1";
    214222            }, false);
    215223           
    216             //debugger;
    217             while (holderDiv.childNodes.length == 1) {
    218             // wait for response
    219             }
    220             var newDiv = holderDiv.childNodes[1];
    221             seqContent.replaceChild(newDiv, element);
    222             plUpdated[i] = "1";
    223         // ALTERNATIVE METHOD TO REPLACECHILD!!!
    224         //seqContent.removeChild(element);
    225         //seqContent.insertBefore(newDiv, nextElement);
    226            
    227            
    228         }
    229         else {
    230            
    231     }
    232     }
    233    
    234     // afterwards, convert the arrays back to strings
    235     var newUpdatedString = "";
    236    
    237     for (var i = 0; i < plUpdated.length; i++) {
    238         newUpdatedString += plUpdated[i]+",";
    239     }
    240    
    241     if (newUpdatedString.substring(newUpdatedString.length - 1) == ",") {   // remove comma at the end of string!
    242         newUpdatedString = newUpdatedString.substring(0, newUpdatedString.length-1);
    243        
    244     }
     224                       
     225            // ALTERNATIVE METHOD TO REPLACECHILD!!!
     226            //seqContent.removeChild(element);
     227            //seqContent.insertBefore(newDiv, nextElement);
     228           
     229            // Now check if dividers are necessary.
     230           
     231            //alert("INSERT CODE FOR UPDATEDIVIDERS HERE!");
     232            updateDividers(newDiv);
     233        }
     234    }
     235   
     236    // afterwards, convert the arrays back to strings and set to appropriate fields
     237    var newUpdatedString = arrayToString(plUpdated, ",");
    245238    document.getElementById("pipelineUpdatedField").value = newUpdatedString;
    246239   
    247240}
     241
     242
     243
     244
     245
     246
     247function updateDividers (element) {
     248    var seqContent = document.getElementById("seqContent");
     249   
     250    if (element.nextSibling){
     251        var nextElement = element.nextSibling;
     252    }
     253    if (element.previousSibling) {
     254        var previousElement = element.previousSibling;
     255    }
     256   
     257    if (nextElement){
     258        if (!hasClass(nextElement, "divider")) {
     259            var holderDiv = document.createElement("div");
     260            newAjaxRequest("uids=divider&types=divider", "returnStep.php", function(result) {
     261                holderDiv.innerHTML = result.responseText;
     262                var newDivider = holderDiv.childNodes[1];
     263                seqContent.insertBefore(newDivider, nextElement);
     264            }, false);
     265        }
     266    }
     267   
     268    if (previousElement){
     269        if (!hasClass(previousElement, "divider")) {
     270            var holderDiv = document.createElement("div");
     271            newAjaxRequest("uids=divider&types=divider", "returnStep.php", function(result) {
     272                holderDiv.innerHTML = result.responseText;
     273                var newDivider = holderDiv.childNodes[1];
     274                seqContent.insertBefore(newDivider, element);
     275            }, false);
     276        }
     277    }
     278   
     279}
     280
     281
     282
     283
     284
    248285
    249286function savePipeline() {
    250287    var answer = confirm("Save changes to pipeline?");
    251288    if (answer) {
    252         newAjaxRequest("", "savesession.php", function(){}, false);
    253         alert("Saved!");
     289        var pipeline = document.getElementById("pipelineStringField").value;
     290        pipeline = pipeline.slice(0, pipeline.length - 1);
     291        var types = document.getElementById("pipelineTypeField").value;
     292        types = types.slice(0, types.length - 1);
     293        var session = document.getElementById("sessionField").value;
     294        var requestString = "uids="+pipeline+"&types="+types+"&sessionUid="+session;
     295        //console.log(requestString);
     296       
     297       
     298        var success;
     299        newAjaxRequest(requestString, "savesession.php", function(result){
     300            success = result.responseText;
     301        }, false);
     302        console.log(success);
    254303    }
    255304}
     
    268317    var plUpdatedString = document.getElementById("pipelineUpdatedField").value;
    269318   
    270     var pl = plString.split(",");
    271     var plType = plTypeString.split(",");
    272     var plUpdated = plUpdatedString.split(",");
    273    
    274    
     319   
     320    var pl = stringToArray(plString, ",");   
     321    var plType = stringToArray(plTypeString, ",");   
     322    var plUpdated = stringToArray(plUpdatedString, ",");   
    275323   
    276324    // set the targeted element's tag for "Needs updating"
    277     for (var i = 0; i < pl.length; i++) {
    278         if (pl[i] == uid) {
    279             plUpdated[i] = 0;
    280         }
    281     }
     325    plUpdated[pl.indexOf(uid)] = "0";
    282326   
    283327    // then rewrite the content strings and set them to the appropriate fields
    284    
    285     var newUpdatedString = "";
    286     for (var i = 0; i < pl.length; i++) {
    287         newUpdatedString += plUpdated[i]+",";
    288     }
    289     if (newUpdatedString.substring(newUpdatedString.length-1) == ",") {
    290         newUpdatedString = newUpdatedString.substring(0, newUpdatedString.length-1);
    291     }
    292    
    293    
     328    var newUpdatedString = arrayToString(plUpdated, ",");
    294329    document.getElementById("pipelineUpdatedField").value = newUpdatedString;
    295 //alert("OOD set");
    296 }
     330}
     331
     332function stringToArray(s, c) {
     333    var a = s.split(c);
     334    for (var i = 0; i < a.length; i++) {    // remove empty items
     335        if (a[i] == "") {
     336            a.splice(i, 1);
     337            i--;
     338        }
     339    }
     340    return a;
     341}
     342
     343function arrayToString(a, c) {
     344    var s = "";
     345    for (var i = 0; i < a.length; i++) {
     346        if (a[i] != "") {
     347            s += a[i]+c;
     348        }
     349    }
     350    return s;
     351}
  • Dev/trunk/savesession.php

    r164 r166  
    33require 'classes/master.php'; //should be at top of every page
    44
    5 $session = $_SESSION['localSessionCopy'];
    6 $dbi = new DatabaseInterface();
    7 $dbi->set($session);
     5if (isset($_POST['uids']) && isset($_POST['types']) && isset($_POST['sessionUid'])) {
     6    if (!empty($_POST['uids']) && !empty($_POST['types']) && !empty($_POST['sessionUid'])) {
     7        // user has passed a pipeline/type string from javascript in order to save the session.
     8        $pl = explode(",", $_POST['uids']);
     9        $t = explode(",", $_POST['types']);
    810
    9 redirect('pipelineEditor.php');
     11        $sessionUid = $_POST['sessionUid'];
     12        //var_dump($t);
     13        $dbi = new DatabaseInterface();
     14        $session_results = $dbi->get("Session", array("uid" => $sessionUid));
     15        if (count($session_results) > 0) {
     16            $session = $session_results[0];
     17        } else {
     18            echo "!!!!!!!!!!!!!!!!!!!!!!NO SESSION FOUND!!!!!!!!!!!!!!!!!!!!";
     19            die();
     20        }
     21        if (count($pl) == count($t)) {
     22            $count = count($pl);
     23        } else {
     24            echo "!!!!!!!!!!!!!!!!!NON MATCHING ARGUMENTS PASSED!!!!!!!!!!!!!!!";
     25            die();
     26        }
     27        for ($i = 0; $i < count($pl); $i++) {
     28            $results = $dbi->get($t[$i], array("uid" => $pl[$i]));
     29            if (count($results) > 0) {
     30                $result = $results[0];
     31            }
     32            $session->pipeline[] = $result;
     33        }
     34
     35        $dbi->set($session);
     36        echo "true";
     37    }
     38}
    1039?>
  • Dev/trunk/selectSession.php

    r163 r166  
    2222                // make new session!
    2323                unset($matching);
    24                 $session = new Session(null, $_POST['newSessionName'], $_SESSION['username'], new DateTime(), null, null);
     24                $creators = $dbi->get("User", array("username"=>$_SESSION['username']));
     25                $creator = $creators[0];
     26                $session = new Session(null, $_POST['newSessionName'], $creator, new DateTime(), null, null);
    2527                $dbi->set($session);
    2628            } else {
Note: See TracChangeset for help on using the changeset viewer.