Skip to content

Commit 9cc361d

Browse files
committed
first commit
0 parents  commit 9cc361d

23 files changed

Lines changed: 1926 additions & 0 deletions

Module.php

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<?php
2+
3+
namespace NodeGraph;
4+
5+
use Omeka\Module\AbstractModule;
6+
use Laminas\Mvc\MvcEvent;
7+
use Laminas\EventManager\SharedEventManagerInterface;
8+
use Omeka\Entity\SitePage;
9+
use Omeka\Api\Representation\SitePageRepresentation;
10+
use Laminas\EventManager\Event;
11+
12+
13+
class Module extends AbstractModule
14+
{
15+
16+
public function getConfig(): array
17+
{
18+
return include __DIR__ . '/config/module.config.php';
19+
}
20+
21+
22+
public function onBootstrap(MvcEvent $event): void
23+
{
24+
// IMPORTANT: ensure base class runs (this is what normally calls attachListeners()).
25+
parent::onBootstrap($event);
26+
27+
$services = $event->getApplication()->getServiceManager();
28+
$viewHelperManager = $services->get('ViewHelperManager');
29+
$headScript = $viewHelperManager->get('headScript');
30+
$headLink = $viewHelperManager->get('headLink');
31+
32+
//Sigma js
33+
$headScript
34+
->appendFile('https://cdnjs.cloudflare.com/ajax/libs/graphology/0.24.0/graphology.umd.min.js')
35+
->appendFile('https://cdn.jsdelivr.net/npm/graphology-library@0.8.0/dist/graphology-library.min.js')
36+
->appendFile('https://cdnjs.cloudflare.com/ajax/libs/sigma.js/3.0.2/sigma.min.js');
37+
}
38+
39+
public function attachListeners(SharedEventManagerInterface $sem): void
40+
{
41+
// After API save (create/update) of site pages, queue builds.
42+
$sem->attach('*', 'api.create.post', [$this, 'onPageSaved']);
43+
$sem->attach('*', 'api.update.post', [$this, 'onPageSaved']);
44+
}
45+
46+
47+
public function onPageSaved(Event $event): void
48+
{
49+
$services = $this->getServiceLocator();
50+
$response = $event->getParam('response');
51+
$content = $response ? $response->getContent() : null;
52+
53+
$pages = is_array($content) ? $content : ($content ? [$content] : []);
54+
$adapter = $services->get('Omeka\ApiAdapterManager')->get('site_pages');
55+
$dispatcher = $services->get(\Omeka\Job\Dispatcher::class);
56+
$conn = $services->get('Omeka\Connection');
57+
58+
foreach ($pages as $page) {
59+
if ($page instanceof SitePage) {
60+
$page = $adapter->getRepresentation($page);
61+
}
62+
if (!$page instanceof SitePageRepresentation) {
63+
continue;
64+
}
65+
66+
foreach ($page->blocks() as $blockRep) {
67+
// Only Node graph block
68+
if ($blockRep->layout() !== 'Node Graph') {
69+
continue;
70+
}
71+
72+
$data = $blockRep->data();
73+
$cacheEnabled = !empty($data['cache_result']);
74+
if (!$cacheEnabled) {
75+
continue;
76+
}
77+
78+
// If caching is on, compute hash of inputs that affect output
79+
$hash = sha1(json_encode($data));
80+
$blockId = (int) $blockRep->id();
81+
82+
// If cache already exist, delete and rebuild
83+
$conn->executeStatement(
84+
'DELETE FROM nodegraph_cache WHERE block_id = ? AND hash = ?',
85+
[$blockId, $hash]
86+
);
87+
88+
// Queue job to (re)build the cache
89+
$dispatcher->dispatch(\NodeGraph\Job\BuildGraph::class, [
90+
'block_id' => $blockId,
91+
'hash' => $hash,
92+
'page_id' => $page->id(),
93+
]);
94+
}
95+
}
96+
}
97+
98+
public function install($serviceLocator)
99+
{
100+
$conn = $serviceLocator->get('Omeka\Connection');
101+
$conn->executeStatement('
102+
CREATE TABLE IF NOT EXISTS nodegraph_cache (
103+
block_id INT NOT NULL PRIMARY KEY,
104+
hash VARCHAR(40) NOT NULL,
105+
payload LONGTEXT NOT NULL,
106+
updated DATETIME NOT NULL
107+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
108+
');
109+
}
110+
111+
public function uninstall($serviceLocator)
112+
{
113+
$conn = $serviceLocator->get('Omeka\Connection');
114+
$conn->executeStatement('DROP TABLE IF EXISTS nodegraph_cache;');
115+
}
116+
}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Omeka S version used for testing: 4.1.1

asset/css/nodegraph.css

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/* Network graph */
2+
#network-container {
3+
width: 100%;
4+
height: 100%;
5+
border: 2px solid black;
6+
background-color: white;
7+
position: relative;
8+
}
9+
10+
#network-tooltip {
11+
position: absolute;
12+
background-color: #fff;
13+
max-width: 200px;
14+
word-wrap: break-word;
15+
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
16+
border-radius: 5px;
17+
padding: 10px;
18+
font-size: 14px;
19+
pointer-events: none;
20+
z-index: 1000;
21+
display: none;
22+
}
23+
24+
#network-tooltip p {
25+
margin-top: 5px;
26+
margin-bottom: 5px;
27+
font-size: 15px;
28+
}
29+
30+
#network-controls {
31+
position: absolute;
32+
left: 10px;
33+
bottom: 10px;
34+
z-index: 100;
35+
}
36+
37+
#legendDiv {
38+
position: absolute;
39+
/* max-width: 20%;
40+
max-height: 25%; */
41+
padding: 10px;
42+
right: 10px;
43+
bottom: 10px;
44+
z-index: 100;
45+
box-shadow: 0 1px 10px rgba(0, 0, 0, 0.4);
46+
border-radius: 10px;
47+
background-color: white;
48+
}
49+
50+
.network-button {
51+
display: block;
52+
margin-bottom: 10px;
53+
width: 50px;
54+
height: 50px;
55+
background-color: #fff;
56+
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
57+
border-radius: 5px;
58+
cursor: pointer;
59+
}
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 1 addition & 0 deletions
Loading

