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