Commit 5e26d835 authored by a001188's avatar a001188
Browse files

Accessobject shows up on its owners row

parent 04c2c301
......@@ -54,12 +54,18 @@ function ec_ciColumnDef(){
title: 'Attribut',
width: '15%'
},
account_id: {
account: {
title: 'Konto',
options: function(data){
return '/cmdb/api/v1/options/accounts/' + data.record.id;
},
width: '5%'
},
account_group: {
group: {
title: 'Grupp',
options: function(data){
return '/cmdb/api/v1/options/groups/' + data.record.id;
},
width: '5%'
},
contacts: {
......
......@@ -45,9 +45,9 @@ function orgColumnDef(){
};
return cd;
}
function createOrgTable(orgColumnDef){
var table = {
title: "Organisation",
......@@ -92,4 +92,5 @@ function orgColumnDef(){
function getOrgFamilyId(data){
return data.record.family_type_id;
}
\ No newline at end of file
}
\ No newline at end of file
......@@ -18,7 +18,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 family_type_id, family_id, display_name";
var sql = "select *, id as account, id as group, (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){
......@@ -72,7 +72,10 @@ 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 family_type_id, family_id, display_name";
var sql ="select *, id as account, id as group, (select count(*) as childs from cmdb.ci child where child.parent_id = parent.id and family_id <> 14) as childs "; //14 = IT-Tjänstekomponent Access med grupper och konton
sql+="from cmdb.ci parent ";
sql+="where parent.parent_id = $1 and family_id <> 14";
sql+="order by family_type_id, family_id, display_name";
var parameter = [req.params['parent_id']];
client.query(sql, parameter, function(err, result){
done();
......
......@@ -127,6 +127,7 @@ router.post('/families', (req, res, next) => {
});
});
router.post('/classes', (req, res, next) => {
var pool = new pg.Pool({
connectionString: connectionString,
......@@ -190,4 +191,89 @@ router.post('/classes/:class_type', (req, res, next) => {
});
});
router.post('/groups/:owner_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 fa.*, c.* from cmdb.ci_family_account fa inner join cmdb.class c on fa.account_type_id = c.id where parent_id = $1;";
var sql = "select * from cmdb.ci_family_group where parent_id = $1;";
var parameters = req.params['owner_id'];
client.query(sql, [parameters], function(err, result){
done();
if (err){
return res.json(JSON.parse('{"Result":"ERROR", "Message":"' + sql + '"}'));
}
else {
return res.json(JSON.parse(formateAccountAndGroupResult(result, parameters)));
}
});
});
});
router.post('/accounts/:owner_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 fa.*, c.* from cmdb.ci_family_account fa inner join cmdb.class c on fa.account_type_id = c.id where parent_id = $1;";
var sql = "select * from cmdb.ci_family_account where parent_id = $1;";
var parameters = req.params['owner_id'];
client.query(sql, [parameters], function(err, result){
done();
if (err){
return res.json(JSON.parse('{"Result":"ERROR", "Message":"' + sql + '"}'));
}
else {
return res.json(JSON.parse(formateAccountAndGroupResult(result, parameters)));
}
});
});
});
function formateAccountAndGroupResult(result, parameters){
var response = '{"Result":"OK", "Options":[';
if(result.rows.length === 0){
response+= '{}';
response+= ']}';
}
else{
response+= '{"DisplayText":"';
for(var i = 0; i<result.rows.length-1; i++){
response+= result.rows[i].display_name + '<br>';
}
response+= result.rows[result.rows.length-1].display_name;
response+= '", "Value":' + parameters;
response+= '}]}';
}
winston.log('info', '/accounts/:owner_id', {
response: response,
rows: result.rows.length
})
return response;
}
module.exports = router;
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