aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorvincent-peugnet <v.peugnet@free.fr>2020-03-23 16:19:48 +0100
committervincent-peugnet <v.peugnet@free.fr>2020-03-23 16:26:48 +0100
commit7d1b16dce7e435caefd39975ca68a08c4f79fc03 (patch)
treeb075ed8e9531bce23845eba0b9fef585901ebde1 /app
parent73e2d40ee0d82c9d68eca8db35b323db77eb5713 (diff)
downloadwcms-7d1b16dce7e435caefd39975ca68a08c4f79fc03.tar.gz
wcms-7d1b16dce7e435caefd39975ca68a08c4f79fc03.zip
map integration in home
Diffstat (limited to 'app')
-rw-r--r--app/class/Controllerhome.php7
-rw-r--r--app/class/Model.php8
-rw-r--r--app/class/Modelhome.php43
-rw-r--r--app/fn/fn.php26
-rw-r--r--app/view/templates/home.php33
5 files changed, 103 insertions, 14 deletions
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 <options> 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 .= '<option value="' . $value . '" ' . $attribute . '>' . $title . '</option>' . 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 @@
<div class="block">
- <h2 class="hidephone">Pages (<?= count($table2) ?>)</h2>
+ <h2 class="hidephone">Pages (<?= count($table2) ?>) <span class="right"><a href="?display=list" <?= $display === 'list' ? 'style="color: white"' : '' ?> >list</a> / <a href="?display=map" <?= $display === 'map' ? 'style="color: white"' : '' ?> >map</a></span> </h2>
+
+ <?php if($display === 'map') { ?>
+
+ <!-- ___________________ M A P _________________________ -->
+
+ <div id="deepsearchbar">
+ <form action="" method="get">
+ <input type="hidden" name="display" value="map">
+ <input type="checkbox" name="" id="orphan" checked>
+ <label for="orphan">Show orphans pages</label>
+ <select name="layout" id="layout">
+ <?= options(Wcms\Model::MAP_LAYOUTS, $layout) ?>
+ </select>
+ <label for="layout">graph style</label>
+ <input type="submit" value="update">
+ </form>
+ </div>
+
+ <div id="graph"></div>
+
+ <script>
+ var data = <?= $json ?>;
+ console.log(data);
+ </script>
+ <script src="<?= Wcms\Model::jspath() ?>map.bundle.js"></script>
+
+ <?php } else { ?>
+
+ <!-- ___________________ L I S T _________________________ -->
<div id="deepsearchbar" class="hidephone">
<form action="<?= $this->url('home') ?>" method="get">
@@ -161,6 +190,8 @@
</table>
</div>
+ <?php } ?>
+
</div>
</section>