Commit 4a2a0051 authored by a001188's avatar a001188
Browse files

Some functions work

parent 2383e8b1
......@@ -9,7 +9,7 @@ var $ = require("jquery");
var index = require('./routes/index');
var relation = require('./routes/relation');
var options = require('./routes/options');
var enterprise_service = require('./routes/enterprise_service');
var ci = require('./routes/ci');
var organisation = require('./routes/organisation');
var structure = require('./routes/structure');
var users = require('./routes/users');
......@@ -27,7 +27,6 @@ app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(lessMiddleware(path.join(__dirname, 'public')));
app.use(express.static(path.join(__dirname, 'public')));
//app.use(express.static(path.join(__dirname, 'public')));
app.use('/', index);
app.use('/view', index);
......@@ -36,7 +35,7 @@ app.use('/cmdb/api/v1/options', options);
app.use('/cmdb/api/v1/relation', relation);
app.use('/cmdb/api/v1/organisation', organisation);
app.use('/cmdb/api/v1/structure', structure);
app.use('/cmdb/api/v1/enterprise_service', enterprise_service);
app.use('/cmdb/api/v1/ci', ci);
// catch 404 and forward to error handler
app.use(function(req, res, next) {
......
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');
}
function enterpriseServiceTable(){
$('#cmdb-table').jtable({
title: "Enterprise Service",
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/enterprise_service/list',
createAction: '/cmdb/api/v1/organisation/create',
updateAction: function(postData) {
return $.Deferred(function ($dfd) {
$.ajax({
url: '/cmdb/api/v1/organisation/update',
type: 'POST',
dataType: 'json',
data: postData,
success: function (data) {
$dfd.resolve(data);
var records = data['Records'];
},
error: function () {
$dfd.reject();
}
});
});
},
deleteAction: '/cmdb/api/v1/organisation/delete'
},
fields: {
subOrg1: {
title: '',
width: '1%',
sorting: false,
edit: false,
create: false,
delete: false,
display: function(parent){
var $imgSubOrg = $('<img src="/images/organisation.png" title="Till nivå 2" />');
$imgSubOrg.click(function (data) {
$('#cmdb-table').jtable('openChildTable', $imgSubOrg.closest('tr'),{
title: parentOrganisation.record.display_name + ':s applikationer',
showCloseButton: true,
actions: {
listAction: '/cmdb/api/v1//cmdb/api/v1/enterprise_service/list/' + parent.record.id // select all rows with parent === data.record.id
},
fields: {
subOrg2: {
title: '',
width: '1%',
sorting: false,
edit: false,
create: false,
delete: false,
display: function(parentOrganisation){
var $imgSubOrg = $('<img src="/images/organisation.png" title="Nivå 3" />');
$imgSubOrg.click(function (data) {
$('#cmdb-table').jtable('openChildTable', $imgSubOrg.closest('tr'),{
title: parentOrganisation.record.display_name + ':s underliggande organisationer',
showCloseButton: true,
actions: {
listAction: '/cmdb/api/v1/organisation/list/' + parentOrganisation.record.id , // select all rows with parent === data.record.id
},
fields: {
subOrg3: {
title: '',
width: '1%',
sorting: false,
edit: false,
create: false,
delete: false,
display: function(parentOrganisation){
var $imgSubOrg = $('<img src="/images/organisation.png" title="Nivå 4" />');
$imgSubOrg.click(function (data) {
updateGraph(parentOrganisation.record.id);
$('#cmdb-table').jtable('openChildTable', $imgSubOrg.closest('tr'),{
title: parentOrganisation.record.display_name + ':s underliggande organisationer',
showCloseButton: true,
actions: {
listAction: '/cmdb/api/v1/organisation/list/' + parentOrganisation.record.id , // select all rows with parent === data.record.id
},
fields: {
subOrg4: {
title: '',
width: '1%',
sorting: false,
edit: false,
create: false,
delete: false,
display: function(parentOrganisation){
var $imgSubOrg = $('<img src="/images/organisation.png" title="Nivå 5" />');
$imgSubOrg.click(function (data) {
$('#cmdb-table').jtable('openChildTable', $imgSubOrg.closest('tr'),{
title: parentOrganisation.record.display_name + ':s underliggande organisationer',
showCloseButton: true,
actions: {
listAction: '/cmdb/api/v1/organisation/list/' + parentOrganisation.record.id , // select all rows with parent === 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_id: {
title: 'Typ',
options: '/cmdb/api/v1/organisation/families/0', //family_type_id
width: '15%'
},
level_id: {
title: 'Nivå',
options: '/cmdb/api/v1/organisation/classes/0', //class_type_id
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_id: {
title: 'Typ',
options: '/cmdb/api/v1/organisation/families/0', //family_type_id
width: '15%'
},
level_id: {
title: 'Nivå',
options: '/cmdb/api/v1/organisation/classes/0', //class_type_id
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_id: {
title: 'Typ',
options: '/cmdb/api/v1/organisation/families/0', //family_type_id
width: '15%'
},
level_id: {
title: 'Nivå',
options: '/cmdb/api/v1/organisation/classes/0', //class_type_id
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_id: {
title: 'Typ',
options: '/cmdb/api/v1/structure/families/' + data.records.family_id,
width: '15%'
},
level_id: {
title: 'Nivå',
options: '/cmdb/api/v1/structure/classes/' + data.records.class_id, //class_type_id
width: '15%'
},
kst: {
title: 'Kostnadsställe',
width: '15%'
},
product: {
title: 'Produkt',
width: '15%'
},
max_service_level: {
title: 'Max servicenivå',
options: '/cmdb/api/v1/structure/classes/' + data.records.class_id, //class_type_id
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_id: {
title: 'Familj',
options: '/cmdb/api/v1/options/families/1', //+ data.options.family_type_id
width: '15%'
},
max_service_level: {
title: 'Max servicenivå',
options: '/cmdb/api/v1/options/classes/9', //class_type_id
width: '15%'
},
service_level_id: {
title: 'Servicenivå',
options: '/cmdb/api/v1/options/classes/9', //class_type_id
width: '15%'
},
service_degree_id: {
title: 'Servicegrad',
options: '/cmdb/api/v1/options/classes/10', //class_type_id
width: '15%'
},
kst: {
title: 'Kostnadsställe',
width: '15%'
},
product: {
title: 'Produkt',
width: '15%'
},
sla: {
title: 'SLA',
width: '15%'
},
sys_overview_ref: {
title: 'Systemöversikt',
width: '15%'
},
sys_overview_date: {
title: 'Godkänd systemöversikt',
width: '15%'
},
sys_operating_manual_ref: {
title: 'DHL',
width: '15%'
},
sys_operating_manual_date: {
title: 'Godkänd DHL',
width: '15%'
}
}
});
$('#cmdb-table').jtable('load');
}
......@@ -4,8 +4,8 @@ $(document).ready(function () {
if(ref.endsWith('family-and-class')){
structureTable();
}
if(ref.endsWith('enterprise-service')){
enterpriseServiceTable();
if(ref.endsWith('ci')){
ciTable();
}
if(ref.endsWith('organisation')){
organiationTable(1);
......
......@@ -7,37 +7,64 @@ const path = require('path');
const connectionString = process.env.DATABASE_URL || 'postgres://jasper.u:Me4sgyAp@postgresql-utv.smhi.se:5432/jasper';
router.post('/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();
console.log(err);
return res.status(500).json({success: false , data: err});
}
// SQL Query > Select Data
var sql = "select * from cmdb.ci_family_enterprise_service order by display_name;";
client.query(sql, [], function(err, result){
done();
if (err){
return res.json(JSON.parse('{"Result":"ERROR", "Message":"/family_type"}'));
}
else {
var response = '{"Result":"OK", "Records":';
response+= JSON.stringify(result.rows);
response+= ',"TotalRecordCount":' + result.rowCount + '}';
return res.json(JSON.parse(response));
router.post('/enterprise_service/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 * from cmdb.ci where family_type_id = 1 and id > 0 order by 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) => {
var pool = new pg.Pool({
connectionString: connectionString,
});
pool.connect(function(err, client, done){
if(err) {
done();
console.log(err);
return res.status(500).json({success: false , data: err});
}
var sql = "select * from cmdb.ci where parent_i