Commit 0ba8a266 authored by a001188's avatar a001188
Browse files

Some functions work

parent 75c31b2a
<html>
<head>
<meta charset="UTF-8">
<link href="/stylesheets/cmdbgui.css" rel="stylesheet" type="text/css" />
<link href="/javascripts/jtable/themes/lightcolor/blue/jtable.min.css" rel="stylesheet" type="text/css" />
<link href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css" rel="stylesheet" >
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery-form-validator/2.1.47/jquery.form-validator.min.js"></script>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<title>CMDB-Viewer</title>
</head>
<body onhashchange="logoutcmdbgui(event)">
<script type="text/javascript" src="/javascripts/menu.js"></script>
<script type="text/javascript" src="/javascripts/dashlets/structure-table.js"></script>
<script type="text/javascript" src="/javascripts/dashlets/structure-graph.js"></script>
<script type="text/javascript" src="/javascripts/jtable/jquery.jtable.min.js"></script>
<script type="text/javascript" src="/javascripts/jtable/jquery.jtable.js"></script>
<script type="text/javascript" src="/javascripts/jtable/localization/jquery.jtable.se.js"></script>
<Table class='cmdbguiSmallText'>
<Tr>
<td style='text-align: left'>SMHI</td><td id="demo"></td>
<td style='text-align: right'>User: A001188 - Peter Lundin</td>
</Tr>
</Table>
<!-- Use this navigation div as your menu bar div -->
<div class="navigation">
<ul class="nav">
<li>
<a href="/">Hem</a>
</li>
<li>
<a href="#">Organisation</a>
<ul>
<li><a href="/index.html?view=0">Linjeorganisation</a></li>
<li><a href="/index.html?view=1">Förvaltningsorganisation</a></li>
<li><a href="/index.html?view=2">Teknisk Förvaltningsorganisation</a></li>
</ul>
</li>
<li>
<a href="#">Person</a>
<ul>
<li><a href="/">Linjeorganisation</a></li>
</ul>
</li>
<li>
<a href="#">IT-Tjänster</a>
<ul>
<li><a href="/">Organisation</a></li>
</ul>
</li>
<li>
<a href="#">Tjänsteobjekt</a>
<ul>
<li><a href="/">FO-relaterade</a></li>
<li><a href="/">TFO-relaterade</a></li>
</ul>
</li>
</ul>
</div>
<form class='cmdbguiSearchForm'>Sök:<input type="text" name="searchString" id="searchString"/></form>
<p class='cmdbguiSmallText'>Innehåll</p>
<div id="cmdb-structure-table"></div>
</body>
</html>
\ No newline at end of file
<html>
<head>
<meta charset="UTF-8">
<link href="/stylesheets/cmdbgui.css" rel="stylesheet" type="text/css" />
<link href="/stylesheets/network-graph.css" rel="stylesheet" type="text/css" />
<link href="/javascripts/jtable/themes/lightcolor/blue/jtable.min.css" rel="stylesheet" type="text/css" />
<link href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css" rel="stylesheet" >
<link href="/javascripts/vis/dist/vis.css" rel="stylesheet" type="text/css" />
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery-form-validator/2.1.47/jquery.form-validator.min.js"></script>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<title>CMDB-Viewer</title>
</head>
<body onhashchange="logoutcmdbgui(event)">
<script type="text/javascript" src="/javascripts/menu.js"></script>
<!--
<script type="text/javascript" src="/javascripts/vis/dist/vis.js"></script>
<script type="text/javascript" src="/javascripts/dashlets/organisation-table.js"></script>
<script type="text/javascript" src="/javascripts/dashlets/organisation-graph.js"></script>
-->
<script type="text/javascript" src="/javascripts/dashlets/structure-table.js"></script>
<script type="text/javascript" src="/javascripts/dashlets/structure-graph.js"></script>
-->
<script type="text/javascript" src="/javascripts/jtable/jquery.jtable.min.js"></script>
<script type="text/javascript" src="/javascripts/jtable/jquery.jtable.js"></script>
<script type="text/javascript" src="/javascripts/jtable/localization/jquery.jtable.se.js"></script>
<Table class='cmdbguiSmallText'>
<Tr>
<td style='text-align: left'>SMHI</td><td id="demo"></td>
<td style='text-align: right'>User: A001188 - Peter Lundin</td>
</Tr>
</Table>
<!-- Use this navigation div as your menu bar div -->
<div class="navigation">
<ul class="nav">
<li>
<a href="/">Hem</a>
</li>
<li>
<a href="#">Organisation</a>
<ul>
<li><a href="/index.html?view=0">Linjeorganisation</a></li>
<li><a href="/index.html?view=1">Förvaltningsorganisation</a></li>
<li><a href="/index.html?view=2">Teknisk Förvaltningsorganisation</a></li>
</ul>
</li>
<li>
<a href="#">Person</a>
<ul>
<li><a href="/">Linjeorganisation</a></li>
</ul>
</li>
<li>
<a href="#">IT-Tjänster</a>
<ul>
<li><a href="/">Organisation</a></li>
</ul>
</li>
<li>
<a href="#">Tjänsteobjekt</a>
<ul>
<li><a href="/">FO-relaterade</a></li>
<li><a href="/">TFO-relaterade</a></li>
</ul>
</li>
</ul>
</div>
<form class='cmdbguiSearchForm'>Sök:<input type="text" name="searchString" id="searchString"/></form>
<p class='cmdbguiSmallText'>Innehåll</p>
<div id="cmdb-table"></div>
<!--
<p class='cmdbguiSmallText'>Relationer</p>
<div id="mynetwork"></div>
-->
</body>
</html>
\ No newline at end of file
<html>
<head>
<link href="/javascripts/vis/dist/vis.css" rel="stylesheet" type="text/css" />
<link href="/stylesheets/network-graph.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="/javascripts/vis/dist/vis.js"></script>
</head>
<body>
<div id="mynetwork"></div>
<script type="text/javascript" src="/javascripts/dashlets/organisation-graph.js"></script>
</body>
</html>
\ No newline at end of file
This diff is collapsed.
subOrg1: {
title: '',
width: '1%',
sorting: false,
edit: false,
create: false,
delete: false,
display: function(data){
var $imgSubOrg = $('<img src="/images/organisation.png" title="Nivå 2" />');
$imgSubOrg.click(function () {
$('#displayarea').jtable('openChildTable', $imgSubOrg.closest('tr'),{
title: 'Organisation nivå 2',
showCloseButton: false,
actions: {
listAction: '/cmdb/api/v1/organisation/list/5' , // select all rows with parent === data.record.id
},
fields: {
closeChild: {
title: '',
width: '1%',
sorting: false,
edit: false,
create: false,
delete: false,
display: function(){
var $imgClose = $('img src="/images/cross.png');
$imgClose.click(function() {
$('#displayarea').jtable('closeChildTable', $($imgClose.closest('tr')));
});
return $imgClose;
}
},
id: {
title: 'id',
width: '15%',
list: false,
key: true
},
display_name: {
title: 'Namn',
width: '15%'
},
description: {
title: 'Beskrivning',
width: '30%'
},
organisation_type: {
title: 'Typ',
options: '/cmdb/api/v1/organisation/types',
width: '15%'
},
organisation_level: {
title: 'Nivå',
options: '/cmdb/api/v1/organisation/levels',
width: '15%'
},
parent_organisation_id: {
list: false,
title: 'Överordnad organisation',
options: '/cmdb/api/v1/organisation/parents',
width: '15%'
}
},
},
function(data){
data.childTable.jtable('load');
});
});
return $imgSubOrg;
}
},
......@@ -17,6 +17,7 @@ function organisationGraph(centralNode){
};
var options = {
height: '1200px',
layout: {
randomSeed: undefined,
improvedLayout:true,
......
......@@ -39,9 +39,8 @@ function organiationTable(){
delete: false,
display: function(parentOrganisation){
var $imgSubOrg = $('<img src="/images/organisation.png" title="Nivå 2" />');
var $imgSubOrg = $('<img src="/images/organisation.png" title="Till nivå 2" />');
$imgSubOrg.click(function () {
updateGraph(parentOrganisation.record.id);
$('#cmdb-table').jtable('openChildTable', $imgSubOrg.closest('tr'),{
title: parentOrganisation.record.display_name + ':s underliggande organisationer',
showCloseButton: true,
......@@ -59,8 +58,7 @@ function organiationTable(){
display: function(parentOrganisation){
var $imgSubOrg = $('<img src="/images/organisation.png" title="Nivå 3" />');
$imgSubOrg.click(function () {
updateGraph(parentOrganisation.record.id);
$imgSubOrg.click(function (data) {
$('#cmdb-table').jtable('openChildTable', $imgSubOrg.closest('tr'),{
title: parentOrganisation.record.display_name + ':s underliggande organisationer',
showCloseButton: true,
......@@ -78,7 +76,7 @@ function organiationTable(){
display: function(parentOrganisation){
var $imgSubOrg = $('<img src="/images/organisation.png" title="Nivå 4" />');
$imgSubOrg.click(function () {
$imgSubOrg.click(function (data) {
updateGraph(parentOrganisation.record.id);
$('#cmdb-table').jtable('openChildTable', $imgSubOrg.closest('tr'),{
title: parentOrganisation.record.display_name + ':s underliggande organisationer',
......@@ -97,8 +95,7 @@ function organiationTable(){
display: function(parentOrganisation){
var $imgSubOrg = $('<img src="/images/organisation.png" title="Nivå 5" />');
$imgSubOrg.click(function () {
updateGraph(parentOrganisation.record.id);
$imgSubOrg.click(function (data) {
$('#cmdb-table').jtable('openChildTable', $imgSubOrg.closest('tr'),{
title: parentOrganisation.record.display_name + ':s underliggande organisationer',
showCloseButton: true,
......@@ -120,20 +117,14 @@ function organiationTable(){
title: 'Beskrivning',
width: '30%'
},
organisation_type: {
family_id: {
title: 'Typ',
options: '/cmdb/api/v1/organisation/class_list/0',
options: '/cmdb/api/v1/organisation/families/0', //family_type_id
width: '15%'
},
organisation_level: {
level_id: {
title: 'Nivå',
options: '/cmdb/api/v1/organisation/class_list/1',
width: '15%'
},
parent_organisation_id: {
list: false,
title: 'Överordnad organisation',
options: '/cmdb/api/v1/organisation/class_list2',
options: '/cmdb/api/v1/organisation/classes/0', //class_type_id
width: '15%'
}
}
......@@ -159,20 +150,14 @@ function organiationTable(){
title: 'Beskrivning',
width: '30%'
},
organisation_type: {
family_id: {
title: 'Typ',
options: '/cmdb/api/v1/organisation/types',
options: '/cmdb/api/v1/organisation/families/0', //family_type_id
width: '15%'
},
organisation_level: {
level_id: {
title: 'Nivå',
options: '/cmdb/api/v1/organisation/levels',
width: '15%'
},
parent_organisation_id: {
list: false,
title: 'Överordnad organisation',
options: '/cmdb/api/v1/organisation/parents',
options: '/cmdb/api/v1/organisation/classes/0', //class_type_id
width: '15%'
}
}
......@@ -198,20 +183,14 @@ function organiationTable(){
title: 'Beskrivning',
width: '30%'
},
organisation_type: {
family_id: {
title: 'Typ',
options: '/cmdb/api/v1/organisation/types',
options: '/cmdb/api/v1/organisation/families/0', //family_type_id
width: '15%'
},
organisation_level: {
level_id: {
title: 'Nivå',
options: '/cmdb/api/v1/organisation/levels',
width: '15%'
},
parent_organisation_id: {
list: false,
title: 'Överordnad organisation',
options: '/cmdb/api/v1/organisation/parents',
options: '/cmdb/api/v1/organisation/classes/0', //class_type_id
width: '15%'
}
}
......@@ -237,20 +216,14 @@ function organiationTable(){
title: 'Beskrivning',
width: '30%'
},
organisation_type: {
family_id: {
title: 'Typ',
options: '/cmdb/api/v1/organisation/types',
options: '/cmdb/api/v1/organisation/families/0', //family_type_id
width: '15%'
},
organisation_level: {
level_id: {
title: 'Nivå',
options: '/cmdb/api/v1/organisation/levels',
width: '15%'
},
parent_organisation_id: {
list: false,
title: 'Överordnad organisation',
options: '/cmdb/api/v1/organisation/parents',
options: '/cmdb/api/v1/organisation/classes/0', //class_type_id
width: '15%'
}
}
......@@ -276,20 +249,14 @@ function organiationTable(){
title: 'Beskrivning',
width: '30%'
},
organisation_type: {
family_id: {
title: 'Typ',
options: '/cmdb/api/v1/organisation/class_list/0',
options: '/cmdb/api/v1/organisation/families/0', //family_type_id
width: '15%'
},
organisation_level: {
level_id: {
title: 'Nivå',
options: '/cmdb/api/v1/organisation/class_list/2',
width: '15%'
},
parent_organisation_id: {
list: false,
title: 'Överordnad organisation',
options: '/cmdb/api/v1/organisation/parent',
options: '/cmdb/api/v1/organisation/classes/0', //class_type_id
width: '15%'
}
}
......
......@@ -5,17 +5,18 @@ function relationGraph(){
$.ajax({
url: '/cmdb/api/v1/relation/edges/'
}).then(function(edges) {
// create a network
var container = document.getElementById('cmdb-net');
// provide the data in the vis format
// provide the data in the vis format
var data = {
nodes: nodes,
edges: edges
};
var options = {};
var options = {
height: '1200px'
};
// options.nodes = {
// color: 'gray'
// }
......
$(document).ready(function () {
var ref = window.location.href;
if(ref.endsWith('family-and-class')){
structureTable();
structureGraph(0);
// structureGraph(0);
}
if(ref.endsWith('organisation')){
organiationTable();
organisationGraph(0);
organiationTable(1);
organisationGraph(1);
}
if(ref.endsWith('relation-types')){
relationTypesTable();
......
......@@ -16,21 +16,22 @@ function structureGraph(centralNode){
};
var options = {
layout: {
randomSeed: undefined,
improvedLayout:true,
hierarchical: {
enabled:true,
levelSeparation: 150,
nodeSpacing: 100,
treeSpacing: 200,
blockShifting: true,
edgeMinimization: true,
parentCentralization: true,
direction: 'DU', // UD, DU, LR, RL
sortMethod: 'directed' // hubsize, directed
height: '1200px',
layout: {
randomSeed: undefined,
improvedLayout:true,
hierarchical: {
enabled:true,
levelSeparation: 150,
nodeSpacing: 100,
treeSpacing: 200,
blockShifting: true,
edgeMinimization: true,
parentCentralization: true,
direction: 'DU', // UD, DU, LR, RL
sortMethod: 'directed' // hubsize, directed
}
}
}
};
// options.nodes = {
// color: 'gray'
......
......@@ -14,11 +14,9 @@ router.get('/', function(req, res, next) {
});
router.get('/view/:id', function(req, res, next) {
var id = req.params['id'];
var id_table = id + '_table';
var id_net = id + '_net';
var id = 'cmdb - ' + req.params['id'];
res.render('index', { title: id, id_table: id_table, id_net: id_net});
res.render('index', { title: id});
});
module.exports = router;
......@@ -8,7 +8,107 @@ const connectionString = process.env.DATABASE_URL || 'postgres://jasper.u:Me4sgy
//const connectionString = process.env.DATABASE_URL || 'postgres://metrix:a001188@localhost:5432/metrix';
router.post('/class/:id', (req, res, next) => {
router.get('/list/nodes/:centralNode', (req, res, next) => {
var pool = new pg.Pool({
connectionString: connectionString
});
// Get a Postgres client from the connection pool
pool.connect(function(err, client, done){
// Handle connection errors
if(err) {
done();
return res.status(500).json({success: false , data: err});
}
// all leaf
var sql = "WITH RECURSIVE tree(id, display_name, parent_id) AS (";
sql+= "SELECT id, display_name, parent_id FROM cmdb.ci_family_organisation c WHERE family_type_id=0 and c.id = $1 ";
sql+= "UNION ";
sql+= "SELECT sub.id, sub.display_name, sub.parent_id ";
sql+= "FROM tree, cmdb.ci_family_organisation sub ";
sql+= "WHERE tree.id = sub.parent_id) ";
sql+= "SELECT id, display_name as label ";
sql+= "FROM tree order by display_name ";
sql+= "limit 100; ";
/*
too root
WITH RECURSIVE org(id, display_name, parent_organisation_id) AS (
SELECT id, display_name, parent_organisation_id FROM cmdb.organisation org WHERE org.id = 6
UNION
SELECT sub.id, sub.display_name, sub.parent_organisation_id
FROM org, cmdb.organisation sub
WHERE sub.id = org.parent_organisation_id
)
SELECT id, display_name, parent_organisation_id
FROM org
limit 10
*/
// var sql = "select id, concat(id, '. ', (select display_name from cmdb.organisation_type as ot where// ot.id=organisation_type), ': ', display_name) as label from cmdb.organisation where id >0;";
var centralNode = req.params['centralNode'];
client.query(sql, [centralNode], function(err, result){
done();
if (err){ //
//console.log(err.message);
return res.json(JSON.parse('{"Result":"ERROR", "Message":"' + err.message + '"}'));
}
else {
return res.json(result.rows);
}
});
});
});
router.get('/list/edges/:centralNode', (req, res, next) => {
var pool = new pg.Pool({
connectionString: connectionString
});
// Get a Postgres client from the connection pool
pool.connect(function(err, client, done){
// Handle connection errors
if(err) {
done();
return res.status(500).json({success: false , data: err});
}
var sql = "WITH RECURSIVE tree(id, display_name, parent_id) AS (";
sql+= "SELECT id, display_name, parent_id FROM cmdb.ci_family_organisation c WHERE family_type_id=0 and c.id = $1 ";
sql+= "UNION ";
sql+= "SELECT sub.id, sub.display_name, sub.parent_id ";
sql+= "FROM tree, cmdb.ci_family_organisation sub ";
sql+= "WHERE tree.id = sub.parent_id) ";
sql+= "SELECT id as from, parent_id as to ";
sql+= "FROM tree ";
sql+= "limit 100; ";
/*
too root
WITH RECURSIVE org(id, display_name, parent_organisation_id) AS (
SELECT id, display_name, parent_organisation_id FROM cmdb.organisation org WHERE org.id = 6
UNION
SELECT sub.id, sub.display_name, sub.parent_organisation_id
FROM org, cmdb.organisation sub
WHERE sub.id = org.parent_organisation_id
)
SELECT id, display_name, parent_organisation_id
FROM org
limit 10
*/