diff --git a/Search.php b/Search.php index 19a2724..90dfe0f 100644 --- a/Search.php +++ b/Search.php @@ -22,6 +22,10 @@ class Search * @var bool also sorts the namespaces */ private $nsort; + /** + * @var bool Group the namespaces and page and sort separately, or mix them and sort together + */ + private $group; /** * @var bool Sort the headpages as defined by global config setting startpage to the top */ @@ -35,6 +39,7 @@ class Search * $sort['msort'] * $sort['rsort'] * $sort['nsort'] + * $sort['group'] * $sort['hsort']; */ public function __construct($sort) @@ -43,6 +48,7 @@ public function __construct($sort) $this->msort = $sort['msort']; $this->rsort = $sort['rsort']; $this->nsort = $sort['nsort']; + $this->group = $sort['group']; $this->hsort = $sort['hsort']; } @@ -657,8 +663,15 @@ public function customSearch(&$data, $base, $func, $opts, $dir = '', $lvl = 1) foreach ($dirs as $dir) { call_user_func_array($func, [&$dirs_tmp, $base, $dir, 'd', $lvl, $opts]); } - //combine directories and pages and sort together - $dirsAndFiles = array_merge($dirs_tmp, $files_tmp); + if($this->group) { + //group directories and pages, and sort separately + $dirsAndFiles = $dirs_tmp; + } else { + // no grouping + //mix directories and pages and sort together + $dirsAndFiles = array_merge($dirs_tmp, $files_tmp); + } + usort($dirsAndFiles, [$this, "compareNodes"]); //add and search each directory @@ -688,7 +701,7 @@ public function customSearch(&$data, $base, $func, $opts, $dir = '', $lvl = 1) if (!$lastItem['hns']) { array_pop($data); } - } elseif (!$this->nsort) { + } elseif (!($this->nsort && !$this->group)) { //add files to index $data = array_merge($data, $files_tmp); } diff --git a/action.php b/action.php index 035b280..e413c63 100644 --- a/action.php +++ b/action.php @@ -289,6 +289,7 @@ private function getDataFancyTree() 'msort' => $INPUT->str('msort'), 'rsort' => $INPUT->bool('rsort'), 'nsort' => $INPUT->bool('nsort'), + 'group' => $INPUT->bool('group'), 'hsort' => $INPUT->bool('hsort') ]; @@ -475,6 +476,7 @@ private function printIndex($ns) $sort['msort'] = $INPUT->str('msort', '', true); $sort['rsort'] = $INPUT->bool('rsort', false, true); $sort['nsort'] = $INPUT->bool('nsort', false, true); + $sort['group'] = $INPUT->bool('group', false, true); $sort['hsort'] = $INPUT->bool('hsort', false, true); $search = new Search($sort); $fsdir = "/" . utf8_encodeFN(str_replace(':', '/', $ns)); diff --git a/script.js b/script.js index 93d48d3..c66d194 100644 --- a/script.js +++ b/script.js @@ -257,6 +257,7 @@ jQuery(function(){ // on page load msort: options.sort.msort ? options.sort.msort : 0, //'indexmenu_n', or metadata 'key subkey' TODO is empty handled correctly? rsort: options.sort.rsort ? 1 : 0, nsort: options.sort.nsort ? 1 : 0, + group: options.sort.group ? 1 : 0, hsort: options.sort.hsort ? 1 : 0, init: 1 @@ -285,6 +286,7 @@ jQuery(function(){ // on page load msort: options.sort.msort ? options.sort.msort : 0, rsort: options.sort.rsort ? 1 : 0, nsort: options.sort.nsort ? 1 : 0, + group: options.sort.group ? 1 : 0, hsort: options.sort.hsort ? 1 : 0, init: 0 diff --git a/syntax/indexmenu.php b/syntax/indexmenu.php index 766ef31..b27c2bc 100644 --- a/syntax/indexmenu.php +++ b/syntax/indexmenu.php @@ -160,6 +160,9 @@ public function handle($match, $state, $pos, Doku_Handler $handler) } //sort directories in the same way as files $nsort = $this->hasOption($defaults, $opts, 'nsort'); + //group namespaces and pages both sorted separately with same sorting, or nogroup: mix them and sort together + $group = !$this->hasOption($defaults, $opts, 'nogroup'); + //sort headpages up $hsort = $this->hasOption($defaults, $opts, 'hsort'); //Metadata sort method @@ -175,6 +178,7 @@ public function handle($match, $state, $pos, Doku_Handler $handler) if ($msort) $jsAjax .= "&msort=" . $msort; if ($rsort) $jsAjax .= "&rsort=1"; if ($nsort) $jsAjax .= "&nsort=1"; + if ($group) $jsAjax .= "&group=1"; if ($hsort) $jsAjax .= "&hsort=1"; if ($nopg) $jsAjax .= "&nopg=1"; @@ -317,7 +321,8 @@ public function handle($match, $state, $pos, Doku_Handler $handler) 'msort' => $msort, 'rsort' => $rsort, 'nsort' => $nsort, - 'hsort' => $hsort, + 'group' => $group, + 'hsort' => $hsort ], [ //3=opts 'level' => $level, // requested depth of initial opened nodes, -1:all @@ -408,7 +413,7 @@ public function render($format, Doku_Renderer $renderer, $data) $ns = $data[0]; //theme, identifier, nocookie, navbar, noscroll, maxJs, notoc, jsAjax, context, nomenu $js_dTreeOpts = $data[1]; - //sort, msort, rsort, nsort, hsort + //sort, msort, rsort, nsort, group, hsort $sort = $data[2]; //opts for search(): level, nons, nopg, subnss, max, maxajax, js, skipns, skipfile, skipnscombined, //skipfilecombined, headpage, hide_headpage @@ -488,7 +493,7 @@ public function render($format, Doku_Renderer $renderer, $data) * @param string $ns * @param array $js_dTreeOpts entries: theme, identifier, nocookie, navbar, noscroll, maxJs, notoc, jsAjax, context, * nomenu - * @param array $sort entries: sort, msort, rsort, nsort, hsort + * @param array $sort entries: sort, msort, rsort, nsort, group, hsort * @param array $opts entries of opts for search(): level, nons, nopg, nss, max, maxajax, js, skipns, skipfile, * skipnscombined, skipfilecombined, headpage, hide_headpage * @param int $jsVersion