”2016-08-18”

This commit is contained in:
Martin Donnelly 2016-08-18 16:45:07 +01:00
parent 1ea4d2961f
commit 62d5b02956
11 changed files with 545 additions and 9 deletions

View File

@ -0,0 +1,110 @@
--
-- PostgreSQL database dump
--
-- Dumped from database version 9.5.1
-- Dumped by pg_dump version 9.5.1
-- Started on 2016-08-18 15:46:39 BST
SET statement_timeout = 0;
SET lock_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SET check_function_bodies = false;
SET client_min_messages = warning;
SET row_security = off;
SET search_path = public, pg_catalog;
SET default_tablespace = '';
SET default_with_oids = false;
--
-- TOC entry 188 (class 1259 OID 63387)
-- Name: meeting; Type: TABLE; Schema: public; Owner: postgres
--
CREATE TABLE meeting (
id integer NOT NULL,
locationid integer,
logged timestamp with time zone,
count smallint,
start timestamp with time zone,
"end" timestamp with time zone
);
ALTER TABLE meeting OWNER TO postgres;
--
-- TOC entry 187 (class 1259 OID 63385)
-- Name: meeting_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--
CREATE SEQUENCE meeting_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER TABLE meeting_id_seq OWNER TO postgres;
--
-- TOC entry 2387 (class 0 OID 0)
-- Dependencies: 187
-- Name: meeting_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--
ALTER SEQUENCE meeting_id_seq OWNED BY meeting.id;
--
-- TOC entry 2266 (class 2604 OID 63390)
-- Name: id; Type: DEFAULT; Schema: public; Owner: postgres
--
ALTER TABLE ONLY meeting ALTER COLUMN id SET DEFAULT nextval('meeting_id_seq'::regclass);
--
-- TOC entry 2382 (class 0 OID 63387)
-- Dependencies: 188
-- Data for Name: meeting; Type: TABLE DATA; Schema: public; Owner: postgres
--
COPY meeting (id, locationid, logged, count, start, "end") FROM stdin;
3 1 2016-08-18 15:39:26+01 4 2016-08-04 13:00:00+01 2016-08-04 13:45:00+01
4 1 2016-08-18 15:39:51+01 11 2014-08-04 14:00:00+01 2014-08-04 14:45:00+01
5 1 2016-08-18 15:40:29+01 2 2016-08-04 14:45:00+01 2016-08-04 14:55:00+01
6 1 2016-08-18 15:40:55+01 3 2016-08-04 15:04:00+01 2016-08-04 16:06:00+01
7 1 2016-08-18 15:41:25+01 2 2016-08-05 11:05:00+01 2016-08-05 12:15:00+01
8 1 2016-08-18 15:41:47+01 1 2016-08-05 14:10:00+01 2016-08-05 14:25:00+01
9 1 2016-08-18 15:42:08+01 4 2016-08-05 15:00:00+01 2016-08-05 15:30:00+01
10 1 2016-08-18 15:42:37+01 4 2016-08-05 15:30:00+01 2016-08-05 16:23:00+01
11 1 2016-08-18 15:43:02+01 8 2016-08-08 11:00:00+01 2016-08-08 12:12:00+01
12 1 2016-08-18 15:43:29+01 7 2016-08-08 15:37:00+01 2016-08-08 16:50:00+01
13 1 2016-08-18 15:44:10+01 5 2016-08-09 10:02:00+01 2016-08-09 10:15:00+01
14 1 2016-08-18 15:44:34+01 6 2016-08-09 10:15:00+01 2016-08-09 12:05:00+01
15 1 2016-08-18 15:44:52+01 1 2016-08-09 13:05:00+01 2016-08-09 13:10:00+01
\.
--
-- TOC entry 2388 (class 0 OID 0)
-- Dependencies: 187
-- Name: meeting_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
--
SELECT pg_catalog.setval('meeting_id_seq', 15, true);
-- Completed on 2016-08-18 15:46:39 BST
--
-- PostgreSQL database dump complete
--

View File

