whimsical-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sam Ruby <ru...@apache.org>
Subject [whimsy.git] [33/50] Commit 3e30baf: buttons => forms; fix etag
Date Fri, 22 Jan 2016 02:40:56 GMT
Commit 3e30bafdbff5089748f01370a27c5e26711a8ec8:
    buttons => forms; fix etag


Branch: refs/heads/master
Author: Sam Ruby <rubys@intertwingly.net>
Committer: Sam Ruby <rubys@intertwingly.net>
Pusher: rubys <rubys@apache.org>

------------------------------------------------------------
routes.rb                                                    | ++++++ -----
views/add-comment.rb                                         | +++++++++ ----
views/agenda.js.rb                                           | + -
views/footer.js.rb                                           | +++ --------
views/main.js.rb                                             | +++++++++++ --
------------------------------------------------------------
104 changes: 67 additions, 37 deletions.
------------------------------------------------------------


diff --git a/routes.rb b/routes.rb
index cb97789..80799fc 100755
--- a/routes.rb
+++ b/routes.rb
@@ -66,19 +66,20 @@
   path = File.expand_path(file, FOUNDATION_BOARD).untaint
   pass unless File.exist? path
 
-  response = _json do
-    file = file.dup.untaint
+  begin
+    _json do
+      file = file.dup.untaint
 
-    if AGENDA_CACHE[file][:mtime] != File.mtime(path)
-      AGENDA_CACHE.parse file
-    end
+      if AGENDA_CACHE[file][:mtime] != File.mtime(path)
+        AGENDA_CACHE.parse file
+      end
 
-    last_modified AGENDA_CACHE[file][:mtime]
-    AGENDA_CACHE[file][:parsed]
+      last_modified AGENDA_CACHE[file][:mtime]
+      AGENDA_CACHE[file][:parsed]
+    end
+  ensure
+    AGENDA_CACHE[file][:etag] = headers['ETag']
   end
-
-  AGENDA_CACHE[file][:etag] = headers['ETag']
-  response
 end
 
 get '/json/minutes/:file' do |file|
diff --git a/views/add-comment.rb b/views/add-comment.rb
index 0d8ab1b..355470d 100644
--- a/views/add-comment.rb
+++ b/views/add-comment.rb
@@ -3,11 +3,16 @@ def initialize
     @save_disabled = true
   end
 
-  def render
-    # comment form button
-    _button.btn.btn_primary 'add comment', type: 'button', 
-      data_toggle: 'modal', data_target: '#comment-form'
+  def self.button
+    {
+      text: 'add comment',
+      class: 'btn_primary',
+      data_toggle: 'modal',
+      data_target: '#comment-form'
+    }
+  end
 
+  def render
     _ModalDialog.comment_form! color: 'commented' do
       # header
       _h4 'Enter a comment'
diff --git a/views/agenda.js.rb b/views/agenda.js.rb
index 72a4667..c8670a2 100644
--- a/views/agenda.js.rb
+++ b/views/agenda.js.rb
@@ -114,7 +114,7 @@ def view
     Report
   end
 
-  def buttons
+  def forms
     [
       (AddComment unless @comments === undefined)
     ]
diff --git a/views/footer.js.rb b/views/footer.js.rb
index 9f70025..67c916f 100644
--- a/views/footer.js.rb
+++ b/views/footer.js.rb
@@ -1,16 +1,4 @@
 class Footer < React
-  def initialize
-    @buttons = nil
-  end
-
-  def componentWillMount()
-    self.componentWillReceiveProps(self.props)
-  end
-
-  def componentWillReceiveProps(newprops)
-    @buttons = newprops.item.buttons
-  end
-
   def render
     _footer.navbar.navbar_fixed_bottom class: @@item.color do
       if @@item.prev
@@ -18,9 +6,11 @@ def render
          href: @@item.prev.href
       end
 
-      if @buttons
-        @buttons.each do |button|
-          React.createElement(button, item: @@item) if button
+      if @@buttons
+        _span do
+          @@buttons.each do |button|
+            React.createElement('button', button.attrs, button.text) if button
+          end
         end
       end
 
diff --git a/views/main.js.rb b/views/main.js.rb
index c23d1d2..fc74a3c 100644
--- a/views/main.js.rb
+++ b/views/main.js.rb
@@ -16,7 +16,7 @@ class Main < React
   def initialize
     @poll = {
       link: "../#{@@page.date}.json",
-      etag: @@etag,
+      etag: @@page.etag,
       interval: 10_000
     }
   end
@@ -24,14 +24,43 @@ def initialize
   # route request based on path and query from the window location (URL)
   def route(path, query)
     if path == 'search'
-      @item = {title: 'Search', view: Search, color: 'blank', query: query}
+      item = {view: Search, query: query}
     elsif path == 'comments'
-      @item = {title: 'Comments', view: Comments, color: 'blank'}
+      item = {view: Comments}
     elsif path and path != '.'
-      @item = Agenda.find(path)
+      item = Agenda.find(path)
     else
-      @item = Agenda
+      item = Agenda
     end
+
+    # provide defaults for required properties
+    item.color ||= 'blank'
+    item.title ||= item.view.displayName
+
+    # determine what buttons are required
+    if item.forms
+      @buttons = item.forms.map do |form|
+        if form and form.button
+          props = {text: 'button', attrs: {className: 'btn'}}
+          for name in form.button
+            if name == 'text'
+              props.text = form.button.text
+            elsif name == 'class' or name == 'classname'
+              props.attrs.className = "btn #{form.button[name].gsub('_', '-')}"
+            else
+              props.attrs[name.gsub('_', '-')] = form.button[name]
+            end
+          end
+          return props
+        else
+          return nil
+        end
+      end
+    else
+      @buttons = []
+    end
+
+    @item = Main.item = item
   end
 
   # common render for all pages: header, main, and footer
@@ -42,7 +71,13 @@ def render
       React.createElement(@item.view, data: @item)
     end
 
-    _Footer item: @item
+    _Footer item: @item, buttons: @buttons
+
+    if @item.forms
+      @item.forms.each do |form|
+        React.createElement(form, item: @item) if form
+      end
+    end
   end
 
   # initial load of the agenda, and route first request
@@ -131,5 +166,4 @@ def xhr.onreadystatechange()
     end
     xhr.send()
   end
-
 end

Mime
View raw message