Skip to content
This repository was archived by the owner on Nov 25, 2020. It is now read-only.

Commit e5b8146

Browse files
committed
Clean listing code for sorting, get page_position on demand when listing unique file, fixes search results not going to correct page when pagination is on.
1 parent e979c82 commit e5b8146

File tree

5 files changed

+68
-52
lines changed

5 files changed

+68
-52
lines changed

core/src/plugins/access.fs/class.fsAccessDriver.php

Lines changed: 57 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -893,18 +893,33 @@ public function switchAction($action, $httpVars, $fileVars)
893893
if (!empty($node->metaData["mimestring_id"]) && array_key_exists($node->metaData["mimestring_id"], $mess)) {
894894
$node->mergeMetadata(array("mimestring" => $mess[$node->metaData["mimestring_id"]]));
895895
}
896+
if(isSet($httpVars["page_position"]) && $httpVars["page_position"] == "true"){
897+
// Detect page position: we have to loading "siblings"
898+
$parentPath = AJXP_Utils::safeDirname($node->getPath());
899+
$siblings = scandir($this->urlBase.$parentPath);
900+
$threshold = $this->repository->getOption("PAGINATION_THRESHOLD");
901+
$limitPerPage = $this->repository->getOption("PAGINATION_NUMBER");
902+
foreach($siblings as $i => $s){
903+
if($this->filterFile($s, true)) unset($siblings[$i]);
904+
if($this->filterFolder($s)) unset($siblings[$i]);
905+
}
906+
if(count($siblings) > $threshold){
907+
usort($siblings, "strcasecmp");
908+
$index = array_search($node->getLabel(), $siblings);
909+
$node->mergeMetadata(array("page_position" => floor($index / $limitPerPage) +1));
910+
}
911+
}
896912
if($this->repository->hasContentFilter()){
897913
$externalPath = $this->repository->getContentFilter()->externalPath($node);
898914
$node->setUrl($this->urlBase.$externalPath);
899915
}
916+
900917
AJXP_XMLWriter::renderAjxpNode($node);
901918
}
902919
AJXP_XMLWriter::close();
903920
break;
904-
}/*else if (!$selection->isEmpty() && $selection->isUnique()){
905-
$uniqueFile = $selection->getUniqueFile();
906-
}*/
907-
921+
}
922+
$orderField = $orderDirection = null;
908923
if ($this->getFilteredOption("REMOTE_SORTING")) {
909924
$orderDirection = isSet($httpVars["order_direction"])?strtolower($httpVars["order_direction"]):"asc";
910925
$orderField = isSet($httpVars["order_column"])?$httpVars["order_column"]:null;
@@ -929,18 +944,13 @@ public function switchAction($action, $httpVars, $fileVars)
929944
$crt_nodes += $countFiles;
930945
}
931946
if (isSet($threshold) && isSet($limitPerPage) && $countFiles > $threshold) {
932-
if (isSet($uniqueFile)) {
933-
$originalLimitPerPage = $limitPerPage;
934-
$offset = $limitPerPage = 0;
935-
} else {
936-
$offset = 0;
937-
$crtPage = 1;
938-
if (isSet($page)) {
939-
$offset = (intval($page)-1)*$limitPerPage;
940-
$crtPage = $page;
941-
}
942-
$totalPages = floor($countFiles / $limitPerPage) + 1;
947+
$offset = 0;
948+
$crtPage = 1;
949+
if (isSet($page)) {
950+
$offset = (intval($page)-1)*$limitPerPage;
951+
$crtPage = $page;
943952
}
953+
$totalPages = floor($countFiles / $limitPerPage) + 1;
944954
} else {
945955
$offset = $limitPerPage = 0;
946956
}
@@ -988,33 +998,10 @@ public function switchAction($action, $httpVars, $fileVars)
988998
$fullList = array("d" => array(), "z" => array(), "f" => array());
989999

9901000
$nodes = scandir($path);
991-
usort($nodes, "strcasecmp");
992-
if (isSet($orderField) && isSet($orderDirection) && $orderField == "ajxp_label" && $orderDirection == "desc") {
993-
$nodes = array_reverse($nodes);
994-
}
995-
if (!empty($this->driverConf["SCANDIR_RESULT_SORTFONC"])) {
996-
usort($nodes, $this->driverConf["SCANDIR_RESULT_SORTFONC"]);
997-
}
998-
if (isSet($orderField) && isSet($orderDirection) && $orderField != "ajxp_label") {
999-
$toSort = array();
1000-
foreach ($nodes as $node) {
1001-
if($orderField == "filesize") $toSort[$node] = is_file($nonPatchedPath."/".$node) ? $this->filesystemFileSize($nonPatchedPath."/".$node) : 0;
1002-
else if($orderField == "ajxp_modiftime") $toSort[$node] = filemtime($nonPatchedPath."/".$node);
1003-
else if($orderField == "mimestring") $toSort[$node] = pathinfo($node, PATHINFO_EXTENSION);
1004-
}
1005-
if($orderDirection == "asc") asort($toSort);
1006-
else arsort($toSort);
1007-
$nodes = array_keys($toSort);
1008-
}
1009-
//while (strlen($nodeName = readdir($handle)) > 0) {
1001+
$nodes = $this->orderNodes($nodes, $nonPatchedPath, $orderField, $orderDirection);
1002+
10101003
foreach ($nodes as $nodeName) {
1011-
if($nodeName == "." || $nodeName == "..") continue;
1012-
if (isSet($uniqueFile) && $nodeName != $uniqueFile) {
1013-
$cursor ++;
1014-
continue;
1015-
}
1016-
if ($offset > 0 && $cursor < $offset) {
1017-
$cursor ++;
1004+
if($nodeName == "." || $nodeName == "..") {
10181005
continue;
10191006
}
10201007
$isLeaf = "";
@@ -1024,6 +1011,10 @@ public function switchAction($action, $httpVars, $fileVars)
10241011
if (RecycleBinManager::recycleEnabled() && $dir == "" && "/".$nodeName == RecycleBinManager::getRecyclePath()) {
10251012
continue;
10261013
}
1014+
if ($offset > 0 && $cursor < $offset) {
1015+
$cursor ++;
1016+
continue;
1017+
}
10271018

10281019
if ($limitPerPage > 0 && ($cursor - $offset) >= $limitPerPage) {
10291020
break;
@@ -1068,9 +1059,6 @@ public function switchAction($action, $httpVars, $fileVars)
10681059

10691060
$fullList[$nodeType][$nodeName] = $node;
10701061
$cursor ++;
1071-
if (isSet($uniqueFile) && $nodeName != $uniqueFile) {
1072-
break;
1073-
}
10741062
}
10751063
if (isSet($httpVars["recursive"]) && $httpVars["recursive"] == "true") {
10761064
$breakNow = false;
@@ -1099,7 +1087,7 @@ public function switchAction($action, $httpVars, $fileVars)
10991087
array_map(array("AJXP_XMLWriter", "renderAjxpNode"), $fullList["f"]);
11001088

11011089
// ADD RECYCLE BIN TO THE LIST
1102-
if ($dir == "" && !$uniqueFile && RecycleBinManager::recycleEnabled() && $this->getFilteredOption("HIDE_RECYCLE", $this->repository->getId()) !== true) {
1090+
if ($dir == "" && RecycleBinManager::recycleEnabled() && $this->getFilteredOption("HIDE_RECYCLE", $this->repository->getId()) !== true) {
11031091
$recycleBinOption = RecycleBinManager::getRelativeRecycle();
11041092
if (file_exists($this->urlBase.$recycleBinOption)) {
11051093
$recycleNode = new AJXP_Node($this->urlBase.$recycleBinOption);
@@ -1134,6 +1122,30 @@ public function switchAction($action, $httpVars, $fileVars)
11341122
return $xmlBuffer;
11351123
}
11361124

1125+
protected function orderNodes($nodes, $path, $orderField, $orderDirection){
1126+
1127+
usort($nodes, "strcasecmp");
1128+
if (isSet($orderField) && isSet($orderDirection) && $orderField == "ajxp_label" && $orderDirection == "desc") {
1129+
$nodes = array_reverse($nodes);
1130+
}
1131+
if (!empty($this->driverConf["SCANDIR_RESULT_SORTFONC"])) {
1132+
usort($nodes, $this->driverConf["SCANDIR_RESULT_SORTFONC"]);
1133+
}
1134+
if (isSet($orderField) && isSet($orderDirection) && $orderField != "ajxp_label") {
1135+
$toSort = array();
1136+
foreach ($nodes as $node) {
1137+
if($orderField == "filesize") $toSort[$node] = is_file($path."/".$node) ? $this->filesystemFileSize($path."/".$node) : 0;
1138+
else if($orderField == "ajxp_modiftime") $toSort[$node] = filemtime($path."/".$node);
1139+
else if($orderField == "mimestring") $toSort[$node] = pathinfo($node, PATHINFO_EXTENSION);
1140+
}
1141+
if($orderDirection == "asc") asort($toSort);
1142+
else arsort($toSort);
1143+
$nodes = array_keys($toSort);
1144+
}
1145+
return $nodes;
1146+
1147+
}
1148+
11371149
public function parseLsOptions($optionString)
11381150
{
11391151
// LS OPTIONS : dz , a, d, z, all of these with or without l

core/src/plugins/access.fs/fsActions.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
<input_param description="Trigger remote order" name="remote_order" type="boolean" mandatory="false" default="false"/>
4242
<input_param description="Remote order column" name="order_column" type="string" mandatory="false"/>
4343
<input_param description="Remote order direction" name="order_direction" type="string" mandatory="false"/>
44+
<input_param description="Find page position of required file for multipage listing" name="page_position" type="boolean" mandatory="false"/>
4445
<output type="AJXP_NODE[]"/>
4546
</serverCallback>
4647
</processing>

core/src/plugins/gui.ajax/res/js/ajaxplorer.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/src/plugins/gui.ajax/res/js/pydio/model/class.AjxpDataModel.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ Class.create("AjxpDataModel", {
116116
var currentPage = ajxpNode.getMetadata().get("paginationData").get("current");
117117
this.loadPathInfoSync(selPath, function(foundNode){
118118
newPage = foundNode.getMetadata().get("page_position");
119-
});
119+
}, true);
120120
if(newPage && newPage != currentPage){
121121
ajxpNode.getMetadata().get("paginationData").set("new_page", newPage);
122122
this.requireContextChange(ajxpNode, true, true);
@@ -171,12 +171,12 @@ Class.create("AjxpDataModel", {
171171
this._iAjxpNodeProvider.refreshNodeAndReplace(nodeOrPath, onComplete);
172172
},
173173

174-
loadPathInfoSync: function (path, callback){
175-
this._iAjxpNodeProvider.loadLeafNodeSync(new AjxpNode(path), callback);
174+
loadPathInfoSync: function (path, callback, getPage){
175+
this._iAjxpNodeProvider.loadLeafNodeSync(new AjxpNode(path), callback, false, getPage);
176176
},
177177

178-
loadPathInfoAsync: function (path, callback){
179-
this._iAjxpNodeProvider.loadLeafNodeSync(new AjxpNode(path), callback, true);
178+
loadPathInfoAsync: function (path, callback, getPage){
179+
this._iAjxpNodeProvider.loadLeafNodeSync(new AjxpNode(path), callback, true, getPage);
180180
},
181181

182182
/**

core/src/plugins/gui.ajax/res/js/pydio/model/class.RemoteNodeProvider.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,15 @@ Class.create("RemoteNodeProvider", {
9191
* @param nodeCallback Function On node loaded
9292
* @param aSync bool
9393
*/
94-
loadLeafNodeSync : function(node, nodeCallback, aSync){
94+
loadLeafNodeSync : function(node, nodeCallback, aSync, getPage){
9595
var conn = new Connexion();
9696
conn.addParameter("get_action", "ls");
9797
conn.addParameter("options", "al");
9898
conn.addParameter("dir", getRepName(node.getPath()));
9999
conn.addParameter("file", getBaseName(node.getPath()));
100+
if(getPage){
101+
conn.addParameter("page_position", "true");
102+
}
100103
if(this.properties){
101104
$H(this.properties).each(function(pair){
102105
conn.addParameter(pair.key, pair.value);

0 commit comments

Comments
 (0)