whimsical-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ru...@apache.org
Subject [whimsy] branch master updated: show unposted reporter.apache.org drafts
Date Sat, 10 Aug 2019 03:39:26 GMT
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


The following commit(s) were added to refs/heads/master by this push:
     new fc17a88  show unposted reporter.apache.org drafts
fc17a88 is described below

commit fc17a8885774c398c235b14f830ab5b74f6f8fbd
Author: Sam Ruby <rubys@intertwingly.net>
AuthorDate: Fri Aug 9 23:38:53 2019 -0400

    show unposted reporter.apache.org drafts
---
 www/board/agenda/main.rb                           |  1 +
 www/board/agenda/models/reporter.rb                | 49 ++++++++++++++++++++++
 www/board/agenda/routes.rb                         |  5 +++
 www/board/agenda/views/actions/reporter.json.rb    |  6 +++
 www/board/agenda/views/app.js.rb                   |  1 +
 www/board/agenda/views/buttons/post.js.rb          |  8 +++-
 .../agenda/views/elements/additional-info.js.rb    | 10 +++++
 www/board/agenda/views/models/reporter.js.rb       | 24 +++++++++++
 www/board/agenda/views/pages/report.js.rb          | 17 +++++++-
 9 files changed, 119 insertions(+), 2 deletions(-)

diff --git a/www/board/agenda/main.rb b/www/board/agenda/main.rb
index b991243..6321eea 100755
--- a/www/board/agenda/main.rb
+++ b/www/board/agenda/main.rb
@@ -48,6 +48,7 @@ require_relative './models/pending'
 require_relative './models/agenda'
 require_relative './models/minutes'
 require_relative './models/comments'
+require_relative './models/reporter'
 require_relative './helpers/string'
 require_relative './helpers/integer'
 require_relative './daemon/session'
diff --git a/www/board/agenda/models/reporter.rb b/www/board/agenda/models/reporter.rb
new file mode 100644
index 0000000..83150b5
--- /dev/null
+++ b/www/board/agenda/models/reporter.rb
@@ -0,0 +1,49 @@
+class Reporter
+  def self.drafts(env)
+    agenda_file = File.basename(
+      Dir["#{FOUNDATION_BOARD}/board_agenda_*.txt"].sort.last).untaint
+    agenda = Agenda.parse(agenda_file, :quick)
+
+    cache = File.join(ASF::Config.get(:cache), 'reporter-drafts.json')
+
+    # if cache is older than a minute, fetch new data
+    if not File.exist? cache or File.mtime(cache) < Time.now - 60
+      # read and prune previous status.  May be used to "fill in the blanks"
+      # should a partial set of reports be received
+      report_status = (JSON.parse(File.read(cache)) rescue {}).
+        select {|project, status| status['agenda'] == agenda_file}.to_h
+
+      # source of truth
+      uri = URI.parse('https://reporter.apache.org/api/drafts/forgotten')
+
+      # fetch and merge in latest report statuses
+      Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
+        request = Net::HTTP::Get.new(uri)
+        request.basic_auth env.user, env.password
+        response = http.request(request)
+        report_status.merge! JSON.parse(response.body)['report_status']
+        File.write cache, report_status.to_json
+      end
+    end
+
+    # extract projects with drafts for this agenda
+    drafts = JSON.parse(File.read(cache)).select do |project, status| 
+      next false unless status['agenda'] == agenda_file
+      last_draft = status['last_draft']
+      last_draft and not last_draft.empty?
+    end
+
+    # return agenda and drafts indexed by attachment
+    {
+      agenda: agenda_file,
+      drafts: drafts.map {|project, status|
+        [status['attach'], {
+          project: project, 
+          timestamp: status['draft_timestamp'],
+          author: status['last_author'],
+          text: status['last_draft']
+        }]
+      }.to_h
+    }
+  end
+end
diff --git a/www/board/agenda/routes.rb b/www/board/agenda/routes.rb
index 76b3942..3b99499 100755
--- a/www/board/agenda/routes.rb
+++ b/www/board/agenda/routes.rb
@@ -328,6 +328,11 @@ get '/json/podlingnamesearch' do
   _json ASF::Podling.namesearch
 end
 
+# podling name searches
+get '/json/reporter' do
+  _json Reporter.drafts(env)
+end
+
 # posted actions
 post '/json/:file' do
   _json :"actions/#{params[:file]}"
