Commit db4d9ea2 authored by a001188's avatar a001188
Browse files

Sort implemented

parent 5e4039c5
......@@ -4,43 +4,15 @@
// sub_queries_included: if filter should be included in subqueries
//**************************************************
function ciTable(family_type, family_name, sub_queries_included){
$('#cmdb-table').jtable(createSearchCiTable(ciColumnDef(), family_type, family_name, sub_queries_included));
$('#cmdb-table').jtable(createCiTable(ciColumnDef(), family_type, family_name, sub_queries_included));
$('#cmdb-table').jtable('load');
}
function ciColumnDef(){
var cd = {
prev: {
title: '',
width: '1%',
display: renderSearchCiParentTable,
sorting: false
},
next: {
title: '',
width: '1%',
display: renderSearchCiChildTable,
sorting: false
},
sibling: {
title: '',
width: '1%',
display: renderSearchCiSiblingTable,
sorting: false
},
family_type_name: {
title: 'Familjetyp',
width: '5%',
sorting: true
},
family_name: {
title: 'Familj',
width: '5%',
sorting: true
},
ci_id: {
title: 'id',
width: '1%',
......@@ -56,14 +28,26 @@ function ciColumnDef(){
title: 'Beskrivning',
width: '10%'
},
family_type_name: {
title: 'Familjetyp',
width: '5%',
sorting: true
},
family_name: {
title: 'Familj',
width: '5%',
sorting: true
},
ci_kst: {
sorting: false,
title: 'Ekonomi',
width: '3%'
},
// sla: {
// title: 'SLA',
// width: '5%'
// },
sla: {
sorting: false,
title: 'SLA',
width: '5%'
},
class_information: {
title: 'Klasser',
width: '15%'
......@@ -73,6 +57,7 @@ function ciColumnDef(){
width: '15%'
},
account: {
sorting: false,
title: 'Konto',
// options: function(data) {
// if(data.source==='list')
......@@ -83,6 +68,7 @@ function ciColumnDef(){
width: '5%'
},
group: {
sorting: false,
title: 'Grupp',
// options: function(data) {
// if(data.source==='list')
......@@ -93,20 +79,46 @@ function ciColumnDef(){
width: '5%'
},
contacts: {
sorting: false,
title: 'Kontaktperson',
width: '5%'
}
},
prev: {
title: '',
width: '1%',
display: renderCiParentTable,
sorting: false
},
next: {
title: '',
width: '1%',
display: renderCiChildTable,
sorting: false
},
sibling: {
title: '',
width: '1%',
display: renderCiSiblingTable,
sorting: false
}
};
return cd;
}
function createSearchCiTable(ciColumnDef, family_type, family_name, sub_queries_included){
function createCiTable(ciColumnDef, family_type, family_name, sub_queries_included){
var sub_query_family_name = ALL;
var sub_query_family_type = ALL;
if(sub_queries_included){
family_name = sub_query_family_name;
family_type = sub_query_family_type;
}
var table = {
title: function (){
if(family_name !== 'Sök')
return 'Sök: ' + family_type + family_name;
if(family_name !== 'All')
return 'Lista: ' + family_type + ' ' + family_name;
else
return 'Sök';
},
......@@ -148,97 +160,115 @@ function ciColumnDef(){
function renderSearchCiChildTable (data) {
function renderCiChildTable (data) {
if(data.record.childs > 0){
return $('<img src="/images/child.png" title="Barn"/>').click(function () {
createSearchCiChildTable(data, $(this).closest('tr'));
createCiChildTable(data, $(this).closest('tr'));
});
}
}
function createSearchCiChildTable(data, row){
$('#cmdb-table').jtable('openChildTable', row, {
title: 'Barn till: ' + data.record.family_type_name + ' ' + data.record.family_name + ' ' + data.record.ci_name,
paging: true, //Enable paging
pageSize: 10, //Set page size (default: 10)
pageList: 'minimal',
sorting: true, //Enable sorting
multiSorting: true,
defaultSorting: 'ci_name ASC', //Set default sorting
actions: {
listAction: '/cmdb/api/v1/ci/child/list/' + data.record.ci_id
},
fields: ciColumnDef()
function createCiChildTable(data, row){
var family_type = data.record.family_type_name;
var family_name = data.record.family_name;
var ci_id = data.record.ci_id;
var ci_name = data.record.ci_name;
$('#cmdb-table').jtable('openChildTable', row, {
title: 'Barn till: ' + family_type + ' - ' + family_name + ' - ' + ci_name,
paging: true, //Enable paging
pageSize: 10, //Set page size (default: 10)
pageList: 'minimal',
sorting: true, //Enable sorting
multiSorting: true,
showCloseButton: true,
defaultSorting: 'ci_name ASC', //Set default sorting
actions: {
listAction: '/cmdb/api/v1/ci/child/list/' + family_type + '/' + family_name +'/' + ci_id
},
function (data) { //opened handler
data.childTable.jtable('load');
});
}
fields: ciColumnDef()
},
function (data) { //opened handler
data.childTable.jtable('load');
});
}
function renderSearchCiSiblingTable(data) {
function renderCiSiblingTable(data) {
if(data.record.siblings > 1){
return $('<img src="/images/sibling.png" title="Syskon"/>').click(function () {
createSearchCiSiblingTable(data, $(this).closest('tr'));
createCiSiblingTable(data, $(this).closest('tr'));
});
}
}
function createSearchCiSiblingTable(data, row){
$('#cmdb-table').jtable('openChildTable', row, {
title: 'Syskon till: ' + data.record.family_type_name + ' ' + data.record.family_name + ' ' + data.record.ci_name,
paging: true, //Enable paging
pageSize: 10, //Set page size (default: 10)
pageList: 'minimal',
sorting: true, //Enable sorting
multiSorting: true,
defaultSorting: 'ci_name ASC', //Set default sorting
actions: {
listAction: '/cmdb/api/v1/ci/child/list/' + data.record.ci_parent_id
},
fields: ciColumnDef()
function createCiSiblingTable(data, row){
var family_type = data.record.family_type_name;
var family_name = data.record.family_name;
var ci_parent_id = data.record.ci_parent_id;
var ci_name = data.record.ci_name;
$('#cmdb-table').jtable('openChildTable', row, {
title: 'Syskon till: ' + family_name + ' - ' + family_name + ' - ' + ci_name,
paging: true, //Enable paging
pageSize: 10, //Set page size (default: 10)
pageList: 'minimal',
sorting: true, //Enable sorting
multiSorting: true,
showCloseButton: true,
defaultSorting: 'ci_name ASC', //Set default sorting
actions: {
listAction: '/cmdb/api/v1/ci/child/list/' + family_type + '/' + family_name +'/' + ci_parent_id
},
function (data) { //opened handler
data.childTable.jtable('load');
});
}
fields: ciColumnDef()
},
function (data) { //opened handler
data.childTable.jtable('load');
});
}
function renderSearchCiParentTable (data) {
function renderCiParentTable (data) {
if(data.record.parents > 0){
return $('<img src="/images/parent.png" title="Förälder"/>').click(function () {
createSearchCiParentTable(data, $(this).closest('tr'));
createCiParentTable(data, $(this).closest('tr'));
});
}
}
function createSearchCiParentTable(data, row){
$('#cmdb-table').jtable('openChildTable', row, {
title: 'Förälder till: ' + data.record.family_type_name + ' ' + data.record.family_name + ' ' + data.record.ci_name,
paging: true, //Enable paging
pageSize: 10, //Set page size (default: 10)
pageList: 'minimal',
sorting: true, //Enable sorting
multiSorting: true,
defaultSorting: 'ci_name ASC', //Set default sorting
actions: {
listAction: '/cmdb/api/v1/ci/parent/list/' + data.record.ci_parent_id
},
fields: ciColumnDef()
function createCiParentTable(data, row){
var family_type = data.record.family_type_name;
var family_name = data.record.family_name;
var ci_parent_id = data.record.ci_parent_id;
var ci_name = data.record.ci_name;
$('#cmdb-table').jtable('openChildTable', row, {
title: 'Förälder till: ' + family_type + ' - ' + family_name + ' - ' + ci_name,
paging: true, //Enable paging
pageSize: 10, //Set page size (default: 10)
pageList: 'minimal',
sorting: true, //Enable sorting
showCloseButton: true,
multiSorting: true,
defaultSorting: 'ci_name ASC', //Set default sorting
actions: {
listAction: '/cmdb/api/v1/ci/parent/list/' + family_type + '/' + family_name +'/' + ci_parent_id
},
function (data) { //opened handler
data.childTable.jtable('load');
});
}
fields: ciColumnDef()
},
function (data) { //opened handler
data.childTable.jtable('load');
});
}
function getSearchCiFamilyId(data){
function getCiFamilyId(data){
return data.record.family_type_id;
}
\ No newline at end of file
function relationTypesTable(){
$('#cmdb-table').jtable({
title: "Typer av relationer",
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/relation/types_group/'
},
fields: {
id: {
title: 'id',
width: '25%',
list: false,
key: true
},
display_name: {
title: 'Namn',
width: '25%'
},
description: {
title: 'Beskrivning',
width: '70%'
},
group_type:{
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(classes){
var $imgGroupType = $('<img src="/images/structure.png" title="Grupptyper" />');
$imgGroupType.click(function () {
$('#cmdb-table').jtable('openChildTable', $imgGroupType.closest('tr'),{
title: '+ Relationstyper inom ' + classes.record.display_name,
actions: {
listAction: '/cmdb/api/v1/relation/types/' + classes.record.id
},
fields: { //family_type
id: {
title: 'id',
width: '3%',
list: true,
key: true
},
display_name: {
title: 'Namn',
width: '25%'
},
description: {
title: 'Beskrivning',
width: '70%'
}
}
},
function(data){
data.childTable.jtable('load');
});
});
return $imgGroupType;
}
},
}
});
$('#cmdb-table').jtable('load');
}
function relationTypesTable(){
$('#cmdb-table').jtable({
title: "Typer av relationer",
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/relation/types/'
},
fields: {
id: {
title: 'id',
width: '25%',
list: false,
key: true
},
display_name: {
title: 'Namn',
width: '25%'
},
description: {
title: 'Beskrivning',
width: '70%'
}
}
});
$('#cmdb-table').jtable('load');
}
const ALL = 'allt';
$(document).ready(function () {
var ref = window.location.href;
......@@ -5,18 +7,21 @@ $(document).ready(function () {
structureTable();
}
if(ref.includes('/ec-system-ci/')){
ciTable('IT-Tjänst','Drift av System',false);
ciTable('IT-Tjänst','Drift av System', false);
// ec_ciTable();
}
if(ref.includes('/ec-file-ci/')){
ciTable('IT-Tjänst','Filtjänst',false);
ciTable('IT-Tjänst','Filtjänst', false);
}
if(ref.includes('/ec-office-ci/')){
ciTable('IT-Tjänst','Klientarbetsplats',false);
ciTable('IT-Tjänst','Klientarbetsplats', false);
}
if(ref.includes('/tfo-ci/')){
tfo_ciTable();
if(ref.includes('/tfo-technical-area-ci/')){
ciTable('Teknikområde infrastruktur', ALL, false);
}
// tfo_ciTable();
if(ref.includes('/organisation/')){
orgTable();
orgGraph(1);
......@@ -29,9 +34,9 @@ $(document).ready(function () {
accessGraph(-1);
}
if(ref.includes('/person/')){
ciTable('','Anställd');
ciTable('Person',ALL, false);
}
if(ref.includes('/search/')){
ciTable('All','Sök',false);
ciTable(ALL, ALL, false);
}
});
\ No newline at end of file
......@@ -7,13 +7,14 @@ const pg = require('pg');
const config = require('./config');
const winston = require('winston');
const connectionString = process.env.DATABASE_URL || config.db_url;
const SEARCH = 'search';
const MAIN = 'main_query';
const ALL = 'allt';
const CHILD = 'child';
const PARENT = 'parent';
router.post('/enterprise_service/list/', (req, res, next) => {
var pool = new pg.Pool({
connectionString: connectionString,
connectionString: connectionString
});
pool.connect(function(err, client, done){
if(err) {
......@@ -64,7 +65,7 @@ router.post('/infrastructure/list', (req, res, next) => {
});
function getSQLSearchQuery(query_type, family_name, req){
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.kst as ci_kst, ci1.description as ci_description, f.display_name as family_name, ft.display_name as family_type_name, ";
......@@ -80,10 +81,12 @@ function getSQLSearchQuery(query_type, family_name, req){
var sql_where_list ="where ci1.id > 0 ";
if(query_type === SEARCH)
if(family_name !== 'Sök')
sql_where_list += "and f.display_name like '" + family_name + "' ";
if(family_name !== ALL)
sql_where_list += "and f.display_name like '" + family_name + "' ";
if(family_type !== ALL)
sql_where_list += "and ft.display_name like '" + family_type + "' ";
var sql_where_search ="and (upper(ci1.display_name) like $1 ";
sql_where_search+="or upper(ci1.description) like $1 ";
sql_where_search+="or upper(ci1.class_information) like $1 ";
......@@ -96,7 +99,7 @@ function getSQLSearchQuery(query_type, family_name, req){
var sql_order_by="order by " + jtSorting + ";";
if(query_type === SEARCH)
if(query_type === MAIN)
sql = sql_select + 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;
......@@ -136,8 +139,9 @@ function formateResult(req, res, result){
router.post('/list/:family_type/:family_name', (req, res, next) => {
var family_type = req.params['family_type'];
var family_name = req.params['family_name'];
var sql = getSQLSearchQuery(SEARCH, family_name, req);
var sql = getSQLSearchQuery(MAIN, family_type, family_name, req);
var ci_search = '%' + req.body.search_string.toUpperCase() + '%';
var parameters = [ci_search];
......@@ -164,9 +168,12 @@ router.post('/list/:family_type/:family_name', (req, res, next) => {
});
router.post('/child/list/:parent_id', (req, res, next) => {
var sql = getSQLSearchQuery(CHILD, '', req);
router.post('/child/list/:family_type/:family_name/:parent_id', (req, res, next) => {
var family_type = req.params['family_type'];
var family_name = req.params['family_name'];
var sql = getSQLSearchQuery(CHILD, family_type, family_name, req);
var parameter = [req.params['parent_id']];
winston.log('info', '*** CHILD TRACE ***', {
parameter:parameter,
sql:sql
......@@ -194,9 +201,12 @@ var pool = new pg.Pool({
router.post('/parent/list/:id', (req, res, next) => {
var sql = getSQLSearchQuery(PARENT, '', req);
router.post('/parent/list/:family_type/:family_name/:id', (req, res, next) => {
var family_type = req.params['family_type'];
var family_name = req.params['family_name'];
var sql = getSQLSearchQuery(PARENT, family_type, family_name, req);
var parameter = [req.params['id']];
winston.log('info', '*** PARENT TRACE ***', {
parameter:parameter,
sql:sql
......
......@@ -9,7 +9,11 @@ const winston = require('winston');
const connectionString = process.env.DATABASE_URL || config.db_url;
router.post('/types', (req, res, next) => {
router.post('/types/:group_id', (req, res, next) => {
var group_id = req.params['group_id'];
var parameter = [group_id];
var pool = new pg.Pool({
connectionString: connectionString,
});
......@@ -22,12 +26,11 @@ router.post('/types', (req, res, next) => {
}
// SQL Query > Select Data
var sql = "select * from cmdb.relation_type order by display_name;";
var parameter = [];
var sql = "select * from cmdb.relation_type where relation_type_group_id = $1 order by display_name;";
client.query(sql, parameter, function(err, result){
done();
if (err){
return res.json(JSON.parse('{"Result":"ERROR", "Message":"relation_type"}'));
return res.json(JSON.parse('{"Result":"ERROR", "Message":"' + sql + '"}'));
}
else {
var response = '{"Result":"OK", "Records":';
......@@ -39,6 +42,35 @@ router.post('/types', (req, res, next) => {
});
});
router.post('/types_group', (req, res, next) => {
var pool = new pg.Pool({
connectionString: connectionString,
});
// Get a Postgres client from the connection pool
pool.connect(function(err, client, done){