Skip to content

Commit

Permalink
doc
Browse files Browse the repository at this point in the history
  • Loading branch information
scardena committed Mar 15, 2016
1 parent 1887a6f commit 883e913
Show file tree
Hide file tree
Showing 4 changed files with 205 additions and 27 deletions.
109 changes: 108 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,116 @@ We do not need to modify the view, since the only thing that changed is the cont

<h1> Creating our first widget </h1>
Now that we know how to store data in mongo, retrieve it nodejs, and sending it to the AdminLTE views, we are going to create our first widget.
For this example we will be using the files that we just modified, this are newdashboard.jade and newdashboard.js.
For this example we will be using the files that we just modified, this are newdashboard.jade and newdashboard.js. Edit the newdashboard.js:


```javascript
var db = req.db;
var collection = db.collection('testing');
collection.find().toArray(function(err,result){
if (err) {console.log(err)}
else {console.log("We've got results!")}
console.log(result)
var name = result[0]["servicename"]
var data = result[0]["data"]
res.render('newdashboard',{
myname:name,
mydata:data
})
});
```

edit the newdashboard.jade file:
```html
.row
.col-lg-4
.small-box.bg-green
.inner
h3
| #{myname}
h2
| #{mydata}

.icon
i.fa.fa-file-o

```
Here we are declaring a new row, so everything that is above that row will not be modified. Please note that the dashboard is one big column of size 12, so we can split the column as we want. Here, our widget will be only of size 4.
If you restart the server, you should see this:

PICTURE


<h1> Creating a table </h1>
Now we are going to create a table. We are going to use a collection that is already created in mongodb, which name is 'tablespacessco'. You can inspect the collection in the mongoshell by typing:
`db.tablespacessco.find().pretty()`

Since we are going to leave right there our first widget that we just created, we are going to do 2 queries to mongo, one for the first widget, and one for the new table. If we want to send data from multiple queries in the same response, we need to import the async module. If it is not installed, you can install it with the Node Package Manager:
`npm install async`

This will require to change our route a little bit:

```javascript
var express = require('express');
var mongodb = require('mongodb');
var async = require('async');
var router = express.Router();

router.get('/', function(req, res) {

async.parallel([
function(callback){
var db = req.db;
var collection = db.collection('testing');
collection.find().toArray(function(err,result){
if (err){
console.log(err);
callback(err);
}
else if (result.length){console.log("We've got results!");}
callback(null,result);
});
},
function(callback){
var db = req.db;
var collection = db.collection('tablespacessco');
collection.find().sort({timestamp:-1}).limit(1).toArray(function(err,result){

if (err){
console.log(err);
callback(err);
}
else if (result.length){console.log("We've got a table!");}
else {console.log("no se encontro nada");}
callback(null,result);
});
}


],

//results comes in an array in the results variable. results[0] is the first query, results[1] is the second query, and so on...
function(err,results){
if (err){
console.log(err);
return res.send(400);
}
data1 = results[0]
scotable = results[1]

res.render('newdashboard',
{
data1:data1,
data2:scotable
}
)
}
});
module.exports = router;
```
<h1> Creating a bar chart</h1>
79 changes: 57 additions & 22 deletions web/routes/newdashboard.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,62 @@
var express = require('express');
var router = express.Router();
var async = require('async');
var mongodb = require('mongodb');
var http = require('http');


/* GET home page. */
router.get('/', function(req, res)
{

var db = req.db;
var collection = db.collection('testing');
collection.find().toArray(function(err,result){
if (err) {console.log(err)}
else {console.log("We've got results!")}
console.log(result)
var mystring = result[0]["servicename"] + " , " + result[0]["data"]
res.render('newdashboard',{data:mystring})
});

var async = require('async');
var router = express.Router();

router.get('/', function(req, res) {

async.parallel([
function(callback){
var db = req.db;
var collection = db.collection('testing');
collection.find().toArray(function(err,result){
if (err){
console.log(err);
callback(err);
}
else if (result.length){console.log("We've got results!");}
callback(null,result);
});
},
function(callback){
var db = req.db;
var collection = db.collection('tablespacessco');
collection.find().sort({timestamp:-1}).limit(1).toArray(function(err,result){

if (err){
console.log(err);
callback(err);
}
else if (result.length){console.log("We've got a table!");}
else {console.log("no se encontro nada");}
callback(null,result);
});
}


],


function(err,results){
if (err){
console.log(err);
return res.send(400);
}
data1 = results[0][0]
scotable = results[1][0]["data"]

console.log(data1)
console.log(scotable)
res.render('newdashboard',
{
data1:data1,
data2:scotable
}
)
//end function results
}
//end async
);
});



module.exports = router;

40 changes: 38 additions & 2 deletions web/views/newdashboard.jade
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,45 @@ block content
// Main content
section.content
.row
h1 New dashboard created!
p #{data}
.box.box-success
.box-header
.i.fa.fa-warning
h3.box-title Success!

.alert.alert-succes
b New dashboard created!
| You are doing great
.row
.col-lg-4
.small-box.bg-green
.inner
- var myname = data1.servicename
- var mydata = data1.data
h3
| #{myname}
h2
| #{mydata}

.icon
i.fa.fa-file-o
.col-lg-6
table.table.table-bordered.table-hover
thead
tr
th Name
th MB Total
th Status
tbody
each value in data2
td #{value.name}
td #{value.mbtotal}
td
- var status = value.status
if status == "ONLINE"
span.label.label-success Online
else
span.label.label-danger Danger
tr
block javascript
// add new calendar event modal
// jQuery 2.0.2
Expand Down
4 changes: 2 additions & 2 deletions web/views/oracle.jade
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ block content
th Datafiles
th Status
tbody
each table, i in tablespacessco
each table in tablespacessco
td #{table.name}
td #{table.mbused}
td #{table.mbfree}
Expand Down Expand Up @@ -293,7 +293,7 @@ block content
th Datafiles
th Status
tbody
each table, i in tablespacesosf
each table in tablespacesosf
td #{table.name}
td #{table.mbused}
td #{table.mbfree}
Expand Down

0 comments on commit 883e913

Please sign in to comment.