From 0893f20446a6645c5f928f2cb41f688a9fc5fcf1 Mon Sep 17 00:00:00 2001 From: vincent-peugnet Date: Wed, 12 Feb 2020 20:20:06 +0100 Subject: refactoring home>desktop, fix #47 --- app/class/Controllerhome.php | 67 +++++++++++++++++++++++++++++--------------- app/class/Routes.php | 1 + 2 files changed, 46 insertions(+), 22 deletions(-) (limited to 'app') diff --git a/app/class/Controllerhome.php b/app/class/Controllerhome.php index 5a9110a..42ace87 100644 --- a/app/class/Controllerhome.php +++ b/app/class/Controllerhome.php @@ -27,23 +27,14 @@ class Controllerhome extends Controllerpage } else { - $table = $this->modelhome->getlister(); - $this->opt = $this->modelhome->optinit($table); + $pagelist = $this->modelhome->getlister(); + $this->opt = $this->modelhome->optinit($pagelist); $vars['colors'] = new Colors($this->opt->taglist()); - if (!isset($_GET['search'])) { - $searchopt = ['title' => 1, 'description' => 1, 'content' => 1, 'other' => 0, 'casesensitive' => 0]; - } else { - $searchopt['title'] = $_GET['title'] ?? 0; - $searchopt['description'] = $_GET['description'] ?? 0; - $searchopt['content'] = $_GET['content'] ?? 0; - $searchopt['other'] = $_GET['other'] ?? 0; - $searchopt['casesensitive'] = $_GET['case'] ?? 0; - } - $regex = $_GET['search'] ?? ''; + $deepsearch = $this->deepsearch(); - $vars['table2'] = $this->modelhome->table2($table, $this->opt, $regex , $searchopt); + $vars['table2'] = $this->modelhome->table2($pagelist, $this->opt, $deepsearch['regex'] , $deepsearch['searchopt']); $vars['columns'] = $this->modelhome->setcolumns($this->user->columns()); @@ -52,22 +43,49 @@ class Controllerhome extends Controllerpage $vars['editorlist'] = $this->usermanager->getlisterbylevel(2, '>='); $vars['user'] = $this->user; $vars['opt'] = $this->opt; - $vars['deepsearch'] = $regex; - $vars['searchopt'] = $searchopt; + $vars['deepsearch'] = $deepsearch['regex']; + $vars['searchopt'] = $deepsearch['searchopt']; - $vars['footer'] = ['version' => getversion(), 'total' => count($table), 'database' => Config::pagetable()]; + $vars['footer'] = ['version' => getversion(), 'total' => count($pagelist), 'database' => Config::pagetable()]; - if (isset($_POST['query']) && $this->user->iseditor()) { - $datas = array_merge($_POST, $_SESSION['opt']); - $this->optlist = $this->modelhome->Optlistinit($table); - $this->optlist->hydrate($datas); - $vars['optlist'] = $this->optlist; - } + $this->listquery($pagelist); + + $vars['optlist'] = $this->optlist ?? null; $this->showtemplate('home', $vars); } } + /** + * Look for GET deepsearch datas and transform it an array + * + * @return array containing `string $regex` and `array $searchopt` + */ + public function deepsearch() : array + { + if (!isset($_GET['search'])) { + $searchopt = ['title' => 1, 'description' => 1, 'content' => 1, 'other' => 0, 'casesensitive' => 0]; + } else { + $searchopt['title'] = $_GET['title'] ?? 0; + $searchopt['description'] = $_GET['description'] ?? 0; + $searchopt['content'] = $_GET['content'] ?? 0; + $searchopt['other'] = $_GET['other'] ?? 0; + $searchopt['casesensitive'] = $_GET['case'] ?? 0; + } + $regex = $_GET['search'] ?? ''; + return ['regex' => $regex, 'searchopt' => $searchopt]; + } + + public function listquery(array $pagelist) + { + if (isset($_POST['query']) && $this->user->iseditor()) { + $datas = array_merge($_POST, $_SESSION['opt']); + $this->optlist = $this->modelhome->Optlistinit($pagelist); + $this->optlist->hydrate($datas); + $vars['optlist'] = $this->optlist; + } + } + public function columns() { if (isset($_POST['columns']) && $this->user->iseditor()) { @@ -110,6 +128,11 @@ class Controllerhome extends Controllerpage } } + public function map() + { + + } + /** * Render every pages in the database */ diff --git a/app/class/Routes.php b/app/class/Routes.php index e71bf59..c538d78 100644 --- a/app/class/Routes.php +++ b/app/class/Routes.php @@ -19,6 +19,7 @@ class Routes $router->addRoutes([ ['GET', '/', 'Controllerhome#desktop', 'home'], ['POST', '/', 'Controllerhome#desktop', 'homequery'], + ['GET', '/map', 'Controllerhome#map', 'map'], ['POST', '/columns', 'Controllerhome#columns', 'homecolumns'], ['POST', '/colors', 'Controllerhome#colors', 'homecolors'], ['GET', '//renderall', 'Controllerhome#renderall', 'homerenderall'], -- cgit v1.2.3 From e115875801c2e32399079c4ef92bb11ceb4f2c1d Mon Sep 17 00:00:00 2001 From: vincent-peugnet Date: Wed, 12 Feb 2020 21:05:46 +0100 Subject: generate cytoscape datas --- app/class/Controllerhome.php | 25 +++++++++++++++++++------ app/class/Modelhome.php | 41 ++++++++++++++++++++++++++++++++++++++++- app/view/templates/map.php | 5 +++++ 3 files changed, 64 insertions(+), 7 deletions(-) create mode 100644 app/view/templates/map.php (limited to 'app') diff --git a/app/class/Controllerhome.php b/app/class/Controllerhome.php index 42ace87..86b2f6f 100644 --- a/app/class/Controllerhome.php +++ b/app/class/Controllerhome.php @@ -86,6 +86,24 @@ class Controllerhome extends Controllerpage } } + /** + * Temporary map display function + */ + public function map() + { + if ($this->user->isadmin()) { + + $pagelist = $this->modelhome->getlister(); + $datas = $this->modelhome->mapdata($pagelist); + + $vars['json'] = json_encode($datas, JSON_PRETTY_PRINT); + + $this->showtemplate('map', $vars); + + } + + } + public function columns() { if (isset($_POST['columns']) && $this->user->iseditor()) { @@ -127,12 +145,7 @@ class Controllerhome extends Controllerpage $this->routedirect('home'); } } - - public function map() - { - - } - + /** * Render every pages in the database */ diff --git a/app/class/Modelhome.php b/app/class/Modelhome.php index 6352282..37eb549 100644 --- a/app/class/Modelhome.php +++ b/app/class/Modelhome.php @@ -130,7 +130,46 @@ class Modelhome extends Modelpage } } return $pageselected; - } + } + + /** + * Transform list of page into list of nodes and edges + */ + public function mapdata(array $pagelist) + { + $nodes = []; + $edges = []; + foreach ($pagelist as $page) { + $node['group'] = 'nodes'; + $node['data']['id'] = $page->id(); + $node['classes'] = [$page->secure('string')]; + $nodes[] = $node; + + + foreach ($page->linkto() as $linkto) { + $edge['group'] = 'edges'; + $edge['data']['id'] = $page->id() . '>' . $linkto; + $edge['data']['source'] = $page->id(); + $edge['data']['target'] = $linkto; + $edges[] = $edge; + } + } + $datas['elements'] = array_merge($nodes, $edges); + + $datas['layout']['name'] = 'preset'; + $datas['style'] = [ + 'selector' => 'node', + 'style' => [ + 'label' => 'data(id)' + ] + ]; + return $datas; + } + + public function cytodata(array $mapdata) + { + + } /** diff --git a/app/view/templates/map.php b/app/view/templates/map.php new file mode 100644 index 0000000..236ff8e --- /dev/null +++ b/app/view/templates/map.php @@ -0,0 +1,5 @@ +
+
+    
+
+
\ No newline at end of file -- cgit v1.2.3 From 87f75ea2869629fedf893942b767765eff40c597 Mon Sep 17 00:00:00 2001 From: n-peugnet Date: Sun, 22 Mar 2020 16:30:35 +0100 Subject: very first graph displayed using cytoscape --- app/class/Modelhome.php | 2 +- app/view/templates/map.php | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) (limited to 'app') diff --git a/app/class/Modelhome.php b/app/class/Modelhome.php index 37eb549..2aedae3 100644 --- a/app/class/Modelhome.php +++ b/app/class/Modelhome.php @@ -156,7 +156,7 @@ class Modelhome extends Modelpage } $datas['elements'] = array_merge($nodes, $edges); - $datas['layout']['name'] = 'preset'; + $datas['layout']['name'] = 'random'; $datas['style'] = [ 'selector' => 'node', 'style' => [ diff --git a/app/view/templates/map.php b/app/view/templates/map.php index 236ff8e..83e6004 100644 --- a/app/view/templates/map.php +++ b/app/view/templates/map.php @@ -1,5 +1,15 @@ -
+
 
-    
+
-
\ No newline at end of file + + + \ No newline at end of file -- cgit v1.2.3 From 3962156bc8187d3752bbbdbaa06f7a23db38d354 Mon Sep 17 00:00:00 2001 From: n-peugnet Date: Sun, 22 Mar 2020 17:49:30 +0100 Subject: first style tests --- app/class/Modelhome.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'app') diff --git a/app/class/Modelhome.php b/app/class/Modelhome.php index 2aedae3..f4b4a56 100644 --- a/app/class/Modelhome.php +++ b/app/class/Modelhome.php @@ -158,11 +158,20 @@ class Modelhome extends Modelpage $datas['layout']['name'] = 'random'; $datas['style'] = [ - 'selector' => 'node', - 'style' => [ - 'label' => 'data(id)' - ] - ]; + [ + 'selector' => 'node', + 'style' => [ + 'label' => 'data(id)', + ], + ], + [ + 'selector' => 'edge', + 'style' => [ + 'curve-style' => 'bezier', + 'target-arrow-shape' => 'triangle', + ], + ], + ]; return $datas; } -- cgit v1.2.3 From 86d0185d570dbc896f9f438c12e133e8cdd83940 Mon Sep 17 00:00:00 2001 From: n-peugnet Date: Mon, 23 Mar 2020 15:13:09 +0100 Subject: feat(graph): better layout with cose-bilkent --- app/class/Modelhome.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app') diff --git a/app/class/Modelhome.php b/app/class/Modelhome.php index f4b4a56..343a879 100644 --- a/app/class/Modelhome.php +++ b/app/class/Modelhome.php @@ -156,7 +156,7 @@ class Modelhome extends Modelpage } $datas['elements'] = array_merge($nodes, $edges); - $datas['layout']['name'] = 'random'; + $datas['layout']['name'] = 'cose-bilkent'; $datas['style'] = [ [ 'selector' => 'node', -- cgit v1.2.3 From 73e2d40ee0d82c9d68eca8db35b323db77eb5713 Mon Sep 17 00:00:00 2001 From: vincent-peugnet Date: Tue, 17 Mar 2020 12:20:58 +0100 Subject: move deepsearch into pages list --- app/view/templates/home.php | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) (limited to 'app') diff --git a/app/view/templates/home.php b/app/view/templates/home.php index 1d15a8d..8078d4a 100644 --- a/app/view/templates/home.php +++ b/app/view/templates/home.php @@ -19,22 +19,6 @@ $this->insert('homemenu', ['user' => $user, 'opt' => $opt, 'optlist' => $optlist, 'pagelist' => $pagelist, 'faviconlist' => $faviconlist, 'thumbnaillist' => $thumbnaillist, 'editorlist' => $editorlist, 'colors' => $colors]); ?> -
-
- - > - - > - - > - - > - - > - - -
-
@@ -48,6 +32,24 @@

