myexperiment-hackers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[myexperiment-hackers] [3724] branches/packs: added clickable checklists


From: noreply
Subject: [myexperiment-hackers] [3724] branches/packs: added clickable checklists
Date: Thu, 26 Sep 2013 11:54:21 +0000 (UTC)

Revision
3724
Author
dgc
Date
2013-09-26 11:54:21 +0000 (Thu, 26 Sep 2013)

Log Message

added clickable checklists

Modified Paths

Added Paths

Removed Paths

Diff

Modified: branches/packs/app/controllers/application_controller.rb (3723 => 3724)


--- branches/packs/app/controllers/application_controller.rb	2013-09-26 08:27:16 UTC (rev 3723)
+++ branches/packs/app/controllers/application_controller.rb	2013-09-26 11:54:21 UTC (rev 3724)
@@ -546,6 +546,8 @@
       render_401
     elsif status_code == :not_found
       render_404
+    elsif status_code == :unprocessable_entity
+      render_422
     elsif status_code == :internal_server_error
       render_500
     else
@@ -573,6 +575,14 @@
     end
   end
 
+  def render_422(message = nil)
+    @message = message
+    respond_to do |format|
+      format.html { render :template => "errors/422", :status => 422 }
+      format.all { render :nothing => true, :status => 422 }
+    end
+  end
+
   def render_500(message = nil)
     @message = message
     respond_to do |format|

Added: branches/packs/app/controllers/checklists_controller.rb (0 => 3724)


--- branches/packs/app/controllers/checklists_controller.rb	                        (rev 0)
+++ branches/packs/app/controllers/checklists_controller.rb	2013-09-26 11:54:21 UTC (rev 3724)
@@ -0,0 +1,37 @@
+# myExperiment: app/controllers/checklists_controller.rb
+#
+# Copyright (c) 2007-2013 The University of Manchester, the University of
+# Oxford, and the University of Southampton.  See license.txt for details.
+
+class ChecklistsController < ApplicationController
+
+  before_filter :find_and_auth_resource_context
+  before_filter :find_checklist
+
+  def show
+  end
+
+private
+
+  def find_and_auth_resource_context
+    @context = extract_resource_context(params)
+
+    if @context.nil?
+      render_404("Checklist context not found.")
+    elsif !Authorization.check('view', @context, current_user)
+      render_401("You are not authorized to view the checklists of this resource.")
+    end
+  end
+
+  def find_checklist
+
+    unless params[:action] == 'index'
+      @checklist = @context.research_object.checklists.find_by_slug(params[:id])
+
+      if @checklist.nil?
+        render_404("Checklist not found.")
+        return
+      end
+    end
+  end
+end

Modified: branches/packs/app/controllers/packs_controller.rb (3723 => 3724)


--- branches/packs/app/controllers/packs_controller.rb	2013-09-26 08:27:16 UTC (rev 3723)
+++ branches/packs/app/controllers/packs_controller.rb	2013-09-26 11:54:21 UTC (rev 3724)
@@ -475,38 +475,16 @@
 
   def update_checklist
 
-    entry = Conf.research_object_checklists[params[:minim]]
+    slug  = params[:checklist]
 
-    checklist_uri = url_with_params(entry["service"],
-      "RO" => @pack.research_object.uri.to_s,
-#     "RO" => "http://alpha2.myexperiment.org/rodl/ROs/Pack15/",
-      "minim" => entry["minim"],
-      "purpose" => entry["purpose"])
-
-#   @results = scrape_checklist_results(File.read("checklist2.html"))
-    @results = scrape_checklist_results(open(checklist_uri))
-    @context = @pack
-
-    clr = @pack.research_object.checklist_results.find_by_minim_url_and_purpose(
-        entry["minim"], entry["purpose"])
-
-    if clr.nil?
-      clr = @context.research_object.checklist_results.create(
-          :minim_url => entry["minim"],
-          :purpose => entry["purpose"])
+    unless Conf.research_object_checklists[slug]
+      render_422("The requested checklist is not defined")
+      return
     end
 
