Commit ed37407e authored by a001188's avatar a001188
Browse files

Some function works

parent 61cd3191
.config.json
\ No newline at end of file
...@@ -15,6 +15,12 @@ var structure = require('./routes/structure'); ...@@ -15,6 +15,12 @@ var structure = require('./routes/structure');
var users = require('./routes/users'); var users = require('./routes/users');
var app = express(); var app = express();
const winston = require('winston'); const winston = require('winston');
var fs = require('fs'),
configPath = '.config.json';
var parsed = JSON.parse(fs.readFileSync(configPath, 'UTF-8'));
exports.storageConfig=parsed;
// view engine setup // view engine setup
app.set('views', path.join(__dirname, 'views')); app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'pug'); app.set('view engine', 'pug');
...@@ -37,6 +43,10 @@ app.use('/cmdb/api/v1/organisation', organisation); ...@@ -37,6 +43,10 @@ app.use('/cmdb/api/v1/organisation', organisation);
app.use('/cmdb/api/v1/structure', structure); app.use('/cmdb/api/v1/structure', structure);
app.use('/cmdb/api/v1/ci', ci); app.use('/cmdb/api/v1/ci', ci);
winston.log('info', 'cmdb-viewer-app started', {
Winston: 'current logger'
})
// catch 404 and forward to error handler // catch 404 and forward to error handler
app.use(function(req, res, next) { app.use(function(req, res, next) {
var err = new Error('Not Found'); var err = new Error('Not Found');
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
"fetchSpec": "~2.6.9" "fetchSpec": "~2.6.9"
}, },
"_requiredBy": [ "_requiredBy": [
"#USER",
"/", "/",
"/body-parser", "/body-parser",
"/express", "/express",
......
...@@ -73,6 +73,11 @@ ...@@ -73,6 +73,11 @@
"integrity": "sha1-104bh+ev/A24qttwIfP+SBAasjQ=", "integrity": "sha1-104bh+ev/A24qttwIfP+SBAasjQ=",
"optional": true "optional": true
}, },
"async": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/async/-/async-1.0.0.tgz",
"integrity": "sha1-+PwEyjoTeErenhZBr5hXjPvWR6k="
},
"asynckit": { "asynckit": {
"version": "0.4.0", "version": "0.4.0",
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
...@@ -215,6 +220,11 @@ ...@@ -215,6 +220,11 @@
"integrity": "sha1-bqa989hTrlTMuOR7+gvz+QMfsYQ=", "integrity": "sha1-bqa989hTrlTMuOR7+gvz+QMfsYQ=",
"optional": true "optional": true
}, },
"colors": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/colors/-/colors-1.0.3.tgz",
"integrity": "sha1-BDP0TYCWgP3rYO0mDxsMJi6CpAs="
},
"combined-stream": { "combined-stream": {
"version": "1.0.5", "version": "1.0.5",
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.5.tgz", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.5.tgz",
...@@ -299,6 +309,11 @@ ...@@ -299,6 +309,11 @@
"resolved": "https://registry.npmjs.org/css-stringify/-/css-stringify-1.0.5.tgz", "resolved": "https://registry.npmjs.org/css-stringify/-/css-stringify-1.0.5.tgz",
"integrity": "sha1-sNBClG2ylTu50pKQCmy19tASIDE=" "integrity": "sha1-sNBClG2ylTu50pKQCmy19tASIDE="
}, },
"cycle": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/cycle/-/cycle-1.0.3.tgz",
"integrity": "sha1-IegLK+hYD5i0aPN5QwZisEbDStI="
},
"dashdash": { "dashdash": {
"version": "1.14.1", "version": "1.14.1",
"resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz", "resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz",
...@@ -450,6 +465,11 @@ ...@@ -450,6 +465,11 @@
"resolved": "https://registry.npmjs.org/extsprintf/-/extsprintf-1.3.0.tgz", "resolved": "https://registry.npmjs.org/extsprintf/-/extsprintf-1.3.0.tgz",
"integrity": "sha1-lpGEQOMEGnpBT4xS48V06zw+HgU=" "integrity": "sha1-lpGEQOMEGnpBT4xS48V06zw+HgU="
}, },
"eyes": {
"version": "0.1.8",
"resolved": "https://registry.npmjs.org/eyes/-/eyes-0.1.8.tgz",
"integrity": "sha1-Ys8SAjTGg3hdkCNIqADvPgzCC8A="
},
"finalhandler": { "finalhandler": {
"version": "1.0.6", "version": "1.0.6",
"resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.0.6.tgz", "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.0.6.tgz",
...@@ -498,6 +518,11 @@ ...@@ -498,6 +518,11 @@
"resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz",
"integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac=" "integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac="
}, },
"fs": {
"version": "0.0.1-security",
"resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz",
"integrity": "sha1-invTcYa23d84E/I4WLV+yq9eQdQ="
},
"function-bind": { "function-bind": {
"version": "1.1.1", "version": "1.1.1",
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz",
...@@ -673,8 +698,7 @@ ...@@ -673,8 +698,7 @@
"isstream": { "isstream": {
"version": "0.1.2", "version": "0.1.2",
"resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz", "resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz",
"integrity": "sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo=", "integrity": "sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo="
"optional": true
}, },
"jade": { "jade": {
"version": "1.11.0", "version": "1.11.0",
...@@ -1527,6 +1551,11 @@ ...@@ -1527,6 +1551,11 @@
} }
} }
}, },
"stack-trace": {
"version": "0.0.10",
"resolved": "https://registry.npmjs.org/stack-trace/-/stack-trace-0.0.10.tgz",
"integrity": "sha1-VHxws0fo0ytOEI6hoqFZ5f3eGcA="
},
"statuses": { "statuses": {
"version": "1.4.0", "version": "1.4.0",
"resolved": "https://registry.npmjs.org/statuses/-/statuses-1.4.0.tgz", "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.4.0.tgz",
...@@ -1708,6 +1737,19 @@ ...@@ -1708,6 +1737,19 @@
"resolved": "https://registry.npmjs.org/window-size/-/window-size-0.1.0.tgz", "resolved": "https://registry.npmjs.org/window-size/-/window-size-0.1.0.tgz",
"integrity": "sha1-VDjNLqk7IC76Ohn+iIeu58lPnJ0=" "integrity": "sha1-VDjNLqk7IC76Ohn+iIeu58lPnJ0="
}, },
"winston": {
"version": "2.4.0",
"resolved": "https://registry.npmjs.org/winston/-/winston-2.4.0.tgz",
"integrity": "sha1-gIBQuT1SZh7Z+2wms/DIJnCLCu4=",
"requires": {
"async": "1.0.0",
"colors": "1.0.3",
"cycle": "1.0.3",
"eyes": "0.1.8",
"isstream": "0.1.2",
"stack-trace": "0.0.10"
}
},
"with": { "with": {
"version": "4.0.3", "version": "4.0.3",
"resolved": "https://registry.npmjs.org/with/-/with-4.0.3.tgz", "resolved": "https://registry.npmjs.org/with/-/with-4.0.3.tgz",
......
...@@ -9,8 +9,9 @@ ...@@ -9,8 +9,9 @@
"bluebird": "^3.5.1", "bluebird": "^3.5.1",
"body-parser": "~1.18.2", "body-parser": "~1.18.2",
"cookie-parser": "~1.4.3", "cookie-parser": "~1.4.3",
"debug": "~2.6.9", "debug": "^2.6.9",
"express": "~4.15.5", "express": "~4.15.5",
"fs": "0.0.1-security",
"jade": "~1.11.0", "jade": "~1.11.0",
"jquery": "^3.2.1", "jquery": "^3.2.1",
"jtable": "^2.5.0", "jtable": "^2.5.0",
...@@ -20,6 +21,7 @@ ...@@ -20,6 +21,7 @@
"pg-promise": "^5.9.7", "pg-promise": "^5.9.7",
"pug": "^2.0.0-rc.4", "pug": "^2.0.0-rc.4",
"serve-favicon": "~2.4.5", "serve-favicon": "~2.4.5",
"vis": "^4.21.0" "vis": "^4.21.0",
"winston": "^2.4.0"
} }
} }
...@@ -17,7 +17,7 @@ function organisationGraph(centralNode){ ...@@ -17,7 +17,7 @@ function organisationGraph(centralNode){
}; };
var options = { var options = {
height: '1200px', height: '800px',
layout: { layout: {
randomSeed: undefined, randomSeed: undefined,
improvedLayout:true, improvedLayout:true,
......
var express = require('express'); var express = require('express');
var router = express.Router(); var router = express.Router();
const pg = require('pg'); const pg = require('pg');
const jQuery = require('jquery'); const jQuery = require('jquery');
const path = require('path'); const path = require('path');
const connectionString = process.env.DATABASE_URL || 'postgres://jasper.u:Me4sgyAp@postgresql-utv.smhi.se:5432/jasper'; var options = require('./options');
//var dburl= options.storageConfig.DBMS + "://" + options.storageConfig.USER + ":" + options.storageConfig.PASSWORD + "@" + options.storageConfig.HOST + ":" + options.storageConfig.POSRT + "://" + options.storageConfig.DATABASE;
const connectionString = process.env.DATABASE_URL || 'postgres://jasper.u:Me4sgyAp@postgresql-utv.smhi.se:5432/jasper';
//const connectionString = process.env.DATABASE_URL || dburl;
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({
......
var express = require('express'); var express = require('express');
var router = express.Router(); var router = express.Router();
const winston = require('winston'); const winston = require('winston');
//const rootpath = '/cmdb/api/v1';
const rootpath = '/cmdb/api/v1';
const pg = require('pg'); const pg = require('pg');
const path = require('path'); const path = require('path');
const connectionString = process.env.DATABASE_URL || 'postgres://jasper:a001188@localhost:5432/jasper'; const connectionString = process.env.DATABASE_URL || 'postgres://jasper:a001188@localhost:5432/jasper';
...@@ -10,23 +9,25 @@ const connectionString = process.env.DATABASE_URL || 'postgres://jasper:a001188@ ...@@ -10,23 +9,25 @@ const connectionString = process.env.DATABASE_URL || 'postgres://jasper:a001188@
/* GET home page. */ /* GET home page. */
router.get('/', function(req, res, next) { router.get('/', function(req, res, next) {
winston.log('info', 'Hello log files!', { return res.render('index', { title: 'cmdb: hem'});
someKey: 'some-value'
});
res.render('index', { title: 'Hem'});
}); });
router.get('/view/:id/:i', function(req, res, next) { router.get('/view/:id/:i', function(req, res, next) {
var id = 'cmdb - ' + req.params['id']; var id = 'cmdb: ' + req.params['id'];
var i = '' + req.params['i']; var i = '' + req.params['i'];
winston.log('info', 'uri: /view/:id/:i', {
id: id,
i: i
})
if(i==='1') if(i==='1')
res.render('index_1', { title: id, index: i}); return res.render('index_1', { title: id, index: i});
if(i==='2') if(i==='2')
res.render('index_2', { title: id, index: i}); return res.render('index_2', { title: id, index: i});
else else
res.render('index', { title: id, index: i}); return res.render('index', { title: id, index: i});
}); });
module.exports = router; module.exports = router;
...@@ -19,9 +19,9 @@ router.post('/family_type', (req, res, next) => { ...@@ -19,9 +19,9 @@ router.post('/family_type', (req, res, next) => {
} }
var sql = "select display_name as \"DisplayText\", id as \"Value\" from cmdb.family_type;"; var sql = "select display_name as \"DisplayText\", id as \"Value\" from cmdb.family_type;";
client.query(sql, [], function(err, result){ client.query(sql, [], function(err, result){
done(); done();
if (err){ if (err){
return res.json(JSON.parse('{"Result":"ERROR", "Message":"' + sql + '"}')); return res.json(JSON.parse('{"Result":"ERROR", "Message":"' + sql + '"}'));
} }
else { else {
var response = '{"Result":"OK", "Options":'; var response = '{"Result":"OK", "Options":';
...@@ -47,9 +47,9 @@ router.post('/parent', (req, res, next) => { ...@@ -47,9 +47,9 @@ router.post('/parent', (req, res, next) => {
} }
var sql = "select display_name as \"DisplayText\", id as \"Value\" from cmdb.ci;"; var sql = "select display_name as \"DisplayText\", id as \"Value\" from cmdb.ci;";
client.query(sql, [], function(err, result){ client.query(sql, [], function(err, result){
done(); done();
if (err){ if (err){
return res.json(JSON.parse('{"Result":"ERROR", "Message":"' + sql + '"}')); return res.json(JSON.parse('{"Result":"ERROR", "Message":"' + sql + '"}'));
} }
else { else {
var response = '{"Result":"OK", "Options":'; var response = '{"Result":"OK", "Options":';
...@@ -71,8 +71,8 @@ router.post('/families/:family_type_id', (req, res, next) => { ...@@ -71,8 +71,8 @@ router.post('/families/:family_type_id', (req, res, next) => {
pool.connect(function(err, client, done){ pool.connect(function(err, client, done){
// Handle connection errors // Handle connection errors
if(err) { if(err) {
done(); done();
return res.status(500).json({success: false , data: err}); return res.status(500).json({success: false , data: err});
} }
// SQL Query > Select Data // SQL Query > Select Data
......
...@@ -50,7 +50,6 @@ limit 10 ...@@ -50,7 +50,6 @@ limit 10
client.query(sql, [centralNode], function(err, result){ client.query(sql, [centralNode], function(err, result){
done(); done();
if (err){ // if (err){ //
//console.log(err.message);
return res.json(JSON.parse('{"Result":"ERROR", "Message":"' + err.message + '"}')); return res.json(JSON.parse('{"Result":"ERROR", "Message":"' + err.message + '"}'));
} }
else { else {
...@@ -192,7 +191,6 @@ router.post('/update', (req, res, next) => { ...@@ -192,7 +191,6 @@ router.post('/update', (req, res, next) => {
// Handle connection errors // Handle connection errors
if(err) { if(err) {
done(); done();
console.log(err);
return res.status(500).json({success: false , data: err}); return res.status(500).json({success: false , data: err});
} }
......
...@@ -180,7 +180,6 @@ router.get('/edges', (req, res, next) => { ...@@ -180,7 +180,6 @@ router.get('/edges', (req, res, next) => {
client.query(sql, [], function(err, result){ client.query(sql, [], function(err, result){
done(); done();
if (err){ if (err){
console.log('paramter: ' + JSON.stringify(parameter));
return res.json(JSON.parse('{"Result":"ERROR", "Message":"' + sql + '"}')); return res.json(JSON.parse('{"Result":"ERROR", "Message":"' + sql + '"}'));
} }
else { else {
......
...@@ -16,7 +16,6 @@ router.post('/family_types', (req, res, next) => { ...@@ -16,7 +16,6 @@ router.post('/family_types', (req, res, next) => {
// Handle connection errors // Handle connection errors
if(err) { if(err) {
done(); done();
console.log(err);
return res.status(500).json({success: false , data: err}); return res.status(500).json({success: false , data: err});
} }
...@@ -58,7 +57,6 @@ router.post('/families/:family_type_id', (req, res, next) => { ...@@ -58,7 +57,6 @@ router.post('/families/:family_type_id', (req, res, next) => {
client.query(sql, parameter, function(err, result){ client.query(sql, parameter, function(err, result){
done(); done();
if (err){ if (err){
console.log('paramter: ' + JSON.stringify(parameter));
return res.json(JSON.parse('{"Result":"ERROR", "Message":"/family/:family_type_id"}')); return res.json(JSON.parse('{"Result":"ERROR", "Message":"/family/:family_type_id"}'));
} }
else { else {
......
...@@ -4,6 +4,7 @@ var router = express.Router(); ...@@ -4,6 +4,7 @@ var router = express.Router();
/* GET users listing. */ /* GET users listing. */
router.get('/', function(req, res, next) { router.get('/', function(req, res, next) {
res.send('respond with a resource'); res.send('respond with a resource');
return;
}); });
module.exports = router; module.exports = router;
extends menu extends menu
block content block content
h1 #{title} p(class='cmdbguiSmallText') #{title}
extends menu extends menu
block content block content
p(class='cmdbguiSmallText') #{title}
#cmdb-table #cmdb-table
extends menu extends menu
block content block content
p(class='cmdbguiSmallText') #{title}
table(style="width: 100%") table(style="width: 100%")
tr tr
td(style="width: 30%; vertical-align: top;") td(style="width: 30%; vertical-align: top;")
......
...@@ -5,7 +5,8 @@ block menu ...@@ -5,7 +5,8 @@ block menu
table(class='cmdbguiSmallText') table(class='cmdbguiSmallText')
tr tr
td(style='text-align: left') CMDB-Viewer td(style='text-align: left') CMDB-Viewer
td(style='text-align: right') a001188 Peter Lundin td(style='text-align: right')
a(href="https://git.smhi.se/a001188/cmdb") git.smhi.se/a001188/cmdb
nav nav
ul(class='nav') ul(class='nav')
li li
...@@ -30,12 +31,12 @@ block menu ...@@ -30,12 +31,12 @@ block menu
a(href="#") Övrig konfiguration a(href="#") Övrig konfiguration
ul ul
li li
a(href="/view/organisation/1") Organisation a(href="/view/organisation/2") Organisation
li li
a(href="/view/person/1") Person a(href="/view/person/1") Person
li li
a(href="/view/financial-account/1") Kontoplan a(href="/view/financial-account/1") Kontoplan
li li
a(href="/view/site") Siter och lokaler a(href="/view/site/1") Siter och lokaler
Supports Markdown
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