Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Peter Lundin
cmdb
Commits
735afea9
Commit
735afea9
authored
Dec 09, 2017
by
a001188
Browse files
Some functions work
parent
8c73b0d5
Changes
9
Hide whitespace changes
Inline
Side-by-side
public/javascripts/dashlets/organisation-graph.js
View file @
735afea9
...
...
@@ -12,7 +12,7 @@ function updateGraph(centralNode){
}).
then
(
function
(
edges
)
{
// create a network
var
container
=
document
.
getElementById
(
'
mynetwork
'
);
var
container
=
document
.
getElementById
(
'
cmdb-net
'
);
// provide the data in the vis format
var
data
=
{
...
...
public/javascripts/dashlets/organisation-table.js
View file @
735afea9
$
(
document
).
ready
(
function
()
{
org_table
();
});
function
org_table
(){
$
(
'
#cmdb-table
'
).
jtable
({
title
:
"
Organisation
"
,
paging
:
false
,
//Enable paging
...
...
@@ -296,5 +299,4 @@ $(document).ready(function () {
}
});
$
(
'
#cmdb-table
'
).
jtable
(
'
load
'
);
});
}
public/javascripts/dashlets/structure-graph.js
View file @
735afea9
...
...
@@ -12,7 +12,7 @@ function updateGraph(centralNode){
}).
then
(
function
(
edges
)
{
// create a network
var
container
=
document
.
getElementById
(
'
mynetwork
'
);
var
container
=
document
.
getElementById
(
'
cmdb-net
'
);
// provide the data in the vis format
var
data
=
{
...
...
public/javascripts/dashlets/structure-table.js
View file @
735afea9
$
(
document
).
ready
(
function
()
{
$
(
'
#cmdb-
structure-
table
'
).
jtable
({
$
(
'
#cmdb-table
'
).
jtable
({
title
:
"
Typer av CI-familjer
"
,
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
//
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/structure/family_type
'
},
...
...
@@ -29,6 +29,6 @@ $(document).ready(function () {
}
});
$
(
'
#cmdb-
structure-
table
'
).
jtable
(
'
load
'
);
$
(
'
#cmdb-table
'
).
jtable
(
'
load
'
);
});
routes/organisation.js
View file @
735afea9
...
...
@@ -116,19 +116,18 @@ router.get('/list/nodes/:centralNode', (req, res, next) => {
// Handle connection errors
if
(
err
)
{
done
();
console
.
log
(
err
);
return
res
.
status
(
500
).
json
({
success
:
false
,
data
:
err
});
}
// all leaf
var
sql
=
"
WITH RECURSIVE
org
(id, display_name, parent_
organisation_id, organisation_level
) AS (
"
;
sql
+=
"
SELECT id, display_name, parent_
organisation_id, organisation_level FROM cmdb.organisation org
WHERE
org
.id = $1
"
;
var
sql
=
"
WITH RECURSIVE
tree
(id, display_name, parent_
id
) AS (
"
;
sql
+=
"
SELECT id, display_name, parent_
id FROM cmdb.ci c
WHERE
c
.id = $1
"
;
sql
+=
"
UNION
"
;
sql
+=
"
SELECT sub.id, sub.display_name, sub.parent_
organisation_id, sub.organisation_level
"
;
sql
+=
"
FROM
org
, cmdb.
organisation
sub
"
;
sql
+=
"
WHERE
org
.id = sub.parent_
organisation_
id)
"
;
sql
+=
"
SELECT sub.id, sub.display_name, sub.parent_
id
"
;
sql
+=
"
FROM
tree
, cmdb.
ci
sub
"
;
sql
+=
"
WHERE
tree
.id = sub.parent_id)
"
;
sql
+=
"
SELECT id, display_name as label
"
;
sql
+=
"
FROM
org
order by
organisation_level
"
;
sql
+=
"
FROM
tree
order by
display_name
"
;
sql
+=
"
limit 10;
"
;
/*
too root
...
...
@@ -146,12 +145,12 @@ limit 10
// var sql = "select id, concat(id, '. ', (select display_name from cmdb.organisation_type as ot where// ot.id=organisation_type), ': ', display_name) as label from cmdb.organisation where id >0;";
var
centralNode
=
[
req
.
params
[
'
centralNode
'
]
]
;
client
.
query
(
sql
,
centralNode
,
function
(
err
,
result
){
var
centralNode
=
req
.
params
[
'
centralNode
'
];
client
.
query
(
sql
,
[
centralNode
]
,
function
(
err
,
result
){
done
();
if
(
err
){
//
JSON.stringify(req.params)
console
.
log
(
err
.
message
);
return
res
.
json
(
JSON
.
parse
(
'
{"Result":"ERROR", "Message":"
'
+
'
.
'
+
'
"}
'
));
if
(
err
){
//
//
console.log(err.message);
return
res
.
json
(
JSON
.
parse
(
'
{"Result":"ERROR", "Message":"
'
+
err
.
message
+
'
"}
'
));
}
else
{
return
res
.
json
(
result
.
rows
);
...
...
@@ -172,14 +171,14 @@ router.get('/list/edges/:centralNode', (req, res, next) => {
console
.
log
(
err
.
message
);
return
res
.
status
(
500
).
json
({
success
:
false
,
data
:
err
});
}
var
sql
=
"
WITH RECURSIVE
org
(id, display_name, parent_
organisation_
id) AS (
"
;
sql
+=
"
SELECT id, display_name, parent_
organisation_id FROM cmdb.organisation org
WHERE
org
.id = $1
"
;
var
sql
=
"
WITH RECURSIVE
tree
(id, display_name, parent_id) AS (
"
;
sql
+=
"
SELECT id, display_name, parent_
id FROM cmdb.ci c
WHERE
c
.id = $1
"
;
sql
+=
"
UNION
"
;
sql
+=
"
SELECT sub.id, sub.display_name, sub.parent_
organisation_
id
"
;
sql
+=
"
FROM
org
, cmdb.
organisation
sub
"
;
sql
+=
"
WHERE
org
.id = sub.parent_
organisation_
id)
"
;
sql
+=
"
SELECT id as from, parent_
organisation_
id as to
"
;
sql
+=
"
FROM
org
"
;
sql
+=
"
SELECT sub.id, sub.display_name, sub.parent_id
"
;
sql
+=
"
FROM
tree
, cmdb.
ci
sub
"
;
sql
+=
"
WHERE
tree
.id = sub.parent_id)
"
;
sql
+=
"
SELECT id as from, parent_id as to
"
;
sql
+=
"
FROM
tree
"
;
sql
+=
"
limit 10;
"
;
/*
too root
...
...
@@ -199,7 +198,7 @@ limit 10
client
.
query
(
sql
,
centralNode
,
function
(
err
,
result
){
done
();
if
(
err
){
return
res
.
json
(
JSON
.
parse
(
'
{"Result":"ERROR", "Message":"
/list/edges/:top
"}
'
));
return
res
.
json
(
JSON
.
parse
(
'
{"Result":"ERROR", "Message":"
'
+
sql
+
'
"}
'
));
}
else
{
return
res
.
json
(
result
.
rows
);
...
...
routes/structure.js
View file @
735afea9
...
...
@@ -7,7 +7,6 @@ const path = require('path');
const
connectionString
=
process
.
env
.
DATABASE_URL
||
'
postgres://jasper.u:Me4sgyAp@postgresql-utv.smhi.se:5432/jasper
'
;
router
.
post
(
'
/family_type
'
,
(
req
,
res
,
next
)
=>
{
var
pool
=
new
pg
.
Pool
({
connectionString
:
connectionString
,
...
...
@@ -24,13 +23,13 @@ router.post('/family_type', (req, res, next) => {
// SQL Query > Select Data
var
sql
=
"
select * from cmdb.family_type order by sort_order;
"
;
var
parameter
=
[];
client
.
query
(
sql
,
parameter
,
function
(
err
,
result
){
client
.
query
(
sql
,
[]
,
function
(
err
,
result
){
done
();
if
(
err
){
return
res
.
json
(
JSON
.
parse
(
'
{"Result":"ERROR", "Message":"/family_type"}
'
));
}
else
{
var
response
=
'
{"Result":"OK", "
Option
s":
'
;
var
response
=
'
{"Result":"OK", "
Record
s":
'
;
response
+=
JSON
.
stringify
(
result
.
rows
);
response
+=
'
,"TotalRecordCount":
'
+
result
.
rowCount
+
'
}
'
;
return
res
.
json
(
JSON
.
parse
(
response
));
...
...
@@ -64,7 +63,7 @@ router.post('/family/:family_type_id', (req, res, next) => {
return
res
.
json
(
JSON
.
parse
(
'
{"Result":"ERROR", "Message":"/family/:family_type_id"}
'
));
}
else
{
var
response
=
'
{"Result":"OK", "
Option
s":
'
;
var
response
=
'
{"Result":"OK", "
Record
s":
'
;
response
+=
JSON
.
stringify
(
result
.
rows
);
response
+=
'
,"TotalRecordCount":
'
+
result
.
rowCount
+
'
}
'
;
return
res
.
json
(
JSON
.
parse
(
response
));
...
...
views/index.pug
View file @
735afea9
...
...
@@ -2,10 +2,11 @@ extends menu
block content
<p class='cmdbguiSmallText'>Visar: #{title}</p>
table
p
table(style="width: 100%")
tr
td(
id='left'
)
<p class='cmdbguiSmallText'>Tabell #{id_table}</p>
td(
id='right'
)
<p class='cmdbguiSmallText'>Relationer #{id_net}</p>
td(
style="width: 50%"
)
#cmdb-table
td(
style="width: 50%"
)
#cmdb-net
views/layout.pug
View file @
735afea9
...
...
@@ -8,16 +8,16 @@ html
link(rel='stylesheet', href='/javascripts/jtable/themes/lightcolor/blue/jtable.min.css')
link(rel='stylesheet', href='//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css')
link(rel='stylesheet', href='/javascripts/vis/dist/vis.css')
script(
'
type
'
='text/javascript',
'
src
'
='//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js')
script(
'
type
'
='text/javascript',
'
src
'
='//cdnjs.cloudflare.com/ajax/libs/jquery-form-validator/2.1.47/jquery.form-validator.min.js')
script(
'
type
'
='text/javascript', '//code.jquery.com/jquery-1.10.2.js')
script(
'
type
'
='text/javascript', '//code.jquery.com/ui/1.10.4/jquery-ui.js')
script(
'
type
'
='text/javascript',
'
src
'
='/javascripts/
menu
.js')
script(
'
type
'
='text/javascript',
'
src
'
='/javascripts/dashlets/structure-
table
.js')
//
script(
'
type
'
='text/javascript',
'
src
'
='/javascripts/
dashlets/structure-graph
.js')
script(
'
type
'
='text/javascript',
'
src
'
='/javascripts/jtable/jquery.jtable.
min.
js')
script(
'
type
'
='text/javascript',
'
src
'
='/javascripts/
jtable/jquery.jtable
.js')
script(
'
type
'
='text/javascript',
'
src
'
='/javascripts/jtable/localization/jquery.jtable.se.js')
script(type='text/javascript', src='//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js')
script(type='text/javascript', src='//cdnjs.cloudflare.com/ajax/libs/jquery-form-validator/2.1.47/jquery.form-validator.min.js')
script(type='text/javascript',
src=
'//code.jquery.com/jquery-1.10.2.js')
script(type='text/javascript',
src=
'//code.jquery.com/ui/1.10.4/jquery-ui.js')
script(type='text/javascript', src='/javascripts/
dashlets/structure-table
.js')
script(type='text/javascript', src='/javascripts/dashlets/structure-
graph
.js')
script(type='text/javascript', src='/javascripts/
jtable/jquery.jtable.min
.js')
script(type='text/javascript', src='/javascripts/jtable/jquery.jtable.js')
script(type='text/javascript', src='/javascripts/
vis/dist/vis
.js')
script(type='text/javascript', src='/javascripts/jtable/localization/jquery.jtable.se.js')
body
block menu
...
...
views/menu.pug
View file @
735afea9
extends layout
block menu
table(class='cmdbguiSmallText')
tr
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment