From d17713051ca2fef29de8025fe876d417838cea7f Mon Sep 17 00:00:00 2001 From: vincent-peugnet Date: Wed, 25 Mar 2020 19:53:38 +0100 Subject: graph look, add redirections, close #50 --- app/class/Config.php | 13 +++++- app/class/Controllerhome.php | 11 ++--- app/class/Modelhome.php | 106 +++++++++++++++++++++++++++++-------------- app/class/Modelrender.php | 7 +-- 4 files changed, 90 insertions(+), 47 deletions(-) (limited to 'app/class') diff --git a/app/class/Config.php b/app/class/Config.php index fa9082f..2cfdcd3 100644 --- a/app/class/Config.php +++ b/app/class/Config.php @@ -3,6 +3,8 @@ namespace Wcms; +use Http\Client\Common\Plugin\RetryPlugin; + abstract class Config { protected static $pagetable = 'mystore'; @@ -129,9 +131,16 @@ abstract class Config return self::$fontsize; } - public static function basepath() + /** + * @param bool $trailingslash If not empty basepath, add a trailing slash after the basepath + */ + public static function basepath(bool $trailingslash = false) : string { - return self::$basepath; + if($trailingslash && !empty(self::$basepath)) { + return self::$basepath . '/'; + } else { + return self::$basepath; + } } public static function route404() diff --git a/app/class/Controllerhome.php b/app/class/Controllerhome.php index 6444ac2..71f110e 100644 --- a/app/class/Controllerhome.php +++ b/app/class/Controllerhome.php @@ -34,11 +34,7 @@ class Controllerhome extends Controllerpage $deepsearch = $this->deepsearch(); - $idlistfilter = $this->modelhome->filter($pagelist, $this->opt); - $pagelistfilter = $this->modelhome->pagelistfilter($pagelist, $idlistfilter); - $pagelistdeep = $this->modelhome->deepsearch($pagelistfilter, $deepsearch['regex'] , $deepsearch['searchopt']); - $pagelistsort = $this->modelhome->sort($pagelistdeep, $this->opt); - $vars['pagelistopt'] = $pagelistsort; + $vars['pagelistopt'] = $this->modelhome->pagetable($pagelist, $this->opt, $deepsearch['regex'], $deepsearch['searchopt']); $vars['columns'] = $this->modelhome->setcolumns($this->user->columns()); @@ -54,8 +50,9 @@ class Controllerhome extends Controllerpage if($vars['display'] === 'map') { $vars['layout'] = $_GET['layout'] ?? 'cose-bilkent'; - $vars['hideorphans'] = boolval($_GET['hideorphans'] ?? false); - $datas = $this->modelhome->cytodata($pagelistsort, $vars['layout'], $vars['hideorphans']); + $vars['showorphans'] = boolval($_GET['showorphans'] ?? false); + $vars['showredirection'] = boolval($_GET['showredirection'] ?? false); + $datas = $this->modelhome->cytodata($vars['pagelistopt'], $vars['layout'], $vars['showorphans'], $vars['showredirection']); $vars['json'] = json_encode($datas, JSON_PRETTY_PRINT); } diff --git a/app/class/Modelhome.php b/app/class/Modelhome.php index ede9179..949c4f7 100644 --- a/app/class/Modelhome.php +++ b/app/class/Modelhome.php @@ -39,6 +39,25 @@ class Modelhome extends Modelpage } + /** + * @param array $pagelist of Pages objects as `id => Page` + * @param Opt $opt + * + * @param string $regex Regex to match. + * @param array $options Option search, could be `content` `title` `description`. + * + * @return array associative array of `Page` objects * + */ + public function pagetable(array $pagelist, Opt $opt, $regex = '', $searchopt = []) : array + { + $pagelist = $this->filter($pagelist, $opt); + if(!empty($regex)) { + $pagelist = $this->deepsearch($pagelist, $regex , $searchopt); + } + $pagelist = $this->sort($pagelist, $opt); + + return $pagelist; + } @@ -66,28 +85,11 @@ class Modelhome extends Modelpage $filter = array_diff($idlist, $filter); } - return $filter; + return array_intersect_key($pagelist, array_flip($filter)); } - /** - * Convert list of id into a list of Page objects - * - * @param array $pagelist - * @param array $idlist - * - * @return array Filtered list of `Page` objects - */ - public function pagelistfilter(array $pagelist, array $fiter) : array - { - return array_intersect_key($pagelist, array_flip($fiter)); - } - - - - - /** * Sort and limit an array of Pages * @@ -160,13 +162,14 @@ class Modelhome extends Modelpage * * @param array $pagelist associative array of pages as `id => Page` * @param string $layout - * @param bool $hideorphans if `true`, remove orphans pages - * + * @param bool $showorphans if `false`, remove orphans pages + * @param bool $showredirection if `true`, add redirections * + * @return array */ - public function cytodata(array $pagelist, string $layout = 'random', bool $hideorphans = false) + public function cytodata(array $pagelist, string $layout = 'random', bool $showorphans = false, bool $showredirection = false) : array { - $datas['elements'] = $this->mapdata($pagelist, $hideorphans); + $datas['elements'] = $this->mapdata($pagelist, $showorphans, $showredirection); $datas['layout'] = [ 'name' => $layout, @@ -175,7 +178,7 @@ class Modelhome extends Modelpage 'randomize' => true, 'nodeDimensionsIncludeLabels' => true, 'tile' => false, - 'edgeElasticity' => 0.75, + 'edgeElasticity' => 0.45, 'gravity' => 0.25, 'idealEdgeLength' => 60, 'numIter' => 10000 @@ -185,6 +188,24 @@ class Modelhome extends Modelpage 'selector' => 'node', 'style' => [ 'label' => 'data(id)', + 'background-image' => 'data(favicon)', + 'background-fit' => 'contain', + 'border-width' => 3, + 'border-color' => '#80b97b' + ], + ], + [ + 'selector' => 'node.not_published', + 'style' => [ + 'shape' => 'round-hexagon', + 'border-color' => '#b97b7b' + ], + ], + [ + 'selector' => 'node.private', + 'style' => [ + 'shape' => 'round-triangle', + 'border-color' => '#b9b67b' ], ], [ @@ -192,6 +213,14 @@ class Modelhome extends Modelpage 'style' => [ 'curve-style' => 'bezier', 'target-arrow-shape' => 'triangle', + 'arrow-scale' => 1.5 + ], + ], + [ + 'selector' => 'edge.redirect', + 'style' => [ + 'line-style' => 'dashed', + 'label' => 'data(refresh)' ], ], ]; @@ -202,15 +231,17 @@ class Modelhome extends Modelpage * Transform list of Pages into cytoscape nodes and edge datas * * @param array $pagelist associative array of pages as `id => Page` - * @param bool $hideorphans if `true`, remove orphans pages - * + * @param bool $showorphans if `false`, remove orphans pages + * @param bool $showredirection if `true`, add redirections + * * @return array of cytoscape datas */ - public function mapdata(array $pagelist, bool $hideorphans = false) : array + public function mapdata(array $pagelist, bool $showorphans = true, bool $showredirection = false) : array { $idlist = array_keys($pagelist); $edges = []; + $notorphans = []; foreach ($pagelist as $page) { foreach ($page->linkto() as $linkto) { if(in_array($linkto, $idlist)) { @@ -220,9 +251,19 @@ class Modelhome extends Modelpage $edge['data']['target'] = $linkto; $edges[] = $edge; $notorphans[] = $linkto; + $notorphans[] = $page->id(); } } - if(!empty($page->linkto())) { + // add redirection edge + if($showredirection && key_exists($page->redirection(), $pagelist)) { + $edger['group'] = 'edges'; + $edger['data']['id'] = $page->id() . '>' . $page->redirection(); + $edger['data']['refresh'] = $page->refresh(); + $edger['data']['source'] = $page->id(); + $edger['data']['target'] = $page->redirection(); + $edger['classes'] = 'redirect'; + $edges[] = $edger; + $notorphans[] = $page->redirection(); $notorphans[] = $page->id(); } } @@ -231,16 +272,11 @@ class Modelhome extends Modelpage $nodes = []; foreach ($pagelist as $id => $page) { - if($hideorphans) { - if(in_array($id, $notorphans)) { - $node['group'] = 'nodes'; - $node['data']['id'] = $page->id(); - $node['classes'] = [$page->secure('string')]; - $nodes[] = $node; - } - } else { + if($showorphans || (!$showorphans && in_array($id, $notorphans))) { $node['group'] = 'nodes'; $node['data']['id'] = $page->id(); + $node['data']['edit'] = $page->id() . DIRECTORY_SEPARATOR . 'edit'; + $node['data']['favicon'] = Model::faviconpath() . $page->favicon(); $node['classes'] = [$page->secure('string')]; $nodes[] = $node; } diff --git a/app/class/Modelrender.php b/app/class/Modelrender.php index 2338eb4..638f3e3 100644 --- a/app/class/Modelrender.php +++ b/app/class/Modelrender.php @@ -7,6 +7,7 @@ use Michelf\MarkdownExtra; class Modelrender extends Modelpage { + /** @var \AltoRouter */ protected $router; /** @var Page */ protected $page; @@ -21,7 +22,7 @@ class Modelrender extends Modelpage const RENDER_VERBOSE = 1; - public function __construct($router) + public function __construct(\AltoRouter $router) { parent::__construct(); @@ -640,10 +641,10 @@ class Modelrender extends Modelpage foreach ($matches as $match) { $optlist = $modelhome->Optlistinit($pagelist); $optlist->parsehydrate($match['options']); - $table2 = $modelhome->table2($pagelist, $optlist, '', []); + $pagetable = $modelhome->pagetable($pagelist, $optlist, '', []); $content = '