Commit 160966c2 authored by a001188's avatar a001188
Browse files

Some functions works

parent ed37407e
......@@ -7,10 +7,11 @@ var bodyParser = require('body-parser');
var lessMiddleware = require('less-middleware');
var $ = require("jquery");
var index = require('./routes/index');
var relation = require('./routes/relation');
var access = require('./routes/access');
var options = require('./routes/options');
var ci = require('./routes/ci');
var organisation = require('./routes/organisation');
var relation = require('./routes/relation');
var structure = require('./routes/structure');
var users = require('./routes/users');
var app = express();
......@@ -38,8 +39,9 @@ app.use('/', index);
app.use('/view', index);
app.use('/users', users);
app.use('/cmdb/api/v1/options', options);
app.use('/cmdb/api/v1/relation', relation);
app.use('/cmdb/api/v1/access', access);
app.use('/cmdb/api/v1/organisation', organisation);
app.use('/cmdb/api/v1/relation', relation);
app.use('/cmdb/api/v1/structure', structure);
app.use('/cmdb/api/v1/ci', ci);
......
function relationGraph(){
function accessGraph(){
$.ajax({
url: '/cmdb/api/v1/relation/nodes'
url: '/cmdb/api/v1/access/nodes'
}).then(function(nodes) {
$.ajax({
url: '/cmdb/api/v1/relation/edges/'
url: '/cmdb/api/v1/access/edges/'
}).then(function(edges) {
// create a network
var container = document.getElementById('cmdb-net');
......@@ -13,6 +13,7 @@ function relationGraph(){
nodes: nodes,
edges: edges
};
for(var i = 0; i<nodes.length; i++){
if(nodes[i].type==='account'){
data.nodes[i].color = '#ffa0a0';
......@@ -25,9 +26,6 @@ function relationGraph(){
var options = {
height: '800px'
};
// options.nodes = {
// color: 'gray'
// }
// initialize your network!
var network = new vis.Network(container, data, options);
......
function relationNodesTable(){
function accessNodesTable(){
$('#cmdb-table').jtable({
title: "Konton och grupper",
paging: false, //Enable paging
......@@ -8,7 +8,7 @@ function relationNodesTable(){
multiSorting: false,
defaultSorting: 'display_name ASC', //Set default sorting
actions: {
listAction: '/cmdb/api/v1/relation/security/list'
listAction: '/cmdb/api/v1/access/security/list'
},
fields: {
id: {
......
......@@ -13,38 +13,38 @@ function columnDef(){
family_type_id: {
title: 'Familjetyp',
options: '/cmdb/api/v1/options/family_type',
width: '15%'
width: '5%'
},
family_id: {
title: 'Familj',
options: '/cmdb/api/v1/options/families',
width: '15%'
width: '5%'
},
id: {
title: 'id',
width: '15%',
width: '1%',
list: false,
key: true
},
display_name: {
title: 'Namn',
width: '15%'
width: '10%'
},
description: {
title: 'Beskrivning',
width: '30%'
width: '15%'
},
kst: {
title: 'Kostnadsställe',
width: '15%'
width: '5%'
},
product: {
title: 'Produkt',
width: '15%'
width: '5%'
},
sla: {
title: 'SLA',
width: '15%'
width: '5%'
},
class_information: {
title: 'Klasser',
......@@ -52,7 +52,7 @@ function columnDef(){
},
attribute_information: {
title: 'Attribut',
width: '15%'
width: '20%'
},
// account_group: {
// title: 'Grupper',
......
......@@ -20,121 +20,122 @@ function structureTable(){
sorting: false, //Enable sorting
multiSorting: false,
defaultSorting: 'display_name ASC', //Set default sorting
display: function(family_type){
var $imgSubOrg = $('<img src="/images/structure.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/structure.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/structure.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: '3%',
list: true,
key: true
},
display_name: {
title: 'Namn',
width: '25%'
display: function(family){
if(family.record.cnt>0){
var $imgSubOrg = $('<img src="/images/structure.png" title="Familjer" />');
$imgSubOrg.click(function () {
$('#cmdb-table').jtable('openChildTable', $imgSubOrg.closest('tr'),{
title: '+ Familjer av typen ' + family.record.display_name,
actions: {
listAction: '/cmdb/api/v1/structure/families/' + family.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(class_type){
if(class_type.record.cnt>0){
var $imgSubOrg = $('<img src="/images/structure.png" title="Klasstyper" />');
$imgSubOrg.click(function () {
$('#cmdb-table').jtable('openChildTable', $imgSubOrg.closest('tr'),{
title: '+ + Klasstyper inom familjen ' + class_type.record.display_name,
actions: {
listAction: '/cmdb/api/v1/structure/class_types/' + class_type.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(classes){
var $imgSubOrg = $('<img src="/images/structure.png" title="Klasser" />');
$imgSubOrg.click(function () {
$('#cmdb-table').jtable('openChildTable', $imgSubOrg.closest('tr'),{
title: '+ + + Klasser av typen ' + classes.record.display_name,
actions: {
listAction: '/cmdb/api/v1/structure/classes/' + classes.record.id
},
fields: { //family_type
id: {
title: 'id',
width: '3%',
list: true,
key: true
},
display_name: {
title: 'Namn',
width: '25%'
},
description: {
title: 'Beskrivning',
width: '70%'
}
}
},
description: {
title: 'Beskrivning',
width: '70%'
}
}
},
function(data){
data.childTable.jtable('load');
});
});
return $imgSubOrg;
function(data){
data.childTable.jtable('load');
});
});
return $imgSubOrg;
}
},
id: {
title: 'id',
width: '3%',
list: true,
key: true
},
display_name: {
title: 'Namn',
width: '25%'
},
description: {
title: 'Beskrivning',
width: '70%'
}
}
},
id: {
title: 'id',
width: '3%',
list: true,
key: true
},
display_name: {
title: 'Namn',
width: '25%'
},
description: {
title: 'Beskrivning',
width: '70%'
}
}
},
function(data){
data.childTable.jtable('load');
});
});
return $imgSubOrg;
function(data){
data.childTable.jtable('load');
});
});
return $imgSubOrg;
}
}
},
id: {
title: 'id',
width: '3%',
list: true,
key: true
},
display_name: {
title: 'Namn',
width: '25%'
},
description: {
title: 'Beskrivning',
width: '70%'
}
},
id: {
title: 'id',
width: '3%',
list: true,
key: true
},
display_name: {
title: 'Namn',
width: '25%'
},
description: {
title: 'Beskrivning',
width: '70%'
}
}
},
function(data){
data.childTable.jtable('load');
},
function(data){
data.childTable.jtable('load');
});
});
});
return $imgSubOrg;
return $imgSubOrg;
}
}
},
id: {
......
function structureTable(){
$('#cmdb-table').jtable(createTable(columnDef()));
$('#cmdb-table').jtable('load');
}
function columnDef(){
var cd = {
next: {
title: 'Nästa',
width: '1%',
display: renderSubTable
},
id: {
title: 'id',
width: '3%',
list: true,
key: true
},
display_name: {
title: 'Namn',
width: '25%'
},
description: {
title: 'Beskrivning',
width: '70%'
}
}
return cd;
}
function createTable(columnDef){
var table = {
title: "Konfigurationselement",
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/ci/enterprise_service/list'
},
fields: columnDef
};
return table;
}
function renderSubTable (data) {
//updateGraph(parentOrganisation.record.id);
if(data.record.childs > 0){
return $('<img src="/images/structure.png" title="Nästa nivå"/>').click(function () {
createSubTable(data, $(this).closest('tr'));
});
}
}
function createSubTable(data, row){
$('#cmdb-table').jtable('openChildTable', row, {
title: 'Komponenter till ' + data.record.display_name,
actions: {
listAction: '/cmdb/api/v1/ci/child/list/' + data.record.id
},
fields: columnDef()
},
function (data) { //opened handler
data.childTable.jtable('load');
});
}
function getFamilyId(data){
return data.record.family_type_id;
}
\ No newline at end of file
......@@ -15,7 +15,7 @@ $(document).ready(function () {
relationTypesTable();
}
if(ref.includes('/access/')){
relationNodesTable();
relationGraph();
accessNodesTable();
accessGraph();
}
});
\ No newline at end of file
var express = require('express');
var router = express.Router();
const pg = require('pg');
const jQuery = require('jquery');
const path = require('path');
const connectionString = process.env.DATABASE_URL || 'postgres://jasper.u:Me4sgyAp@postgresql-utv.smhi.se:5432/jasper';
router.post('/types', (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.relation_type order by display_name;";
var parameter = [];
client.query(sql, parameter, function(err, result){
done();
if (err){
return res.json(JSON.parse('{"Result":"ERROR", "Message":"relation_type"}'));
}
else {
var response = '{"Result":"OK", "Records":';
response+= JSON.stringify(result.rows);
response+= ',"TotalRecordCount":' + result.rowCount + '}';
return res.json(JSON.parse(response));
}
});
});
});
router.post('/security/list', (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 *, group_type_id as class_id from cmdb.ci_family_group union select *, account_type_id as class_id from cmdb.ci_family_account order by class_id "
var parameter = [];
client.query(sql, [], function(err, result){
done();
if (err){
return res.json(JSON.parse('{"Result":"ERROR", "Message":"' + sql + '"}'));
}
else {
var response = '{"Result":"OK", "Records":';
response+= JSON.stringify(result.rows);
response+= ',"TotalRecordCount":' + result.rowCount + '}';
return res.json(JSON.parse(response));
}
});
});
});
router.post('/security/: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 *, group_type_id as class_id from cmdb.ci_family_group union select *, account_type_id as class_id from cmdb.ci_family_account order by class_id "
var parameter = [];
client.query(sql, [], function(err, result){
done();
if (err){
return res.json(JSON.parse('{"Result":"ERROR", "Message":"' + sql + '"}'));
}
else {
var response = '{"Result":"OK", "Records":';
response+= JSON.stringify(result.rows);
response+= ',"TotalRecordCount":' + result.rowCount + '}';
return res.json(JSON.parse(response));
}
});
});
});
router.post('/node/list', (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 id, display_name as label, description from cmdb.ci c inner join cmdb.relation r on c.id=r.to_ci_id ";
sql+= "union ";
sql+= "select id, display_name as label, description from cmdb.ci c inner join cmdb.relation r on c.id=r.from_ci_id ";
sql+= "group by id, display_name, description"
var parameter = [];
client.query(sql, [], function(err, result){
done();
if (err){
return res.json(JSON.parse('{"Result":"ERROR", "Message":"' + sql + '"}'));
}
else {
var response = '{"Result":"OK", "Records":';
response+= JSON.stringify(result.rows);
response+= ',"TotalRecordCount":' + result.rowCount + '}';
return res.json(JSON.parse(response));
}
});
});