Skip to content

Commit

Permalink
Add subgroup UI changes see BT#12861
Browse files Browse the repository at this point in the history
  • Loading branch information
jmontoyaa committed Jun 23, 2017
1 parent 93ae3e1 commit 3bd75b8
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 52 deletions.
3 changes: 3 additions & 0 deletions main/cron/import_csv.php
Expand Up @@ -2407,6 +2407,8 @@ private function importCareersDiagram(
$groupValue = $row['Group'];
$rowValue = $row['Row'];
$arrow = $row['DrawArrowFrom'];
$subGroup = $row['SubGroup'];

if ($graph->hasVertex($currentCourseId)) {
// Avoid double insertion
continue;
Expand All @@ -2418,6 +2420,7 @@ private function importCareersDiagram(
$current->setAttribute('Row', $rowValue);
$current->setAttribute('Group', $groupValue);
$current->setAttribute('DrawArrowFrom', $arrow);
$current->setAttribute('SubGroup', $subGroup);

//$current->setAttribute('graphviz.color', 'blue');
$current->setAttribute('graphviz.shape', 'box');
Expand Down
145 changes: 93 additions & 52 deletions main/inc/lib/career.lib.php
Expand Up @@ -469,8 +469,10 @@ public static function parseColumns($list, $group, $columnList, $maxColumn, $wid
$showGroupLine = false;
}
}

$borderLine = $showGroupLine ? 'border-style:solid;' : '';
$graphHtml = '<div id="'.$groupIdTag.'" style="padding:15px; '.$borderLine.' float:left; margin-left:'.$leftGroup.'; width:'.$widthGroup.'%">';

foreach ($columnList as $column => $rows) {
$leftColumn = ($defaultSpace).'px';
if ($column == 1) {
Expand All @@ -490,54 +492,93 @@ public static function parseColumns($list, $group, $columnList, $maxColumn, $wid
}

$newRowList = [];
$defaultSubGroup = -1;
$subGroupCountList = [];
for ($i = 0; $i < $maxRow; $i++) {
$newRowList[$i+1] = isset($rows[$i+1]) ? $rows[$i+1] : null;
/** @var Vertex $vertex */
$vertex = isset($rows[$i+1]) ? $rows[$i+1] : null;
if (!is_null($vertex)) {
$subGroup = $vertex->getAttribute('SubGroup');
if ($subGroup == '' || empty($subGroup)) {
$defaultSubGroup = 0;
} else {
$defaultSubGroup = (int) $subGroup;
}
}
$newRowList[$i+1][$defaultSubGroup][] = $vertex;
if (!isset($subGroupCountList[$defaultSubGroup])) {
$subGroupCountList[$defaultSubGroup] = 1;
} else {
$subGroupCountList[$defaultSubGroup]++;
}
}

//$graphHtml .= '<div id="'.$groupIdTag.'" style="padding:15px; '.$borderLine.' float:left; margin-left:'.$leftGroup.'; width:'.$widthGroup.'%">';
$subGroup = null;
$subGroupAdded = [];
/** @var Vertex $vertex */
foreach ($newRowList as $row => $vertex) {
if (is_null($vertex)) {
$graphHtml .= '<div class="empty" style="height: 120px">';
$graphHtml .= '</div>';
continue;
}
$id = $vertex->getId();
$rowId = "row_$row";
$top = $topValue*($row-1);
$graphHtml .= '<div id = "row_'.$id.'" class="'.$rowId.'" >';
$color = '';
if ($vertex->getAttribute('HasColor') == 1) {
$color = 'danger';
}
$content = $vertex->getAttribute('Notes');
$content .= '<div class="pull-right">['.$id.']</div>';

$graphHtml .= Display::panel(
$content,
$vertex->getAttribute('graphviz.label'),
null,
$color,
null
);
$graphHtml .= '</div>';

$arrow = $vertex->getAttribute('DrawArrowFrom');

if (!empty($arrow)) {
$parts = explode('G', $arrow);
if (empty($parts[0]) && count($parts) == 2) {
$groupArrow = $parts[1];
$graphHtml .= self::createConnection(
"group_$groupArrow",
"row_$id",
['Left', 'Right']
);
} else {
$graphHtml .= self::createConnection(
"row_$arrow",
"row_$id",
['Left', 'Right']
foreach ($newRowList as $row => $subGroupList) {
foreach ($subGroupList as $subGroup => $vertexList) {
if (!empty($subGroup) && $subGroup != -1) {
if (!isset($subGroupAdded[$subGroup])) {
$subGroupAdded[$subGroup] = 1;
} else {
$subGroupAdded[$subGroup]++;
}
if ($subGroupAdded[$subGroup] == 1) {
$graphHtml .= '<div id="sub_group_'.$subGroup.'" style="margin-bottom:20px; padding:15px; border-style:solid; width:100%">';
}
}

foreach ($vertexList as $vertex) {
if (is_null($vertex)) {
$graphHtml .= '<div class="empty" style="height: 120px">';
$graphHtml .= '</div>';
continue;
}

$id = $vertex->getId();
$rowId = "row_$row";
$top = $topValue * ($row - 1);
$graphHtml .= '<div id = "row_'.$id.'" class="'.$rowId.'" >';
$color = '';
if ($vertex->getAttribute('HasColor') == 1) {
$color = 'danger';
}
$content = $vertex->getAttribute('Notes');
$content .= '<div class="pull-right">['.$id.']</div>';

$graphHtml .= Display::panel(
$content,
$vertex->getAttribute('graphviz.label'),
null,
$color,
null
);
$graphHtml .= '</div>';

$arrow = $vertex->getAttribute('DrawArrowFrom');
if (!empty($arrow)) {
$parts = explode('G', $arrow);
if (empty($parts[0]) && count($parts) == 2) {
$groupArrow = $parts[1];
$graphHtml .= self::createConnection(
"group_$groupArrow",
"row_$id",
['Left', 'Right']
);
} else {
$graphHtml .= self::createConnection(
"row_$arrow",
"row_$id",
['Left', 'Right']
);
}
}
}

if (!empty($subGroup) && $subGroup != -1 && $subGroupCountList[$subGroup] == $subGroupAdded[$subGroup]) {
$graphHtml .= '</div>';
}
}
}
Expand Down Expand Up @@ -583,15 +624,15 @@ public static function createConnection($source, $target, $anchor = [])
$anchor = implode('","', $anchor);
$html = '<script> jsPlumb.ready(function() { ';
$html .= 'jsPlumb.connect({
source:"'.$source.'",
target:"'.$target.'",
endpoint:[ "Rectangle", { width:1, height:1 }],
connector: ["Flowchart"],
anchor: ["'.$anchor.'"],
overlays: [
[ "Arrow", { location:0.5 } ],
],
});';
source:"'.$source.'",
target:"'.$target.'",
endpoint:[ "Rectangle", { width:1, height:1 }],
connector: ["Flowchart"],
anchor: ["'.$anchor.'"],
overlays: [
[ "Arrow", { location:0.5 } ],
],
});';
$html .= '});</script>'.PHP_EOL;

return $html;
Expand Down

0 comments on commit 3bd75b8

Please sign in to comment.