-    clr.update_attributes(
-        :score     => @results[:score],
-        :max_score => @results[:max_score])
+    checklist = @pack.research_object.run_checklist!(slug)
 
-    clr.checklist_item_results.delete_all
-
-    @results[:sub_results].each do |sr|
-      clr.checklist_item_results.build(:colour => sr[:colour].to_s, :text => sr[:text]).save
-    end
-
-    render "research_objects/checklist"
+    redirect_to polymorphic_path(address@hidden, checklist])
   end
 
   protected
@@ -697,34 +675,4 @@
     ro.create_folder_entry(relative_uri(resource_uri, @pack.research_object.uri), folder.path, user_path(current_user))
   end
 
-  # This is a stop-gap solution.  Yes, really.
-
-  def scrape_checklist_results(html)
-
-    doc = Nokogiri::HTML(html)
-
-    classes = {
-      "trafficlight small fail should" => { :colour => :red,   :score => 0 },
-      "trafficlight small fail must"   => { :colour => :amber, :score => 1 },
-      "trafficlight small pass"        => { :colour => :green, :score => 2 }
-    }
-
-    score     = 0
-    max_score = 0
-
-    sub_results = doc.xpath("//address@hidden'sub_result']").map do |tr|
-      tds = tr.xpath("td")
-
-      score += classes[tds[1].attributes["class"].to_s][:score]
-      max_score += 2
-
-      {
-        :text   => tds[2].text,
-        :colour => classes[tds[1].attributes["class"].to_s][:colour]
-      }
-    end
-
-    { :score => score, :max_score => max_score, :sub_results => sub_results }
-  end
-
 end

Copied: branches/packs/app/models/checklist.rb (from rev 3723, branches/packs/app/models/checklist_result.rb) (0 => 3724)


--- branches/packs/app/models/checklist.rb	                        (rev 0)
+++ branches/packs/app/models/checklist.rb	2013-09-26 11:54:21 UTC (rev 3724)
@@ -0,0 +1,76 @@
+# myExperiment: app/models/checklist.rb
+#
+# Copyright (c) 2007-2013 The University of Manchester, the University of
+# Oxford, and the University of Southampton.  See license.txt for details.
+
+class Checklist < ActiveRecord::Base
+
+  belongs_to :research_object
+
+  has_many :checklist_items, :dependent => :destroy
+
+  def to_param
+    slug
+  end 
+
+
+  def run_checklist!
+
+    entry = Conf.research_object_checklists[slug]
+
+    query = {
+#     "RO"      => "http://alpha2.myexperiment.org/rodl/ROs/Pack15/",
+      "RO"      => @pack.research_object.uri.to_s,
+      "minim"   => entry["minim"],
+      "purpose" => entry["purpose"]
+    }
+
+    checklist_uri = "#{entry["service"]}?#{query.to_query}"
+
+#   results = scrape_checklist_results(File.read("checklist2.html"))
+    results = scrape_checklist_results(open(checklist_uri))
+
+    update_attributes(
+        :score     => results[:score],
+        :max_score => results[:max_score])
+
+    checklist_items.delete_all
+
+    results[:sub_results].each do |sr|
+      checklist_items.build(:colour => sr[:colour].to_s, :text => sr[:text]).save
+    end
+  end
+
+private
+
+  # FIXME: This is a stop-gap solution.  Yes, really.
+
+  def scrape_checklist_results(html)
+
+    doc = Nokogiri::HTML(html)
+
+    classes = {
+      "trafficlight small fail should" => { :colour => :red,   :score => 0 },
+      "trafficlight small fail must"   => { :colour => :amber, :score => 1 },
+      "trafficlight small pass"        => { :colour => :green, :score => 2 }
+    }
+
+    score     = 0
+    max_score = 0
+
+    sub_results = doc.xpath("//address@hidden'sub_result']").map do |tr|
+      tds = tr.xpath("td")
+
+      score += classes[tds[1].attributes["class"].to_s][:score]
+      max_score += 2
+
+      {
+        :text   => tds[2].text,
+        :colour => classes[tds[1].attributes["class"].to_s][:colour]
+      }
+    end
+
+    { :score => score, :max_score => max_score, :sub_results => sub_results }
+  end
+
+end

