add saving and reloading layout data

This commit is contained in:
Uwe Steinmann 2016-08-31 11:54:51 +02:00
parent 84a65f0f32
commit bdd0dd6582
2 changed files with 40 additions and 25 deletions

View File

@ -152,6 +152,8 @@ else if ($action == "setrenderdata") {
$data = $_POST["data"];
$workflow->setLayoutData($data);
header('Content-Type: application/json');
echo json_encode(array('success'=>true, 'message'=>getMLText("workflow_layoutdata_saved")));
exit;

View File

@ -35,7 +35,16 @@ class SeedDMS_View_WorkflowGraph extends SeedDMS_Bootstrap_Style {
$this->workflow = $this->params['workflow'];
header('Content-Type: application/javascript; charset=UTF-8');
$renderdata = '';
$renderdata = $this->workflow->getLayoutData();
if($renderdata) {
$positions = array();
$data = json_decode($renderdata);
foreach($data->nodes as $node) {
if($node->group == 'nodes') {
$positions[$node->data->id] = $node->position;
}
}
}
?>
var cy = cytoscape({
container: document.getElementById('canvas'),
@ -106,7 +115,7 @@ var cy = cytoscape({
'curve-style': 'bezier'
}
}]
<?php if($renderdata) echo ",".$renderdata; ?>
<?php //if($renderdata) echo ",elements: ".$renderdata; ?>
}
);
@ -139,11 +148,9 @@ cy.on('free', 'node', function(evt) {
$('#png').attr('src', cy.png({'full': true}));
});
<?php
if(!$renderdata)
$this->printGraph();
$this->printGraph($positions);
?>
cy.layout({ name: '<?php echo $renderdata ? 'preset' : 'cose'; ?>', condense: true, ready: function() {$('#png').attr('src', cy.png({'full': true}))} });
// $('#png').attr('src', cy.png({'full': true}));
cy.layout({ name: '<?php echo $renderdata ? 'preset' : 'cose'; ?>', ready: function() {$('#png').attr('src', cy.png({'full': true}))} });
$(document).ready(function() {
$('body').on('click', '#savelayout', function(ev){
@ -159,7 +166,7 @@ $(document).ready(function() {
<?php
} /* }}} */
function printGraph() { /* {{{ */
function printGraph($positions) { /* {{{ */
$transitions = $this->workflow->getTransitions();
if($transitions) {
@ -198,13 +205,15 @@ $(document).ready(function() {
foreach($transgroups as $transgroup) {
$gnames[] = $transgroup->getGroup()->getName();
}
$nodeid = "A".$transition->getID()."-".$action->getID();
echo "cy.add({
data: {
id: 'A".$transition->getID()."-".$action->getID()."',
name: \"".str_replace('"', "\\\"", $action->getName()).($unames ? "\\n(".str_replace('"', "\\\"", implode(", ", $unames)).")" : '').($gnames ? "\\n(".str_replace('"', "\\\"", implode(", ", $gnames)).")" : '')."\"
},
classes: 'action'
});\n";
data: {
id: '".$nodeid."',
name: \"".str_replace('"', "\\\"", $action->getName()).($unames ? "\\n(".str_replace('"', "\\\"", implode(", ", $unames)).")" : '').($gnames ? "\\n(".str_replace('"', "\\\"", implode(", ", $gnames)).")" : '')."\"
},".(isset($positions[$nodeid]) ? "
position: {x: ".$positions[$nodeid]->x.", y: ".$positions[$nodeid]->y."}," : "")."
classes: 'action'
});\n";
}
if(!isset($this->states[$state->getID()])) {
@ -212,24 +221,28 @@ $(document).ready(function() {
$initstate = '';
if($state == $this->workflow->getInitState())
$initstate = getMLText('workflow_initstate');
$nodeid = "S".$state->getID();
echo "cy.add({
data: {
id: 'S".$state->getID()."',
name: \"".str_replace('"', "\\\"", $state->getName()."\\n".$initstate)."\"
},
classes: 'state ".($state == $this->workflow->getInitState() ? 'init' : '')."'
});\n";
data: {
id: '".$nodeid."',
name: \"".str_replace('"', "\\\"", $state->getName()."\\n".$initstate)."\"
},".(isset($positions[$nodeid]) ? "
position: {x: ".$positions[$nodeid]->x.", y: ".$positions[$nodeid]->y."}," : "")."
classes: 'state ".($state == $this->workflow->getInitState() ? 'init' : '')."'
});\n";
}
if(!isset($this->states[$nextstate->getID()])) {
$this->states[$nextstate->getID()] = $nextstate;
$docstatus = $nextstate->getDocumentStatus();
$nodeid = "S".$nextstate->getID();
echo "cy.add({
data: {
id: 'S".$nextstate->getID()."',
name: '".str_replace('"', "\\\"", $nextstate->getName())/*.($docstatus == S_RELEASED || $docstatus == S_REJECTED ? "\\n(".getOverallStatusText($docstatus).")" : '')*/."'
},
classes: 'state".($docstatus == S_RELEASED ? ' released' : ($docstatus == S_REJECTED ? ' rejected' : ''))."'
});\n";
data: {
id: '".$nodeid."',
name: '".str_replace('"', "\\\"", $nextstate->getName())/*.($docstatus == S_RELEASED || $docstatus == S_REJECTED ? "\\n(".getOverallStatusText($docstatus).")" : '')*/."'
},".(isset($positions[$nodeid]) ? "
position: {x: ".$positions[$nodeid]->x.", y: ".$positions[$nodeid]->y."}," : "")."
classes: 'state".($docstatus == S_RELEASED ? ' released' : ($docstatus == S_REJECTED ? ' rejected' : ''))."'
});\n";
}
}