Refactoring a few things after code review with David.
authorAndrew Otto <acotto@gmail.com>
Mon, 16 Apr 2012 22:01:37 +0000 (18:01 -0400)
committerAndrew Otto <acotto@gmail.com>
Mon, 16 Apr 2012 22:01:37 +0000 (18:01 -0400)
lib/graph/graph-list-view.co [moved from lib/graph/graph-index-view.co with 55% similarity]
lib/graph/index.co
lib/main-graph-list.co
lib/template/dashboard.jade
lib/template/graph-index.jade [deleted file]
lib/template/graph-list.jade [new file with mode: 0644]
www/modules.yaml

similarity index 55%
rename from lib/graph/graph-index-view.co
rename to lib/graph/graph-list-view.co
index 7c352f8..6ce2b93 100644 (file)
@@ -11,20 +11,26 @@ DEBOUNCE_RENDER = 100ms
 /**
  * @class View for a showing a list of all saved graphs
  */
-GraphIndexView = exports.GraphIndexView = BaseView.extend do # {{{
+GraphListView = exports.GraphListView = BaseView.extend do # {{{
     __bind__  : <[
         render
     ]>
     __debounce__: <[ render ]>
     
     tagName   : 'section'
-    className : 'graph-index-view'
-    template  : require 'kraken/template/graph-index'
+    className : 'graph-list-view'
+    template  : require 'kraken/template/graph-list'
     
     data  : {}
     ready : false
-
-    initialize : (o={}) ->
-        @model = new GraphList (o['graph_list_data'])
+    
+    initialize : ->
+        @model = @collection or= new GraphList
         BaseView::initialize ...
         console.log "#this.initialize!"
+    
+    toTemplateLocals: ->
+        locals = BaseView::toTemplateLocals ...
+        locals.collection = @collection
+        locals
+    
\ No newline at end of file
index 978ece3..8ea477e 100644 (file)
@@ -1,6 +1,6 @@
-models        = require 'kraken/graph/graph-model'
-display_views = require 'kraken/graph/graph-display-view'
-edit_views    = require 'kraken/graph/graph-edit-view'
-index_views    = require 'kraken/graph/graph-index-view'
+models         = require 'kraken/graph/graph-model'
+display_views  = require 'kraken/graph/graph-display-view'
+edit_views     = require 'kraken/graph/graph-edit-view'
+index_views    = require 'kraken/graph/graph-list-view'
 
 exports import models import display_views import edit_views import index_views
index f4eda3b..e724e4d 100644 (file)
@@ -2,27 +2,25 @@
 } = require 'kraken/util'
 { BaseView, BaseModel, BaseList,
 } = require 'kraken/base'
-{ Graph, GraphList, GraphIndexView
+{ Graph, GraphList, GraphListView
 } = require 'kraken/graph'
 
-root = this
-
-# instantiates a new GraphIndexView with the
+# instantiates a new GraphListView with the
 # passed in JSON graph_list_data, and then
 # appends the rendered view to the DOM.
 main = (graph_list_data) ->
-    view = new GraphIndexView { 'graph_list_data': graph_list_data }
+    graphs = new GraphList graph_list_data
+    view = new GraphListView { 'collection': graphs }
     $ '#content .inner' .append view.el
 
 # URL to query for saved graph JSON data.
-graph_list_url = 'http://localhost:8081/graphslist'
+graph_list_url = '/graphslist'
 
 jQuery.ajax do
-    url : 'http://localhost:8081/graphslist'
+    url : graph_list_url
     dataType : 'json'
     success : (res) ->
-        console.log("got %o", res)
         # result will be the returned JSON
         # data of all of the saved graphs
-        jQuery main res
+        jQuery main.bind this, res
     error : (err) -> console.error err
index 3688666..654be23 100644 (file)
@@ -1,4 +1,4 @@
-section#dashboard
+section#graph-list
     .page-header
         h1 Wikimedia Report Card 
             small February 2012
diff --git a/lib/template/graph-index.jade b/lib/template/graph-index.jade
deleted file mode 100644 (file)
index 4c3bef0..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-ul
-    - model.forEach(function(graph) {
-      li
-        a(href="#{graph.toLink()}") #{graph.attributes.name}
-    - })
diff --git a/lib/template/graph-list.jade b/lib/template/graph-list.jade
new file mode 100644 (file)
index 0000000..ca8951d
--- /dev/null
@@ -0,0 +1,7 @@
+section#graph-list
+    .page-header
+        h1 Saved Graphs
+    ul
+        for graph in collection.models
+            li
+                a(href="#{graph.toLink()}") #{graph.get('name')}
index 28d37b3..732ad82 100644 (file)
@@ -72,7 +72,7 @@ dev:
                 - graph-display.jade
                 - graph-edit.jade
                 - dashboard.jade
-                - graph-index.jade
+                - graph-list.jade
             - chart:
                 - chart-type
                 - dygraphs
@@ -94,7 +94,7 @@ dev:
                 - graph-model
                 - graph-display-view
                 - graph-edit-view
-                - graph-index-view
+                - graph-list-view
                 - index
             - dashboard:
                 - dashboard-model