Copied: branches/packs/app/models/checklist_item.rb (from rev 3723, branches/packs/app/models/checklist_item_result.rb) (0 => 3724)


--- branches/packs/app/models/checklist_item.rb	                        (rev 0)
+++ branches/packs/app/models/checklist_item.rb	2013-09-26 11:54:21 UTC (rev 3724)
@@ -0,0 +1,11 @@
+# myExperiment: app/models/checklist_item_result.rb
+#
+# Copyright (c) 2007-2013 The University of Manchester, the University of
+# Oxford, and the University of Southampton.  See license.txt for details.
+
+class ChecklistItem < ActiveRecord::Base
+
+  belongs_to :checklist
+
+end
+

Deleted: branches/packs/app/models/checklist_item_result.rb (3723 => 3724)


--- branches/packs/app/models/checklist_item_result.rb	2013-09-26 08:27:16 UTC (rev 3723)
+++ branches/packs/app/models/checklist_item_result.rb	2013-09-26 11:54:21 UTC (rev 3724)
@@ -1,11 +0,0 @@
-# myExperiment: app/models/checklist_item_result.rb
-#
-# Copyright (c) 2007-2013 The University of Manchester, the University of
-# Oxford, and the University of Southampton.  See license.txt for details.
-
-class ChecklistItemResult < ActiveRecord::Base
-
-  belongs_to :checklist_result
-
-end
-

Deleted: branches/packs/app/models/checklist_result.rb (3723 => 3724)


--- branches/packs/app/models/checklist_result.rb	2013-09-26 08:27:16 UTC (rev 3723)
+++ branches/packs/app/models/checklist_result.rb	2013-09-26 11:54:21 UTC (rev 3724)
@@ -1,12 +0,0 @@
-# myExperiment: app/models/checklist_result.rb
-#
-# Copyright (c) 2007-2013 The University of Manchester, the University of
-# Oxford, and the University of Southampton.  See license.txt for details.
-
-class ChecklistResult < ActiveRecord::Base
-
-  belongs_to :research_object
-
-  has_many :checklist_item_results, :dependent => :destroy
-
-end

Modified: branches/packs/app/models/research_object.rb (3723 => 3724)


--- branches/packs/app/models/research_object.rb	2013-09-26 08:27:16 UTC (rev 3723)
+++ branches/packs/app/models/research_object.rb	2013-09-26 11:54:21 UTC (rev 3724)
@@ -27,7 +27,7 @@
 
   belongs_to :context, :polymorphic => true
 
-  has_many :checklist_results, :dependent => :destroy
+  has_many :checklists, :dependent => :destroy
 
   validates_presence_of :slug
 
@@ -809,6 +809,25 @@
     zip_file_name
   end
 
+  def run_checklist!(slug)
+
+    checklist = checklists.find_by_slug(slug)
+
+    entry = Conf.research_object_checklists[slug]
+
+    if checklist.nil?
+      checklist = checklists.create(
+          :slug => slug,
+          :label => entry["label"],
+          :minim_url => entry["minim"],
+          :purpose => entry["purpose"])
+    end
+
+    checklist.run_checklist!
+
+    checklist
+  end
+
 private
 
   def create_manifest #:nodoc:

Added: branches/packs/app/views/checklists/_breadcrumbs.html.erb (0 => 3724)


