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 2018/06/05 23:19:35 UTC

[whimsy] branch master updated (971110b -> 66cea4c)

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

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


    from 971110b  force serviceworker reload on change
     new 0e1b8ad  add some tests
     new b464fe2  enable logging in development mode
     new 2ceb851  broadcast latest changes to all clients
     new 2f5328a  show service worker URL
     new 66cea4c  move to latest agenda if the current one isn't the latest

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


Summary of changes:
 www/board/agenda/main.rb                      |  4 ++-
 www/board/agenda/spec/reflow_spec.rb          | 41 +++++++++++++++++++++++++++
 www/board/agenda/views/layout/main.js.rb      |  3 ++
 www/board/agenda/views/models/pagecache.js.rb | 40 +++++++++++++++++++++++---
 www/board/agenda/views/pages/cache.js.rb      |  8 ++++++
 www/board/agenda/views/sw.js.rb               | 29 +++++++++++++------
 6 files changed, 111 insertions(+), 14 deletions(-)
 create mode 100644 www/board/agenda/spec/reflow_spec.rb

-- 
To stop receiving notification emails like this one, please contact
rubys@apache.org.

[whimsy] 01/05: add some tests

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://gitbox.apache.org/repos/asf/whimsy.git

commit 0e1b8adc07fc291956111248ddc731282f972b62
Author: Sam Ruby <ru...@intertwingly.net>
AuthorDate: Mon Jun 4 09:13:55 2018 -0400

    add some tests
---
 www/board/agenda/spec/reflow_spec.rb | 41 ++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

diff --git a/www/board/agenda/spec/reflow_spec.rb b/www/board/agenda/spec/reflow_spec.rb
new file mode 100644
index 0000000..56199ec
--- /dev/null
+++ b/www/board/agenda/spec/reflow_spec.rb
@@ -0,0 +1,41 @@
+#
+# component tests for client side forms
+#
+
+require_relative 'spec_helper'
+require_relative 'vue_server'
+
+describe "reflow", type: :feature, server: :vue do
+  #
+  # Comment form
+  #
+  describe "incubator rules" do
+    it "handles ordered lists" do
+      on_vue_server do
+        class TestReflow < Vue
+          def render
+            _ Flow.text("1. a\n2. b")
+          end
+        end
+
+        Vue.renderResponse(TestReflow, response)
+      end
+
+      expect(page.body).to eq "1. a\n2. b"
+    end
+
+    it "handles questions and colons" do
+      on_vue_server do
+        class TestReflow < Vue
+          def render
+            _ Flow.text("a?\nb:\nc", '', true)
+          end
+        end
+
+        Vue.renderResponse(TestReflow, response)
+      end
+
+      expect(page.body).to eq "a?\nb:\nc"
+    end
+  end
+end

-- 
To stop receiving notification emails like this one, please contact
rubys@apache.org.

[whimsy] 05/05: move to latest agenda if the current one isn't the latest

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://gitbox.apache.org/repos/asf/whimsy.git

commit 66cea4cb6fe8fb44734e5e1dd32b556d44f0b623
Author: Sam Ruby <ru...@intertwingly.net>
AuthorDate: Tue Jun 5 19:17:58 2018 -0400

    move to latest agenda if the current one isn't the latest
    
    Background: client will optimistically show the latest agenda it knows about
    and then inquire to the server to see if it is correct.
---
 www/board/agenda/views/layout/main.js.rb      |  3 ++
 www/board/agenda/views/models/pagecache.js.rb | 40 ++++++++++++++++++++++++---
 www/board/agenda/views/sw.js.rb               | 10 +++----
 3 files changed, 44 insertions(+), 9 deletions(-)

diff --git a/www/board/agenda/views/layout/main.js.rb b/www/board/agenda/views/layout/main.js.rb
index d63c636..7d54767 100644
--- a/www/board/agenda/views/layout/main.js.rb
+++ b/www/board/agenda/views/layout/main.js.rb
@@ -82,6 +82,7 @@ class Main < Vue
     self.route(path, query)
     history.pushState({path: path, query: query}, nil, path)
     window.onresize()
+    Main.latest = false if path
   end
 
   # refresh the current page
@@ -99,6 +100,7 @@ class Main < Vue
     Main.navigate = self.navigate
     Main.refresh  = self.refresh
     Main.view  = $refs.view
+    Main.item = Agenda
 
     # store initial state in history, taking care not to overwrite
     # history set by the Search component.
