From: Steve Sutton Date: Sun, 9 Aug 2015 21:47:03 +0000 (-0400) Subject: Adding new files to pull real data from postgres. X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=3b7ee1c69e07812890f6f00b879c78619cf7ee9b;p=prog%2FDash.git Adding new files to pull real data from postgres. Yeah!, that's what I'm talking about. I have it set to poll for the project tasks every 20 sec. It's taking on average 54ms to pull each projects tasks in json. --- diff --git a/dash/app.js b/dash/app.js index 4282508..e3e870d 100644 --- a/dash/app.js +++ b/dash/app.js @@ -1,45 +1,48 @@ $(document).ready(function(){ // Emmet Government + var emmetTasks = new Tasks([ + ]); + emmetTasks.url = '/fetchTask.php'; + emmetTasks.fetch({data: {pid: 3878}}); var emmetList = new TaskListView({ el: '#emmetList', - collection: [ - new Task({title: "Main Navigation", project: 1, employee: "Laury", status: "On Hold"}), - new Task({title: "Plugin Req: Uber Menu", project: 1, employee: "Laury", status: "New"}), - new Task({title: "Department Section", project: 1, employee: "Laury", status: "In Progress"}), - new Task({title: "Content Migration", project: 1, employee: "Steve", status: "New"}), - ]}); + collection: emmetTasks}); // Western UP + var westernTasks = new Tasks([ + ]); + westernTasks.url = '/fetchTask.php'; + westernTasks.fetch({data: {pid: 3937}}); var westernList = new TaskListView({ el: '#westernList', - collection: [ - new Task({title: "Banner Ads", project: 2, employee: "Steve", status: "New"}), - new Task({title: "Contact Forms MailChimp", project: 2, employee: "Laury", status: "New"}), - new Task({title: "Events", project: 2, employee: "Laury", status: "New"}), - new Task({title: "Events", project: 2, employee: "Laury", status: "New"}), - new Task({title: "Members", project: 2, employee: "Laury", status: "New"}), - new Task({title: "Wordress Setup", project: 2, employee: "Laury", status: "New"}), - new Task({title: "Content Migration", project: 2, employee: "Steve", status: "New"}), - ]}); + collection: westernTasks}); // NLEA + var nleaTasks = new Tasks([ + ]); + nleaTasks.url = '/fetchTask.php'; + nleaTasks.fetch({data: {pid: 3936}}); var nleaList = new TaskListView({ el: '#nleaList', - collection: [ - new Task({title: "Constant Contact", project: 3, employee: "Steve", status: "New"}), - new Task({title: "Forms", project: 3, employee: "Steve", status: "New"}), - ]}); + collection: nleaTasks}); // Mount Pleasant Wow + var mountTasks = new Tasks([ + ]); + mountTasks.url = '/fetchTask.php'; + mountTasks.fetch({data: {pid: 3929}}); var mountList = new TaskListView({ el: '#mountList', - collection: [ - new Task({title: "Break Out / Theme", project: 4, employee: "Ian", status: "New"}), - new Task({title: "Forms", project: 4, employee: "Steve", status: "New"}), - new Task({title: "Coupons", project: 4, employee: "Steve", status: "New"}), - new Task({title: "Events", project: 4, employee: "Steve", status: "New"}), - new Task({title: "Members", project: 4, employee: "Steve", status: "New"}), - new Task({title: "Photos/Videos", project: 4, employee: "Steve", status: "New"}), - ]}); + collection: mountTasks}); + + setInterval(function(){ + var curDate = new Date(); + var curTime = curDate.getTime(); + emmetTasks.fetch({data: {pid: 3878, t: curTime}, reset: true}); + westernTasks.fetch({data: {pid: 3937, t: curTime}, reset: true}); + nleaTasks.fetch({data: {pid: 3936, t: curTime}, reset: true}); + mountTasks.fetch({data: {pid: 3929, t: curTime}, reset: true}); + }, 20000); + }); diff --git a/dash/views/task.js b/dash/views/task.js index ae10a55..b706e1b 100644 --- a/dash/views/task.js +++ b/dash/views/task.js @@ -4,7 +4,11 @@ var TaskView = Backbone.View.extend({ template: _.template( '<%= employee %>' + '<%= status %>' + - '<%= title %>'), + '<%= title %>' + + '<%= deadline %>'), + initialize: function(){ + this.listenTo(this.model, 'change', this.render) + }, render: function(){ this.$el.append(this.template(this.model.toJSON())); return this; diff --git a/dash/views/taskList.js b/dash/views/taskList.js index 36854c6..f8bf4b0 100644 --- a/dash/views/taskList.js +++ b/dash/views/taskList.js @@ -2,11 +2,16 @@ var TaskListView = Backbone.View.extend({ el: '#myList', tagName: 'section', initialize: function(){ + this.collection.bind('add', this.onModelAdded, this); this.render(); }, setEl: function(myEl){ this.el = myEl; }, + onModelAdded: function(item){ + var taskView = new TaskView({model: item}); + this.$el.append(taskView.render().el); + }, render: function(){ var taskView = this.collection.map(function(task){ return (new TaskView({model: task})).render().el; diff --git a/fetchTask.php b/fetchTask.php new file mode 100644 index 0000000..76ef23a --- /dev/null +++ b/fetchTask.php @@ -0,0 +1,62 @@ + PDO::FETCH_ASSOC + ) + ); + $dbh->setAttribute( + PDO::ATTR_ERRMODE, + PDO::ERRMODE_EXCEPTION + ); + $pid = filter_var($_REQUEST['pid'], FILTER_VALIDATE_INT); + $where = ($pid) + ? "t.pid = {$pid}" + : "t.pid IN (3937, 3936, 3878, 3929)"; + $sql = " + SELECT t.name as title,t.pid as project, + t.status,e.fname as employee, + to_char(t.deadline, 'MON DD') as deadline + FROM tasks t + LEFT OUTER JOIN employees e ON e.eid=t.eid + WHERE t.status <> 'archived' + AND t.archived <> true + AND $where + ORDER BY t.pid,t.deadline"; + $stmt = $dbh->query($sql); + $data = array(); + while ($task = $stmt->fetch()) { + switch ($task['status']) { + case 'new': + $task['status'] = 'New'; + break; + case 'on_hold': + $task['status'] = 'On Hold'; + break; + case 'billing': + $task['status'] = 'Billing'; + break; + case 'client_review': + $task['status'] = 'Client Review'; + break; + case 'ready_for_review': + $task['status'] = 'Ready For Review'; + break; + case 'in_progress': + $task['status'] = 'In Progress'; + break; + case 'complate': + $task['status'] = 'Complete'; + break; + } + $data[] = $task; + //echo '
' . print_r($task, true) . '
'; + } + header('Content-Type: text/javascript; charset=utf8'); + echo json_encode($data); +} catch(PDOException $e){ + echo '
' . print_r($e, true) . '
'; +} diff --git a/index.html b/index.html index be3768f..0b849c1 100644 --- a/index.html +++ b/index.html @@ -36,7 +36,7 @@
-
+

NLEA

@@ -45,11 +45,12 @@ +
Employee Status Task NameDeadline
-
+

Emmet - Gov't

@@ -58,11 +59,12 @@ +
Employee Status Task NameDeadline
-
+

Western UP

@@ -71,11 +73,12 @@ +
Employee Status Task NameDeadline
-
+

Mount Pleasant Wow

@@ -84,6 +87,7 @@ +
Employee Status Task NameDeadline
diff --git a/php.php b/php.php deleted file mode 100644 index c931d5e..0000000 --- a/php.php +++ /dev/null @@ -1 +0,0 @@ -