--- branches/packs/app/views/checklists/_breadcrumbs.html.erb	                        (rev 0)
+++ branches/packs/app/views/checklists/_breadcrumbs.html.erb	2013-09-26 11:54:21 UTC (rev 3724)
@@ -0,0 +1,12 @@
+<% if @context %>
+  <li><%= link_to visible_name(@context).pluralize, polymorphic_url(@context.class.name.underscore.pluralize) %></li>
+  <li><%= link_to h(@context.label), @context %></li>
+  <% if false %>
+    <li><%= link_to("Checklists", polymorphic_path(address@hidden, :checklists])) -%></li>
+  <% end %>
+  <li>Checklists</li>
+<% end %>
+
+<% case controller.action_name.to_s; when "show" %>
+  <li><%=h @checklist.label -%></li>
+<% end %>

Copied: branches/packs/app/views/checklists/_checklist_box.html.erb (from rev 3723, branches/packs/app/views/packs/_checklist.html.erb) (0 => 3724)


--- branches/packs/app/views/checklists/_checklist_box.html.erb	                        (rev 0)
+++ branches/packs/app/views/checklists/_checklist_box.html.erb	2013-09-26 11:54:21 UTC (rev 3724)
@@ -0,0 +1,34 @@
+<div class="contribution_section_box">
+	<p class="heading">
+		<%= info_icon_with_tooltip("These are the results from checklists that measure the progress of this pack") %>
+		Progress
+  </p>
+
+  <% Conf.research_object_checklists.each do |slug, checklist| %>
+    <% clr = context.research_object.checklists.find_by_slug(slug) %>
+    <% if clr %>
+      <% score_percent = 100 * clr.score / clr.max_score %>
+      <div class="checklist">
+        <div class="label">
+          <%= link_to(h(checklist["label"]), polymorphic_path([context, clr])) -%>
+        </div>
+        <div class="bar">
+          <div class="score" style="width: <%= score_percent -%>%">
+          </div>
+        </div>
+      </div>
+    <% end %>
+
+
+  <% end %>
+
+  <% if Authorization.check('view', context, current_user) %>
+    <p>
+      <% form_tag(update_checklist_pack_path(context), :method => :post) do -%>
+        <%= select_tag("checklist", options_for_select(Conf.research_object_checklists.keys.map { |x| [Conf.research_object_checklists[x]["label"], x] } )) -%>
+        <%= submit_tag("Run") -%>
+      <% end %>
+    </p>
+  <% end %>
+
+</div>

Copied: branches/packs/app/views/checklists/show.html.erb (from rev 3723, branches/packs/app/views/research_objects/checklist.html.erb) (0 => 3724)


--- branches/packs/app/views/checklists/show.html.erb	                        (rev 0)
+++ branches/packs/app/views/checklists/show.html.erb	2013-09-26 11:54:21 UTC (rev 3724)
@@ -0,0 +1,18 @@
+<h1>Checklist result: <%=h @checklist.label -%></h1>
+
+<table class="checklist simple">
+  <% @checklist.checklist_items.each do |item| %>
+    <tr>
+      <td class="<%= item.colour -%>">
+        <% case item.colour; when "red" %>
+          <%= image_tag('famfamfam_silk/cross.png') -%>
+        <% when "amber" %>
+          <%= image_tag('amber_cross.png') -%>
+        <% when "green" %>
+          <%= image_tag('famfamfam_silk/tick.png') -%>
+        <% end %>
+      </td>
+      <td><%=h item.text -%></td>
+    </tr>
+  <% end %>
+</table>

Added: branches/packs/app/views/errors/422.html.erb (0 => 3724)


--- branches/packs/app/views/errors/422.html.erb	                        (rev 0)
+++ branches/packs/app/views/errors/422.html.erb	2013-09-26 11:54:21 UTC (rev 3724)
@@ -0,0 +1,8 @@
+<div class="error">
+  <h1>422 - Unprocessable Entity</h1>
+  <% if @message %>
+    <%= @message %>
+  <% else %>
+    The request was well-formed but was unable to be followed due to semantic errors.
+  <% end %>
+</div>

