diff --git a/SmearcarDB/server.py b/SmearcarDB/server.py
index 72bf35f..4c15b8c 100644
--- a/SmearcarDB/server.py
+++ b/SmearcarDB/server.py
@@ -36,8 +36,8 @@ class Update(db.Model):
author = db.Column(db.String(30), nullable=False)
title = db.Column(db.String(100), nullable=False)
content = db.Column(db.Text, nullable=False)
- date = db.Column(db.String(50), nullable=False,
- default=datetime.datetime.now().strftime("%m/%d/%Y | %A, %B %d, %Y"))
+ date = db.Column(db.DateTime, nullable=False,
+ default=datetime.datetime.now())
class Editor(db.Model):
@@ -214,11 +214,11 @@ def updates():
update.content = received['content']
db.session.commit()
- return jsonify([{"author": update.name,
+ return jsonify([{"author": update.author,
"id": update.id,
"title": update.title,
"content": update.content,
- "date": update.date}
+ "date": update.date.strftime("%m/%d/%Y | %A, %B %d, %Y")}
for update in Update.query.all()])
# Manipulate Editor
diff --git a/SmearcarDB/static/index.js b/SmearcarDB/static/index.js
index 6854c5f..a7bf560 100644
--- a/SmearcarDB/static/index.js
+++ b/SmearcarDB/static/index.js
@@ -42,7 +42,7 @@ function Rnd(item,fig) {
function varType(variable) {
var type = typeof variable;
if(type === "object") {
- return (variable.constructor === Array) ? "Array" : "Object";
+ return (variable.constructor === Array) ? "Array" : "Object";
} else {
return type[0].toUpperCase() + type.slice(1);
}
@@ -310,41 +310,36 @@ document.onclick = function(event) {
};
function homeCards() {
- // GET posts from server
- var week = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
- var month = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
- var examplePost = [
- {
- author: "Kenneth Jao",
- title: "Test Post!",
- content: "This is test post! Link This link should work.
Newlines work.",
- date: new Date(2018, 0, 26, 4, 51)
- }
- ];
- var home = document.getElementById("home");
- for(var i = 0; i < examplePost.length; i++) {
- var div = document.createElement("div");
- div.className = "card";
- var h2 = document.createElement("h2");
- h2.textContent = examplePost[i].title;
- div.appendChild(h2);
- var h3 = document.createElement("h3");
- var dt = examplePost[i].date;
- var smallDate = (function() {
- var m = (dt.getMonth()+1).toString();
- var d = (dt.getDay()+1).toString();
- m = (m.length === 1) ? "0" + m : m;
- d = (d.length === 1) ? "0" + d : d;
- return m+"/"+d+"/"+dt.getFullYear().toString();
- })();
- var fullDate = week[dt.getDay()] + ", " + month[dt.getMonth()] + " " + dt.getDate().toString() + ", " + dt.getFullYear().toString();
- h3.textContent = smallDate + " | " + fullDate;
- div.appendChild(h3);
- var p = document.createElement("p");
- p.innerHTML = examplePost[i].content;
- div.appendChild(p);
- home.appendChild(div);
- }
+ // TODO GET posts from server
+
+ $.ajax({
+ url: serverURL + '/updates',
+ type: 'GET'
+ })
+ .then(
+ function success(incoming) {
+ var postList = incoming;
+ var home = document.getElementById("home");
+ for(var i = 0; i < postList.length; i++) {
+ var div = document.createElement("div");
+ div.className = "card";
+ var h2 = document.createElement("h2");
+ h2.textContent = postList[i].title;
+ div.appendChild(h2);
+ var h3 = document.createElement("h3");
+ h3.textContent = postList[i].date;
+ div.appendChild(h3);
+ var p = document.createElement("p");
+ p.innerHTML = postList[i].content;
+ div.appendChild(p);
+ home.appendChild(div);
+ }
+ },
+ function error(e) {
+ console.log(e);
+ }
+ );
+
}
function chartOptions(graphData) {