asset/image/sigma.js/zoom-in.svg

Lines changed: 1 addition & 0 deletions
Loading

asset/image/sigma.js/zoom-out.svg

Lines changed: 1 addition & 0 deletions
Loading

config/module.config.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace NodeGraph;
4+
5+
return [
6+
'view_manager' => [
7+
'template_path_stack' => [dirname(__DIR__) . '/view'],
8+
],
9+
'block_layouts' => [
10+
'invokables' => [
11+
'Node Graph' => \NodeGraph\Site\BlockLayout\NodeGraphBlock::class,
12+
],
13+
],
14+
'form_elements' => [
15+
'factories' => [
16+
\NodeGraph\Form\Fieldset\GroupByFieldset::class => \Laminas\ServiceManager\Factory\InvokableFactory::class,
17+
\NodeGraph\Form\Fieldset\NodeColorsFieldset::class => \Laminas\ServiceManager\Factory\InvokableFactory::class,
18+
\NodeGraph\Form\Fieldset\NodeColorPairFieldset::class => \Laminas\ServiceManager\Factory\InvokableFactory::class,
19+
\NodeGraph\Form\Fieldset\NodeIconsFieldset::class => \Laminas\ServiceManager\Factory\InvokableFactory::class,
20+
\NodeGraph\Form\Fieldset\NodeIconPairFieldset::class => \Laminas\ServiceManager\Factory\InvokableFactory::class,
21+
],
22+
],
23+
];
24+
25+
26+
// To do: Node colors and icons if preset. remove button wont work

config/module.ini

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[info]
2+
name = "Node Graph"
3+
version = "1.0.0"
4+
author = "Systemik"
5+
description = "TBD"

0 commit comments

Comments
 (0)