Commit 7c0ac8b0 authored by a001188's avatar a001188
Browse files

Some functions work

parent 5e835aea
......@@ -10,6 +10,16 @@ function columnDef(){
width: '1%',
display: renderSubTable
},
family_type_id: {
title: 'Familjetyp',
options: '/cmdb/api/v1/options/family_type',
width: '15%'
},
family_id: {
title: 'Familj',
options: '/cmdb/api/v1/options/families',
width: '15%'
},
id: {
title: 'id',
width: '15%',
......@@ -24,16 +34,6 @@ function columnDef(){
title: 'Beskrivning',
width: '30%'
},
family_type_id: {
title: 'Familjetyp',
options: '/cmdb/api/v1/options/family_type', //+ data.options.family_type_id
width: '15%'
},
family_id: {
title: 'Familj',
//options: '/cmdb/api/v1/options/families/' + data.record.family_type_id,
width: '15%'
},
kst: {
title: 'Kostnadsställe',
width: '15%'
......@@ -54,18 +54,18 @@ function columnDef(){
title: 'Attribut',
width: '15%'
},
account_group: {
title: 'Grupper',
width: '15%'
},
account_id: {
title: 'Konton',
width: '15%'
},
contacts: {
title: 'Kontaktpersoner',
width: '15%'
}
// account_group: {
// title: 'Grupper',
// width: '15%'
// },
// account_id: {
// title: 'Konton',
// width: '15%'
// },
// contacts: {
// title: 'Kontaktpersoner',
// width: '15%'
// }
}
return cd;
}
......@@ -115,3 +115,6 @@ function columnDef(){
});
}
function getFamilyId(data){
return data.record.family_type_id;
}
\ No newline at end of file
function ciTable(){
$('#cmdb-table').jtable({
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: {
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(data){
var $imgSubOrg = $('<img src="/images/organisation.png" title="Underliggande komponenter" />');
$imgSubOrg.click(function () {
// updateGraph(parentOrganisation.record.id);
$('#cmdb-table').jtable('openChildTable', $imgSubOrg.closest('tr'),{
title: '+ Komponenter under ' + data.record.display_name,
actions: {
listAction: '/cmdb/api/v1/ci/child/list/' + data.record.id
},
fields: {
id: {
title: 'id',
width: '15%',
list: false,
key: true
},
display_name: {
title: 'Namn',
width: '15%'
},
description: {
title: 'Beskrivning',
width: '30%'
},
family_type_id: {
title: 'Familjetyp',
options: '/cmdb/api/v1/options/family_type', //+ data.options.family_type_id
width: '15%'
},
family_id: {
title: 'Familj',
display: function(data){
options: '/cmdb/api/v1/options/families/' + data.record.family_type_id;
},
width: '15%'
},
kst: {
title: 'Kostnadsställe',
width: '15%'
},
product: {
title: 'Produkt',
width: '15%'
},
sla: {
title: 'SLA',
width: '15%'
},
class_information: {
title: 'Klasser',
width: '15%'
},
attribute_information: {
title: 'Attribut',
width: '15%'
},
// account_group: {
// title: 'Grupper',
// width: '15%'
// },
// account_id: {
// title: 'Konton',
// width: '15%'
// },
// contacts: {
// title: 'Kontaktpersoner',
// width: '15%'
// }
}
},
function(data){
data.childTable.jtable('load');
});
});
return $imgSubOrg;
}
},
id: {
title: 'id',
width: '15%',
list: false,
key: true
},
display_name: {
title: 'Namn',
width: '15%'
},
description: {
title: 'Beskrivning',
width: '30%'
},
family_type_id: {
title: 'Familjetyp',
options: '/cmdb/api/v1/options/family_type',
width: '15%'
},
family_id: {
title: 'Familj',
display: function(data){
options: '/cmdb/api/v1/options/families/' + data.record.family_type_id;
},
width: '15%'
},
kst: {
title: 'Kostnadsställe',
width: '15%'
},
product: {
title: 'Produkt',
width: '15%'
},
sla: {
title: 'SLA',
width: '15%'
},
class_information: {
title: 'Klasser',
width: '15%'
},
attribute_information: {
title: 'Attribut',
width: '15%'
},
// account_group: {
// title: 'Grupper',
// width: '15%'
// },
// account_id: {
// title: 'Konton',
// width: '15%'
// },
// contacts: {
// title: 'Kontaktpersoner',
// width: '15%'
// }
}
});
$('#cmdb-table').jtable('load');
}
......@@ -21,7 +21,7 @@ function structureTable(){
multiSorting: false,
defaultSorting: 'display_name ASC', //Set default sorting
display: function(family_type){
var $imgSubOrg = $('<img src="/images/organisation.png" title="Familjer" />');
var $imgSubOrg = $('<img src="/images/structure.png" title="Familjer" />');
$imgSubOrg.click(function () {
// updateGraph(parentOrganisation.record.id);
$('#cmdb-table').jtable('openChildTable', $imgSubOrg.closest('tr'),{
......@@ -40,7 +40,7 @@ function structureTable(){
multiSorting: false,
defaultSorting: 'display_name ASC', //Set default sorting
display: function(family){
var $imgSubOrg = $('<img src="/images/organisation.png" title="Klasstyper" />');
var $imgSubOrg = $('<img src="/images/structure.png" title="Klasstyper" />');
$imgSubOrg.click(function () {
// updateGraph(parentOrganisation.record.id);
$('#cmdb-table').jtable('openChildTable', $imgSubOrg.closest('tr'),{
......@@ -59,7 +59,7 @@ function structureTable(){
multiSorting: false,
defaultSorting: 'display_name ASC', //Set default sorting
display: function(class_type){
var $imgSubOrg = $('<img src="/images/organisation.png" title="Klasser" />');
var $imgSubOrg = $('<img src="/images/structure.png" title="Klasser" />');
$imgSubOrg.click(function () {
// updateGraph(parentOrganisation.record.id);
$('#cmdb-table').jtable('openChildTable', $imgSubOrg.closest('tr'),{
......@@ -70,8 +70,8 @@ function structureTable(){
fields: { //family_type
id: {
title: 'id',
width: '25%',
list: false,
width: '3%',
list: true,
key: true
},
display_name: {
......@@ -93,8 +93,8 @@ function structureTable(){
},
id: {
title: 'id',
width: '25%',
list: false,
width: '3%',
list: true,
key: true
},
display_name: {
......@@ -116,8 +116,8 @@ function structureTable(){
},
id: {
title: 'id',
width: '25%',
list: false,
width: '3%',
list: true,
key: true
},
display_name: {
......@@ -139,8 +139,8 @@ function structureTable(){
},
id: {
title: 'id',
width: '25%',
list: false,
width: '3%',
list: true,
key: true
},
display_name: {
......
......@@ -39,7 +39,7 @@ function organiationTable(){
delete: false,
display: function(parentOrganisation){
var $imgSubOrg = $('<img src="/images/organisation.png" title="Avdelningar" />');
var $imgSubOrg = $('<img src="/images/structure.png" title="Avdelningar" />');
$imgSubOrg.click(function () {
$('#cmdb-table').jtable('openChildTable', $imgSubOrg.closest('tr'),{
title: parentOrganisation.record.display_name + ':s underliggande organisationer',
......@@ -57,7 +57,7 @@ function organiationTable(){
delete: false,
display: function(parentOrganisation){
var $imgSubOrg = $('<img src="/images/organisation.png" title="Enheter" />');
var $imgSubOrg = $('<img src="/images/structure.png" title="Enheter" />');
$imgSubOrg.click(function (data) {
$('#cmdb-table').jtable('openChildTable', $imgSubOrg.closest('tr'),{
title: parentOrganisation.record.display_name + ':s underliggande organisationer',
......@@ -75,7 +75,7 @@ function organiationTable(){
delete: false,
display: function(parentOrganisation){
var $imgSubOrg = $('<img src="/images/organisation.png" title="Grupper" />');
var $imgSubOrg = $('<img src="/images/structure.png" title="Grupper" />');
$imgSubOrg.click(function (data) {
$('#cmdb-table').jtable('openChildTable', $imgSubOrg.closest('tr'),{
title: parentOrganisation.record.display_name + ':s underliggande organisationer',
......
function relationGraph(){
$.ajax({
url: '/cmdb/api/v1/relation/nodes/'
url: '/cmdb/api/v1/relation/nodes'
}).then(function(nodes) {
$.ajax({
url: '/cmdb/api/v1/relation/edges/'
......@@ -13,9 +13,17 @@ function relationGraph(){
nodes: nodes,
edges: edges
};
for(var i = 0; i<nodes.length; i++){
if(nodes[i].type==='account'){
data.nodes[i].color = '#ffa0a0';
}
else{
data.nodes[i].color = '#d0d0ff';
}
}
var options = {
height: '1200px'
height: '800px'
};
// options.nodes = {
// color: 'gray'
......
function relationNodesTable(){
$('#cmdb-table').jtable({
title: "Relationstyper",
title: "Konton och grupper",
paging: false, //Enable paging
pageSize: 10, //Set page size (default: 10)
pageList: 'minimal',
......@@ -8,19 +8,24 @@ function relationNodesTable(){
multiSorting: false,
defaultSorting: 'display_name ASC', //Set default sorting
actions: {
listAction: '/cmdb/api/v1/relation/node/list'
listAction: '/cmdb/api/v1/relation/security/list'
},
fields: {
id: {
title: 'id',
width: '25%',
list: false,
list: true,
key: true
},
label: {
display_name: {
title: 'Namn',
width: '25%'
},
class_id: {
title: 'Typ',
options: '/cmdb/api/v1/options/classes',
width: '70%'
},
description: {
title: 'Beskrivning',
width: '70%'
......
$(document).ready(function () {
var ref = window.location.href;
if(ref.endsWith('family-and-class')){
if(ref.includes('/family-and-class/')){
structureTable();
}
if(ref.endsWith('ci')){
if(ref.includes('/ci/')){
ciTable();
}
if(ref.endsWith('organisation')){
if(ref.includes('/organisation/')){
organiationTable(1);
organisationGraph(1);
}
if(ref.endsWith('relation-types')){
if(ref.includes('/relation-types/')){
relationTypesTable();
}
if(ref.endsWith('access')){
if(ref.includes('/access/')){
relationNodesTable();
relationGraph();
}
......
.jtable-data-row{
vertical-align: top
}
/*Mainmenu*/
.cmdbguiSmallText {
color: #333;
......
......@@ -19,7 +19,7 @@ router.post('/enterprise_service/list', (req, res, next) => {
done();
return res.status(500).json({success: false , data: err});
}
var sql = "select * , (select count(*) from cmdb.ci c where c.parent_id = id) as childs from cmdb.ci where family_type_id = 1 and id > 0 order by display_name";
var sql = "select * , (select count(*) from cmdb.ci c where c.parent_id = id) as childs from cmdb.ci where family_type_id = 1 and id > 0 order by family_type_id, family_id, display_name";
client.query(sql, [], function(err, result){
done();
if (err){
......@@ -48,7 +48,7 @@ router.post('/child/list/:parent_id', (req, res, next) => {
console.log(err);
return res.status(500).json({success: false , data: err});
}
var sql = "select * , (select count(*) as childs from cmdb.ci child where child.parent_id = parent.id) as childs from cmdb.ci parent where parent.parent_id = $1 order by display_name";
var sql = "select * , (select count(*) as childs from cmdb.ci child where child.parent_id = parent.id) as childs from cmdb.ci parent where parent.parent_id = $1 order by family_type_id, family_id, display_name";
var parameter = [req.params['parent_id']];
client.query(sql, parameter, function(err, result){
done();
......
......@@ -6,17 +6,23 @@ const pg = require('pg');
const path = require('path');
const connectionString = process.env.DATABASE_URL || 'postgres://jasper:a001188@localhost:5432/jasper';
/* GET home page. */
router.get('/', function(req, res, next) {
res.render('index', { title: 'Hem'});
res.render('index', { title: 'Hem'});
});
router.get('/view/:id', function(req, res, next) {
var id = 'cmdb - ' + req.params['id'];
res.render('index', { title: id});
router.get('/view/:id/:i', function(req, res, next) {
var id = 'cmdb - ' + req.params['id'];
var i = '' + req.params['i'];
if(i==='1')
res.render('index_1', { title: id, index: i});
if(i==='2')
res.render('index_2', { title: id, index: i});
else
res.render('index', { title: id, index: i});
});
module.exports = router;
......@@ -63,13 +63,39 @@ router.post('/parent', (req, res, next) => {
router.post('/families/:family_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 display_name as \"DisplayText\", id as \"Value\" from cmdb.family where family_type_id=$1;";
var parameters = req.params['family_type_id'];
client.query(sql, [parameters], function(err, result){
done();
if (err){
return res.json(JSON.parse('{"Result":"ERROR", "Message":"' + sql + '"}'));
}
else {
var response = '{"Result":"OK", "Options":';
response+= JSON.stringify(result.rows);
response+= ',"TotalRecordCount":' + result.rowCount + '}';
return res.json(JSON.parse(response));
}
});
});
});
router.post('/families/:family_type', (req, res, next) => {
router.post('/families', (req, res, next) => {
var pool = new pg.Pool({
connectionString: connectionString,
});
......@@ -82,9 +108,39 @@ router.post('/families/:family_type', (req, res, next) => {
}
// SQL Query > Select Data
var sql = "select display_name as \"DisplayText\", id as \"Value\" from cmdb.family where family_type_id = $1;";
var sql = "select display_name as \"DisplayText\", id as \"Value\" from cmdb.family;";
var parameters = req.params['family_type'];
client.query(sql, [parameters], function(err, result){
client.query(sql, [], function(err, result){
done();
if (err){
return res.json(JSON.parse('{"Result":"ERROR", "Message":"' + sql + '"}'));
}
else {
var response = '{"Result":"OK", "Options":';
response+= JSON.stringify(result.rows);
response+= ',"TotalRecordCount":' + result.rowCount + '}';
return res.json(JSON.parse(response));
}
});
});
});
router.post('/classes', (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 display_name as \"DisplayText\", id as \"Value\" from cmdb.class;";
var parameters = req.params['class_type'];
client.query(sql, [], function(err, result){
done();
if (err){
return res.json(JSON.parse('{"Result":"ERROR", "Message":"' + sql + '"}'));
......
......@@ -38,6 +38,69 @@ router.post('/types', (req, res, next) => {
});
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));
}