@ -31,6 +31,7 @@ var isProduction = false;
var mdotApi = require('./lib/mdot/api.js');
var mdotApiV2 = require('./lib/mdot/apiv2.js');
var trackApi = require('./lib/mdot/track.js');
var meetingApi = require('./lib/mdot/meeting.js');
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
@ -83,6 +84,7 @@ function originIsAllowed(origin) {
mdotApi(app);
mdotApiV2(app);
trackApi(app);
meetingApi(app);
//app.get('/api/mdot/:id', mDot.getData);

View File

@ -155,7 +155,7 @@
var that = this;
that.$el.append(this.template);
/* Var that = this;
/* var that = this;
this.$el.empty();
this.collection.each(function(model) {
var events = model.get('events');

View File

@ -0,0 +1,57 @@
'use strict';
/* global Backbone, _, $, AmCharts */
/* global meetingView */
/* jshint browser: true , devel: true */
(function($) {
var MeetingModel = Backbone.Model.extend({
url: '/apiv2/meeting'
});
var MeetingView = Backbone.View.extend({
el: '#meetingForm',
initialize: function() {
},
events: {
submit: 'submit'
},
submit: function(event) {
var self = this;
var newObj = {};
var dString;
event.preventDefault();
notification.clearAll();
newObj.roomId = parseInt(this.$el.find('select#device')[0].value);
dString = [this.$el.find('input#from')[0].value, this.$el.find('input#start')[0].value].join(' ');
newObj.start = Date.create(dString);
dString = [this.$el.find('input#from')[0].value, this.$el.find('input#end')[0].value].join(' ');
newObj.end = Date.create(dString);
newObj.occupancy = parseInt(this.$el.find('input#occupancy')[0].value);
var meetingRec = new MeetingModel(newObj);
meetingRec.save(null, {
success: function(model, response) {
console.log('success');
notification.notify('success', 'Meeting successfully logged.');
self.$el[0].reset();
},
error: function(model, response) {
console.error('error', response);
notification.notify('error', 'The meeting couldn\'t be logged.');
}
});
}
});
var meetingView = new MeetingView();
})(jQuery);

View File

@ -0,0 +1,76 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
<title>Meetings</title>
<link href="css/mui.css" rel="stylesheet" type="text/css"/>
<link href="css/notification.css" rel="stylesheet" type="text/css"/>
<script src="lib/mui.js"></script>
</head>
<body>
<div class="mui-container">
<div class='mui-row'>
<div class="mui-panel">
<div class="mui--text-title">Meeting Log</div>
</div>
</div>
<div class='mui-row'>
<div class="mui-panel">
<form id="meetingForm">
<legend>New Meeting</legend>
<div class="mui-select">
<select id="device" name="device" required>
<option></option>
<option value="1">
Large Meeting Room
</option>
<option value="2">
Small Meeting Room
</option>
<option value="3">
Lab
</option>
</select> <label>Room</label>
</div>
<div class="mui-row">
<div class="mui-col-md-4">
<div class="mui-textfield">
<input type="date" placeholder="" id='from' name="from" required/>
<label>Day</label>
</div>
</div>
<div class="mui-col-md-4">
<div class="mui-textfield">
<input type="time" placeholder="" id='start' name="start" required/>
<label>Start</label>
</div>
</div>
<div class="mui-col-md-4">
<div class="mui-textfield">
<input type="time" placeholder="" id='end' name="end" required/>
<label>End</label>
</div>
</div>
</div>
<div class="mui-textfield mui-textfield--float-label">
<input type="number" value="0" id="occupancy" required/> <label>Occupants</label>
</div>
<button type="submit" class="mui-btn mui-btn--raised">Submit</button>
</form>
</div>
</div>
</div>
<script src="lib/jquery.js"
integrity="sha256-laXWtGydpwqJ8JA+X9x2miwmaiKhn8tVmOVEigRNtP4="
crossorigin="anonymous"></script>
<script src="lib/underscore.js"></script>
<script src="lib/backbone.js"></script>
<script src="lib/sugar-date.js"></script>
<script src="lib/notification.js"></script>
<script src="js/meeting.js"></script>
</
</body>
</html>

View File

@ -2,10 +2,11 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<title>Graph</title>
<link href="css/mui.css" rel="stylesheet" type="text/css"/>
<link href="css/test.css" rel="stylesheet" type="text/css"/>
<link href="css/style.css" rel="stylesheet" type="text/css"/>
<script src="lib/mui.js"></script>
<script src="lib/notification.js"></script>
<link rel="stylesheet" href="css/notification.css">
</head>
@ -13,8 +14,8 @@
<div class="mui-container">
<div class='mui-row'>
<div class="mui-col-md-3 panel">
<div id="main"></div>
<div id="graph"></div>
<div class='mui-panel' id="main"></div>
<div class='mui-panel' id="graph"></div>
<div id="output"></div>
</div>
<div class="mui-col-md-9">
@ -100,9 +101,12 @@
</div>
</div>
<div class="mui-row">
<button id='refresh'
class="mui-btn mui-btn--small mui-btn--primary">Refresh
</button>
<div class="mui-col-md-12">
<button id='refresh'
class="mui-btn mui-btn--small mui-btn--primary">Refresh
</button>
</div>
</div>
</script>
<script type="text/template" id="list-template">
@ -200,7 +204,6 @@
<script src="lib/sugar-date.js"></script>
<script src="lib/amcharts.js"></script>
<script src="lib/serial.js"></script>
<script src="lib/amstock.js"></script>
<script src="js/mdot.js"></script>
</body>
</html>

View File

@ -0,0 +1,89 @@
/**
*
* User: Martin Donnelly
* Date: 2016-08-12
* Time: 13:41
*
*/
'use strict';
var logger = require('log4js').getLogger();
var db = require('../server/db-connector').dbConnection;
var dbMeeting = require('../server/db-meeting')(db);
module.exports = function(app) {
var express = require('express');
var mdotRouter = express.Router();
mdotRouter.post('/', function(req, res) {
var body = req.body;
var data = {};
logger.debug('body', body);
if (!Object.hasOwnProperty.call(body, 'roomId') ||
!Object.hasOwnProperty.call(body, 'start') ||
!Object.hasOwnProperty.call(body, 'end') ||
!Object.hasOwnProperty.call(body, 'occupancy')){
logger.error('Meeting','Missing required parameter');
res.status(400).send({
status: 'error',
error: 'missing required parameter'
});
return;
} else {
data.locationid = req.body.roomId;
data.count = req.body.occupancy;
data.start = req.body.start;
data.end = req.body.end;
dbMeeting.addNewMeeting(data)
.then((d) => {
res.json({d: d});
})
.catch((e) => {
logger.error(e);
res.status(500).json({});
});
}
});
mdotRouter.get('/:id', function(req, res) {
console.log(req.headers);
var data = {};
logger.debug('track-GetData');
if (!req.params.id) {
logger.error('Track','Missing required parameter');
res.status(400).send({
status: 'error',
error: 'missing required parameter'
});
return;
}
if (req.params.hasOwnProperty('id')) {
data.locationid = req.params.id;
dbMeeting.doGet(data)
.then((d) => {
res.json({tracks:d});
})
.catch((e) => {
logger.error(e);
res.status(500).json({});
});
}
});
app.use('/apiv2/meeting/', mdotRouter);
};

View File

@ -7,7 +7,6 @@
*/
'use strict';
var logger = require('log4js').getLogger();
var mdot = require('./mdot.js');
var db = require('../server/db-connector').dbConnection;

View File

@ -0,0 +1,53 @@
'use strict';
var logger = require('log4js').getLogger();
module.exports = function(db) {
var module = {};
module.sqlInsertMeeting = function(data) {
let _data = data;
logger.debug('sqlInsertMeeting', _data.locationid, _data.timestamp);
return new Promise(function(resolve, reject) {
db.none('INSERT into meeting(locationid, logged, count, start, "end") Values( ${locationid}, ${timestamp}, ${count}, ${start}, ${end})', _data)
.then(()=> {
return resolve('ok');
})
.catch((err)=> {
return reject(err);
});
});
};
module.addNewMeeting = function(data) {
logger.debug('addNewMeeting');
var self = this;
return new Promise((resolve, reject) => {
let _data = {};
_data.timestamp = new Date();
_data.locationid = data.locationid;
_data.count = data.count;
_data.start = new Date(data.start);
_data.end = new Date(data.end);
console.log('_data', _data);
self.sqlInsertMeeting(_data)
.then((d)=> {
logger.debug('Postgres returns', d);
return resolve({reply: 'track inserted'});
})
.catch((err)=> {
return reject(err);
});
});
};
return module;
};

View File

@ -0,0 +1,33 @@
-- Sequence: public.meeting_id_seq
-- DROP SEQUENCE public.meeting_id_seq;
CREATE SEQUENCE public.meeting_id_seq
INCREMENT 1
MINVALUE 1
MAXVALUE 9223372036854775807
START 1
CACHE 1;
ALTER TABLE public.meeting_id_seq
OWNER TO postgres;
-- Table: public.meeting
-- DROP TABLE public.meeting;
CREATE TABLE public.meeting
(
id integer NOT NULL DEFAULT nextval('meeting_id_seq'::regclass),
locationid integer,
logged timestamp with time zone,
count smallint,
start timestamp with time zone,
"end" timestamp with time zone
)
WITH (
OIDS=FALSE
);
ALTER TABLE public.meeting
OWNER TO postgres;

View File

@ -0,0 +1,114 @@
--
-- PostgreSQL database dump
--
-- Dumped from database version 9.5.1
-- Dumped by pg_dump version 9.5.1
-- Started on 2016-08-18 15:46:39 BST
SET statement_timeout = 0;
SET lock_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SET check_function_bodies = false;
SET client_min_messages = warning;
SET row_security = off;
SET search_path = public, pg_catalog;
SET default_tablespace = '';
SET default_with_oids = false;
--
-- TOC entry 188 (class 1259 OID 63387)
-- Name: meeting; Type: TABLE; Schema: public; Owner: postgres
--
DROP SEQUENCE public.meeting_id_seq;
DROP TABLE public.meeting;
CREATE TABLE meeting (
id integer NOT NULL,
locationid integer,
logged timestamp with time zone,
count smallint,
start timestamp with time zone,
"end" timestamp with time zone
);
ALTER TABLE meeting OWNER TO postgres;
--
-- TOC entry 187 (class 1259 OID 63385)
-- Name: meeting_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--
CREATE SEQUENCE meeting_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER TABLE meeting_id_seq OWNER TO postgres;
--
-- TOC entry 2387 (class 0 OID 0)
-- Dependencies: 187
-- Name: meeting_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--
ALTER SEQUENCE meeting_id_seq OWNED BY meeting.id;
--
-- TOC entry 2266 (class 2604 OID 63390)
-- Name: id; Type: DEFAULT; Schema: public; Owner: postgres
--
ALTER TABLE ONLY meeting ALTER COLUMN id SET DEFAULT nextval('meeting_id_seq'::regclass);
--
-- TOC entry 2382 (class 0 OID 63387)
-- Dependencies: 188
-- Data for Name: meeting; Type: TABLE DATA; Schema: public; Owner: postgres
--
COPY meeting (id, locationid, logged, count, start, "end") FROM stdin;
3 1 2016-08-18 15:39:26+01 4 2016-08-04 13:00:00+01 2016-08-04 13:45:00+01
4 1 2016-08-18 15:39:51+01 11 2014-08-04 14:00:00+01 2014-08-04 14:45:00+01
5 1 2016-08-18 15:40:29+01 2 2016-08-04 14:45:00+01 2016-08-04 14:55:00+01
6 1 2016-08-18 15:40:55+01 3 2016-08-04 15:04:00+01 2016-08-04 16:06:00+01
7 1 2016-08-18 15:41:25+01 2 2016-08-05 11:05:00+01 2016-08-05 12:15:00+01
8 1 2016-08-18 15:41:47+01 1 2016-08-05 14:10:00+01 2016-08-05 14:25:00+01
9 1 2016-08-18 15:42:08+01 4 2016-08-05 15:00:00+01 2016-08-05 15:30:00+01
10 1 2016-08-18 15:42:37+01 4 2016-08-05 15:30:00+01 2016-08-05 16:23:00+01
11 1 2016-08-18 15:43:02+01 8 2016-08-08 11:00:00+01 2016-08-08 12:12:00+01
12 1 2016-08-18 15:43:29+01 7 2016-08-08 15:37:00+01 2016-08-08 16:50:00+01
13 1 2016-08-18 15:44:10+01 5 2016-08-09 10:02:00+01 2016-08-09 10:15:00+01
14 1 2016-08-18 15:44:34+01 6 2016-08-09 10:15:00+01 2016-08-09 12:05:00+01
15 1 2016-08-18 15:44:52+01 1 2016-08-09 13:05:00+01 2016-08-09 13:10:00+01
\.
--
-- TOC entry 2388 (class 0 OID 0)
-- Dependencies: 187
-- Name: meeting_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
--
SELECT pg_catalog.setval('meeting_id_seq', 15, true);
-- Completed on 2016-08-18 15:46:39 BST
--
-- PostgreSQL database dump complete
--