|
var MongoClient = require('mongodb').MongoClient;
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
var url = "mongodb://localhost:27017/";
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }))
app.listen(5000, function () {
console.log('listening on 5000')
})
app.use(express.static(__dirname))
MongoClient.connect(url, function (err, db) {
if (err) throw err;
var dbo = db.db("mydb");
app.use(function (req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
app.post("/GetData", (req, res) => {
dbo.collection('ScheduleData').find({}).toArray((err, cus) => {
res.send(cus);
});
});
app.post("/BatchData", (req, res) => {
var eventData = [];
if (req.body.action == "insert" || (req.body.action == "batch" && req.body.added.length > 0)) {
(req.body.action == "insert") ? eventData.push(req.body.value) : eventData = req.body.added;
for (var i = 0; i < eventData.length; i++) {
var sdate = new Date(eventData[i].StartTime);
var edate = new Date(eventData[i].EndTime);
eventData[i].StartTime = (new Date(+sdate - (sdate.getTimezoneOffset() * 60000)));
eventData[i].EndTime = (new Date(+edate - (edate.getTimezoneOffset() * 60000)));
dbo.collection('ScheduleData').insertOne(eventData[i]);
}
}
if (req.body.action == "update" || (req.body.action == "batch" && req.body.changed.length > 0)) {
(req.body.action == "update") ? eventData.push(req.body.value) : eventData = req.body.changed;
for (var i = 0; i < eventData.length; i++) {
delete eventData[i]._id;
var sdate = new Date(eventData[i].StartTime);
var edate = new Date(eventData[i].EndTime);
eventData[i].StartTime = (new Date(+sdate - (sdate.getTimezoneOffset() * 60000)));
eventData[i].EndTime = (new Date(+edate - (edate.getTimezoneOffset() * 60000)));
dbo.collection('ScheduleData').updateOne({ "Id": eventData[i].Id }, eventData[i]);
}
}
if (req.body.action == "remove" || (req.body.action == "batch" && req.body.deleted.length > 0)) {
(req.body.action == "remove") ? eventData.push(req.body.value) : eventData = req.body.deleted;
for (var i = 0; i < eventData.length; i++) {
dbo.collection('ScheduleData').deleteOne({ "Id": eventData[i].Id }, eventData[i]);
}
}
res.send(req.body);
});
}); |
|
let data = new DataManager({ url: 'http://localhost:5000/GetData', crudUrl: 'http://localhost:5000/BatchData', adaptor: new UrlAdaptor, crossDomain: true });
export default class App extends React.Component<{}, {}> {
public render() {
return (
<ScheduleComponent id="schedule" height="550px" selectedDate={new Date(2018, 11, 11)} eventSettings={{ dataSource: data }} currentView="Week">
<ViewsDirective>
<ViewDirective option="Day" />
<ViewDirective option="Week" />
<ViewDirective option="WorkWeek" />
<ViewDirective option="Month" />
<ViewDirective option="Agenda" />
<ViewDirective option="MonthAgenda" />
</ViewsDirective>
<Inject services={[Day, Week, WorkWeek, Month, Agenda, MonthAgenda]} />
</ScheduleComponent>
);
}
} |
|
public componentDidMount() {
this.signalr = new HubConnectionBuilder().withUrl("http://localhost:62869/hubs/schedulehub").withAutomaticReconnect().build();
this.signalr.on("UpdateClient", (action: string, data: View | Object[]) => {
if (action == "view") {
this.scheduleObj.currentView = data as View;
}
if (action === "eventCreated" || action === "eventChanged" || action === "eventRemoved") {
this.scheduleObj.eventSettings.dataSource = data as Object[];
}
});
this.signalr.start().then(() => { console.log("Hub Connected..!"); }).catch((err: any) => { console.log(err); });
}
public componentWillUnmount(): void {
this.signalr.stop().then(() => { console.log("Hub Disconnected.."); }).catch((err: any) => { console.log(err); });
} |