Commit bd803276 authored by a001188's avatar a001188
Browse files

Improvement

parent 1f93e106
......@@ -18,9 +18,15 @@ function accessGraph(node_id){
if(nodes[i].type_id===11){
data.nodes[i].color = '#ffa0a0';
}
else{
else if(nodes[i].type_id===12){
data.nodes[i].color = '#d0d0ff';
}
else if(nodes[i].type_id===-1){
data.nodes[i].color = '#cccccc';
}
else {
data.nodes[i].color = '#eeeeee';
}
}
var options = {
......
......@@ -236,18 +236,31 @@ router.get('/node/:id', (req, res, next) => {
}
// SQL Query > Select Data
var sql = "select c.id, concat('grupp: ', c.display_name) as label, (select class_type_id from cmdb.class c2 where c2.id=c.group_type_id) as type_id from cmdb.ci_family_group c inner join cmdb.relation r on r.from_ci_id = c.id where r.relation_type_id=0 and r.to_ci_id = $1 ";
var sql = "select distinct * from ("; //
sql+= "select c.id, concat('grupp: ', c.display_name) as label, (select class_type_id from cmdb.class c2 where c2.id=c.group_type_id) as type_id from cmdb.ci_family_group c inner join cmdb.relation r on r.from_ci_id = c.id where r.relation_type_id=0 and r.to_ci_id = $1 ";
sql+= "UNION ";
sql+= "select c.id, concat('grupp: ', c.display_name) as label, (select class_type_id from cmdb.class c2 where c2.id=c.group_type_id) as type_id from cmdb.ci_family_group c inner join cmdb.relation r on r.to_ci_id = c.id where r.relation_type_id=0 and r.from_ci_id = $1 ";
sql+= "UNION ";
sql+= "select c.id, concat('grupp: ', c.display_name) as label, (select class_type_id from cmdb.class c2 where c2.id=c.group_type_id) as type_id from cmdb.ci_family_group c where c.id = $1 ";
sql+= "UNION ";
sql+= "select c.id, concat('användare: ', c.display_name) as label, (select class_type_id from cmdb.class c2 where c2.id=c.account_type_id) as type_id from cmdb.ci_family_account c inner join cmdb.relation r on r.from_ci_id = c.id where r.relation_type_id=0 and r.to_ci_id = $1 ";
sql+= "select c.id, concat('konto: ', c.display_name) as label, (select class_type_id from cmdb.class c2 where c2.id=c.account_type_id) as type_id from cmdb.ci_family_account c inner join cmdb.relation r on r.from_ci_id = c.id where r.relation_type_id=0 and r.to_ci_id = $1 ";
sql+= "UNION ";
sql+= "select c.id, concat('användare: ', c.display_name) as label, (select class_type_id from cmdb.class c2 where c2.id=c.account_type_id) from cmdb.ci_family_account c inner join cmdb.relation r on r.to_ci_id = c.id where r.relation_type_id=0 and r.from_ci_id = $1 ";
sql+= "select c.id, concat('konto: ', c.display_name) as label, (select class_type_id from cmdb.class c2 where c2.id=c.account_type_id) from cmdb.ci_family_account c inner join cmdb.relation r on r.to_ci_id = c.id where r.relation_type_id=0 and r.from_ci_id = $1 ";
sql+= "UNION ";
sql+= "select c.id, concat('användare: ', c.display_name) as label, (select class_type_id from cmdb.class c2 where c2.id=c.account_type_id) from cmdb.ci_family_account c where c.id = $1 ";
sql+= "select c.id, concat('konto: ', c.display_name) as label, (select class_type_id from cmdb.class c2 where c2.id=c.account_type_id) from cmdb.ci_family_account c where c.id = $1 ";
sql+= "UNION ";
sql+= "select c.parent_id as id, concat('ägare: ', (select c3.display_name from cmdb.ci c3 where c3.id = c.parent_id)) as label, -1 as type_id from cmdb.ci_family_group c inner join cmdb.relation r on r.from_ci_id = c.id where r.relation_type_id=0 and r.to_ci_id = $1 ";
sql+= "UNION ";
sql+= "select c.parent_id as id, concat('ägare: ', (select c3.display_name from cmdb.ci c3 where c3.id = c.parent_id)) as label, -1 as type_id from cmdb.ci_family_group c inner join cmdb.relation r on r.to_ci_id = c.id where r.relation_type_id=0 and r.from_ci_id = $1 ";
sql+= "UNION ";
sql+= "select c.parent_id as id, concat('ägare: ', (select c3.display_name from cmdb.ci c3 where c3.id = c.parent_id)) as label, -1 as type_id from cmdb.ci_family_group c where c.id = $1 ";
sql+= "UNION ";
sql+= "select c.parent_id as id, concat('ägare: ', (select c3.display_name from cmdb.ci c3 where c3.id = c.parent_id)) as label, -1 as type_id from cmdb.ci_family_account c inner join cmdb.relation r on r.from_ci_id = c.id where r.relation_type_id=0 and r.to_ci_id = $1 ";
sql+= "UNION ";
sql+= "select c.parent_id as id, concat('ägare: ', (select c3.display_name from cmdb.ci c3 where c3.id = c.parent_id)) as label, -1 as type_id from cmdb.ci_family_account c inner join cmdb.relation r on r.to_ci_id = c.id where r.relation_type_id=0 and r.from_ci_id = $1 ";
sql+= "UNION ";
sql+= "select c.parent_id as id, concat('ägare: ', (select c3.display_name from cmdb.ci c3 where c3.id = c.parent_id)) as label, -1 as type_id from cmdb.ci_family_account c where c.id = $1 ";
sql+= ") as sub";
var parameter = [req.params['id']];
client.query(sql, parameter, function(err, result){
done();
......@@ -265,7 +278,14 @@ router.get('/node/:id', (req, res, next) => {
});
});
});
[
{"id":30,"label":"kontoägare: Bergaby App1","type_id":-2},
{"id":31,"label":"gruppägare: Mora App1","type_id":-1},
{"id":31,"label":"kontoägare: Mora App1","type_id":-2},
{"id":40,"label":"konto: bergaby.u","type_id":11},
{"id":42,"label":"konto: mora.u","type_id":11},
{"id":43,"label":"konto: mora","type_id":11},
{"id":50,"label":"grupp: moragu","type_id":12}]
router.get('/edge/:id', (req, res, next) => {
var pool = new pg.Pool({
......@@ -280,13 +300,37 @@ router.get('/edge/:id', (req, res, next) => {
}
// SQL Query > Select Data
var sql = "select from_ci_id as from, to_ci_id as to, rt.display_name as label, '__FONT__' as font from cmdb.relation r inner join cmdb.relation_type rt on r.relation_type_id=rt.id ";
sql+="where from_ci_id = $1 or to_ci_id = $1;";
var sql = "select from_ci_id as from, to_ci_id as to, rt.display_name as label, '__FONT__' as font ";
sql+="from cmdb.relation r1 inner join cmdb.relation_type rt on r1.relation_type_id=rt.id ";
sql+="where r1.from_ci_id = $1 or r1.to_ci_id = $1 ";
sql+="union ";
sql+="select distinct fr_ci.parent_id as from, fr_ci.id as to, 'äger' as label, '__FONT__' as font ";
sql+="from cmdb.relation r2 inner join cmdb.ci fr_ci on r2.to_ci_id = fr_ci.id ";
sql+="where r2.from_ci_id = $1 ";
sql+="union ";
// sql+="select distinct fr_ci.parent_id as from, fr_ci.id as to, 'äger' as label, '__FONT__' as font ";
// sql+="from cmdb.relation r2 inner join cmdb.ci fr_ci on r2.from_ci_id = fr_ci.id ";
// sql+="where r2.from_ci_id = $1 ";
// sql+="union ";
sql+="select distinct to_ci.parent_id as from, to_ci.id as to, 'äger' as label, '__FONT__' as font ";
sql+="from cmdb.relation r3 inner join cmdb.ci to_ci on r3.from_ci_id = to_ci.id ";
sql+="where r3.to_ci_id = $1 ";
sql+="union ";
// sql+="select distinct to_ci.parent_id as from, to_ci.id as to, 'äger' as label, '__FONT__' as font ";
// sql+="from cmdb.relation r3 inner join cmdb.ci to_ci on r3.to_ci_id = to_ci.id ";
// sql+="where r3.to_ci_id = $1 ";
// sql+="union ";
sql+="select distinct c1.parent_id as from, c1.id as to, 'äger' as label, '__FONT__' as font ";
sql+="from cmdb.ci c1 ";
sql+="where c1.id = $1 ";
var parameter = [req.params['id']];
client.query(sql, parameter, function(err, result){
done();
if (err){
winston.log('error', '/edges/:id', {
sql: sql
})
return res.json(JSON.parse('{"Result":"ERROR", "Message":"' + sql + '"}'));
}
else {
......@@ -295,7 +339,7 @@ router.get('/edge/:id', (req, res, next) => {
for(var i=0; i<jsonResponse.length; i++)
jsonResponse[i].font = f;
winston.debug('info', '/edges/:id', {
winston.log('info', '/edges/:id', {
jsonResponse: jsonResponse
})
return res.json(jsonResponse);
......
......@@ -69,7 +69,7 @@ function getSQLSearchQuery(query_type, family_type, family_name, req){
var jtSorting = req.query['jtSorting'].trim();
var sql_select ="select ci1.id as ci_id, ci1.parent_id as ci_parent_id, ci1.class_information, ci1.attribute_information, f.id as f_id, ft.id as ft_id, ci1.display_name as ci_name, ci1.description as ci_description, f.display_name as family_name, ft.display_name as family_type_name, ";
sql_select+="concat('<b>Kst: </b>' , ci1.kst, '<br><b>Prod: </b>', ci1.product) as economy, ";
sql_select+="concat(CASE WHEN char_length(ci1.kst) >0 THEN concat('<b>Kst: </b>', ci1.kst, '<BR>') else '' end, CASE WHEN char_length(ci1.kst) > 0 THEN concat('<b>Prod: </b>', ci1.product) else '' end) as economy, ";
sql_select+="(select string_agg(ci_account.display_name, '<br>') from cmdb.ci_family_account ci_account where ci_account.parent_id = ci1.id) as account, ";//f.display_name <> 'Access') as childs, ";
sql_select+="(select string_agg(ci_group.display_name, '<br>') from cmdb.ci_family_group ci_group where ci_group.parent_id = ci1.id) as group, ";//f.display_name <> 'Access') as childs, ";
sql_select+="(select count(*) from cmdb.ci ci2 inner join cmdb.family f2 on ci2.family_id = f2.id where ci2.parent_id = ci1.id and f2.display_name <> 'Access') as childs, ";//f.display_name <> 'Access') as childs, ";
......@@ -110,11 +110,11 @@ function getSQLSearchQuery(query_type, family_type, family_name, req){
if(query_type === MAIN)
sql = sql_select + sql_select_contact + sql_from + sql_where_list + sql_where_search + sql_order_by;
else if(query_type === CHILD)
sql = sql_select + sql_from + sql_where_child + sql_order_by;
sql = sql_select + sql_select_contact + sql_from + sql_where_child + sql_order_by;
else if(query_type === PARENT)
sql = sql_select + sql_from + sql_where_parent + sql_order_by;
sql = sql_select + sql_select_contact + sql_from + sql_where_parent + sql_order_by;
else
sql= sql_select + sql_from + sql_where_search + sql_order_by;
sql = sql_select + sql_select_contact + sql_from + sql_where_search + sql_order_by;
winston.log('info', '*** TRACE ***', {
sql:sql
......
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