Deleted: branches/packs/app/views/packs/_checklist.html.erb (3723 => 3724)


--- branches/packs/app/views/packs/_checklist.html.erb	2013-09-26 08:27:16 UTC (rev 3723)
+++ branches/packs/app/views/packs/_checklist.html.erb	2013-09-26 11:54:21 UTC (rev 3724)
@@ -1,34 +0,0 @@
-<div class="contribution_section_box">
-	<p class="heading">
-		<%= info_icon_with_tooltip("These are the results from checklists that measure the progress of this pack") %>
-		Progress
-  </p>
-
-  <% Conf.research_object_checklists.each do |label, checklist| %>
-    <% clr = @pack.research_object.checklist_results.find(:first, :conditions => { :minim_url => checklist["minim"], :purpose => checklist["purpose"] } ) %>
-    <% if clr %>
-      <% score_percent = 100 * clr.score / clr.max_score %>
-      <div class="checklist">
-        <div class="label">
-          <%=h label -%>
-        </div>
-        <div class="bar">
-          <div class="score" style="width: <%= score_percent -%>%">
-          </div>
-        </div>
-      </div>
-    <% end %>
-
-
-  <% end %>
-
-  <% if Authorization.check('view', @pack, current_user) %>
-    <p>
-      <% form_tag(update_checklist_pack_path(@pack), :method => :post) do -%>
-        <%= select_tag("minim", options_for_select(Conf.research_object_checklists.keys )) -%>
-        <%= submit_tag("Run") -%>
-      <% end %>
-    </p>
-  <% end %>
-
-</div>

Modified: branches/packs/app/views/packs/show.rhtml (3723 => 3724)


--- branches/packs/app/views/packs/show.rhtml	2013-09-26 08:27:16 UTC (rev 3723)
+++ branches/packs/app/views/packs/show.rhtml	2013-09-26 11:54:21 UTC (rev 3724)
@@ -187,7 +187,7 @@
 		</p>
 	</div>
 
-  <%= render :partial => "checklist", :locals => { :contributable => @pack } %>
+  <%= render :partial => "checklists/checklist_box", :locals => { :context => @pack } %>
 
   <%= render :partial => "contributions/license_box", :locals => { :contributable => @pack } %>
 

Deleted: branches/packs/app/views/research_objects/checklist.html.erb (3723 => 3724)


--- branches/packs/app/views/research_objects/checklist.html.erb	2013-09-26 08:27:16 UTC (rev 3723)
+++ branches/packs/app/views/research_objects/checklist.html.erb	2013-09-26 11:54:21 UTC (rev 3724)
@@ -1,24 +0,0 @@
-
-<h1>Checklist result for: <%=h @context.label -%></h1>
-
-<table class="checklist simple">
-  <% @results[:sub_results].each do |sub_result| %>
-    <tr>
-      <td class="<%= sub_result[:colour] -%>">
-        <% case sub_result[:colour]; when :red %>
-          <%= image_tag('famfamfam_silk/cross.png') -%>
-        <% when :amber %>
-          <%= image_tag('amber_cross.png') -%>
-        <% when :green %>
-          <%= image_tag('famfamfam_silk/tick.png') -%>
-        <% end %>
-      </td>
-      <td><%=h sub_result[:text] -%></td>
-    </tr>
-  <% end %>
-</table>
-
-<% if false %>
-  <h2>Debug</h2>
-<pre><%=h @results.to_yaml -%></pre>
-<% end %>

Modified: branches/packs/config/default_settings.yml (3723 => 3724)


--- branches/packs/config/default_settings.yml	2013-09-26 08:27:16 UTC (rev 3723)
+++ branches/packs/config/default_settings.yml	2013-09-26 11:54:21 UTC (rev 3724)
@@ -2089,15 +2089,17 @@
 
 research_object_checklists:
 
-  Workflow:
+  "workflow":
 
