Diff
Added: branches/apace/app/controllers/algorithms_controller.rb (0 => 2129)
--- branches/apace/app/controllers/algorithms_controller.rb (rev 0)
+++ branches/apace/app/controllers/algorithms_controller.rb 2009-03-18 14:29:21 UTC (rev 2129)
@@ -0,0 +1,340 @@
+# myExperiment: app/controllers/blobs_controller.rb
+#
+# Copyright (c) 2007 University of Manchester and the University of Southampton.
+# See license.txt for details.
+
+class AlgorithmsController < ApplicationController
+ before_filter :login_required, :except => [:index, :show, :statistics, :search, :all]
+ before_filter :find_algorithms, : [:all]
+ before_filter :find_algorithm_aux, :except => [:search, :index, :new, :create, :all]
+ before_filter :create_empty_object, : [:new, :create]
+ before_filter :set_sharing_mode_variables, : [:show, :new, :create, :edit, :update]
+ before_filter :check_can_edit, : [:edit, :update]
+
+ # declare sweepers and which actions should invoke them
+ cache_sweeper :blob_sweeper, : [ :create, :update, :destroy ]
+ cache_sweeper :permission_sweeper, : [ :create, :update, :destroy ]
+ cache_sweeper :bookmark_sweeper, : [ :destroy, :favourite, :favourite_delete ]
+ cache_sweeper :tag_sweeper, : [ :create, :update, :tag, :destroy ]
+ cache_sweeper :download_viewing_sweeper, : [ :show, :download, :named_download ]
+ cache_sweeper :comment_sweeper, : [ :comment, :comment_delete ]
+ cache_sweeper :rating_sweeper, : [ :rate ]
+
+ # GET /algorithms;search
+ def search
+ @query = params[:query] || ''
+ @query.strip!
+
+ @algorithms = (SOLR_ENABLE && address@hidden) ? Algorithm.find_by_solr(@query, :limit => 100).results : []
+ @algorithms_found_total_count = (SOLR_ENABLE && address@hidden) ? Algorithm.count_by_solr(@query) : 0
+
+ respond_to do |format|
+ format.html # search.rhtml
+ end
+ end
+
+ # GET /files/1;download
+ def download
+ if allow_statistics_logging(@blob)
+ @download = Download.create(:contribution => @blob.contribution, :user => (logged_in? ? current_user : nil), :user_agent => request.env['HTTP_USER_AGENT'], :accessed_from_site => accessed_from_website?())
+ end
+
+ send_data(@blob.content_blob.data, :filename => @blob.local_name, :type => @blob.content_type)
+
+ #send_file("#{RAILS_ROOT}/#{controller_name}/address@hidden/address@hidden/address@hidden", :filename => @blob.local_name, :type => @blob.content_type)
+ end
+
+ # GET /files/:id/download/:name
+ def named_download
+
+ # check that we got the right filename for this workflow
+ if params[:name] == @blob.local_name
+ download
+ else
+ render :nothing => true, :status => "404 Not Found"
+ end
+ end
+
+ # GET /files
+ def index
+ respond_to do |format|
+ format.html # index.rhtml
+ end
+ end
+
+ # GET /files/all
+ def all
+ respond_to do |format|
+ format.html # all.rhtml
+ end
+ end
+
+ # GET /algorithms/1
+ def show
+ if allow_statistics_logging(@algorithm)
+ @viewing = Viewing.create(:contribution => @algorithm.contribution, :user => (logged_in? ? current_user : nil), :user_agent => request.env['HTTP_USER_AGENT'], :accessed_from_site => accessed_from_website?())
+ end
+ end
+
+ # GET /algorithms/new
+ def new
+ end
+
+ # GET /algorithms/1;edit
+ def edit
+ end
+
+ # POST /algorithms
+ def create
+
+ @algorithm = Algorithm.new(
+ :contributor => current_user,
+ :title => params[:algorithm][:title],
+ :description => params[:algorithm][:description],
+ :license => params[:algorithm][:license])
+
+ if @algorithm.save == false
+ render :action ="" "new"
+ return
+ end
+
+ if params[:algorithm][:tag_list]
+ @algorithm.tags_user_id = current_user
+ @algorithm.tag_list = convert_tags_to_gem_format params[:algorithm][:tag_list]
+ @algorithm.update_tags
+ end
+
+ # update policy
+ @algorithm.contribution.update_attributes(params[:contribution])
+
+ policy_err_msg = update_policy(@algorithm, params)
+
+ update_credits(@algorithm, params)
+ update_attributions(@algorithm, params)
+
+ if policy_err_msg.blank?
+ flash[:notice] = 'Algorithm was successfully created.'
+ redirect_to algorithm_url(@algorithm)
+ else
+ flash[:notice] = "Algorithm was successfully created. However some problems occurred, please see these below.</br></br><span style='color: red;'>" + policy_err_msg + "</span>"
+ redirect_to :controller => 'algorithms', :id => @algorithm, :action ="" "edit"
+ end
+ end
+
+ # PUT /algorithms/1
+ def update
+ # hack for select contributor form
+ if params[:contributor_pair]
+ params[:contribution][:contributor_type], params[:contribution][:contributor_id] = params[:contributor_pair][:class_id].split("-")
+ params.delete("contributor_pair")
+ end
+
+ # remove protected columns
+ if params[:algorithm]
+ [:contributor_id, :contributor_type, :content_type, :local_name, :created_at, :updated_at].each do |column_name|
+ params[:algorithm].delete(column_name)
+ end
+ end
+
+ respond_to do |format|
+ if @algorithm.update_attributes(params[:algorithm])
+ @algorithm.refresh_tags(convert_tags_to_gem_format(params[:algorithm][:tag_list]), current_user) if params[:algorithm][:tag_list]
+
+ policy_err_msg = update_policy(@algorithm, params)
+ update_credits(@algorithm, params)
+ update_attributions(@algorithm, params)
+
+ if policy_err_msg.blank?
+ flash[:notice] = 'Algorithm was successfully updated.'
+ format.html { redirect_to algorithm_url(@algorithm) }
+ else
+ flash[:error] = policy_err_msg
+ format.html { redirect_to :controller => 'algorithms', :id => @algorithm, :action ="" "edit" }
+ end
+ else
+ format.html { render :action ="" "edit" }
+ end
+ end
+ end
+
+ # DELETE /files/1
+ def destroy
+ success = @blob.destroy
+
+ respond_to do |format|
+ if success
+ flash[:notice] = "File has been deleted."
+ format.html { redirect_to files_url }
+ else
+ flash[:error] = "Failed to delete File. Please contact your administrator."
+ format.html { redirect_to file_url(@blob) }
+ end
+ end
+ end
+
+ # POST /files/1;comment
+ def comment
+ text = params[:comment][:comment]
+
+ if text and text.length > 0
+ comment = Comment.create(:user => current_user, :comment => text)
+ @blob.comments << comment
+ end
+
+ respond_to do |format|
+ format.html { render :partial => "comments/comments", :locals => { :commentable => @blob } }
+ end
+ end
+
+ # DELETE /files/1;comment_delete
+ def comment_delete
+ if params[:comment_id]
+ comment = Comment.find(params[:comment_id].to_i)
+ # security checks:
+ if comment.user_id == current_user.id and comment.commentable_type.downcase == 'blob' and comment.commentable_id == @blob.id
+ comment.destroy
+ end
+ end
+
+ respond_to do |format|
+ format.html { render :partial => "comments/comments", :locals => { :commentable => @blob } }
+ end
+ end
+
+ # POST /files/1;rate
+ def rate
+ if @blob.contributor_type == 'User' and @blob.contributor_id == current_user.id
+ error("You cannot rate your own file!", "")
+ else
+ Rating.delete_all(["rateable_type = ? AND rateable_id = ? AND user_id = ?", @blob.class.to_s, @blob.id, current_user.id])
+
+ @blob.ratings << Rating.create(:user => current_user, :rating => params[:rating])
+
+ respond_to do |format|
+ format.html {
+ render :update do |page|
+ page.replace_html "ratings_inner", :partial => "contributions/ratings_box_inner", :locals => { :contributable => @blob, :controller_name => controller.controller_name }
+ page.replace_html "ratings_breakdown", :partial => "contributions/ratings_box_breakdown", :locals => { :contributable => @blob }
+ end }
+ end
+ end
+ end
+
+ # POST /files/1;tag
+ def tag
+ @blob.tags_user_id = current_user # acts_as_taggable_redux
+ @blob.tag_list = "address@hidden, #{convert_tags_to_gem_format params[:tag_list]}" if params[:tag_list]
+ @blob.update_tags # hack to get around acts_as_versioned
+
+ respond_to do |format|
+ format.html {
+ render :update do |page|
+ unique_tag_count = @blob.tags.uniq.length
+ page.replace_html "mini_nav_tag_link", "(#{unique_tag_count})"
+ page.replace_html "tags_box_header_tag_count_span", "(#{unique_tag_count})"
+ page.replace_html "tags_inner_box", :partial => "tags/tags_box_inner", :locals => { :taggable => @blob, :owner_id => @blob.contributor_id }
+ end
+ }
+ end
+ end
+
+ # POST /files/1;favourite
+ def favourite
+ @blob.bookmarks << Bookmark.create(:user => current_user) unless @blob.bookmarked_by_user?(current_user)
+
+ respond_to do |format|
+ flash[:notice] = "You have successfully added this item to your favourites."
+ format.html { redirect_to file_url(@blob) }
+ end
+ end
+
+ # DELETE /files/1;favourite_delete
+ def favourite_delete
+ @blob.bookmarks.each do |b|
+ if b.user_id == current_user.id
+ b.destroy
+ end
+ end
+
+ respond_to do |format|
+ flash[:notice] = "You have successfully removed this item from your favourites."
+ redirect_url = params[:return_to] ? params[:return_to] : file_url(@blob)
+ format.html { redirect_to redirect_url }
+ end
+ end
+
+ protected
+
+ def find_algorithms
+ found = Blob.find(:all,
+ :order => "content_type ASC, local_name ASC, created_at DESC",
+ :page => { :size => 20,
+ :current => params[:page] })
+
+ found.each do |blob|
+ blob.content_blob.data = "" unless Authorization.is_authorized?("download", nil, blob, current_user)
+ end
+
+ @blobs = found
+ end
+
+ def find_algorithm_aux
+ begin
+ algorithm = Algorithm.find(params[:id])
+
+ if Authorization.is_authorized?(action_name, nil, algorithm, current_user)
+ @algorithm = algorithm
+
+ @algorithm_entry_url = url_for : false,
+ :host => base_host,
+ :id => @algorithm.id
+
+ else
+ if logged_in?
+ error("Algorithm not found (id not authorized)", "is invalid (not authorized)")
+ return false
+ else
+ find_algorithm_aux if login_required
+ end
+ end
+ rescue ActiveRecord::RecordNotFound
+ error("Algorithm not found", "is invalid")
+ return false
+ end
+ end
+
+ def create_empty_object
+ @algorithm = Algorithm.new
+ end
+
+ def set_sharing_mode_variables
+ case action_name
+ when "new"
+ @sharing_mode = 0
+ @updating_mode = 6
+ when "create", "update"
+ @sharing_mode = params[:sharing][:class_id].to_i if params[:sharing]
+ @updating_mode = params[:updating][:class_id].to_i if params[:updating]
+ when "show", "edit"
+ @sharing_mode = @algorithm.contribution.policy.share_mode
+ @updating_mode = @algorithm.contribution.policy.update_mode
+ end
+ end
+
+ def check_can_edit
+ if @algorithm && !Authorization.is_authorized?('edit', nil, @algorithm, current_user)
+ error("You are not authorised to manage this Algorithm", "")
+ end
+ end
+
+ private
+
+ def error(notice, message, attr=:id)
+ flash[:error] = notice
+ (err = Algorithm.new.errors).add(attr, message)
+
+ respond_to do |format|
+ format.html { redirect_to algorithms_url }
+ end
+ end
+end
Added: branches/apace/app/models/algorithm.rb (0 => 2129)
--- branches/apace/app/models/algorithm.rb (rev 0)
+++ branches/apace/app/models/algorithm.rb 2009-03-18 14:29:21 UTC (rev 2129)
@@ -0,0 +1,33 @@
+# myExperiment: app/models/algorithm.rb
+
+# Copyright (c) 2009 University of Manchester and the University of Southampton.
+# See license.txt for details.
+
+require 'acts_as_contributable'
+require 'acts_as_creditable'
+require 'acts_as_attributor'
+require 'acts_as_attributable'
+
+class Algorithm < ActiveRecord::Base
+ acts_as_contributable
+
+ acts_as_bookmarkable
+ acts_as_commentable
+ acts_as_rateable
+ acts_as_taggable
+
+ acts_as_creditable
+
+ acts_as_attributor
+ acts_as_attributable
+
+ has_many :algorithm_instances
+ has_many :apps, :through => :algorithm_instances
+
+ acts_as_solr(:fields => [:title, :description]) if SOLR_ENABLE
+
+ validates_presence_of :title
+ validates_inclusion_of :license, :in => ["by-nd", "by-sa", "by"]
+
+ format_attribute :description
+end
Added: branches/apace/app/models/algorithm_instance.rb (0 => 2129)
--- branches/apace/app/models/algorithm_instance.rb (rev 0)
+++ branches/apace/app/models/algorithm_instance.rb 2009-03-18 14:29:21 UTC (rev 2129)
@@ -0,0 +1,10 @@
+# myExperiment: app/models/algorithm_instance.rb
+#
+# Copyright (c) 2009 University of Manchester and the University of Southampton.
+# See license.txt for details.
+
+class AlgorithmInstance < ActiveRecord::Base
+ belongs_to :algorithm
+ belongs_to :app
+end
+
Added: branches/apace/app/models/app.rb (0 => 2129)
--- branches/apace/app/models/app.rb (rev 0)
+++ branches/apace/app/models/app.rb 2009-03-18 14:29:21 UTC (rev 2129)
@@ -0,0 +1,32 @@
+# myExperiment: app/models/app.rb
+#
+# Copyright (c) 2009 University of Manchester and the University of Southampton.
+# See license.txt for details.
+
+require 'acts_as_contributable'
+require 'acts_as_creditable'
+require 'acts_as_attributor'
+require 'acts_as_attributable'
+
+class App < ActiveRecord::Base
+ acts_as_contributable
+
+ acts_as_bookmarkable
+ acts_as_commentable
+ acts_as_rateable
+ acts_as_taggable
+
+ acts_as_creditable
+
+ acts_as_attributor
+ acts_as_attributable
+
+ has_many :algorithm_instances
+ has_many :algorithms, :through => :algorithm_instances
+
+ acts_as_solr(:fields => [:title, :description]) if SOLR_ENABLE
+
+ validates_inclusion_of :license, :in => [ "by-nd", "by-sa", "by" ]
+
+ format_attribute :description
+end
Added: branches/apace/app/views/algorithms/_all_tags.rhtml (0 => 2129)
--- branches/apace/app/views/algorithms/_all_tags.rhtml (rev 0)
+++ branches/apace/app/views/algorithms/_all_tags.rhtml 2009-03-18 14:29:21 UTC (rev 2129)
@@ -0,0 +1,6 @@
+<% unless (tags = tags_for_type("Algorithm", 50)).empty? %>
+ <h2>Top <%= tags.length %> tags for Algorithms   <small>[<%= link_to "See All Tags", tags_path %>]</small></h2>
+ <%= tag_cloud_from_collection(tags, false, "algorithms") %>
+ <br/>
+ <br/>
+ <% end %>
Added: branches/apace/app/views/algorithms/_blob.rhtml (0 => 2129)
--- branches/apace/app/views/algorithms/_blob.rhtml (rev 0)
+++ branches/apace/app/views/algorithms/_blob.rhtml 2009-03-18 14:29:21 UTC (rev 2129)
@@ -0,0 +1,33 @@
+<center>
+ <table width="320" class="contributable">
+ <tr>
+ <td>
+ <p>
+ <strong>File name:</strong><br/>
+ <%=h algorithm.local_name %>
+ </p>
+
+ <p>
+ <strong>File type:</strong><br />
+ <%=h algorithm.content_type %>
+ </p>
+
+ <p>
+ <strong>Downloaded:</strong> <%=pluralize algorithm.contribution.downloads_count, "time" %>
+ </p>
+ </td>
+ <td>
+ <strong>Uploader:</strong><br/>
+ <%= contributor(algorithm.contribution.contributor_id, algorithm.contribution.contributor_type, true, 60) %>
+ </td>
+ </tr>
+ <tr>
+ <td colspan="2">
+ <% if Authorization.is_authorized?('download', nil, algorithm, current_user) %><%= icon "download", download_file_path(algorithm) %> <% end %>
+ <% if Authorization.is_authorized?('show', nil, algorithm, current_user) %><%= icon "show", file_path(algorithm), nil, nil, "View" %> <% end %>
+ <% if logged_in? and Authorization.is_authorized?('edit', nil, algorithm, current_user) %><%= icon "edit", edit_file_path(algorithm) %> <% end %>
+ <% if logged_in? and algorithm.owner?(current_user) %><%= icon "destroy", file_path(algorithm), nil, :confirm => 'Are you sure?', :method => :delete %><% end %>
+ </td>
+ </tr>
+ </table>
+</center>
Added: branches/apace/app/views/algorithms/_breadcrumbs.rhtml (0 => 2129)
--- branches/apace/app/views/algorithms/_breadcrumbs.rhtml (rev 0)
+++ branches/apace/app/views/algorithms/_breadcrumbs.rhtml 2009-03-18 14:29:21 UTC (rev 2129)
@@ -0,0 +1,21 @@
+<li><%= link_to 'Algorithms', algorithms_path -%></li>
+
+<% if ["show", "new", "edit", "all", "search"].include? controller.action_name.to_s -%>
+ <li><b>»</b></li>
+
+ <% case controller.action_name.to_s; when "show" -%>
+ <li><%= contributable_name(@algorithm.id, 'Algorithm') -%></li>
+ <% when "new" %>
+ <li>New Algorithm</li>
+ <% when "edit" %>
+ <li><%= link_to "#{contributable_name(@algorithm.id, 'Algorithm')}", algorithm_path(@algorithm) -%></li>
+ <li><b>»</b></li>
+ <li>Manage</li>
+ <% when "all" %>
+ <li>All Algorithms</li>
+ <% when "search" %>
+ <li>Search Results</li>
+ <% else %>
+ <!-- no breadcrumb -->
+ <% end %>
+<% end %>
Added: branches/apace/app/views/algorithms/_license.rhtml (0 => 2129)
--- branches/apace/app/views/algorithms/_license.rhtml (rev 0)
+++ branches/apace/app/views/algorithms/_license.rhtml 2009-03-18 14:29:21 UTC (rev 2129)
@@ -0,0 +1,108 @@
+<% case (algorithm.license.to_s); when "by-nd" %>
+
+<!--
+
+<rdf:RDF xmlns="http://web.resource.org/cc/"
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
+<Work rdf:about="">
+ <dc:title><%= algorithm.title %></dc:title>
+ <dc:date><%= algorithm.created_at %></dc:date>
+ <dc:description><%= algorithm.description_html %></dc:description>
+ <dc:creator><Agent>
+ <dc:title><%= contributor(algorithm.contribution.contributor_id, algorithm.contribution.contributor_type, link=false) %></dc:title>
+ </Agent></dc:creator>
+ <dc:rights><Agent>
+ <dc:title><%= contributor(algorithm.contribution.contributor_id, algorithm.contribution.contributor_type, link=false) %></dc:title>
+ </Agent></dc:rights>
+ <dc:type rdf:resource="http://purl.org/dc/dcmitype/Data" />
+ <dc:source rdf:resource="http://www.myexperiment.org<%= request.request_uri %>"/>
+ <license rdf:resource="http://creativecommons.org/licenses/by-nd/3.0/" />
+</Work>
+
+<License rdf:about="http://creativecommons.org/licenses/by-nd/3.0/">
+ <permits rdf:resource="http://web.resource.org/cc/Reproduction" />
+ <permits rdf:resource="http://web.resource.org/cc/Distribution" />
+ <requires rdf:resource="http://web.resource.org/cc/Notice" />
+ <requires rdf:resource="http://web.resource.org/cc/Attribution" />
+ <prohibits rdf:resource="http://web.resource.org/cc/DerivativeWorks" />
+</License>
+
+</rdf:RDF>
+
+-->
+
+<% when "by-sa" %>
+
+<!--
+
+<rdf:RDF xmlns="http://web.resource.org/cc/"
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
+<Work rdf:about="">
+ <dc:title><%= algorithm.title %></dc:title>
+ <dc:date><%= algorithm.created_at %></dc:date>
+ <dc:description><%= algorithm.description_html %></dc:description>
+ <dc:creator><Agent>
+ <dc:title><%= contributor(algorithm.contribution.contributor_id, algorithm.contribution.contributor_type, link=false) %></dc:title>
+ </Agent></dc:creator>
+ <dc:rights><Agent>
+ <dc:title><%= contributor(algorithm.contribution.contributor_id, algorithm.contribution.contributor_type, link=false) %></dc:title>
+ </Agent></dc:rights>
+ <dc:type rdf:resource="http://purl.org/dc/dcmitype/Data" />
+ <dc:source rdf:resource="http://www.myexperiment.org<%= request.request_uri %>"/>
+ <license rdf:resource="http://creativecommons.org/licenses/by-sa/3.0/" />
+</Work>
+
+<License rdf:about="http://creativecommons.org/licenses/by-sa/3.0/">
+ <permits rdf:resource="http://web.resource.org/cc/Reproduction" />
+ <permits rdf:resource="http://web.resource.org/cc/Distribution" />
+ <requires rdf:resource="http://web.resource.org/cc/Notice" />
+ <requires rdf:resource="http://web.resource.org/cc/Attribution" />
+ <permits rdf:resource="http://web.resource.org/cc/DerivativeWorks" />
+ <requires rdf:resource="http://web.resource.org/cc/ShareAlike" />
+</License>
+
+</rdf:RDF>
+
+-->
+
+<% when "by" %>
+
+<!--
+
+<rdf:RDF xmlns="http://web.resource.org/cc/"
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
+<Work rdf:about="">
+ <dc:title><%= algorithm.title %></dc:title>
+ <dc:date><%= algorithm.created_at %></dc:date>
+ <dc:description><%= algorithm.description_html %></dc:description>
+ <dc:creator><Agent>
+ <dc:title><%= contributor(algorithm.contribution.contributor_id, algorithm.contribution.contributor_type, link=false) %></dc:title>
+ </Agent></dc:creator>
+ <dc:rights><Agent>
+ <dc:title><%= contributor(algorithm.contribution.contributor_id, algorithm.contribution.contributor_type, link=false) %></dc:title>
+ </Agent></dc:rights>
+ <dc:type rdf:resource="http://purl.org/dc/dcmitype/Data" />
+ <dc:source rdf:resource="http://www.myexperiment.org<%= request.request_uri %>"/>
+ <license rdf:resource="http://creativecommons.org/licenses/by/3.0/" />
+</Work>
+
+<License rdf:about="http://creativecommons.org/licenses/by/3.0/">
+ <permits rdf:resource="http://web.resource.org/cc/Reproduction" />
+ <permits rdf:resource="http://web.resource.org/cc/Distribution" />
+ <requires rdf:resource="http://web.resource.org/cc/Notice" />
+ <requires rdf:resource="http://web.resource.org/cc/Attribution" />
+ <permits rdf:resource="http://web.resource.org/cc/DerivativeWorks" />
+</License>
+
+</rdf:RDF>
+
+-->
+
+<% end %>
+
+<p>
+ All versions of this File are licensed under the <%= license_link algorithm.license.to_s %>.
+</p>
Added: branches/apace/app/views/algorithms/_license_form.rhtml (0 => 2129)
--- branches/apace/app/views/algorithms/_license_form.rhtml (rev 0)
+++ branches/apace/app/views/algorithms/_license_form.rhtml 2009-03-18 14:29:21 UTC (rev 2129)
@@ -0,0 +1,91 @@
+<% if params[:algorithm] && !params[:algorithm][:license].blank? %>
+ <% license = params[:algorithm][:license] %>
+<% elsif edit %>
+ <% license = @algorithm.license %>
+<% else %>
+ <% license = 'by-sa' %>
+<% end %>
+
+<div class="fold">
+ <div class="foldTitle">
+ <%= info_icon_with_tooltip("This section allows you to specify the <strong>rights</strong> that people have when they download and use this File, by setting the license. <br/><br/>By default, the license specifies that people are allowed to build on this File as long as they give the original author credit and share their resulting work under the same conditions.") %>
+ License/Rights
+ <% if edit %>
+ <hr />
+ <small>Current: <%= license_link(license) %></small>
+ <% else %>
+ <hr />
+ <small>Default: people are allowed to build on this File, but must give author(s) credit and give attribution to this File. They must also share under the same conditions. (<%= license_link license %>)</small>
+ <% end %>
+ </div>
+ <div class="foldContent" style="display: none;">
+ <p class="box_infotext">
+ This section allows you to specify the <strong>rights</strong> that people have when they download and use this File, by setting the license.
+ </p>
+ <br />
+ <p>
+ <strong>What license do you want people to adhere to if they download and use this File?</strong>
+ </p>
+ <div style="padding-left: 1em;">
+ <div style="padding: 0.5em; border: 1px dotted #999999; margin: 1.5em 3em; text-align: center;">
+ <p style="text-align: center;">
+ <img alt="Science Commons" src="" /></p>
+ <p style="text-align: center;">
+ Below you can configure what rights people will have with this File, based on
+ the <a href="" Commons</a>
+ licenses. Sharing Files and letting others build upon them is a useful contribution
+ and is highly recommended.</p>
+ </div>
+ <p>
+ When someone downloads this Files, are they allowed to build upon it (such as
+ extend, reuse, repurpose etc)?
+ </p>
+ <table style="border-collapse: collapse; border-spacing: 0;">
+ <tbody>
+ <tr>
+ <td style="vertical-align: top; text-align: center;">
+ <input id="algorithm_license_bysa" <%= 'checked="checked"' if (license == 'by-sa') %> name="algorithm[license]" type="radio" value="by-sa"/>
+ </td>
+ <td style="vertical-align: top; text-align: left;">
+ <p style="padding: 0; margin: 0;">
+ Yes, as long as they <strong>give the author(s) credit</strong> and <strong>give attribution to this File</strong>.
+ They must also <strong>share</strong> the resulting work <strong>under the same conditions</strong>.
+ <br/>
+ - <%= license_link "by-sa" %>
+ </p>
+ </td>
+ </tr>
+ <tr>
+ <td style="vertical-align: top; text-align: center;">
+ <input id="algorithm_license_by" <%= 'checked="checked"' if (license == 'by') %> name="algorithm[license]" type="radio" value="by"/>
+ </td>
+ <td style="vertical-align: top; text-align: left;">
+ <p style="padding: 0; margin: 0;">
+ Yes, as long as they <strong>give the author(s) credit</strong> and <strong>give attribution to this File</strong>.
+ <br/>
+ - <%= license_link "by" %>
+ </p>
+ </td>
+ </tr>
+ <tr>
+ <td style="vertical-align: top; text-align: center;">
+ <input id="algorithm_license_bynd" <%= 'checked="checked"' if (license == 'by-nd') %> name="algorithm[license]" type="radio" value="by-nd"/>
+ </td>
+ <td style="vertical-align: top; text-align: left;">
+ <p style="padding: 0; margin: 0;">
+ No. They may only use the File for reference.
+ <br/>
+ - <%= license_link "by-nd" %>
+ </p>
+ </td>
+ </tr>
+ </tbody>
+ </table>
+ <small>Nothing in these licenses impairs or restricts the author's moral rights.</small></p>
+ </div>
+ </div>
+</div>
+
+
+
+
Added: branches/apace/app/views/algorithms/_table.rhtml (0 => 2129)
--- branches/apace/app/views/algorithms/_table.rhtml (rev 0)
+++ branches/apace/app/views/algorithms/_table.rhtml 2009-03-18 14:29:21 UTC (rev 2129)
@@ -0,0 +1,98 @@
+<% query ||= false -%>
+<% odd_row = false -%>
+<% unless collection.empty? %>
+
+<table class="alt_table">
+ <% for algorithm in collection %>
+ <% # If only one item in collection, check if 'show' permission is available (eg: if this partial was called from contributions/table) -%>
+ <% if collection.size == 1 -%>
+ <% show ||= Authorization.is_authorized?('show', nil, algorithm, current_user) -%>
+ <% else -%>
+ <% show = Authorization.is_authorized?('show', nil, algorithm, current_user) -%>
+ <% end -%>
+ <% if show -%>
+ <tr class="<%= (odd_row = !odd_row) ? "odd_row" : "even_row" %>">
+ <% cache(:controller => 'files_cache', :action ="" 'listing', :id => algorithm.id) do -%>
+ <td style="width: 100px;">
+ <p style="margin-top:0; padding-top:0; text-align: center;"><b>Uploader:</b></p>
+ <center><%= contributor(algorithm.contribution.contributor_id, algorithm.contribution.contributor_type, true, 60) %></center>
+ </td>
+ <td style="text-align: left;">
+ <p class="title">
+ <%= icon "algorithm", nil, nil, nil, '' %>
+ <% title = contributable_name(algorithm.id, 'Blob') %>
+ <%=link_to(query ? highlight_all(title, query) : title, algorithm_path(algorithm)) %>
+ </p>
+
+ <p style="font-size: 85%; margin-top: 0; padding-top: 0;">
+ <b>Created:</b> <%=datetime algorithm.contribution.created_at, false %>
+ <% unless algorithm.contribution.created_at == algorithm.contribution.updated_at %>
+ | <b>Last updated:</b> <%=datetime algorithm.contribution.updated_at, false %>
+ <% end %>
+ </p>
+
+ <% unless (creditors = algorithm.creditors).empty? %>
+ <p style="font-size:85%;">
+ <b>Credits:</b>
+ <% creditors.each do |c| %>
+ <% if c.creditor_type == 'User' %>
+ <%= icon('user', nil, nil, nil, '') %>
+ <% elsif c.creditor_type == 'Network' %>
+ <%= icon('network-member', nil, nil, nil, '') %>
+ <% end %>
+ <%= contributor(c.creditor_id, c.creditor_type) %>
+ <% end %>
+ </p>
+ <% end %>
+ <% unless (attributors = algorithm.attributors).empty? %>
+ <p style="font-size:85%;">
+ <b>Attributions:</b>
+ <% attributors.each do |a| %>
+ <% if Authorization.is_authorized?("show", nil, a.attributor, current_user) -%>
+ <% if a.attributor_type == 'Workflow' %>
+ <%= icon('workflow', nil, nil, nil, '') %>
+ <% elsif a.attributor_type == 'Blob' %>
+ <%= icon('algorithm', nil, nil, nil, '') %>
+ <% end %>
+ <%= contributable(a.attributor_id, a.attributor_type) %>
+ <% end -%>
+ <% end %>
+ </p>
+ <% end %>
+
+ <p style="font-size:85%;"><b>License: </b><%= license_link algorithm.license.to_s %></p>
+
+ <div class="desc" style="font-size: 85%;">
+ <% if algorithm.description and algorithm.description.length > 0 %>
+ <% desc = truncate(strip_html(algorithm.description), 500) %>
+ <%= query ? highlight_all(desc, query) : desc %>
+ <% else -%>
+ <span class="none_text">No description</span>
+ <% end %>
+ </div>
+
+ <p style="font-size: 85%;">
+ <a href="" algorithm_path(algorithm) + '#ratings' -%>"><b>Rating: </b><%= number_with_precision(algorithm.rating, 1) %> / 5 (<%= pluralize algorithm.ratings_count, 'rating' %>)</a> |
+ <a href="" algorithm_path(algorithm) + '#comments' -%>"><b>Comments: </b><%= algorithm.comments_count %></a> |
+ <b>Viewed internally:</b> <%= pluralize Viewing.total_site_viewings_count_for_contribution(algorithm.contribution.id), "time" %>
+ </p>
+
+ <% unless (tags = algorithm.tags).empty? %>
+ <a href="" algorithm_path(algorithm) + '#tags' -%>"><p style="font-size: 85%;"><b>Tags:</b></p></a>
+ <div style="display:inline;" class="tags_onesize"><%= tag_cloud_from_collection tags, true %></div>
+ <% else %>
+ <p style="font-size: 85%;"><i>This File has no tags!</i></p>
+ <% end %>
+ </td>
+ <% end %>
+
+ <td class="actions" style="width: 80px;">
+ <%= icon "show", algorithm_path(algorithm), nil, nil, "View" %>
+ <% if mine?(algorithm) %><%= icon "manage", edit_file_path(algorithm), nil, nil, "Manage" %><% end %>
+ </td>
+ </tr>
+ <% end %>
+ <% end %>
+</table>
+
+<% end %>
Added: branches/apace/app/views/algorithms/all.rhtml (0 => 2129)
--- branches/apace/app/views/algorithms/all.rhtml (rev 0)
+++ branches/apace/app/views/algorithms/all.rhtml 2009-03-18 14:29:21 UTC (rev 2129)
@@ -0,0 +1,9 @@
+<% t "All" -%>
+
+<h2>All Files</h2>
+
+<%= render :partial => "layouts/paginate", :locals => { :collection => @algorithms } %>
+
+<%= render :partial => "algorithms/table", :locals => { :collection => @algorithms } %>
+
+<%= render :partial => "layouts/paginate", :locals => { :collection => @algorithms } %>
Added: branches/apace/app/views/algorithms/edit.rhtml (0 => 2129)
--- branches/apace/app/views/algorithms/edit.rhtml (rev 0)
+++ branches/apace/app/views/algorithms/edit.rhtml 2009-03-18 14:29:21 UTC (rev 2129)
@@ -0,0 +1,44 @@
+<% t "Manage" -%>
+
+<%= _javascript__include_tag :fckeditor %>
+<%= _javascript__include_tag "osp.js" %>
+
+<h1>Manage Algorithm: <%= contributable_name(@algorithm.id, 'Algorithm') %></h1>
+
+<%= error_messages_for :algorithm %>
+
+<% form_for(:algorithm, :url ="" algorithm_path(@algorithm), :html => { :method => :put }) do |f| %>
+
+ <p style="text-align: center;">
+ <strong>Title: </strong>
+ <br/>
+ <%= f.text_field :title, :size => 60 %>
+ </p>
+
+ <br/>
+
+ <p style="text-align: center;">
+ <strong>Description: </strong>
+ </p>
+ <center>
+ <%= fckeditor_textarea(:algorithm, :description, :toolbarSet => 'Simple', :width => '600px', :height => '300px') %>
+ </center>
+
+ <br/>
+
+ <%= render :partial => "tags/tags_form", :locals => { :edit => true, :taggable => @algorithm } %>
+
+ <%= render :partial => "contributions/credit_attribution_form", :locals => { :edit => true, :contributable => @algorithm } %>
+
+ <% if Authorization.is_authorized?("edit", nil, @algorithm, current_user) %>
+ <%= render :partial => "contributions/sharing_form", :locals => { :edit => true, :contributable => @algorithm, :update_perms => true } %>
+ <%= render :partial => "algorithms/license_form", :locals => { :edit => true } %>
+ <% end %>
+
+ <p>
+ <center>
+ <%= submit_tag "Update",:disable_with => "Updating..." %>
+ or <%= link_to "Cancel", algorithm_path(@algorithm) %>
+ </center>
+ </p>
+<% end %>
Added: branches/apace/app/views/algorithms/index.rhtml (0 => 2129)
--- branches/apace/app/views/algorithms/index.rhtml (rev 0)
+++ branches/apace/app/views/algorithms/index.rhtml 2009-03-18 14:29:21 UTC (rev 2129)
@@ -0,0 +1,10 @@
+<ul class="sectionIcons">
+ <li><%= icon "algorithm", new_algorithm_path, nil, nil, "Register new Algorithm" %></li>
+ <li><%= icon "view-all", all_algorithms_path, nil, nil, "View all Algorithms" %></li>
+</ul>
+
+<% cache(:controller => 'algorithms', :action ="" 'all_tags') do -%>
+ <%= render :partial => "algorithms/all_tags" %>
+<% end -%>
+
+<%= render :partial => "contributions/most_tabs", :locals => { :type => "Algorithm" } %>
Added: branches/apace/app/views/algorithms/new.rhtml (0 => 2129)
--- branches/apace/app/views/algorithms/new.rhtml (rev 0)
+++ branches/apace/app/views/algorithms/new.rhtml 2009-03-18 14:29:21 UTC (rev 2129)
@@ -0,0 +1,47 @@
+<% t "New" -%>
+
+<%= _javascript__include_tag :fckeditor %>
+<%= _javascript__include_tag "osp.js" %>
+
+<h1>New Algorithm</h1>
+
+<%= error_messages_for :algorithm %>
+
+<% form_tag({ :action ="" :create }, :multipart => true) do %>
+
+ <p style="text-align: center;">
+ <strong>Title: </strong>
+ <br/>
+ <%= text_field_tag "algorithm[title]", nil, :size => 60 %>
+ </p>
+
+ <br/>
+
+ <p style="text-align: center;">
+ <strong>Description:</strong>
+ </p>
+
+ <center>
+ <%= fckeditor_textarea(:algorithm, :description, :toolbarSet => 'Simple', :width => '600px', :height => '300px') %>
+ </center>
+
+ <br />
+
+ <%= render :partial => "tags/tags_form", :locals => { :edit => false, :taggable => @algorithm } %>
+
+ <%= render :partial => "contributions/credit_attribution_form", :locals => { :edit => false, :contributable => @algorithm } %>
+
+ <%= render :partial => "contributions/sharing_form", :locals => { :edit => false, :contributable => @algorithm, :update_perms => true } %>
+
+ <%= render :partial => "algorithms/license_form", :locals => { :edit => false } %>
+
+ <%= render :partial => 'contributions/terms_and_conditions' %>
+
+ <br/>
+
+ <p style="text-align: center;">
+ <%= submit_tag "Save", :disable_with => "Saving..." %>
+ </p>
+
+<% end %>
+
Added: branches/apace/app/views/algorithms/search.rhtml (0 => 2129)
--- branches/apace/app/views/algorithms/search.rhtml (rev 0)
+++ branches/apace/app/views/algorithms/search.rhtml 2009-03-18 14:29:21 UTC (rev 2129)
@@ -0,0 +1,12 @@
+<% t "Search" -%>
+
+<h1>Search Results</h1>
+
+<h2>Showing <%= pluralize(@algorithms.length, "file") %> of <%= @algorithms_found_total_count -%> found for <%= @query ? "\"address@hidden"" : "" %></h2>
+
+<%= view_privileges_notice %>
+<br/>
+
+<%= render :partial => "algorithms/table", :locals => { :collection => @algorithms } %>
+
+<br />
Added: branches/apace/app/views/algorithms/show.rhtml (0 => 2129)
--- branches/apace/app/views/algorithms/show.rhtml (rev 0)
+++ branches/apace/app/views/algorithms/show.rhtml 2009-03-18 14:29:21 UTC (rev 2129)
@@ -0,0 +1,145 @@
+<% t "#{contributable_name(@algorithm.id, 'Algorithm')} (#{h @algorithm.contributor_name})" -%>
+
+<ul class="sectionIcons">
+ <% if Authorization.is_authorized?('edit', nil, @algorithm, current_user) -%>
+ <li><%= icon('manage', edit_algorithm_path(@algorithm), nil, nil, 'Manage Algorithm Entry')%></li>
+ <% end -%>
+ <% if Authorization.is_authorized?('destroy', nil, @algorithm, current_user) %>
+ <li><%= icon('destroy', algorithm_path(@algorithm), nil, { :confirm => 'This deletes the Algorithm and all metadata such as tags, comments and ratings. Are you sure?', :method => :delete }, 'Delete Algorithm Entry') %></li>
+ <% end %>
+</ul>
+
+<h1 class="contribution_title">Algorithm Entry: <%= contributable_name(@algorithm.id, 'Algorithm') %></h1>
+
+<%= render :partial => "contributions/datetime_info", :locals => { :contributable => @algorithm } -%>
+
+<div class="contribution_mini_nav">
+ |
+ <%= link_to "License", "#license" %>
+ |
+ <%= link_to "Credits (address@hidden)", "#credits" %>
+ |
+ <%= link_to "Attributions (address@hidden)", "#attributions" %>
+ |
+ <%= link_to "Tags <span id='mini_nav_tag_link'>(address@hidden)</span>", "#tags" %>
+ |
+ <%= link_to "Featured in Packs (#{Pack.packs_with_contributable(@algorithm).length})", "#featured_in_packs" %>
+ |
+ <%= link_to "Ratings (address@hidden)", "#ratings" %>
+ |
+ <%= link_to "Attributed By (address@hidden)", "#attributed_by" %>
+ |
+ <%= link_to "Favourited By (address@hidden)", "#favourited_by" %>
+ |
+ <% if logged_in? and @algorithm.owner?(current_user) %>
+ <br/>
+ |
+ <!-- NB! Index of the 'sharing' tab might change! -->
+ <a href=""
+ |
+ <% end %>
+ <%= link_to "Comments (address@hidden)", "#comments" %>
+ |
+</div>
+
+<div class="contribution_left_box">
+ <div class="contribution_version_box">
+ <div class="contribution_version_inner_box">
+ <p>
+ <b>Title:</b>
+ <span class="title"><%=h @algorithm.title %></span>
+ </p>
+
+ <h3>
+ <%= info_icon_with_tooltip("This section shows the overall description for this Algorithm") %>
+ Description
+ </h3>
+
+ <% unless @algorithm.description.blank? %>
+ <div class="contribution_description">
+ <%= @algorithm.description_html %>
+ </div>
+ <% else %>
+ <p class="none_text">
+ Not set
+ </p>
+ <% end %>
+ </div>
+
+ </div>
+
+</div>
+
+<div class="contribution_right_box">
+ <%= render :partial => "contributions/uploader_box", :locals => { :contributable => @algorithm } %>
+
+ <%= render :partial => "contributions/license_box", :locals => { :contributable => @algorithm } %>
+
+ <%= render :partial => "contributions/credits_attributions_box", :locals => { :contributable => @algorithm, :edit_path => edit_algorithm_path(@algorithm) } %>
+
+ <%= render :partial => "tags/tags_box", :locals => { :taggable => @algorithm,
+ :owner_id => ((@algorithm.contributor_type == 'User') ? @algorithm.contributor_id : nil),
+ :add_path => tag_algorithm_path(@algorithm),
+ :edit_path => edit_algorithm_path(@algorithm),
+ :allow_edit => Authorization.is_authorized?('edit', nil, @algorithm, current_user) } %>
+
+ <%= render :partial => "contributions/shared_with_groups_box", :locals => { :contributable => @algorithm } %>
+
+ <%= render :partial => "contributions/in_packs_box", :locals => { :contributable => @algorithm, :contributable_url => @algorithm_entry_url } %>
+
+ <%= render :partial => "contributions/ratings_box", :locals => { :contributable => @algorithm } %>
+
+ <%= render :partial => "contributions/attributed_by", :locals => { :contributable => @algorithm } %>
+
+ <%= render :partial => "contributions/favourited_box", :locals => { :contributable => @algorithm,
+ :add_to_favourites_path => favourite_file_url(@algorithm),
+ :remove_from_favourites_path => favourite_delete_file_url(@algorithm) } %>
+
+ <%= render :partial => "contributions/statistics_box", :locals => { :contributable => @algorithm } %>
+</div>
+
+<div class="clearer"> </div>
+
+<!-- BEGIN tabs -->
+
+<br/>
+
+<div id="tabsContainer" class="tabsContainer"></div>
+
+<% if logged_in? and @algorithm.owner? current_user %>
+
+ <a name="sharing"></a>
+ <div class="tabContainer">
+ <div class="tabTitle">Sharing</div>
+ <div class="tabContent">
+
+ <%= render :partial => "contributions/sharing_summary", :locals => { :contributable => @algorithm } %>
+ <%= render :partial => "contributions/updating_summary", :locals => { :contributable => @algorithm } %>
+
+ <% if Authorization.is_authorized?('edit', nil, @algorithm, current_user) %>
+ <ul class="sectionIcons">
+ <li><%= icon('edit', edit_algorithm_path(@algorithm), nil, nil, 'Edit')%></li>
+ </ul>
+ <% end %>
+ </div>
+ </div>
+
+ <% if false %>
+ <div class="tabContainer">
+ <div class="tabTitle">Viewing History</div>
+ <div class="tabContent">
+ <%= render :partial => "contributions/history", :object => @algorithm.contribution %>
+ </div>
+ </div>
+ <% end %>
+
+<% end %>
+
+<!-- END tabs -->
+
+<br/>
+<br/>
+
+<div id="commentsBox">
+ <%= render :partial => "comments/comments", :locals => { :commentable => @algorithm } %>
+</div>
Added: branches/apace/app/views/algorithms/statistics.rhtml (0 => 2129)
--- branches/apace/app/views/algorithms/statistics.rhtml (rev 0)
+++ branches/apace/app/views/algorithms/statistics.rhtml 2009-03-18 14:29:21 UTC (rev 2129)
@@ -0,0 +1 @@
+<%= render :partial => "contributions/statistics_detailed", :locals => { :contributable => @blob } %>
\ No newline at end of file
Modified: branches/apace/config/routes.rb (2128 => 2129)
--- branches/apace/config/routes.rb 2009-03-18 14:18:12 UTC (rev 2128)
+++ branches/apace/config/routes.rb 2009-03-18 14:29:21 UTC (rev 2129)
@@ -86,6 +86,19 @@
workflow.resources :reviews
end
+ # algorithms
+ map.resources :algorithms,
+ :collection => { :all => :get, :search => :get },
+ :member => { :download => :get,
+ :statistics => :get,
+ :favourite => :post,
+ :favourite_delete => :delete,
+ :comment => :post,
+ :comment_delete => :delete,
+ :rate => :post,
+ :tag => :post } do |algorithm|
+ end
+
# files (downloadable)
map.resources :files,
:controller => :blobs,
Added: branches/apace/db/migrate/074_create_algorithms.rb (0 => 2129)
--- branches/apace/db/migrate/074_create_algorithms.rb (rev 0)
+++ branches/apace/db/migrate/074_create_algorithms.rb 2009-03-18 14:29:21 UTC (rev 2129)
@@ -0,0 +1,24 @@
+# myExperiment: db/migrate/074_create_algorithms.rb
+#
+# Copyright (c) 2009 University of Manchester and the University of Southampton.
+# See license.txt for details.
+
+class CreateAlgorithms < ActiveRecord::Migration
+ def self.up
+ create_table :algorithms do |t|
+ t.column :contributor_id, :integer
+ t.column :contributor_type, :string
+ t.column :title, :string
+ t.column :description, :text
+ t.column :description_html, :text
+ t.column :license, :string
+ t.column :url, :text
+ t.column :created_at, :datetime
+ t.column :updated_at, :datetime
+ end
+ end
+
+ def self.down
+ drop_table :algorithms
+ end
+end
Added: branches/apace/db/migrate/075_create_apps.rb (0 => 2129)
--- branches/apace/db/migrate/075_create_apps.rb (rev 0)
+++ branches/apace/db/migrate/075_create_apps.rb 2009-03-18 14:29:21 UTC (rev 2129)
@@ -0,0 +1,23 @@
+# myExperiment: db/migrate/075_create_apps.rb
+#
+# Copyright (c) 2009 University of Manchester and the University of Southampton.
+# See license.txt for details.
+
+class CreateApps < ActiveRecord::Migration
+ def self.up
+ create_table :apps do |t|
+ t.column :contributor_id, :integer
+ t.column :contributor_type, :string
+ t.column :title, :string
+ t.column :description, :text
+ t.column :description_html, :text
+ t.column :license, :string
+ t.column :created_at, :datetime
+ t.column :updated_at, :datetime
+ end
+ end
+
+ def self.down
+ drop_table :apps
+ end
+end
Added: branches/apace/db/migrate/076_create_algorithm_instances.rb (0 => 2129)
--- branches/apace/db/migrate/076_create_algorithm_instances.rb (rev 0)
+++ branches/apace/db/migrate/076_create_algorithm_instances.rb 2009-03-18 14:29:21 UTC (rev 2129)
@@ -0,0 +1,18 @@
+# myExperiment: db/migrate/076_create_algorithm_instances.rb
+#
+# Copyright (c) 2009 University of Manchester and the University of Southampton.
+# See license.txt for details.
+
+class CreateAlgorithmInstances < ActiveRecord::Migration
+ def self.up
+ create_table :algorithm_instances do |t|
+ t.column :algorithm_id, :integer
+ t.column :app_id, :integer
+ end
+ end
+
+ def self.down
+ drop_table :algorithm_instances
+ end
+end
+