@@ -111,6 +113,7 @@ class Main < Vue
         if path.start_with? base
           path = path.slice(base.length) 
         elsif path.end_with? '/latest/'
+          Main.latest = true
           path = '.'
         end
       end
diff --git a/www/board/agenda/views/models/pagecache.js.rb b/www/board/agenda/views/models/pagecache.js.rb
index 873fc66..0d0b0e1 100644
--- a/www/board/agenda/views/models/pagecache.js.rb
+++ b/www/board/agenda/views/models/pagecache.js.rb
@@ -45,11 +45,13 @@ class PageCache
     navigator.serviceWorker.register(swjs, scope).then do
       # watch for reload requests from the service worker
       navigator.serviceWorker.addEventListener 'message' do |event|
-        if event.data.type == 'reload'
-          # ignore reload request if any input or textarea element is visible
-          inputs = document.querySelectorAll('input, textarea')
-          unless Array(inputs).map {|element| element.offsetWidth}.max() > 0
+        # ignore requests if any input or textarea element is visible
+        inputs = document.querySelectorAll('input, textarea')
+        unless Array(inputs).map {|element| element.offsetWidth}.max() > 0
+          if event.data.type == 'reload'
             window.location.reload() 
+          elsif event.data.type == 'latest' and Main.latest
+            self.latest(event.data.body)
           end
         end
       end
@@ -61,5 +63,35 @@ class PageCache
           url: base + 'bootstrap.html'
       end
     end
+
+    if Main.item == Agenda and Main.latest
+      fetch('bootstrap.html').then do |response|
+        response.text().then do |body|
+          self.latest(body)
+        end
+      end
+    end
+  end
+
+  # if the entry point URL is /latest/, the service worker will optimistically
+  # show the latest known agenda. If it turns out that there is a later one,
+  # refresh with that page.
+  def self.latest(body)
+    # ignore requests if any input or textarea element is visible
+    inputs = document.querySelectorAll('input, textarea')
+    return if Array(inputs).map {|element| element.offsetWidth}.max() > 0
+
+    latest = nil
+    data = body[/"agendas":\[.*?\]/]
+
+    agenda_re = Regexp.new('board_agenda_\d\d\d\d_\d\d_\d\d.txt', 'g')
+    while agenda = agenda_re.exec(data)
+      latest = agenda[0] unless latest and latest > agenda[0]
+    end
+
+    if latest and latest != Agenda.file
+      date = latest[/\d\d\d\d_\d\d_\d\d/].gsub('_', '-')
+      window.location.href = "../#{date}/"
+    end
   end
 end
diff --git a/www/board/agenda/views/sw.js.rb b/www/board/agenda/views/sw.js.rb
index 72e614f..e24b437 100644
--- a/www/board/agenda/views/sw.js.rb
+++ b/www/board/agenda/views/sw.js.rb
@@ -54,10 +54,10 @@ def cache_replace(cache, request, response)
 end
 
 # broadcast a message to all clients
-def broadcast(type)
+def broadcast(message)
   clients.matchAll().then do |clients|
     clients.each do |client|
-      client.postMessage(type: type)
+      client.postMessage(message)
     end
   end
 end
@@ -80,7 +80,7 @@ def preload(cache, base, text, toolate)
         fetch(request).then do |response|
           cache_replace(cache, request, response) if response.ok
           count -= 1
-          broadcast(:reload) if toolate and changed and count == 0
+          broadcast(type: 'reload') if toolate and changed and count == 0
         end
       end
     end
@@ -120,9 +120,9 @@ def latest(event)
             request = Request.new(match.url, cache: "no-store")
             fetch(request).then do |response| 
               if response.ok
-                response.match().text().then do |after|
+                response.clone().text().then do |after|
                   cache.put request, response
-                  broadcast(:latest) if after != before
+                  broadcast(type: 'latest', body: after) # if after != before
                 end
               end
             end

-- 
To stop receiving notification emails like this one, please contact
rubys@apache.org.

[whimsy] 04/05: show service worker URL

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://gitbox.apache.org/repos/asf/whimsy.git

commit 2f5328a532c6b2370dca0add49d10502da69bb4d
Author: Sam Ruby <ru...@intertwingly.net>
AuthorDate: Tue Jun 5 09:09:08 2018 -0400

    show service worker URL
