diff --git a/db3.js b/db3.js
new file mode 100644
index 0000000..3fec2aa
--- /dev/null
+++ b/db3.js
@@ -0,0 +1,64 @@
+"use strict";
+
+var MongoClient = require('mongodb').MongoClient;
+var ObjectId = require('mongodb').ObjectID;
+var assert = require('assert');
+var url = 'mongodb://localhost:27017/gstv';
+var db;
+MongoClient.connect(url, function(err, my_db) {
+ assert.equal(null, err);
+ db = my_db;
+});
+
+var db_module = (function() {
+ function db_module() {
+ this.process_query = function(query, callback) {
+ db.collection(query.collection, function (error, objects) {
+ if (error) {
+ console.error(error);
+ return;
+ }
+ if (query.object._id && typeof query.object._id != "object") {
+ query.object._id = new ObjectId(query.object._id);
+ }
+ if (query.object.foreignId && typeof query.object.foreignId != "object") {
+ query.object.foreignId = new ObjectId(query.object.foreignId);
+ }
+ if (query.verb == "post") {
+ objects.save(query.object, {safe: true}, function (error, result) {
+ if (error) {
+ console.log(error);
+ }
+ var data = result, response = {data: data};
+ callback(null, response);
+ });
+ }
+ else if (query.verb == "get") {
+ objects.find(query.object, function (error, result) {
+ if (error) {
+ console.error(error);
+ return;
+ }
+ result.toArray(function (error, results) {
+ var data = results, response = {data: data};
+ callback(null, response);
+ });
+ });
+ }
+ else if (query.verb == "put") {
+ objects.save(query.object, {safe: true}, function (error, result) {
+ if (error) {
+ console.error(error);
+ }
+ var data = result, response = {data: data};
+ callback(null, response);
+ });
+ }
+ });
+ }
+ }
+
+ return db_module;
+})();
+
+module.exports = db_module;
\ No newline at end of file
diff --git a/models/time.js b/models/time.js
new file mode 100644
index 0000000..8d633b6
--- /dev/null
+++ b/models/time.js
@@ -0,0 +1,17 @@
+var time = (function () {
+ //timezone
+ //daylight savings time
+ function time(value_start, value_end, day, time_start, time_end, is_24, owner_id, deleted, _id) {
+ this.value_start = value_start;
+ this.value_end = value_end;
+ this.day = day;
+ this.time_start = time_start;
+ this.time_end = time_end;
+ this.is_24 = is_24;
+ this.owner_id = owner_id.toString();
+ this.deleted = deleted ? deleted : null;
+ this._id = _id;
+ }
+ return time;
+})();
+exports.time = time;
diff --git a/notes.txt b/notes.txt
new file mode 100644
index 0000000..35f9650
--- /dev/null
+++ b/notes.txt
@@ -0,0 +1,22 @@
+Notes:
+
+This took me a bit longer than I expected. I had not used Mongodb since discovering firebase(really awesome, check it out) over a year ago
+and had to update mongodb, how I connected to it and my node version as well. The last time I was using mongodb was with socket io and redis
+trying to make something similar to firebase, I had it mostly working but shortly after found firebase. If you wish I can walk you through that
+project as well. I tried to stay focused on the backend, but the frontend needed a lot of functionality. Some is copy and paste from previous projects
+so not all is es6 perfect. Obviously there is a lot that could be done, optimizations, unit testing, better ui, bring in mongoose, etc, but I hope
+this demonstrates some of my abilities. Everything is working on my end, so please let me know if you have any issues.
+
+
+cd C:\Users\Tim\websitesWorking\GSTV\node-coding-exercise
+node server
+
+if on another pc, move mongodb install to this location, copy paste.
+C:\mongodb\Server\3.2\bin\mongod
+
+
+
+
+
+
+
diff --git a/package.json b/package.json
index 74d77ee..f9054f9 100644
--- a/package.json
+++ b/package.json
@@ -18,5 +18,15 @@
"bugs": {
"url": "https://github.com/GasStationTV/node-coding-exercise/issues"
},
- "homepage": "https://github.com/GasStationTV/node-coding-exercise#readme"
+ "homepage": "https://github.com/GasStationTV/node-coding-exercise#readme",
+ "dependencies": {
+ "assert": "^1.3.0",
+ "co-body": "^4.0.0",
+ "koa": "^1.1.2",
+ "koa-router": "^5.3.0",
+ "koa-send": "^3.1.0",
+ "mongod": "^1.3.0",
+ "path": "^0.12.7",
+ "validate.js": "^0.9.0"
+ }
}
diff --git a/public/components_riot/layout/layout.js b/public/components_riot/layout/layout.js
new file mode 100644
index 0000000..9a55b2b
--- /dev/null
+++ b/public/components_riot/layout/layout.js
@@ -0,0 +1,7 @@
+riot.tag2('layout', '
Time Schedule
', 'layout h1,[riot-tag="layout"] h1{ margin: 10px 0 0 0; }', '', function(opts) {
+"use strict";
+
+var owner_id = 1;
+
+this.on('mount', function () {});
+}, '{ }');
\ No newline at end of file
diff --git a/public/components_riot/layout/layout.tag b/public/components_riot/layout/layout.tag
new file mode 100644
index 0000000..14a6794
--- /dev/null
+++ b/public/components_riot/layout/layout.tag
@@ -0,0 +1,35 @@
+
+
+
Time Schedule
+
+
+
+
+
+
\ No newline at end of file
diff --git a/public/components_riot/time_form/time_form.js b/public/components_riot/time_form/time_form.js
new file mode 100644
index 0000000..fe04942
--- /dev/null
+++ b/public/components_riot/time_form/time_form.js
@@ -0,0 +1,111 @@
+riot.tag2('time_form', '', 'time_form .hidden,[riot-tag="time_form"] .hidden{ display: none; }', '', function(opts) {
+"use strict";
+
+var _this = this;
+
+var time_start = undefined;
+var time_end = undefined;
+
+var is_24_elem = undefined;
+this.is_24 = this.opts.is_24 ? true : false;
+
+function validate_form(time_start_value, time_end_value) {
+ var message = undefined;
+ if (time_start_value >= time_end_value) {
+ message = 'Unable to Create/Update: The start time must be before the end time. ';
+ }
+ if (time_start_value === 0) {
+ message += 'Unable to Create/Update: start time is required. ';
+ }
+ if (time_end_value === 0) {
+ message += 'Unable to Create/Update: end time is required. ';
+ }
+
+ return message ? message : true;
+}
+
+this.submit_form = function (event) {
+ var is_valid = undefined;
+ event.preventDefault();
+ is_valid = validate_form(parseInt(time_start.value), parseInt(time_end.value));
+ if (is_valid === true) {
+ _this.error_message.style.display = 'none';
+ _this.opts.submit_callback(_this.calculate_time_value({ time_start: time_start.options[time_start.selectedIndex].value,
+ time_end: time_end.options[time_end.selectedIndex].value,
+ day: _this.opts.day,
+ is_24: _this.is_24,
+ _id: _this.opts._id }));
+ } else {
+ _this.error_message.style.display = 'block';
+ _this.error_message.innerText = is_valid;
+ }
+};
+this.checked_changed = function (event) {
+ _this.is_24 = is_24_elem.checked;
+ _this.update();
+};
+this.delete_time = function (event) {
+ _this.opts.delete_callback({ time_start: time_start.selectedIndex != -1 ? time_start.options[time_start.selectedIndex].value : 1,
+ time_end: time_end.selectedIndex != -1 ? time_end.options[time_end.selectedIndex].value : 1,
+ day: _this.opts.day,
+ is_24: _this.is_24,
+ _id: _this.opts._id });
+};
+this.on('mount', function () {
+ setTimeout(function () {
+ if (_this.opts._id) {
+ time_start = document.getElementById('time_start' + _this.opts._id);
+ time_end = document.getElementById('time_end' + _this.opts._id);
+
+ is_24_elem = document.getElementById('is_24_check' + _this.opts._id);
+ time_start.value = _this.opts.time_start;
+ time_end.value = _this.opts.time_end;
+ } else {
+ time_start = _this.time_start;
+ time_end = _this.time_end;
+ }
+ }, 1);
+});
+
+this.calculate_time_value = function (time_to_add) {
+ var value = 0,
+ value_start = 0,
+ value_end = 0;
+ switch (time_to_add.day) {
+ case "1":
+ value = 0;
+ break;
+ case "2":
+ value = 48;
+ break;
+ case "3":
+ value = 96;
+ break;
+ case "4":
+ value = 144;
+ break;
+ case "5":
+ value = 192;
+ break;
+ case "6":
+ value = 240;
+ break;
+ default:
+ value = 288;
+ }
+ if (time_to_add.day === "7") {
+ value_start = value + parseInt(time_to_add.time_start);
+ if (parseInt(time_to_add.time_end) > 48) {
+ value_end = parseInt(time_to_add.time_end);
+ } else {
+ value_end = value + parseInt(time_to_add.time_end);
+ }
+ } else {
+ value_start = value + parseInt(time_to_add.time_start);
+ value_end = value + parseInt(time_to_add.time_end);
+ }
+ time_to_add.value_start = value_start;
+ time_to_add.value_end = value_end;
+ return time_to_add;
+};
+}, '{ }');
\ No newline at end of file
diff --git a/public/components_riot/time_form/time_form.tag b/public/components_riot/time_form/time_form.tag
new file mode 100644
index 0000000..9f90bdc
--- /dev/null
+++ b/public/components_riot/time_form/time_form.tag
@@ -0,0 +1,259 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/public/components_riot/times_added/times_added.js b/public/components_riot/times_added/times_added.js
new file mode 100644
index 0000000..ffcb2a6
--- /dev/null
+++ b/public/components_riot/times_added/times_added.js
@@ -0,0 +1,156 @@
+riot.tag2('times_added', '