Pages ()

+ +
+
+ + > + + > + + > + + > + + > + + +
+
+
-- cgit v1.2.3 From 7d1b16dce7e435caefd39975ca68a08c4f79fc03 Mon Sep 17 00:00:00 2001 From: vincent-peugnet Date: Mon, 23 Mar 2020 16:19:48 +0100 Subject: map integration in home --- app/class/Controllerhome.php | 7 +++++++ app/class/Model.php | 8 ++++++++ app/class/Modelhome.php | 43 +++++++++++++++++++++++++++++++------------ app/fn/fn.php | 26 +++++++++++++++++++++++++- app/view/templates/home.php | 33 ++++++++++++++++++++++++++++++++- 5 files changed, 103 insertions(+), 14 deletions(-) (limited to 'app') diff --git a/app/class/Controllerhome.php b/app/class/Controllerhome.php index 86b2f6f..7b7024d 100644 --- a/app/class/Controllerhome.php +++ b/app/class/Controllerhome.php @@ -45,6 +45,13 @@ class Controllerhome extends Controllerpage $vars['opt'] = $this->opt; $vars['deepsearch'] = $deepsearch['regex']; $vars['searchopt'] = $deepsearch['searchopt']; + $vars['display'] = $_GET['display'] ?? 'list'; + + $vars['layout'] = $_GET['layout'] ?? 'random'; + if($vars['display'] === 'map') { + $datas = $this->modelhome->cytodata($vars['table2'], $vars['layout']); + $vars['json'] = json_encode($datas, JSON_PRETTY_PRINT); + } $vars['footer'] = ['version' => getversion(), 'total' => count($pagelist), 'database' => Config::pagetable()]; diff --git a/app/class/Model.php b/app/class/Model.php index 5847f74..ae56c2f 100644 --- a/app/class/Model.php +++ b/app/class/Model.php @@ -20,6 +20,14 @@ abstract class Model const GLOBAL_DIR = 'assets'. DIRECTORY_SEPARATOR . 'global' . DIRECTORY_SEPARATOR; const DATABASE_DIR = '.' . DIRECTORY_SEPARATOR . 'database' . DIRECTORY_SEPARATOR; const PAGES_DIR = self::DATABASE_DIR . 'pages' . DIRECTORY_SEPARATOR; + + const MAP_LAYOUTS = [ + 'cose' => 'cose', + 'circle' => 'circle', + 'random' => 'random', + 'cose-bilkent' => 'cose-bilkent' + ]; + const MEDIA_EXT = [ 'jpg' => 'image', diff --git a/app/class/Modelhome.php b/app/class/Modelhome.php index 343a879..18ae1a5 100644 --- a/app/class/Modelhome.php +++ b/app/class/Modelhome.php @@ -45,8 +45,10 @@ class Modelhome extends Modelpage * @param array $table * @param Opt $opt * @param string $regex + * + * @return array of `Page` object */ - public function table2(array $table, Opt $opt, string $regex = "", array $searchopt = []) + public function table2(array $table, Opt $opt, string $regex = "", array $searchopt = []) : array { @@ -135,17 +137,11 @@ class Modelhome extends Modelpage /** * Transform list of page into list of nodes and edges */ - public function mapdata(array $pagelist) + public function cytodata(array $pagelist, string $layout = 'random') { - $nodes = []; - $edges = []; - foreach ($pagelist as $page) { - $node['group'] = 'nodes'; - $node['data']['id'] = $page->id(); - $node['classes'] = [$page->secure('string')]; - $nodes[] = $node; - + $datas['elements'] = $this->mapdata($pagelist); +<<<<<<< HEAD foreach ($page->linkto() as $linkto) { $edge['group'] = 'edges'; $edge['data']['id'] = $page->id() . '>' . $linkto; @@ -157,6 +153,11 @@ class Modelhome extends Modelpage $datas['elements'] = array_merge($nodes, $edges); $datas['layout']['name'] = 'cose-bilkent'; +======= + $datas['layout'] = [ + 'name' => $layout, + ]; +>>>>>>> map integration in home $datas['style'] = [ [ 'selector' => 'node', @@ -175,9 +176,27 @@ class Modelhome extends Modelpage return $datas; } - public function cytodata(array $mapdata) + public function mapdata(array $pagelist) { - + $nodes = []; + $edges = []; + foreach ($pagelist as $page) { + $node['group'] = 'nodes'; + $node['data']['id'] = $page->id(); + $node['classes'] = [$page->secure('string')]; + $nodes[] = $node; + + + foreach ($page->linkto() as $linkto) { + $edge['group'] = 'edges'; + $edge['data']['id'] = $page->id() . '>' . $linkto; + $edge['data']['source'] = $page->id(); + $edge['data']['target'] = $linkto; + $edges[] = $edge; + } + } + return array_merge($nodes, $edges); + } diff --git a/app/fn/fn.php b/app/fn/fn.php index 6dfeb2c..60e4722 100644 --- a/app/fn/fn.php +++ b/app/fn/fn.php @@ -2,6 +2,8 @@ use Wcms\Medialist; +use function Clue\StreamFilter\fun; + function readablesize($bytes) { $format = ' %d %s'; @@ -292,7 +294,29 @@ function recurse_copy($src,$dst) { } } closedir($dir); -} +} + +/** + * Generate a list of html drop down list + * + * @param array $options as `value => title` + * @param string|int $selected value of actualy selected option + * + * @return string HTML list of options + */ +function options(array $options, $selected = null) : string +{ + $html = ''; + foreach ($options as $value => $title) { + if($value == $selected) { + $attribute = 'selected'; + } else { + $attribute = ''; + } + $html .= '' . PHP_EOL; + } + return $html; +} diff --git a/app/view/templates/home.php b/app/view/templates/home.php index 8078d4a..204864f 100644 --- a/app/view/templates/home.php +++ b/app/view/templates/home.php @@ -30,8 +30,37 @@
-

Pages ()

+

Pages () >list / >map

+ + + + + +
+
+ + + + + + + +
+ +
+ + + + + + +
@@ -161,6 +190,8 @@
+ + -- cgit v1.2.3 From 21569fcabfdcedbdd7f0185d9a7c5518f52f880c Mon Sep 17 00:00:00 2001 From: vincent-peugnet Date: Mon, 23 Mar 2020 16:31:56 +0100 Subject: resolve conflicts --- app/class/Modelhome.php | 14 -------------- 1 file changed, 14 deletions(-) (limited to 'app') diff --git a/app/class/Modelhome.php b/app/class/Modelhome.php index 18ae1a5..9aab4f2 100644 --- a/app/class/Modelhome.php +++ b/app/class/Modelhome.php @@ -141,23 +141,9 @@ class Modelhome extends Modelpage { $datas['elements'] = $this->mapdata($pagelist); -<<<<<<< HEAD - foreach ($page->linkto() as $linkto) { - $edge['group'] = 'edges'; - $edge['data']['id'] = $page->id() . '>' . $linkto; - $edge['data']['source'] = $page->id(); - $edge['data']['target'] = $linkto; - $edges[] = $edge; - } - } - $datas['elements'] = array_merge($nodes, $edges); - - $datas['layout']['name'] = 'cose-bilkent'; -======= $datas['layout'] = [ 'name' => $layout, ]; ->>>>>>> map integration in home $datas['style'] = [ [ 'selector' => 'node', -- cgit v1.2.3 From a7174bb27de46b2f64118181221fad3658f511d3 Mon Sep 17 00:00:00 2001 From: n-peugnet Date: Mon, 23 Mar 2020 18:03:00 +0100 Subject: clean: remove temporary map dev page --- app/class/Controllerhome.php | 18 ------------------ app/class/Routes.php | 1 - app/view/templates/map.php | 15 --------------- 3 files changed, 34 deletions(-) delete mode 100644 app/view/templates/map.php (limited to 'app') diff --git a/app/class/Controllerhome.php b/app/class/Controllerhome.php index 7b7024d..4fa9a0b 100644 --- a/app/class/Controllerhome.php +++ b/app/class/Controllerhome.php @@ -93,24 +93,6 @@ class Controllerhome extends Controllerpage } } - /** - * Temporary map display function - */ - public function map() - { - if ($this->user->isadmin()) { - - $pagelist = $this->modelhome->getlister(); - $datas = $this->modelhome->mapdata($pagelist); - - $vars['json'] = json_encode($datas, JSON_PRETTY_PRINT); - - $this->showtemplate('map', $vars); - - } - - } - public function columns() { if (isset($_POST['columns']) && $this->user->iseditor()) { diff --git a/app/class/Routes.php b/app/class/Routes.php index c538d78..e71bf59 100644 --- a/app/class/Routes.php +++ b/app/class/Routes.php @@ -19,7 +19,6 @@ class Routes $router->addRoutes([ ['GET', '/', 'Controllerhome#desktop', 'home'], ['POST', '/', 'Controllerhome#desktop', 'homequery'], - ['GET', '/map', 'Controllerhome#map', 'map'], ['POST', '/columns', 'Controllerhome#columns', 'homecolumns'], ['POST', '/colors', 'Controllerhome#colors', 'homecolors'], ['GET', '//renderall', 'Controllerhome#renderall', 'homerenderall'], diff --git a/app/view/templates/map.php b/app/view/templates/map.php deleted file mode 100644 index 83e6004..0000000 --- a/app/view/templates/map.php +++ /dev/null @@ -1,15 +0,0 @@ - - -
- - - - \ No newline at end of file -- cgit v1.2.3 From 1a93d70c938f3ae2b050f3a102c961cf1cc3cefc Mon Sep 17 00:00:00 2001 From: vincent-peugnet Date: Mon, 23 Mar 2020 21:04:15 +0100 Subject: filter map and orphans hide --- app/class/Controllerhome.php | 12 +++- app/class/Model.php | 5 +- app/class/Modelhome.php | 157 ++++++++++++++++++++++++++++++------------- app/class/Modelpage.php | 26 +++++-- app/view/templates/home.php | 10 +-- 5 files changed, 151 insertions(+), 59 deletions(-) (limited to 'app') diff --git a/app/class/Controllerhome.php b/app/class/Controllerhome.php index 4fa9a0b..6444ac2 100644 --- a/app/class/Controllerhome.php +++ b/app/class/Controllerhome.php @@ -34,7 +34,12 @@ class Controllerhome extends Controllerpage $deepsearch = $this->deepsearch(); - $vars['table2'] = $this->modelhome->table2($pagelist, $this->opt, $deepsearch['regex'] , $deepsearch['searchopt']); + $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['columns'] = $this->modelhome->setcolumns($this->user->columns()); @@ -47,9 +52,10 @@ class Controllerhome extends Controllerpage $vars['searchopt'] = $deepsearch['searchopt']; $vars['display'] = $_GET['display'] ?? 'list'; - $vars['layout'] = $_GET['layout'] ?? 'random'; if($vars['display'] === 'map') { - $datas = $this->modelhome->cytodata($vars['table2'], $vars['layout']); + $vars['layout'] = $_GET['layout'] ?? 'cose-bilkent'; + $vars['hideorphans'] = boolval($_GET['hideorphans'] ?? false); + $datas = $this->modelhome->cytodata($pagelistsort, $vars['layout'], $vars['hideorphans']); $vars['json'] = json_encode($datas, JSON_PRETTY_PRINT); } diff --git a/app/class/Model.php b/app/class/Model.php index ae56c2f..9e66af4 100644 --- a/app/class/Model.php +++ b/app/class/Model.php @@ -23,9 +23,12 @@ abstract class Model const MAP_LAYOUTS = [ 'cose' => 'cose', + 'cose-bilkent' => 'cose-bilkent', 'circle' => 'circle', + 'breadthfirst' => 'breadthfirst', + 'concentric' => 'concentric', + 'grid' => 'grid', 'random' => 'random', - 'cose-bilkent' => 'cose-bilkent' ]; diff --git a/app/class/Modelhome.php b/app/class/Modelhome.php index 9aab4f2..ede9179 100644 --- a/app/class/Modelhome.php +++ b/app/class/Modelhome.php @@ -40,65 +40,84 @@ class Modelhome extends Modelpage + /** - * @param array $table + * Filter the pages list acording to the options and invert + * + * @param array $pagelist of `Page` objects * @param Opt $opt - * @param string $regex * - * @return array of `Page` object + * @return array of `string` pages id */ - public function table2(array $table, Opt $opt, string $regex = "", array $searchopt = []) : array - { + public function filter(array $pagelist, Opt $opt) : array + { - $filtertagfilter = $this->filtertagfilter($table, $opt->tagfilter(), $opt->tagcompare()); - $filterauthorfilter = $this->filterauthorfilter($table, $opt->authorfilter(), $opt->authorcompare()); - $filtersecure = $this->filtersecure($table, $opt->secure()); - $filterlinkto = $this->filterlinkto($table, $opt->linkto()); + $filtertagfilter = $this->filtertagfilter($pagelist, $opt->tagfilter(), $opt->tagcompare()); + $filterauthorfilter = $this->filterauthorfilter($pagelist, $opt->authorfilter(), $opt->authorcompare()); + $filtersecure = $this->filtersecure($pagelist, $opt->secure()); + $filterlinkto = $this->filterlinkto($pagelist, $opt->linkto()); $filter = array_intersect($filtertagfilter, $filtersecure, $filterauthorfilter, $filterlinkto); - $table2 = []; - $table2invert = []; - foreach ($table as $page) { - if (in_array($page->id(), $filter)) { - $table2[] = $page; - } else { - $table2invert[] = $page; - } - + if($opt->invert()) { + $idlist = array_keys($pagelist); + $filter = array_diff($idlist, $filter); } - if (!empty($opt->invert())) { - $table2 = $table2invert; - } + return $filter; + } - if(!empty($regex)) { - $table2 = $this->deepsearch($regex, $searchopt, $table2); - } - $this->pagelistsort($table2, $opt->sortby(), $opt->order()); + + /** + * 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 + * + * @param array $pagelist of `Page` objects + * @param Opt $opt + * + * @return array associative array of `Page` objects + */ + public function sort(array $pagelist, Opt $opt) : array + { + $this->pagelistsort($pagelist, $opt->sortby(), $opt->order()); if($opt->limit() !== 0) { - $table2 = array_slice($table2, 0, $opt->limit()); + $pagelist = array_slice($pagelist, 0, $opt->limit()); } - - return $table2; + return $pagelist; } /** * Search for regex and count occurences * + * @param array $page list Array of Pages. * @param string $regex Regex to match. * @param array $options Option search, could be `content` `title` `description`. - * @param array $page list Array of Pages. * - * @return array associative array of Pages + * @return array associative array of `Page` objects */ - public function deepsearch(string $regex, array $options, array $pagelist) : array + public function deepsearch(array $pagelist, string $regex, array $options) : array { if($options['casesensitive']) { $case = ''; @@ -128,21 +147,38 @@ class Modelhome extends Modelpage $count += preg_match($regex, $page->description()); } if ($count !== 0) { - $pageselected[] = $page; + $pageselected[$page->id()] = $page; } } return $pageselected; } + + /** * Transform list of page into list of nodes and edges + * + * @param array $pagelist associative array of pages as `id => Page` + * @param string $layout + * @param bool $hideorphans if `true`, remove orphans pages + * + * */ - public function cytodata(array $pagelist, string $layout = 'random') + public function cytodata(array $pagelist, string $layout = 'random', bool $hideorphans = false) { - $datas['elements'] = $this->mapdata($pagelist); + $datas['elements'] = $this->mapdata($pagelist, $hideorphans); $datas['layout'] = [ 'name' => $layout, + 'quality' => 'proof', + 'fit' => true, + 'randomize' => true, + 'nodeDimensionsIncludeLabels' => true, + 'tile' => false, + 'edgeElasticity' => 0.75, + 'gravity' => 0.25, + 'idealEdgeLength' => 60, + 'numIter' => 10000 ]; $datas['style'] = [ [ @@ -162,25 +198,54 @@ class Modelhome extends Modelpage return $datas; } - public function mapdata(array $pagelist) + /** + * 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 + * + * @return array of cytoscape datas + */ + public function mapdata(array $pagelist, bool $hideorphans = false) : array { - $nodes = []; + $idlist = array_keys($pagelist); + $edges = []; foreach ($pagelist as $page) { - $node['group'] = 'nodes'; - $node['data']['id'] = $page->id(); - $node['classes'] = [$page->secure('string')]; - $nodes[] = $node; + foreach ($page->linkto() as $linkto) { + if(in_array($linkto, $idlist)) { + $edge['group'] = 'edges'; + $edge['data']['id'] = $page->id() . '>' . $linkto; + $edge['data']['source'] = $page->id(); + $edge['data']['target'] = $linkto; + $edges[] = $edge; + $notorphans[] = $linkto; + } + } + if(!empty($page->linkto())) { + $notorphans[] = $page->id(); + } + } + $notorphans = array_unique($notorphans); - foreach ($page->linkto() as $linkto) { - $edge['group'] = 'edges'; - $edge['data']['id'] = $page->id() . '>' . $linkto; - $edge['data']['source'] = $page->id(); - $edge['data']['target'] = $linkto; - $edges[] = $edge; + $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 { + $node['group'] = 'nodes'; + $node['data']['id'] = $page->id(); + $node['classes'] = [$page->secure('string')]; + $nodes[] = $node; } } + return array_merge($nodes, $edges); } diff --git a/app/class/Modelpage.php b/app/class/Modelpage.php index 9344089..43ba117 100644 --- a/app/class/Modelpage.php +++ b/app/class/Modelpage.php @@ -27,7 +27,7 @@ class Modelpage extends Modeldb /** * Scan library for all pages as objects * - * @return array of Pages objects + * @return array of Pages objects as `id => Page` */ public function getlister() { @@ -232,7 +232,7 @@ class Modelpage extends Modeldb public function pagelistsort(&$pagelist, $sortby, $order = 1) { - return usort($pagelist, $this->buildsorter($sortby, $order)); + return uasort($pagelist, $this->buildsorter($sortby, $order)); } @@ -241,7 +241,7 @@ class Modelpage extends Modeldb * @param array $tagchecked list of tags * @param string $tagcompare string, can be 'OR' or 'AND', set the tag filter method * - * @return array $array + * @return array $array of `string` page id */ public function filtertagfilter(array $pagelist, array $tagchecked, $tagcompare = 'OR') @@ -267,6 +267,16 @@ class Modelpage extends Modeldb return $filteredlist; } + + + /** + * @param array $pagelist List of Page + * @param array $authorchecked list of authors + * @param string $authorcompare, can be 'OR' or 'AND', set the author filter method + * + * @return array $array of `string` page id + */ + public function filterauthorfilter(array $pagelist, array $authorchecked, $authorcompare = 'OR') { @@ -290,7 +300,15 @@ class Modelpage extends Modeldb return $filteredlist; } - public function filtersecure(array $pagelist, $secure) : array + /** + * @param array $pagelist List of Page + * @param int $secure secure level + * @param string $authorcompare, can be 'OR' or 'AND', set the author filter method + * + * @return array $array of `string` page id + */ + + public function filtersecure(array $pagelist, int $secure) : array { $filteredlist = []; foreach ($pagelist as $page) { diff --git a/app/view/templates/home.php b/app/view/templates/home.php index 204864f..33bca81 100644 --- a/app/view/templates/home.php +++ b/app/view/templates/home.php @@ -30,7 +30,7 @@
-

Pages () >list / >map

+

Pages () >list / >map

@@ -39,12 +39,12 @@
- - + > + - +
@@ -134,7 +134,7 @@ - + issupereditor()) { ?> -- cgit v1.2.3 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 +-- app/view/templates/home.php | 8 ++-- app/view/templates/homeopt.php | 2 + 6 files changed, 97 insertions(+), 50 deletions(-) (limited to 'app') 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 = '
    ' . PHP_EOL ; - foreach ($table2 as $page ) { + foreach ($pagetable as $page ) { $content .= '
  • ' . PHP_EOL; $content .= '' . $page->title() . '' . PHP_EOL; if($optlist->description()) { diff --git a/app/view/templates/home.php b/app/view/templates/home.php index 33bca81..482ce17 100644 --- a/app/view/templates/home.php +++ b/app/view/templates/home.php @@ -24,7 +24,7 @@
    - insert('homeopt', ['opt' => $opt, 'user' => $user]) ?> + insert('homeopt', ['opt' => $opt, 'user' => $user, 'display' => $display]) ?>
    @@ -39,8 +39,10 @@
    - > - + > + + > + diff --git a/app/view/templates/homeopt.php b/app/view/templates/homeopt.php index d1f70da..ed7315d 100644 --- a/app/view/templates/homeopt.php +++ b/app/view/templates/homeopt.php @@ -159,6 +159,8 @@
    + + -- cgit v1.2.3