Commit b5d094b5 authored by a001188's avatar a001188
Browse files

Sort implemented

parent 87f6de5a
......@@ -6,20 +6,35 @@ function search_ciTable(){
function search_ciColumnDef(){
var cd = {
prev: {
title: '',
width: '1%',
display: renderSearchCiSuperTable,
sorting: false
},
next: {
title: 'Nästa',
title: '',
width: '1%',
display: renderSearchCiSubTable,
sorting: false
},
sibling: {
title: '',
width: '1%',
display: renderSearchCiSubTable
display: renderSearchCiSiblingTable,
sorting: false
},
family_type_id: {
title: 'Familjetyp',
options: '/cmdb/api/v1/options/family_type',
width: '5%'
width: '5%',
sorting: false
},
family_id: {
title: 'Familj',
options: '/cmdb/api/v1/options/families',
width: '5%'
width: '5%',
sorting: false
},
id: {
title: 'id',
......@@ -29,7 +44,8 @@ function search_ciColumnDef(){
},
display_name: {
title: 'Namn',
width: '8%'
width: '8%',
sorting: true
},
description: {
title: 'Beskrivning',
......@@ -126,21 +142,69 @@ function search_ciColumnDef(){
function renderSearchCiSubTable (data) {
function renderSearchCiSubTable (data) {
if(data.record.childs > 0){
return $('<img src="/images/child.png" title="Barn"/>').click(function () {
createSearchCiSubTable(data, $(this).closest('tr'));
});
}
}
function createSearchCiSubTable(data, row){
$('#cmdb-table').jtable('openChildTable', row, {
title: 'Barn till ' + data.record.display_name,
actions: {
listAction: '/cmdb/api/v1/ci/child/list/' + data.record.id
},
fields: search_ciColumnDef()
},
function (data) { //opened handler
data.childTable.jtable('load');
});
}
function renderSearchCiSiblingTable (data) {
if(data.record.childs > 0){
return $('<img src="/images/sibling.png" title="Syskon"/>').click(function () {
createSearchCiSiblingTable(data, $(this).closest('tr'));
});
}
}
function createSearchCiSiblingTable(data, row){
$('#cmdb-table').jtable('openChildTable', row, {
title: 'Syskon till ' + data.record.display_name,
actions: {
listAction: '/cmdb/api/v1/ci/child/list/' + data.record.parent_id
},
fields: search_ciColumnDef()
},
function (data) { //opened handler
data.childTable.jtable('load');
});
}
function renderSearchCiSuperTable (data) {
if(data.record.childs > 0){
return $('<img src="/images/structure.png" title="Nästa nivå"/>').click(function () {
createSearchCiSubTable(data, $(this).closest('tr'));
return $('<img src="/images/parent.png" title="Förälder"/>').click(function () {
createSearchCiSuperTable(data, $(this).closest('tr'));
});
}
}
function createSearchCiSubTable(data, row){
function createSearchCiSuperTable(data, row){
$('#cmdb-table').jtable('openChildTable', row, {
title: 'Komponenter till ' + data.record.display_name,
title: 'Förälder till ' + data.record.display_name,
actions: {
listAction: '/cmdb/api/v1/ci/child/list/' + data.record.id
listAction: '/cmdb/api/v1/ci/list/' + data.record.parent_id
},
fields: search_ciColumnDef()
},
......@@ -149,6 +213,8 @@ function search_ciColumnDef(){
});
}
function getSearchCiFamilyId(data){
return data.record.family_type_id;
}
\ No newline at end of file
......@@ -3,7 +3,6 @@ var router = express.Router();
const jQuery = require('jquery');
const path = require('path');
var options = require('./options');
const pg = require('pg');
const config = require('./config');
const winston = require('winston');
......@@ -37,69 +36,77 @@ router.post('/enterprise_service/list/', (req, res, next) => {
router.post('/search/list', (req, res, next) => {
var pool = new pg.Pool({
connectionString: connectionString,
var cnt = 0;
var jtStartIndex = req.query['jtStartIndex'];
var jtPageSize = req.query['jtPageSize'];
var jtSorting = req.query['jtSorting'];
var ci_search = '%' + req.body.search_string.toUpperCase() + '%';
var sql_select = "select *, id as account, id as group, ";
sql_select+="(select count(*) from cmdb.ci ci2 where ci2.parent_id = ci1.id) as childs ";
var sql_select_count="select count(*) as \"TotalRecordCount\" ";
var sql_from ="from cmdb.ci ci1 ";
var sql_where ="where id > 0 and (";
sql_where+="upper(ci1.display_name) like $1 ";
sql_where+="or upper(ci1.description) like $1 ";
sql_where+="or upper(ci1.class_information) like $1 ";
sql_where+="or upper(ci1.attribute_information) like $1 ";
sql_where+="or upper(ci1.contact_information) like $1 ";
sql_where+=") ";
var sql_order_by="order by $2 ";
var sql_limit ="LIMIT $3 OFFSET $4";
var sql = sql_select + sql_from + sql_where + sql_order_by + sql_limit;
var sql_cnt = sql_select_count + sql_from + sql_where;
var parameters = [ci_search, jtSorting, jtPageSize, jtStartIndex];
var parameters_cnt = [ci_search];
winston.log('info', '0', {
head: '************************************************************',
jtSorting:jtSorting
});
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});
}
client.query(sql_cnt, parameters_cnt, function(err, result_cnt){
done();
if (err){
return res.json(JSON.parse('{"Result":"ERROR", "Message":"' +sql_cnt + '"}'));
}
else {
cnt = result_cnt.rows[0];
}
});
pool.connect(function(err, client, done){
});
pool.connect(function(err, client, done){
if(err) {
done();
return res.status(500).json({success: false, data: err});
}
var jtStartIndex = req.query['jtStartIndex'];
var jtPageSize = req.query['jtPageSize'];
var jtSorting = req.query['jtSorting'];
var ci_search = '%' + req.body.search_string.toUpperCase() + '%';
var sql_select = "select *, id as account, id as group, ";
sql_select+="(select count(*) from cmdb.ci ci2 where ci2.parent_id = ci1.id) as childs ";
var sql_count="select count(*) ";
var sql_from ="from cmdb.ci ci1 ";
var sql_where ="where id > 0 and (";
sql_where+="upper(ci1.display_name) like $1 ";
sql_where+="or upper(ci1.description) like $1 ";
sql_where+="or upper(ci1.class_information) like $1 ";
sql_where+="or upper(ci1.attribute_information) like $1 ";
sql_where+="or upper(ci1.contact_information) like $1 ";
sql_where+=") ";
var sql_order_by="order by $2 ";
var sql_limit ="LIMIT $3 OFFSET $4";
var sql = sql_select + sql_from + sql_where + sql_order_by + sql_limit;
var sql_cnt = sql_count + sql_from + sql_where;
var count;
var parameters = [ci_search, jtSorting, jtPageSize, jtStartIndex];
var parameters_cnt = [ci_search];
client.query(sql, parameters, function(err, result){
done();
if (err){
return res.json(JSON.parse('{"Result":"ERROR", "Message":"' +sql + '"}'));
}
else {
client.query(sql_cnt, parameters_cnt, function(err, result){
done();
if (err){
return res.json(JSON.parse('{"Result":"ERROR", "Message":"' +sql_cnt + '"}'));
}
else {
count = result.rows.length;
winston.log('info', 'ci/search', {
head: '************************************************************',
parameters: parameters,
count:count
});
}
});
var count = cnt['TotalRecordCount'];
var response = '{"Result":"OK", "Records":';
response+= JSON.stringify(result.rows);
response+= ',"TotalRecordCount":' + 21 + '}';
response+= ',"TotalRecordCount":' + count + '}';
return res.json(JSON.parse(response));
}
});
});
});
});
......@@ -161,6 +168,39 @@ router.post('/child/list/:parent_id', (req, res, next) => {
router.post('/list/: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 *, 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.id = $1 and family_id <> 14";
sql+="order by family_type_id, family_id, display_name";
var parameter = [req.params['id']];
client.query(sql, parameter, 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('/families/:family_type_id', (req, res, next) => {
var pool = new pg.Pool({
......
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