I have followed the DTHMLX Scheduler tutorial, but I haven't been able to get the db.event.insert()
to work, because the route for it is not firing off. However, I am able to display data from my MongoDB when I insert data through the shell.
Like the tutorial, I used MongoSkin as the MongoDB driver. Both MongoSkin and Express are the same version "mongoskin": "~0.6.0"
& "express": "~3.3.8"
as it is in the tutorial.
<!-- index.html -->
<!doctype html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Basic initialization</title>
</head>
<script src="codebase/dhtmlxscheduler.js" type="text/javascript" charset="utf-8"></script>
<link rel="stylesheet" href="codebase/dhtmlxscheduler.css" type="text/css" media="screen" title="no title" charset="utf-8">
<style type="text/css" media="screen">
html, body{
margin:0px;
padding:0px;
height:100%;
overflow:hidden;
}
</style>
<script type="text/javascript" charset="utf-8">
function init() {
scheduler.config.xml_date="%Y-%m-%d %H:%i"; //changes date format
scheduler.init('scheduler_here',new Date(),"month"); // when the calendar is initialized
scheduler.templates.xml_date = function(value){ return new Date(value); };
scheduler.load("/data", "json");
var dp = new dataProcessor("/data");
dp.init(scheduler);
dp.setTransactionMode("POST", true);
console.log('init on index finished');
}
</script>
<body onload="init();">
<div id="scheduler_here" class="dhx_cal_container" style='width:100%; height:100%;'>
<div class="dhx_cal_navline">
<div class="dhx_cal_prev_button"> </div>
<div class="dhx_cal_next_button"> </div>
<div class="dhx_cal_today_button"></div>
<div class="dhx_cal_date"></div>
<div class="dhx_cal_tab" name="day_tab" style="right:204px;"></div>
<div class="dhx_cal_tab" name="week_tab" style="right:140px;"></div>
<div class="dhx_cal_tab" name="month_tab" style="right:76px;"></div>
</div>
<div class="dhx_cal_header">
</div>
<div class="dhx_cal_data">
</div>
</div>
</body>
The server file is pretty bare bones like the tutorial. The Server file is changed from app.js to server.js.
//server.js
var express = require('express');
var path = require('path');
var bodyParser = require('body-parser');
var db = require('mongoskin').db("mongodb://localhost:27017/testdb", { w: 0});
db.bind('event');
var app = express();
app.use(express.static(path.join(__dirname, 'public')));
app.use(express.bodyParser());
app.get('/init', function(req, res){
if (err) throw err;
console.log('before object');
db.event.insert({
text:"My test event A",
start_date: new Date(2017,5,1),
end_date: new Date(2017,5,5)
}, console.log('first object run'));
db.event.insert({
text:"My test event B",
start_date: new Date(2017,5,19),
end_date: new Date(2017,5,24)
});
db.event.insert({
text:"Morning event",
start_date: new Date(2017,5,4),
end_date: new Date(2017,5,4)
});
db.event.insert({
text:"One more test event",
start_date: new Date(2017,5,3),
end_date: new Date(2017,5,8),
color: "#DD8616"
});
res.send("Test events were added to the database");
console.log('events inserted?')
});
app.get('/data', function(req, res){
db.event.find().toArray(function(err, data){
//set id property for all records
for (var i = 0; i < data.length; i++)
// console.log('in for loop');
data[i].id = data[i]._id;
//output response
res.send(data);
console.log('data sent');
});
});
app.listen(3000);
console.log('listening on port 3000');
I am able to use the app.get('/data'
route and callback function and get my collection printed onto the calendar, but only after inserting it in the MongoDB's shell command line.
The same can be said from inserting data, as db.event.insert
method is missed because the app.get('/init'
route never gets fired off. I found from testing, using console.logs.
I read through the DHTMLX Scheduler tutorial, the website's documentation, MongoDB documentation, and the MongoSkin docs. I could be completely missing an obvious solution, but I can't seem to find what I'm missing here so any help would be appreciated. Thanks.