+    label:   "Workflow"
     service: "http://sandbox.wf4ever-project.org/roevaluate/evaluate/trafficlight_html"
     minim:   "http://wf4ever.github.io/ro-catalogue/v0.1/Timbus-demo-test/Timbus-demo-minim.rdf"
-    purpose: complete
+    purpose: "complete"
 
-  Workflow and Services:
+  "workflow-and-services":
 
+    label:   "Workflow and Services"
     service: "http://sandbox.wf4ever-project.org/roevaluate/evaluate/trafficlight_html"
     minim:   "http://wf4ever.github.io/ro-catalogue/v0.1/Timbus-demo-test/Timbus-demo-minim.rdf"
-    purpose: complete
+    purpose: "complete"
 

Modified: branches/packs/config/routes.rb (3723 => 3724)


--- branches/packs/config/routes.rb	2013-09-26 08:27:16 UTC (rev 3723)
+++ branches/packs/config/routes.rb	2013-09-26 11:54:21 UTC (rev 3724)
@@ -70,6 +70,7 @@
     pack.resources :relationships, :collection => { :edit_relationships => :get }
     pack.resources :annotations
     pack.resources :items, :requirements => { :id => /[^;]+/ }
+    pack.resources :checklists
   end
 
   # workflows (downloadable)

Modified: branches/packs/db/migrate/20130924164435_add_checklist_tables.rb (3723 => 3724)


--- branches/packs/db/migrate/20130924164435_add_checklist_tables.rb	2013-09-26 08:27:16 UTC (rev 3723)
+++ branches/packs/db/migrate/20130924164435_add_checklist_tables.rb	2013-09-26 11:54:21 UTC (rev 3724)
@@ -5,8 +5,10 @@
 
 class AddChecklistTables < ActiveRecord::Migration
   def self.up
-    create_table "checklist_results", :force => true do |t|
+    create_table "checklists", :force => true do |t|
       t.integer "research_object_id"
+      t.string  "slug"
+      t.string  "label"
       t.integer "score"
       t.integer "max_score"
       t.string  "minim_url"
@@ -15,15 +17,15 @@
       t.timestamps
     end
 
-    create_table "checklist_item_results", :force => true do |t|
-      t.integer "checklist_result_id"
+    create_table "checklist_items", :force => true do |t|
+      t.integer "checklist_id"
       t.string  "colour"
       t.string  "text"
     end
   end
 
   def self.down
-    drop_table :checklist_item_results
-    drop_table :checklist_results
+    drop_table :checklist_items
+    drop_table :checklists
   end
 end

Modified: branches/packs/db/schema.rb (3723 => 3724)


--- branches/packs/db/schema.rb	2013-09-26 08:27:16 UTC (rev 3723)
+++ branches/packs/db/schema.rb	2013-09-26 11:54:21 UTC (rev 3724)
@@ -105,14 +105,16 @@
 
   add_index "bookmarks", ["user_id"], :name => "index_bookmarks_on_user_id"
 
-  create_table "checklist_item_results", :force => true do |t|
-    t.integer "checklist_result_id"
+  create_table "checklist_items", :force => true do |t|
+    t.integer "checklist_id"
     t.string  "colour"
     t.string  "text"
   end
 
-  create_table "checklist_results", :force => true do |t|
+  create_table "checklists", :force => true do |t|
     t.integer  "research_object_id"
+    t.string   "slug"
+    t.string   "label"
     t.integer  "score"
     t.integer  "max_score"
     t.string   "minim_url"
@@ -655,9 +657,9 @@
     t.datetime "created_at"
     t.datetime "updated_at"
     t.string   "uuid",               :limit => 36
+    t.text     "title"
+    t.string   "context_type"
     t.integer  "context_id"
-    t.string   "context_type"
-    t.text     "title"
   end
 
   create_table "reviews", :force => true do |t|

reply via email to

[Prev in Thread] Current Thread [Next in Thread]