You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@whimsical.apache.org by ru...@apache.org on 2016/07/26 01:47:16 UTC

[whimsy] branch master updated (3248bee -> 161d230)

This is an automated email from the ASF dual-hosted git repository.

rubys pushed a change to branch master
in repository https://git-dual.apache.org/repos/asf/whimsy.git.

      from  3248bee   display cache pages
       new  09bae00   show response headers
       new  161d230   fetch and cache agenda json

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "adds" were already present in the repository and have only
been added to this reference.


Summary of changes:
 www/board/agenda/views/keyboard.js.rb      |  2 +-
 www/board/agenda/views/models/agenda.js.rb | 62 +++++++++++++++++++++++++-----
 www/board/agenda/views/pages/cache.js.rb   | 20 ++++++++++
 3 files changed, 73 insertions(+), 11 deletions(-)

-- 
To stop receiving notification emails like this one, please contact
['"commits@whimsical.apache.org" <co...@whimsical.apache.org>'].

[whimsy] 01/02: show response headers

Posted by ru...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rubys pushed a commit to branch master
in repository https://git-dual.apache.org/repos/asf/whimsy.git

commit 09bae000bfaf2248faa9dba70bee662c7d66caa3
Author: Sam Ruby <ru...@intertwingly.net>
AuthorDate: Mon Jul 25 21:44:15 2016 -0400

    show response headers
---
 www/board/agenda/views/keyboard.js.rb    |  2 +-
 www/board/agenda/views/pages/cache.js.rb | 20 ++++++++++++++++++++
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/www/board/agenda/views/keyboard.js.rb b/www/board/agenda/views/keyboard.js.rb
index fd80093..4edfc1c 100644
--- a/www/board/agenda/views/keyboard.js.rb
+++ b/www/board/agenda/views/keyboard.js.rb
@@ -85,7 +85,7 @@ class Keyboard
           Main.refresh()
         end
         return false
-      elsif event.keyCode == '='.ord
+      elsif event.keyCode == '='.ord or event.keyCode == 187 # "="
         Main.navigate "cache/"
         return false
       end
diff --git a/www/board/agenda/views/pages/cache.js.rb b/www/board/agenda/views/pages/cache.js.rb
index bf540f0..c94c8e6 100644
--- a/www/board/agenda/views/pages/cache.js.rb
+++ b/www/board/agenda/views/pages/cache.js.rb
@@ -98,6 +98,26 @@ class CachePage < React
   def render
     _h2 @response.url
     _p "#{@response.status} #{@response.statusText}"
+
+    if @response.headers
+      # avoid buggy @response.headers.keys()
+      keys = []
+      iterator = @response.headers.entries()
+      entry = iterator.next()
+      while not entry.done
+        keys << entry.value[0] unless entry.value[0] == 'status'
+        entry = iterator.next()
+      end
+
+      keys.sort()
+
+      _ul do 
+        keys.each do |key|
+          _li "#{key}: #{@response.headers.get(key)}"
+        end
+      end
+    end
+
     _pre @text
   end
 

-- 
To stop receiving notification emails like this one, please contact
"commits@whimsical.apache.org" <co...@whimsical.apache.org>.

[whimsy] 02/02: fetch and cache agenda json

Posted by ru...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rubys pushed a commit to branch master
in repository https://git-dual.apache.org/repos/asf/whimsy.git

commit 161d230378a802f067ae61667a521248f4f609f1
Author: Sam Ruby <ru...@intertwingly.net>
AuthorDate: Mon Jul 25 21:45:13 2016 -0400

    fetch and cache agenda json
---
 www/board/agenda/views/models/agenda.js.rb | 62 +++++++++++++++++++++++++-----
 1 file changed, 52 insertions(+), 10 deletions(-)

diff --git a/www/board/agenda/views/models/agenda.js.rb b/www/board/agenda/views/models/agenda.js.rb
index e35c45e..49a9350 100644
--- a/www/board/agenda/views/models/agenda.js.rb
+++ b/www/board/agenda/views/models/agenda.js.rb
@@ -58,18 +58,60 @@ class Agenda
     if etag
       @@etag = etag
     elsif digest != @@digest or not @@etag
-      xhr = XMLHttpRequest.new()
-      xhr.open('GET', "../#{@@date}.json", true)
-      xhr.setRequestHeader('If-None-Match', @@etag) if @@etag
-      xhr.responseType = 'text'
-      def xhr.onreadystatechange()
-        if xhr.readyState == 4 and xhr.status == 200 and xhr.responseText != ''
-          @@etag = xhr.getResponseHeader('ETag')
-          Agenda.load(JSON.parse(xhr.responseText))
-          Main.refresh()
+      if PageCache.enabled
+        loaded = false
+
+        # if bootstrapping and cache is available, load it
+        if not digest
+          caches.open('board/agenda').then do |cache|
+            cache.match("#{@@date}.json").then do |response|
+              if response
+                response.json().then do |json| 
+                  Agenda.load(json) unless loaded
+                  Main.refresh()
+                end
+              end
+            end
+          end
         end
+
+        # set fetch options: credentials and etag
+        options = {credentials: 'include'}
+        options['headers'] = {'If-None-Match' => @@etag} if @@etag
+
+        # perform fetch
+        fetch("../#{@@date}.json", options).then do |response|
+          if response
+            loaded = true
+
+            # load response into the agenda
+            response.clone().json().then do |json| 
+              @@etag = response.headers.get('etag')
+              Agenda.load(json)
+              Main.refresh()
+            end
+
+            # save response in the cache
+            caches.open('board/agenda').then do |cache|
+              cache.put("#{@@date}.json", response)
+            end
+          end
+        end
+      else
+        # AJAX fallback
+        xhr = XMLHttpRequest.new()
+        xhr.open('GET', "../#{@@date}.json", true)
+        xhr.setRequestHeader('If-None-Match', @@etag) if @@etag
+        xhr.responseType = 'text'
+        def xhr.onreadystatechange()
+          if xhr.readyState==4 and xhr.status==200 and xhr.responseText!=''
+            @@etag = xhr.getResponseHeader('ETag')
+            Agenda.load(JSON.parse(xhr.responseText))
+            Main.refresh()
+          end
+        end
+        xhr.send()
       end
-      xhr.send()
     end
 
     @@digest = digest

-- 
To stop receiving notification emails like this one, please contact
"commits@whimsical.apache.org" <co...@whimsical.apache.org>.