Skip to content

Commit 561599a

Browse files
authored
Merge pull request #32 from inab/feature/recursive-workspace-tree
Fix and refactor workspace table to allow subfolders
2 parents 938f646 + 8eb9a21 commit 561599a

22 files changed

Lines changed: 1125 additions & 565 deletions

front_end/openVRE/public/applib/getDataMove.php

Lines changed: 71 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,51 @@
99
redirect($GLOBALS['BASEURL']."/workspace/");
1010
}
1111

12+
/**
13+
* Collect all directories under a project (depth-first) for move targets.
14+
*/
15+
function collectMoveTargetDirsRecursive($dirId, $projectPath, &$dirs)
16+
{
17+
$dir = getGSFile_fromId($dirId);
18+
if (!$dir || !isset($dir['files'])) {
19+
return;
20+
}
21+
22+
if (isset($dir['path']) && $dir['path'] == $_SESSION['User']['id']) {
23+
return;
24+
}
25+
26+
$relPath = substr($dir['path'], strlen($projectPath) + 1);
27+
28+
$dirs[] = [
29+
"id" => $dir["_id"],
30+
"name" => $relPath,
31+
"path" => $dir["path"],
32+
];
33+
34+
foreach ($dir['files'] as $childId) {
35+
$child = getGSFile_fromId($childId);
36+
if ($child && isset($child['files'])) {
37+
collectMoveTargetDirsRecursive($childId, $projectPath, $dirs);
38+
}
39+
}
40+
}
41+
42+
function collectMoveTargetDirs($projectId, $projectPath)
43+
{
44+
$dirs = [];
45+
$project = getGSFile_fromId($projectId);
46+
if (!isset($project['files'])) {
47+
return $dirs;
48+
}
49+
50+
foreach ($project['files'] as $childId) {
51+
collectMoveTargetDirsRecursive($childId, $projectPath, $dirs);
52+
}
53+
54+
return $dirs;
55+
}
56+
1257
switch ($_REQUEST['op']){
1358
case 'rename':
1459
$file_raw = getGSFile_fromId($_REQUEST['id']);
@@ -19,19 +64,35 @@
1964
$returnData = ["path" => $path, "name" => $name, "type" => $file["type"]];
2065
print(json_encode($returnData));
2166
break;
22-
case 'move': $file_raw = getGSFile_fromId($_REQUEST['id']);
67+
case 'move':
68+
$file_raw = getGSFile_fromId($_REQUEST['id']);
2369
$file = formatData($file_raw);
24-
$prjData = ["name" => $file['longfilename'], "execution" => $file['longexecutionname'], "project" => $file['project'], "type" => $file['type'], "projects" => []];
70+
$parentPath = ($file['type'] == 'file' && !empty($file['parentDir']))
71+
? $file['parentDir']
72+
: '';
73+
$parentRelPath = '';
74+
if ($parentPath !== '' && preg_match('/(.*\/__PROJ[^\/]*)/', $parentPath, $match)) {
75+
$parentRelPath = substr($parentPath, strlen($match[1]) + 1);
76+
}
77+
78+
$prjData = [
79+
"name" => $file['longfilename'],
80+
"execution" => $file['longexecutionname'],
81+
"project" => $file['project'],
82+
"type" => $file['type'],
83+
"parent_path" => $parentPath,
84+
"parent_rel_path" => $parentRelPath,
85+
"projects" => [],
86+
];
2587
$projects = getProjects_byOwner();
2688
foreach($projects as $pr) {
27-
$excData = [];
28-
foreach($pr["files"] as $execution) {
29-
$exc = getGSFile_fromId($execution);
30-
$p = explode("/",$exc["path"]);
31-
$name = array_pop($p);
32-
$excData[] = ["id" => $exc["_id"], "name" => $name, "path" => $exc["path"]];
33-
}
34-
$prjData["projects"][] = ["id" => $pr["_id"], "name" => $pr["name"], "path" => $pr["path"], "executions" => $excData];
89+
$excData = collectMoveTargetDirs($pr['_id'], $pr['path']);
90+
$prjData["projects"][] = [
91+
"id" => $pr["_id"],
92+
"name" => $pr["name"],
93+
"path" => $pr["path"],
94+
"executions" => $excData,
95+
];
3596
}
3697
print(json_encode($prjData, JSON_PRETTY_PRINT));
3798
break;

front_end/openVRE/public/assets/layouts/layout/css/custom.min.css

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,25 @@ input.tt-hint {
556556
cursor: pointer;
557557
}
558558

559+
#workspace .folder-name-line .collapse-folder {
560+
flex-shrink: 0;
561+
margin: 0;
562+
font-size: 18px;
563+
}
564+
565+
#workspace .folder-name-line .fa-stack.collapse-folder {
566+
margin-top: 12px;
567+
height: 9px;
568+
width: 20px;
569+
}
570+
571+
#workspace .folder-name-line .truncate {
572+
float: none;
573+
flex: 0 1 auto;
574+
min-width: 0;
575+
max-width: 280px;
576+
}
577+
559578
.denser {
560579
padding: 2px 4px 2px 4px!important;
561580
}

front_end/openVRE/public/assets/pages/scripts/actions-home.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ function move(file) {
112112
usrPrjStr = JSON.parse(data);
113113
$('#modalMove .modal-title').html('Move <strong>' + usrPrjStr.name + '</strong>');
114114
if (usrPrjStr.type == "file") {
115-
$('#modalMove .modal-body p').html('File <strong>' + usrPrjStr.name + '</strong> currently located at <strong>/' + usrPrjStr.project + '/' + usrPrjStr.execution + '/</strong>');
115+
var currentLoc = usrPrjStr.parent_rel_path || usrPrjStr.execution;
116+
$('#modalMove .modal-body p').html('File <strong>' + usrPrjStr.name + '</strong> currently located at <strong>/' + usrPrjStr.project + '/' + currentLoc + '/</strong>');
116117
$('#col-1-move').addClass('col-md-3');
117118
$('#col-1-move').removeClass('col-md-4');
118119
$('#col-2-move').addClass('col-md-3');
@@ -144,7 +145,7 @@ function move(file) {
144145
$("#project-name").append('<option value="' + v.id + '" ' + sel + '>' + v.name + '</option>');
145146
if (v.name == usrPrjStr.project) {
146147
$.each(v.executions, function (k1, v1) {
147-
if (v1.name == usrPrjStr.execution) var sel = "selected";
148+
var sel = (usrPrjStr.parent_path && v1.path == usrPrjStr.parent_path) ? "selected" : "";
148149
$("#execution-name").append('<option value="' + v1.id + '" ' + sel + '>' + v1.name + '</option>');
149150
});
150151
}
@@ -178,7 +179,7 @@ function moveAllFiles() {
178179
success: function (data) {
179180

180181
$('#modalMove .modal-title').html('Move selected files');
181-
$('#modalMove .modal-body p').html('Select the project and execution where you want to move all the selected files:');
182+
$('#modalMove .modal-body p').html('Select the project and folder where you want to move all the selected files:');
182183
$('#col-1-move').addClass('col-md-4');
183184
$('#col-1-move').removeClass('col-md-3');
184185
$('#col-2-move').addClass('col-md-4');

0 commit comments

Comments
 (0)