Commit 3dcbea3a authored by a001188's avatar a001188
Browse files

Some functions works

parent b68ff579
function ciTable(){
$('#cmdb-table').jtable(createTable(columnDef()));
function ec_ciTable(){
$('#cmdb-table').jtable(createEcCiTable(ec_ciColumnDef()));
$('#cmdb-table').jtable('load');
}
function columnDef(){
function ec_ciColumnDef(){
var cd = {
next: {
title: 'Nästa',
width: '1%',
display: renderSubTable
display: renderEcCiSubTable
},
family_type_id: {
title: 'Familjetyp',
......@@ -72,9 +72,9 @@ function columnDef(){
function createTable(columnDef){
function createEcCiTable(ciColumnDef){
var table = {
title: "Konfigurationselement",
title: "Konfigurationselement CI",
paging: false, //Enable paging
pageSize: 10, //Set page size (default: 10)
pageList: 'minimal',
......@@ -84,37 +84,36 @@ function columnDef(){
actions: {
listAction: '/cmdb/api/v1/ci/enterprise_service/list'
},
fields: columnDef
fields: ciColumnDef
};
return table;
}
function renderSubTable (data) {
//updateGraph(parentOrganisation.record.id);
function renderEcCiSubTable (data) {
if(data.record.childs > 0){
return $('<img src="/images/structure.png" title="Nästa nivå"/>').click(function () {
createSubTable(data, $(this).closest('tr'));
createEcCiSubTable(data, $(this).closest('tr'));
});
}
}
function createSubTable(data, row){
function createEcCiSubTable(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()
fields: ec_ciColumnDef()
},
function (data) { //opened handler
data.childTable.jtable('load');
});
}
function getFamilyId(data){
function getEcCiFamilyId(data){
return data.record.family_type_id;
}
\ No newline at end of file
function organisationGraph(centralNode){
function orgGraph(centralNode){
$.ajax({
url: '/cmdb/api/v1/organisation/list/nodes/' + centralNode
}).then(function(nodes) {
......@@ -16,6 +16,17 @@ function organisationGraph(centralNode){
edges: edges
};
for(var i = 0; i<nodes.length; i++){
if(nodes[i].type_id===11)
data.nodes[i].color = '#ffa0a0';
if(nodes[i].type_id===11)
data.nodes[i].color = '#ffa0a0';
if(nodes[i].type_id===11)
data.nodes[i].color = '#ffa0a0';
else
data.nodes[i].color = '#d0d0ff';
}
var options = {
height: '800px',
layout: {
......
function organisationTable(){
$('#cmdb-table').jtable(createTable(columnDef()));
function orgTable(){
$('#cmdb-table').jtable(createOrgTable(orgColumnDef()));
$('#cmdb-table').jtable('load');
}
function columnDef(){
function orgColumnDef(){
var cd = {
next: {
title: 'Nästa',
width: '1%',
display: renderSubTable
display: renderOrgSubTable
},
id: {
title: 'id',
......@@ -48,7 +48,7 @@ function columnDef(){
function createTable(columnDef){
function createOrgTable(orgColumnDef){
var table = {
title: "Organisation",
paging: false, //Enable paging
......@@ -60,37 +60,36 @@ function columnDef(){
actions: {
listAction: '/cmdb/api/v1/organisation/list/0'
},
fields: columnDef
fields: orgColumnDef
};
return table;
}
function renderSubTable (data) {
//updateGraph(parentOrganisation.record.id);
function renderOrgSubTable (data) {
if(data.record.childs > 0){
return $('<img src="/images/structure.png" title="Nästa nivå"/>').click(function () {
createSubTable(data, $(this).closest('tr'));
createOrgSubTable(data, $(this).closest('tr'));
});
}
}
function createSubTable(data, row){
function createOrgSubTable(data, row){
$('#cmdb-table').jtable('openChildTable', row, {
title: 'Underordnade organisationer ' + data.record.display_name,
actions: {
listAction: '/cmdb/api/v1/organisation/list/' + data.record.id
},
fields: columnDef()
fields: orgColumnDef()
},
function (data) { //opened handler
data.childTable.jtable('load');
});
}
function getFamilyId(data){
function getOrgFamilyId(data){
return data.record.family_type_id;
}
\ No newline at end of file
function tfo_ciTable(){
$('#cmdb-table').jtable(createTfoCiTable(tfo_ciColumnDef()));
$('#cmdb-table').jtable('load');
}
function tfo_ciColumnDef(){
var cd = {
next: {
title: 'Nästa',
width: '1%',
display: renderTfoCiSubTable
},
family_type_id: {
title: 'Familjetyp',
options: '/cmdb/api/v1/options/family_type',
width: '5%'
},
family_id: {
title: 'Familj',
options: '/cmdb/api/v1/options/families',
width: '5%'
},
id: {
title: 'id',
width: '1%',
list: false,
key: true
},
display_name: {
title: 'Namn',
width: '10%'
},
description: {
title: 'Beskrivning',
width: '15%'
},
kst: {
title: 'Kostnadsställe',
width: '5%'
},
product: {
title: 'Produkt',
width: '5%'
},
sla: {
title: 'SLA',
width: '5%'
},
class_information: {
title: 'Klasser',
width: '15%'
},
attribute_information: {
title: 'Attribut',
width: '20%'
},
// account_group: {
// title: 'Grupper',
// width: '15%'
// },
// account_id: {
// title: 'Konton',
// width: '15%'
// },
// contacts: {
// title: 'Kontaktpersoner',
// width: '15%'
// }
}
return cd;
}
function createTfoCiTable(ciColumnDef){
var table = {
title: "Konfigurationselement CI",
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/infrastructure/list'
},
fields: ciColumnDef
};
return table;
}
function renderTfoCiSubTable (data) {
if(data.record.childs > 0){
return $('<img src="/images/structure.png" title="Nästa nivå"/>').click(function () {
createTfoCiSubTable(data, $(this).closest('tr'));
});
}
}
function createTfoCiSubTable(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 getTfoCiFamilyId(data){
return data.record.family_type_id;
}
\ No newline at end of file
......@@ -4,12 +4,15 @@ $(document).ready(function () {
if(ref.includes('/family-and-class/')){
structureTable();
}
if(ref.includes('/ci/')){
ciTable();
if(ref.includes('/ec-ci/')){
ec_ciTable();
}
if(ref.includes('/tfo-ci/')){
tfo_ciTable();
}
if(ref.includes('/organisation/')){
organisationTable();
organisationGraph(1);
orgTable();
orgGraph(1);
}
if(ref.includes('/relation-types/')){
relationTypesTable();
......
......@@ -34,7 +34,32 @@ router.post('/enterprise_service/list', (req, res, next) => {
});
});
//select * , (select count(*) from cmdb.ci child where child.parent_id = id) as childs from cmdb.ci where parent_id = 27 order by display_name
router.post('/infrastructure/list', (req, res, next) => {
var pool = new pg.Pool({
connectionString: connectionString,
});
pool.connect(function(err, client, done){
if(err) {
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 = 5 and id > 0 order by family_type_id, family_id, display_name";
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('/child/list/:parent_id', (req, res, next) => {
......
......@@ -8,16 +8,15 @@ const pg = require('pg');
const winston = require('winston');
const connectionString = process.env.DATABASE_URL || config.storageConfig;
router.get('/list/nodes/:centralNode', (req, res, next) => {
var pool = new pg.Pool({
connectionString: connectionString
connectionString: connectionString
});
// Get a Postgres client from the connection pool
pool.connect(function(err, client, done){
// Handle connection errors
pool.connect(function(err, client, done){
if(err) {
done();
return res.status(500).json({success: false , data: err});
done();
return res.status(500).json({success: false , data: err});
}
// all leaf
......
......@@ -18,7 +18,8 @@ html
script(type='text/javascript', src='/javascripts/vis/dist/vis.js')
script(type='text/javascript', src='/javascripts/select.js')
script(type='text/javascript', src='/javascripts/dashlets/ci-table.js')
script(type='text/javascript', src='/javascripts/dashlets/ec-ci-table.js')
script(type='text/javascript', src='/javascripts/dashlets/tfo-ci-table.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/family_and_classes-table.js')
......
......@@ -22,9 +22,9 @@ block menu
a(href="#") Teknisk konfiguration
ul
li
a(href="/view/ci/1") Konfigurationselement
a(href="/view/ec-ci/1") Företagstjänster (CI)
li
a(href="/view/infrastructure/1") Infrastruktur
a(href="/view/tfo-ci/1") Infrastruktur (CI)
li
a(href="/view/access/2") Behörighet
li
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment