Commit db4d9ea2 authored by a001188's avatar a001188
Browse files

Sort implemented

parent 5e4039c5
...@@ -4,43 +4,15 @@ ...@@ -4,43 +4,15 @@
// sub_queries_included: if filter should be included in subqueries // sub_queries_included: if filter should be included in subqueries
//************************************************** //**************************************************
function ciTable(family_type, family_name, sub_queries_included){ 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'); $('#cmdb-table').jtable('load');
} }
function ciColumnDef(){ function ciColumnDef(){
var cd = { 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: { ci_id: {
title: 'id', title: 'id',
width: '1%', width: '1%',
...@@ -56,14 +28,26 @@ function ciColumnDef(){ ...@@ -56,14 +28,26 @@ function ciColumnDef(){
title: 'Beskrivning', title: 'Beskrivning',
width: '10%' width: '10%'
}, },
family_type_name: {
title: 'Familjetyp',
width: '5%',
sorting: true
},
family_name: {
title: 'Familj',
width: '5%',
sorting: true
},
ci_kst: { ci_kst: {
sorting: false,
title: 'Ekonomi', title: 'Ekonomi',
width: '3%' width: '3%'
}, },
// sla: { sla: {
// title: 'SLA', sorting: false,
// width: '5%' title: 'SLA',
// }, width: '5%'
},
class_information: { class_information: {
title: 'Klasser', title: 'Klasser',
width: '15%' width: '15%'
...@@ -73,6 +57,7 @@ function ciColumnDef(){ ...@@ -73,6 +57,7 @@ function ciColumnDef(){
width: '15%' width: '15%'
}, },
account: { account: {
sorting: false,
title: 'Konto', title: 'Konto',
// options: function(data) { // options: function(data) {
// if(data.source==='list') // if(data.source==='list')
...@@ -83,6 +68,7 @@ function ciColumnDef(){ ...@@ -83,6 +68,7 @@ function ciColumnDef(){
width: '5%' width: '5%'
}, },
group: { group: {
sorting: false,
title: 'Grupp', title: 'Grupp',
// options: function(data) { // options: function(data) {
// if(data.source==='list') // if(data.source==='list')
...@@ -93,20 +79,46 @@ function ciColumnDef(){ ...@@ -93,20 +79,46 @@ function ciColumnDef(){
width: '5%' width: '5%'
}, },
contacts: { contacts: {
sorting: false,
title: 'Kontaktperson', title: 'Kontaktperson',
width: '5%' 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; 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 = { var table = {
title: function (){ title: function (){
if(family_name !== 'Sök') if(family_name !== 'All')
return 'Sök: ' + family_type + family_name; return 'Lista: ' + family_type + ' ' + family_name;
else else
return 'Sök'; return 'Sök';
}, },
...@@ -148,97 +160,115 @@ function ciColumnDef(){ ...@@ -148,97 +160,115 @@ function ciColumnDef(){
function renderSearchCiChildTable (data) { function renderCiChildTable (data) {
if(data.record.childs > 0){ if(data.record.childs > 0){
return $('<img src="/images/child.png" title="Barn"/>').click(function () { return $('<img src="/images/child.png" title="Barn"/>').click(function () {
createSearchCiChildTable(data, $(this).closest('tr')); createCiChildTable(data, $(this).closest('tr'));
}); });
} }
} }
function createSearchCiChildTable(data, row){ function createCiChildTable(data, row){
$('#cmdb-table').jtable('openChildTable', row, { var family_type = data.record.family_type_name;
title: 'Barn till: ' + data.record.family_type_name + ' ' + data.record.family_name + ' ' + data.record.ci_name, var family_name = data.record.family_name;
paging: true, //Enable paging var ci_id = data.record.ci_id;
pageSize: 10, //Set page size (default: 10) var ci_name = data.record.ci_name;
pageList: 'minimal',
sorting: true, //Enable sorting $('#cmdb-table').jtable('openChildTable', row, {
multiSorting: true, title: 'Barn till: ' + family_type + ' - ' + family_name + ' - ' + ci_name,
defaultSorting: 'ci_name ASC', //Set default sorting paging: true, //Enable paging
actions: { pageSize: 10, //Set page size (default: 10)
listAction: '/cmdb/api/v1/ci/child/list/' + data.record.ci_id pageList: 'minimal',
}, sorting: true, //Enable sorting
fields: ciColumnDef() 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 fields: ciColumnDef()
data.childTable.jtable('load'); },
}); function (data) { //opened handler
} data.childTable.jtable('load');
});
}
function renderSearchCiSiblingTable(data) { function renderCiSiblingTable(data) {
if(data.record.siblings > 1){ if(data.record.siblings > 1){
return $('<img src="/images/sibling.png" title="Syskon"/>').click(function () { return $('<img src="/images/sibling.png" title="Syskon"/>').click(function () {
createSearchCiSiblingTable(data, $(this).closest('tr')); createCiSiblingTable(data, $(this).closest('tr'));
}); });
} }
} }
function createSearchCiSiblingTable(data, row){ function createCiSiblingTable(data, row){
$('#cmdb-table').jtable('openChildTable', row, { var family_type = data.record.family_type_name;
title: 'Syskon till: ' + data.record.family_type_name + ' ' + data.record.family_name + ' ' + data.record.ci_name, var family_name = data.record.family_name;
paging: true, //Enable paging var ci_parent_id = data.record.ci_parent_id;
pageSize: 10, //Set page size (default: 10) var ci_name = data.record.ci_name;
pageList: 'minimal',
sorting: true, //Enable sorting $('#cmdb-table').jtable('openChildTable', row, {
multiSorting: true, title: 'Syskon till: ' + family_name + ' - ' + family_name + ' - ' + ci_name,
defaultSorting: 'ci_name ASC', //Set default sorting paging: true, //Enable paging
actions: { pageSize: 10, //Set page size (default: 10)
listAction: '/cmdb/api/v1/ci/child/list/' + data.record.ci_parent_id pageList: 'minimal',
}, sorting: true, //Enable sorting
fields: ciColumnDef() 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 fields: ciColumnDef()
data.childTable.jtable('load'); },
}); function (data) { //opened handler
} data.childTable.jtable('load');
});
}
function renderSearchCiParentTable (data) { function renderCiParentTable (data) {
if(data.record.parents > 0){ if(data.record.parents > 0){
return $('<img src="/images/parent.png" title="Förälder"/>').click(function () { 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){ function createCiParentTable(data, row){
$('#cmdb-table').jtable('openChildTable', row, { var family_type = data.record.family_type_name;
title: 'Förälder till: ' + data.record.family_type_name + ' ' + data.record.family_name + ' ' + data.record.ci_name, var family_name = data.record.family_name;
paging: true, //Enable paging var ci_parent_id = data.record.ci_parent_id;
pageSize: 10, //Set page size (default: 10) var ci_name = data.record.ci_name;
pageList: 'minimal',
sorting: true, //Enable sorting $('#cmdb-table').jtable('openChildTable', row, {
multiSorting: true, title: 'Förälder till: ' + family_type + ' - ' + family_name + ' - ' + ci_name,
defaultSorting: 'ci_name ASC', //Set default sorting paging: true, //Enable paging
actions: { pageSize: 10, //Set page size (default: 10)
listAction: '/cmdb/api/v1/ci/parent/list/' + data.record.ci_parent_id pageList: 'minimal',
}, sorting: true, //Enable sorting
fields: ciColumnDef() 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 fields: ciColumnDef()
data.childTable.jtable('load'); },
}); function (data) { //opened handler
} data.childTable.jtable('load');
});
}
function getSearchCiFamilyId(data){ function getCiFamilyId(data){
return data.record.family_type_id; 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 () { $(document).ready(function () {
var ref = window.location.href; var ref = window.location.href;
...@@ -5,18 +7,21 @@ $(document).ready(function () { ...@@ -5,18 +7,21 @@ $(document).ready(function () {
structureTable(); structureTable();
} }
if(ref.includes('/ec-system-ci/')){ if(ref.includes('/ec-system-ci/')){
ciTable('IT-Tjänst','Drift av System',false); ciTable('IT-Tjänst','Drift av System', false);
// ec_ciTable(); // ec_ciTable();
} }
if(ref.includes('/ec-file-ci/')){ 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/')){ 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/')){ if(ref.includes('/organisation/')){
orgTable(); orgTable();
orgGraph(1); orgGraph(1);
...@@ -29,9 +34,9 @@ $(document).ready(function () { ...@@ -29,9 +34,9 @@ $(document).ready(function () {
accessGraph(-1); accessGraph(-1);
} }
if(ref.includes('/person/')){ if(ref.includes('/person/')){
ciTable('','Anställd'); ciTable('Person',ALL, false);
} }
if(ref.includes('/search/')){ 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'); ...@@ -7,13 +7,14 @@ const pg = require('pg');
const config = require('./config'); const config = require('./config');
const winston = require('winston'); const winston = require('winston');
const connectionString = process.env.DATABASE_URL || config.db_url; const connectionString = process.env.DATABASE_URL || config.db_url;
const SEARCH = 'search'; const MAIN = 'main_query';
const ALL = 'allt';
const CHILD = 'child'; const CHILD = 'child';
const PARENT = 'parent'; const PARENT = 'parent';
router.post('/enterprise_service/list/', (req, res, next) => { router.post('/enterprise_service/list/', (req, res, next) => {
var pool = new pg.Pool({ var pool = new pg.Pool({
connectionString: connectionString, connectionString: connectionString
}); });
pool.connect(function(err, client, done){ pool.connect(function(err, client, done){
if(err) { if(err) {
...@@ -64,7 +65,7 @@ router.post('/infrastructure/list', (req, res, next) => { ...@@ -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 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, "; 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){ ...@@ -80,10 +81,12 @@ function getSQLSearchQuery(query_type, family_name, req){
var sql_where_list ="where ci1.id > 0 "; var sql_where_list ="where ci1.id > 0 ";
if(query_type === SEARCH) if(family_name !== ALL)
if(family_name !== 'Sök') sql_where_list += "and f.display_name like '" + family_name + "' ";
sql_where_list += "and f.display_name like '" + family_name + "' ";