-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 0d33164
Showing
17 changed files
with
706 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Arche Dashboard |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
name: arche_dashboard | ||
type: module | ||
description: 'ARCHE GUI Dashboard' | ||
core: 8.x | ||
package: oeaw | ||
configure: arche_dashboard.settings_form | ||
libraries: | ||
- arche_dashboard/repo-styles | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
arche-dashboard-css-and-js: | ||
css: | ||
theme: | ||
css/arche-dashboard.css: {} | ||
js: | ||
js/arche-dashboard.js: {} | ||
dependencies: | ||
- core/jquery |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
function arche_dashboard_page_attachments(&$page) | ||
{ | ||
// This could in most cases be added in template as well with: | ||
$page['#attached']['library'][] = 'arche_dashboard/arche-dashboard-css-and-js'; | ||
} | ||
|
||
function arche_dashboard_theme($existing, $type, $theme, $path) | ||
{ | ||
return [ | ||
//define the template name | ||
'arche-dashboard-table' => [ | ||
//define the variables | ||
'variables' => ['basic' => NULL, 'key' => NULL] | ||
], | ||
'arche-dashboard-overview' => [ | ||
'variables' => ['basic' => NULL] | ||
], | ||
]; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
### Dashboard | ||
dashboard_overview: | ||
### this will be the url on the gui | ||
path: '/dashboard_overview' | ||
defaults: | ||
### this is the function which will be called | ||
_controller: '\Drupal\arche_dashboard\Controller\DashboardController::dashboard_overview' | ||
requirements: | ||
_permission: 'access content' | ||
_access: 'TRUE' | ||
|
||
dashboard_detail: | ||
path: '/dashboard/{key}' | ||
defaults: | ||
_controller: '\Drupal\arche_dashboard\Controller\DashboardController::dashboard_detail' | ||
requirements: | ||
_permission: 'access content' | ||
_access: 'TRUE' |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "acdh-oeaw/arche-dashboard", | ||
"description": "Drupal module to ACDH ARCHE repository", | ||
"type": "drupal-module", | ||
"homepage": "https://github.com/acdh-oeaw/arche-dashboard", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Norbert Czirjak", | ||
"email": "norbert.czirjak@oeaw.ac.at" | ||
} | ||
], | ||
"require": { | ||
"acdh-oeaw/arche-core" : "*", | ||
"acdh-oeaw/arche-lib" : "*", | ||
"acdh-oeaw/arche-lib-disserv" : "*", | ||
"acdh-oeaw/arche-lib-schema" : "*" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^8" | ||
} | ||
} | ||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
(function ($, Drupal) { | ||
'use strict'; | ||
|
||
|
||
})(jQuery, Drupal); | ||
|
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
namespace Drupal\arche_dashboard\Controller; | ||
|
||
use Drupal\Core\Controller\ControllerBase; | ||
|
||
class DashboardController extends ControllerBase { | ||
|
||
private $data = array(); | ||
private $repo; | ||
private $model; | ||
|
||
public function __construct() { | ||
$this->config = drupal_get_path('module', 'acdh_repo_gui').'/config/config.yaml'; | ||
$this->repo = \acdhOeaw\acdhRepoLib\Repo::factory($this->config); | ||
//setup the dashboard model class | ||
$this->model = new \Drupal\arche_dashboard\Model\DashboardModel(); | ||
} | ||
|
||
/** | ||
* Dashboard property count view | ||
* | ||
* @return array | ||
*/ | ||
public function dashboard_detail(string $key="properties"): array { | ||
//generate the view | ||
$data = $this->generateView($key); | ||
|
||
if (count($data) > 0 ) { | ||
$cols = get_object_vars($data[0]); | ||
} else { | ||
$cols = array(); | ||
} | ||
// print_r ($cols); | ||
//return the theme with the | ||
return [ | ||
'#theme' => 'arche-dashboard-table', | ||
'#basic' => $data, | ||
'#key' => $key, | ||
'#cols' => $cols, | ||
'#cache' => ['max-age' => 0] | ||
]; | ||
} | ||
|
||
|
||
public function dashboard_overview(): array { | ||
|
||
//return the theme with the | ||
return [ | ||
'#theme' => 'arche-dashboard-overview', | ||
'#cache' => ['max-age' => 0] | ||
]; | ||
} | ||
|
||
public function generateView($key): array { | ||
|
||
//get the data from the DB | ||
$this->data = $this->model->getViewData($key); | ||
//pass the DB result to the Object generate functions | ||
|
||
return $this->data; | ||
} | ||
|
||
public function generateHeaders($key): array { | ||
|
||
return $this->model->getHeaders($key); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
namespace Drupal\arche_dashboard\Model; | ||
|
||
/** | ||
* Description of DashboardModel | ||
* | ||
* @author norbertczirjak | ||
*/ | ||
class DashboardModel { | ||
|
||
private $repodb; | ||
|
||
private $queries=array("properties"=> " | ||
SELECT | ||
property, count(*) as cnt | ||
from public.metadata | ||
group by property", | ||
"classes"=>"select value as class, count(*) as cnt | ||
from public.metadata | ||
where property = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type' | ||
group by value", | ||
"classesproperties"=>"select t_class.value as class, tp.property, count(distinct tp.value) as cnt_distinct_value, count(*) as cnt | ||
from | ||
(select id, value | ||
from public.metadata | ||
where property = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type' | ||
) t_class | ||
inner join public.metadata tp on t_class.id =tp.id | ||
group by t_class.value, tp.property" | ||
); | ||
|
||
|
||
|
||
public function __construct() { | ||
//set up the DB connections | ||
\Drupal\Core\Database\Database::setActiveConnection('repo'); | ||
$this->repodb = \Drupal\Core\Database\Database::getConnection('repo'); | ||
} | ||
|
||
/** | ||
* Generate the sql data | ||
* @return array | ||
*/ | ||
public function getViewData($key="properties"): array { | ||
|
||
if(array_key_exists($key, $this->queries)) { | ||
$queryStr = $this->queries[$key]; | ||
} else { # default query, but better to return empty result, or error message | ||
$queryStr = " | ||
SELECT | ||
property as key, count(*) as cnt | ||
from public.metadata | ||
group by property"; | ||
} | ||
try { | ||
$query = $this->repodb->query($queryStr); | ||
$return = $query->fetchAll(); | ||
|
||
$this->changeBackDBConnection(); | ||
return $return; | ||
} catch (Exception $ex) { | ||
\Drupal::logger('arche_dashboard')->notice($ex->getMessage()); | ||
return array(); | ||
} catch (\Drupal\Core\Database\DatabaseExceptionWrapper $ex) { | ||
\Drupal::logger('arche_dashboard')->notice($ex->getMessage()); | ||
return array(); | ||
} | ||
|
||
} | ||
|
||
public function changeBackDBConnection() | ||
{ | ||
\Drupal\Core\Database\Database::setActiveConnection(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
namespace Drupal\arche_dashboard\Model; | ||
|
||
/** | ||
* Description of DashboardModel | ||
* | ||
* @author norbertczirjak | ||
*/ | ||
class DashboardModel extends ArcheModel { | ||
|
||
private $repodb; | ||
|
||
private $queries=array("properties"=> " | ||
SELECT | ||
property, count(*) as cnt | ||
from public.metadata | ||
group by property", | ||
"classes"=>"select value, count(*) as cnt | ||
from public.metadata | ||
where property = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type' | ||
group by value", | ||
"classesproperties"=>"select t_class.value as cl, tp.property, count(distinct tp.value) as cnt_distinct_value, count(*) as cnt | ||
from | ||
(select id, value | ||
from public.metadata | ||
where property = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type' | ||
) t_class | ||
inner join public.metadata tp on t_class.id =tp.id | ||
group by t_class.value, tp.property" | ||
); | ||
|
||
|
||
|
||
public function __construct() { | ||
//set up the DB connections | ||
\Drupal\Core\Database\Database::setActiveConnection('repo'); | ||
$this->repodb = \Drupal\Core\Database\Database::getConnection('repo'); | ||
(isset($_SESSION['language'])) ? $this->siteLang = strtolower($_SESSION['language']) : $this->siteLang = "en"; | ||
} | ||
|
||
/** | ||
* Generate the sql data | ||
* @return array | ||
*/ | ||
public function getViewData(): array { | ||
|
||
$queryStr = " | ||
SELECT | ||
property, count(*) as cnt | ||
from public.metadata | ||
group by property"; | ||
|
||
try { | ||
$query = $this->repodb->query($queryStr); | ||
$return = $query->fetchAll(); | ||
|
||
$this->changeBackDBConnection(); | ||
return $return; | ||
} catch (Exception $ex) { | ||
\Drupal::logger('arche_dashboard')->notice($ex->getMessage()); | ||
return array(); | ||
} catch (\Drupal\Core\Database\DatabaseExceptionWrapper $ex) { | ||
\Drupal::logger('arche_dashboard')->notice($ex->getMessage()); | ||
return array(); | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<table class="display table table-striped" id='db-properties' cellspacing="0" width="100%"> | ||
<thead> | ||
<tr> | ||
<th>Property</th> | ||
<th>Counts</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{% for key,value in basic %} | ||
<tr> | ||
<td width='70%'> | ||
{{ value.property }} | ||
</td> | ||
<td width='30%'> | ||
{{ value.cnt }} | ||
</td> | ||
</tr> | ||
{% endfor %} | ||
</tbody> | ||
</table> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<h1>Dashboard</h1> | ||
<p>Statistics about metadata</p> | ||
|
||
<ul> | ||
<li><a href="dashboard/properties">Properties</a></li> | ||
<li><a href="dashboard/classes" >Classes</a></li> | ||
<li><a href="dashboard/classesproperties" >Classes properties</a></li> | ||
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<h2>Statistics - {{key}} </h2> | ||
<table class="display table table-striped" id='db-properties' cellspacing="0" width="100%"> | ||
<thead> | ||
<tr> | ||
{% for key,value in cols %} | ||
<th>{{ key }}</th> | ||
{% endfor %} | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{% for key,value in basic %} | ||
<tr> | ||
|
||
{% if value.class %} | ||
<td > | ||
{{ value.class }} | ||
</td> | ||
{% endif %} | ||
{% if value.property %} | ||
<td > | ||
{{ value.property }} | ||
</td> | ||
{% endif %} | ||
|
||
{% if value.cnt_distinct_value %} | ||
<td > | ||
{{ value.cnt_distinct_value }} | ||
</td> | ||
{% endif %} | ||
<td width='20%'> | ||
{{ value.cnt }} | ||
</td> | ||
</tr> | ||
{% endfor %} | ||
</tbody> | ||
</table> |