---
 www/board/agenda/views/pages/cache.js.rb | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/www/board/agenda/views/pages/cache.js.rb b/www/board/agenda/views/pages/cache.js.rb
index 37f897b..3fb02af 100644
--- a/www/board/agenda/views/pages/cache.js.rb
+++ b/www/board/agenda/views/pages/cache.js.rb
@@ -41,13 +41,21 @@ class CacheStatus < Vue
     else
       _table.table do
         _thead do
+          _th 'URL'
           _th 'Scope'
           _th 'Status'
         end
 
         _tbody @registrations do |registration|
           _tr do
+            _td do
+              if registration.active
+                _span registration.active.scriptURL
+              end
+            end
+
             _td registration.scope
+
             _td do
               if registration.installing
                 _span 'installing' 

-- 
To stop receiving notification emails like this one, please contact
rubys@apache.org.

[whimsy] 03/05: broadcast latest changes to all clients

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://gitbox.apache.org/repos/asf/whimsy.git

commit 2ceb85152f8b1372b2c09d33b7bbea960deca68d
Author: Sam Ruby <ru...@intertwingly.net>
AuthorDate: Tue Jun 5 09:02:34 2018 -0400

    broadcast latest changes to all clients
---
 www/board/agenda/views/sw.js.rb | 29 ++++++++++++++++++++---------
 1 file changed, 20 insertions(+), 9 deletions(-)

diff --git a/www/board/agenda/views/sw.js.rb b/www/board/agenda/views/sw.js.rb
index edd1582..72e614f 100644
--- a/www/board/agenda/views/sw.js.rb
+++ b/www/board/agenda/views/sw.js.rb
@@ -53,11 +53,11 @@ def cache_replace(cache, request, response)
   cache.put(request, response)
 end
 
-# request all clients to reload content if css or js changed
-def reload()
+# broadcast a message to all clients
+def broadcast(type)
   clients.matchAll().then do |clients|
     clients.each do |client|
-      client.postMessage(type: 'reload')
+      client.postMessage(type: type)
     end
   end
 end
@@ -80,7 +80,7 @@ def preload(cache, base, text, toolate)
         fetch(request).then do |response|
           cache_replace(cache, request, response) if response.ok
           count -= 1
-          reload() if toolate and changed and count == 0
+          broadcast(:reload) if toolate and changed and count == 0
         end
       end
     end
@@ -99,7 +99,9 @@ def fetch_from_cache(event)
   end
 end
 
-# Return latest bootstrap page from the cache
+# Return latest bootstrap page from the cache; then update the bootstrap
+# from the server.  If the body has changed, broadcast that information to
+# all the browser window clients.
 def latest(event)
   return Promise.new do |fulfill, reject|
     caches.open('board/agenda').then do |cache|
@@ -112,10 +114,19 @@ def latest(event)
 	end
 
         if match
-          fulfill(match)
-
-          request = Request.new(match.url, cache: "no-store")
-          fetch(request).then {|response| cache.put request, response}
+          match.clone().text().then do |before|
+            fulfill(match)
+
+            request = Request.new(match.url, cache: "no-store")
+            fetch(request).then do |response| 
+              if response.ok
+                response.match().text().then do |after|
+                  cache.put request, response
+                  broadcast(:latest) if after != before
+                end
+              end
+            end
+          end
         else
           fetch(event.request).then(fulfill, reject)
         end

-- 
To stop receiving notification emails like this one, please contact
rubys@apache.org.

[whimsy] 02/05: enable logging in development mode

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://gitbox.apache.org/repos/asf/whimsy.git

commit b464fe225f26e9dfd8c48f32441917260996378d
Author: Sam Ruby <ru...@intertwingly.net>
AuthorDate: Tue Jun 5 09:01:33 2018 -0400

    enable logging in development mode
---
 www/board/agenda/main.rb | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/www/board/agenda/main.rb b/www/board/agenda/main.rb
index e2d5058..bbcf8e6 100755
--- a/www/board/agenda/main.rb
+++ b/www/board/agenda/main.rb
@@ -24,7 +24,9 @@ require 'mail'
 require 'open-uri'
 require 'erubis'
 
-disable :logging # suppress log of requests to stderr/error.log
+unless ENV['RACK_ENV'] == 'development'
+  disable :logging # suppress log of requests to stderr/error.log
+end
 
 # determine where relevant data can be found
 if ENV['RACK_ENV'] == 'test'

-- 
To stop receiving notification emails like this one, please contact
rubys@apache.org.