Adding new files to pull real data from postgres.
authorSteve Sutton <ssutton@gmail.com>
Sun, 9 Aug 2015 21:47:03 +0000 (17:47 -0400)
committerSteve Sutton <ssutton@gmail.com>
Sun, 9 Aug 2015 21:47:03 +0000 (17:47 -0400)
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.

dash/app.js
dash/views/task.js
dash/views/taskList.js
fetchTask.php [new file with mode: 0644]
index.html
php.php [deleted file]

index 4282508..e3e870d 100644 (file)
@@ -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);
+
 
 });
index ae10a55..b706e1b 100644 (file)
@@ -4,7 +4,11 @@ var TaskView = Backbone.View.extend({
     template: _.template(
         '<td><%= employee %></td>' +
         '<td><%= status %></td>' +
-        '<td><%= title %></td>'),
+        '<td><%= title %></td>' +
+        '<td><%= deadline %></td>'),
+    initialize: function(){
+        this.listenTo(this.model, 'change', this.render)
+    },
     render: function(){
         this.$el.append(this.template(this.model.toJSON()));
         return this;
index 36854c6..f8bf4b0 100644 (file)
@@ -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 (file)
index 0000000..76ef23a
--- /dev/null
@@ -0,0 +1,62 @@
+<?php
+try {
+    $dbh = new PDO(
+        'pgsql: host=localhost dbname=glmdb user=postgres',
+        null,
+        null,
+        array(
+            PDO::ATTR_DEFAULT_FETCH_MODE => 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 '<pre>' . print_r($task, true) . '</pre>';
+    }
+    header('Content-Type: text/javascript; charset=utf8');
+    echo json_encode($data);
+} catch(PDOException $e){
+    echo '<pre>' . print_r($e, true) . '</pre>';
+}
index be3768f..0b849c1 100644 (file)
@@ -36,7 +36,7 @@
         </nav>
         <div class="container">
             <div class="row">
-                <div class="col-xs-12 col-sm-6 col-md-4 col-lg-4">
+                <div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
                     <h3>NLEA</h3>
                     <table id="nleaList"
                         class="table table-condensed table-striped table-bordered table-hover">
                                 <th>Employee</th>
                                 <th>Status</th>
                                 <th>Task Name</th>
+                                <th>Deadline</th>
                             </tr>
                         </thead>
                     </table>
                 </div>
-                <div class="col-xs-12 col-sm-6 col-md-4 col-lg-4">
+                <div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
                     <h3>Emmet - Gov't</h3>
                     <table id="emmetList"
                         class="table table-condensed table-striped table-bordered table-hover">
                                 <th>Employee</th>
                                 <th>Status</th>
                                 <th>Task Name</th>
+                                <th>Deadline</th>
                             </tr>
                         </thead>
                     </table>
                 </div>
-                <div class="col-xs-12 col-sm-6 col-md-4 col-lg-4">
+                <div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
                     <h3>Western UP</h3>
                     <table id="westernList"
                         class="table table-condensed table-striped table-bordered table-hover">
                                 <th>Employee</th>
                                 <th>Status</th>
                                 <th>Task Name</th>
+                                <th>Deadline</th>
                             </tr>
                         </thead>
                     </table>
                 </div>
-                <div class="col-xs-12 col-sm-6 col-md-4 col-lg-4">
+                <div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
                     <h3>Mount Pleasant Wow</h3>
                     <table id="mountList"
                         class="table table-condensed table-striped table-bordered table-hover">
@@ -84,6 +87,7 @@
                                 <th>Employee</th>
                                 <th>Status</th>
                                 <th>Task Name</th>
+                                <th>Deadline</th>
                             </tr>
                         </thead>
                     </table>
diff --git a/php.php b/php.php
deleted file mode 100644 (file)
index c931d5e..0000000
--- a/php.php
+++ /dev/null
@@ -1 +0,0 @@
-<?php phpinfo();?>