diff --git a/www/board/agenda/views/actions/reporter.json.rb b/www/board/agenda/views/actions/reporter.json.rb
new file mode 100644
index 0000000..7d4eaff
--- /dev/null
+++ b/www/board/agenda/views/actions/reporter.json.rb
@@ -0,0 +1,6 @@
+# find the latest agenda
+agenda_file = Dir["#{FOUNDATION_BOARD}/board_agenda_*.txt"].sort.last.untaint
+agenda = Agenda.parse File.basename(agenda_file), :quick
+
+agenda
+
diff --git a/www/board/agenda/views/app.js.rb b/www/board/agenda/views/app.js.rb
index 2046d34..d45c075 100644
--- a/www/board/agenda/views/app.js.rb
+++ b/www/board/agenda/views/app.js.rb
@@ -77,4 +77,5 @@ require_relative 'models/responses'
 require_relative 'models/user'
 require_relative 'models/posted'
 require_relative 'models/comments'
+require_relative 'models/reporter'
 require_relative 'models/jsonstorage'
diff --git a/www/board/agenda/views/buttons/post.js.rb b/www/board/agenda/views/buttons/post.js.rb
index 39a2f4d..ab4b46d 100644
--- a/www/board/agenda/views/buttons/post.js.rb
+++ b/www/board/agenda/views/buttons/post.js.rb
@@ -331,6 +331,8 @@ class Post < Vue
 
   # match form title, input label, and commit message with button text
   def retitle()
+    @report = nil
+
     case @button
     when 'post report'
       @header = 'Post Report'
@@ -346,6 +348,10 @@ class Post < Vue
         end
       end
 
+      # if there is a draft being prepared at reporter.apache.org, use it
+      draft = Reporter.find(@@item)
+      @report = draft.text if draft
+
     when 'edit item'
       @header = 'Edit Discussion Item'
       @label = 'text'
@@ -383,7 +389,7 @@ class Post < Vue
     end
 
     if not @edited
-      text = @@item.text || '' 
+      text = @report || @@item.text || '' 
       if @@item.title == 'President'
         text.sub! /\s*Additionally, please see Attachments \d through \d\./, ''
       end
diff --git a/www/board/agenda/views/elements/additional-info.js.rb b/www/board/agenda/views/elements/additional-info.js.rb
index c8cff0b..7a04783 100644
--- a/www/board/agenda/views/elements/additional-info.js.rb
+++ b/www/board/agenda/views/elements/additional-info.js.rb
@@ -45,6 +45,16 @@ class AdditionalInfo < Vue
       end
     end
 
+    # draft reports
+    draft = Reporter.find(@@item)
+    if draft and @prefix
+      _span.hilite do 
+        _em 'Unposted draft being prepared at '
+        _a 'reporter.apache.org',
+          href: "https://reporter.apache.org/wizard?#{draft.project}"
+      end
+    end
+
     # action items
     if @@item.title != 'Action Items' and not @@item.actions.empty?
       _h4 id: "#{@prefix}actions" do
diff --git a/www/board/agenda/views/models/reporter.js.rb b/www/board/agenda/views/models/reporter.js.rb
new file mode 100644
index 0000000..abdbc52
--- /dev/null
+++ b/www/board/agenda/views/models/reporter.js.rb
@@ -0,0 +1,24 @@
+#
+# Fetch, retain, and query the list of reporter drafts
+#
+
+class Reporter
+  Vue.util.defineReactive @@forgotten, nil
+
+  def self.find(item)
+    if @@forgotten != nil
+      return false if @@forgotten.agenda != Agenda.file
+      return false unless item.attach =~ /^[A-Z]+$/ and item.stats
+
+      draft = @@forgotten.drafts[item.attach]
+      if draft and draft.project == item.stats.split('?')[1]
+        return draft
+      end
+    else
+      @@forgotten = {}
+      JSONStorage.fetch 'reporter' do |forgotten|
+        @@forgotten = forgotten
+      end
+    end
+  end
+end
diff --git a/www/board/agenda/views/pages/report.js.rb b/www/board/agenda/views/pages/report.js.rb
index f5551e9..55e4aa9 100644
--- a/www/board/agenda/views/pages/report.js.rb
+++ b/www/board/agenda/views/pages/report.js.rb
@@ -26,7 +26,18 @@ class Report < Vue
           if @@item.text
             _Text raw: @@item.text, filters: filters
           elsif @@item.missing
-            _p {_em 'Missing'} 
+            draft = Reporter.find(@@item)
+            if draft
+              _p do 
+                _em 'Unposted draft being prepared at '
+                _a 'reporter.apache.org',
+                  href: "https://reporter.apache.org/wizard?#{draft.project}"
+                _span ':'
+              end
+              _Text raw: draft.text, filters: [self.draft]
+            else
+              _p {_em 'Missing'} 
+            end
           else
             _p {_em 'Empty'} 
           end
@@ -348,4 +359,8 @@ class Report < Vue
 
     return text
   end
+
+  def draft(text)
+    return "<div class='private'>#{text}</div>"
+  end
 end


Mime
View raw message