Skip to content

Commit

Permalink
dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
nczirjak-acdh committed May 14, 2020
0 parents commit 0d33164
Show file tree
Hide file tree
Showing 17 changed files with 706 additions and 0 deletions.
340 changes: 340 additions & 0 deletions LICENSE.txt

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Arche Dashboard
9 changes: 9 additions & 0 deletions arche_dashboard.info.yml
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

8 changes: 8 additions & 0 deletions arche_dashboard.libraries.yml
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
22 changes: 22 additions & 0 deletions arche_dashboard.module
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]
],
];
}

18 changes: 18 additions & 0 deletions arche_dashboard.routing.yml
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 added arche_dashboard.services.yml
Empty file.
23 changes: 23 additions & 0 deletions composer.json
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 added css/arche-dashboard.css
Empty file.
6 changes: 6 additions & 0 deletions js/arche-dashboard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(function ($, Drupal) {
'use strict';


})(jQuery, Drupal);

Binary file added src/.DS_Store
Binary file not shown.
68 changes: 68 additions & 0 deletions src/Controller/DashboardController.php
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);
}
}
77 changes: 77 additions & 0 deletions src/Model/DashboardModel.php
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();
}

}
70 changes: 70 additions & 0 deletions src/Model/DashboardModel_noParam.php
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();
}

}

}
20 changes: 20 additions & 0 deletions templates/acdh-repo-gui-dashboard-property.html.twig
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>
8 changes: 8 additions & 0 deletions templates/arche-dashboard-overview.html.twig
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>
36 changes: 36 additions & 0 deletions templates/arche-dashboard-table.html.twig
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>

0 comments on commit 0d33164

Please sign in to comment.