Commit 64527781 authored by a001188's avatar a001188
Browse files

Some functions work

parent 735afea9
$(document).ready(function () {
updateGraph(0);
});
function updateGraph(centralNode){
function organisationGraph(centralNode){
$.ajax({
url: '/cmdb/api/v1/organisation/list/nodes/' + centralNode
}).then(function(nodes) {
......
$(document).ready(function () {
org_table();
});
function org_table(){
function organiationTable(){
$('#cmdb-table').jtable({
title: "Organisation",
paging: false, //Enable paging
......
$(document).ready(function () {
var ref = window.location.href;
if(ref.endsWith('family-class')){
structureTable();
structureGraph(0);
}
if(ref.endsWith('organisation')){
organiationTable();
organisationGraph(0);
}
else;
});
\ No newline at end of file
$(document).ready(function () {
updateGraph(0);
});
function updateGraph(centralNode){
function structureGraph(centralNode){
$.ajax({
url: '/cmdb/api/v1/organisation/list/nodes/' + centralNode
url: '/cmdb/api/v1/structure/list/nodes/' + centralNode
}).then(function(nodes) {
$.ajax({
url: '/cmdb/api/v1/organisation/list/edges/' + centralNode
url: '/cmdb/api/v1/structure/list/edges/' + centralNode
}).then(function(edges) {
// create a network
......
$(document).ready(function () {
function structureTable(){
$('#cmdb-table').jtable({
title: "Typer av CI-familjer",
// paging: false, //Enable paging
// pageSize: 10, //Set page size (default: 10)
// pageList: 'minimal',
// sorting: false, //Enable sorting
// multiSorting: false,
// defaultSorting: 'display_name ASC', //Set default sorting
title: "Typer av familjer",
paging: false, //Enable paging
pageSize: 10, //Set page size (default: 10)
pageList: 'minimal',
sorting: false, //Enable sorting
multiSorting: false,
defaultSorting: 'display_name ASC', //Set default sorting
actions: {
listAction: '/cmdb/api/v1/structure/family_type'
listAction: '/cmdb/api/v1/structure/family_types/'
},
fields: { //family_type
fields: {
families:{
title: '',
width: '4%',
paging: false, //Enable paging
pageSize: 10, //Set page size (default: 10)
pageList: 'minimal',
sorting: false, //Enable sorting
multiSorting: false,
defaultSorting: 'display_name ASC', //Set default sorting
display: function(family_type){
var $imgSubOrg = $('<img src="/images/organisation.png" title="Familjer" />');
$imgSubOrg.click(function () {
// updateGraph(parentOrganisation.record.id);
$('#cmdb-table').jtable('openChildTable', $imgSubOrg.closest('tr'),{
title: '+ Familjer av typen ' + family_type.record.display_name,
actions: {
listAction: '/cmdb/api/v1/structure/families/' + family_type.record.id
},
fields: { //family_type
class_types:{
title: '',
width: '4%',
paging: false, //Enable paging
pageSize: 10, //Set page size (default: 10)
pageList: 'minimal',
sorting: false, //Enable sorting
multiSorting: false,
defaultSorting: 'display_name ASC', //Set default sorting
display: function(family){
var $imgSubOrg = $('<img src="/images/organisation.png" title="Klasstyper" />');
$imgSubOrg.click(function () {
// updateGraph(parentOrganisation.record.id);
$('#cmdb-table').jtable('openChildTable', $imgSubOrg.closest('tr'),{
title: '+ + Klasstyper inom familjen ' + family.record.display_name,
actions: {
listAction: '/cmdb/api/v1/structure/class_types/' + family.record.id
},
fields: {
classes:{
title: '',
width: '4%',
paging: false, //Enable paging
pageSize: 10, //Set page size (default: 10)
pageList: 'minimal',
sorting: false, //Enable sorting
multiSorting: false,
defaultSorting: 'display_name ASC', //Set default sorting
display: function(class_type){
var $imgSubOrg = $('<img src="/images/organisation.png" title="Klasser" />');
$imgSubOrg.click(function () {
// updateGraph(parentOrganisation.record.id);
$('#cmdb-table').jtable('openChildTable', $imgSubOrg.closest('tr'),{
title: '+ + + Klasser av typen ' + class_type.record.display_name,
actions: {
listAction: '/cmdb/api/v1/structure/classes/' + class_type.record.id
},
fields: { //family_type
id: {
title: 'id',
width: '25%',
list: false,
key: true
},
display_name: {
title: 'Namn',
width: '25%'
},
description: {
title: 'Beskrivning',
width: '70%'
}
}
},
function(data){
data.childTable.jtable('load');
});
});
return $imgSubOrg;
}
},
id: {
title: 'id',
width: '25%',
list: false,
key: true
},
display_name: {
title: 'Namn',
width: '25%'
},
description: {
title: 'Beskrivning',
width: '70%'
}
}
},
function(data){
data.childTable.jtable('load');
});
});
return $imgSubOrg;
}
},
id: {
title: 'id',
width: '25%',
list: false,
key: true
},
display_name: {
title: 'Namn',
width: '25%'
},
description: {
title: 'Beskrivning',
width: '70%'
}
}
},
function(data){
data.childTable.jtable('load');
});
});
return $imgSubOrg;
}
},
id: {
title: 'id',
width: '15%',
width: '25%',
list: false,
key: true
},
display_name: {
title: 'Namn',
width: '15%'
width: '25%'
},
description: {
title: 'Beskrivning',
width: '30%'
width: '70%'
}
}
});
$('#cmdb-table').jtable('load');
});
}
......@@ -13,4 +13,4 @@ $(document).ready(
}
);
}
);
\ No newline at end of file
);
......@@ -9,7 +9,6 @@ const connectionString = process.env.DATABASE_URL || 'postgres://jasper:a001188@
/* GET home page. */
router.get('/', function(req, res, next) {
console.log = ("index" );
res.render('index', { title: 'Hem'});
});
......
......@@ -107,107 +107,6 @@ router.get('/class_list/:class_type_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 c WHERE c.id = $1 ";
sql+= "UNION ";
sql+= "SELECT sub.id, sub.display_name, sub.parent_id ";
sql+= "FROM tree, cmdb.ci sub ";
sql+= "WHERE tree.id = sub.parent_id) ";
sql+= "SELECT id, display_name as label ";
sql+= "FROM tree order by display_name ";
sql+= "limit 10; ";
/*
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();
console.log(err.message);
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 c WHERE c.id = $1 ";
sql+= "UNION ";
sql+= "SELECT sub.id, sub.display_name, sub.parent_id ";
sql+= "FROM tree, cmdb.ci sub ";
sql+= "WHERE tree.id = sub.parent_id) ";
sql+= "SELECT id as from, parent_id as to ";
sql+= "FROM tree ";
sql+= "limit 10; ";
/*
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 centralNode = [req.params['centralNode']];
client.query(sql, centralNode, function(err, result){
done();
if (err){
return res.json(JSON.parse('{"Result":"ERROR", "Message":"' + sql + '"}'));
}
else {
return res.json(result.rows);
}
});
});
});
router.post('/update', (req, res, next) => {
var id = req.body.id;
var display_name = req.body.display_name;
......
......@@ -7,7 +7,7 @@ const path = require('path');
const connectionString = process.env.DATABASE_URL || 'postgres://jasper.u:Me4sgyAp@postgresql-utv.smhi.se:5432/jasper';
router.post('/family_type', (req, res, next) => {
router.post('/family_types', (req, res, next) => {
var pool = new pg.Pool({
connectionString: connectionString,
});
......@@ -21,7 +21,7 @@ router.post('/family_type', (req, res, next) => {
}
// SQL Query > Select Data
var sql = "select * from cmdb.family_type order by sort_order;";
var sql = "select * from cmdb.family_type order by display_name;";
var parameter = [];
client.query(sql, [], function(err, result){
done();
......@@ -40,7 +40,7 @@ router.post('/family_type', (req, res, next) => {
router.post('/family/:family_type_id', (req, res, next) => {
router.post('/families/:family_type_id', (req, res, next) => {
var pool = new pg.Pool({
connectionString: connectionString,
});
......@@ -49,12 +49,11 @@ router.post('/family/:family_type_id', (req, res, next) => {
// Handle connection errors
if(err) {
done();
console.log(err);
return res.status(500).json({success: false , data: err});
}
// SQL Query > Select Data
var sql = "select * from cmdb.family where family_type_id = $1 order by sort_order;";
var sql = "select * from cmdb.family where family_type_id = $1 order by display_name;";
var parameter = [req.params['family_type_id']];
client.query(sql, parameter, function(err, result){
done();
......@@ -73,4 +72,166 @@ router.post('/family/:family_type_id', (req, res, next) => {
});
router.post('/class_types/:family_id', (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});
}
// SQL Query > Select Data
var sql = "select * from cmdb.class_type where family_id = $1 order by display_name;";
var parameter = [req.params['family_id']];
client.query(sql, parameter, function(err, result){
done();
if (err){
return res.json(JSON.parse('{"Result":"ERROR", "Message":"class_type"}'));
}
else {
var response = '{"Result":"OK", "Records":';
response+= JSON.stringify(result.rows);
response+= ',"TotalRecordCount":' + result.rowCount + '}';
return res.json(JSON.parse(response));
}
});
});
});
router.post('/classes/:class_type_id', (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});
}
// SQL Query > Select Data
var sql = "select * from cmdb.class where class_type_id = $1 order by display_name;";
var parameter = [req.params['class_type_id']];
client.query(sql, parameter, function(err, result){
done();
if (err){
return res.json(JSON.parse('{"Result":"ERROR", "Message":"class"}'));
}
else {
var response = '{"Result":"OK", "Records":';
response+= JSON.stringify(result.rows);
response+= ',"TotalRecordCount":' + result.rowCount + '}';
return res.json(JSON.parse(response));
}
});
});
});
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 c WHERE c.id = $1 ";
sql+= "UNION ";
sql+= "SELECT sub.id, sub.display_name, sub.parent_id ";
sql+= "FROM tree, cmdb.ci 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 c WHERE c.id = $1 ";
sql+= "UNION ";
sql+= "SELECT sub.id, sub.display_name, sub.parent_id ";
sql+= "FROM tree, cmdb.ci 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
*/
var centralNode = [req.params['centralNode']];
client.query(sql, centralNode, function(err, result){
done();
if (err){
return res.json(JSON.parse('{"Result":"ERROR", "Message":"' + sql + '"}'));
}
else {
return res.json(result.rows);
}
});
});
});
module.exports = router;
extends menu
block content
p
table(style="width: 100%")
tr
td(style="width: 50%")
......
......@@ -12,12 +12,16 @@ html
script(type='text/javascript', src='//cdnjs.cloudflare.com/ajax/libs/jquery-form-validator/2.1.47/jquery.form-validator.min.js')
script(type='text/javascript', src='//code.jquery.com/jquery-1.10.2.js')
script(type='text/javascript', src='//code.jquery.com/ui/1.10.4/jquery-ui.js')
script(type='text/javascript', src='/javascripts/dashlets/structure-table.js')
script(type='text/javascript', src='/javascripts/dashlets/structure-graph.js')
script(type='text/javascript', src='/javascripts/jtable/jquery.jtable.min.js')
script(type='text/javascript', src='/javascripts/jtable/jquery.jtable.js')
script(type='text/javascript', src='/javascripts/vis/dist/vis.js')
script(type='text/javascript', src='/javascripts/jtable/localization/jquery.jtable.se.js')
script(type='text/javascript', src='/javascripts/vis/dist/vis.js')
script(type='text/javascript', src='/javascripts/dashlets/select.js')
script(type='text/javascript', src='/javascripts/dashlets/organisation-table.js')
script(type='text/javascript', src='/javascripts/dashlets/organisation-graph.js')
script(type='text/javascript', src='/javascripts/dashlets/structure-table.js')
script(type='text/javascript', src='/javascripts/dashlets/structure-graph.js')
body
block menu
......
<
extends layout
block menu
table(class='cmdbguiSmallText')
tr
td(style='text-align: left') CMDB-Viewer
......@@ -8,35 +9,26 @@ block menu
nav
ul(class='nav')
li
a(href="#") Hem