myexperiment-hackers
[Top][All Lists]
Advanced

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

[myexperiment-hackers] [1930] trunk: part of the tag suggestions code


From: noreply
Subject: [myexperiment-hackers] [1930] trunk: part of the tag suggestions code
Date: Fri, 7 Nov 2008 11:38:04 -0500 (EST)

Revision
1930
Author
dgc
Date
2008-11-07 11:38:04 -0500 (Fri, 07 Nov 2008)

Log Message

part of the tag suggestions code

Modified Paths

Added Paths

Diff

Modified: trunk/app/controllers/workflows_controller.rb (1929 => 1930)


--- trunk/app/controllers/workflows_controller.rb	2008-11-07 15:57:20 UTC (rev 1929)
+++ trunk/app/controllers/workflows_controller.rb	2008-11-07 16:38:04 UTC (rev 1930)
@@ -559,6 +559,10 @@
     end
   end
   
+  def tag_suggestions
+    @suggestions = @workflow.get_tag_suggestions
+  end
+
 protected
 
   def find_workflows

Modified: trunk/app/models/policy.rb (1929 => 1930)


--- trunk/app/models/policy.rb	2008-11-07 15:57:20 UTC (rev 1929)
+++ trunk/app/models/policy.rb	2008-11-07 16:38:04 UTC (rev 1930)
@@ -340,6 +340,7 @@
                                   "comment_delete", 
                                   "rate", 
                                   "tag", 
+                                  "tag_suggestions",
                                   "view", 
                                   "comments_timeline", 
                                   "comments",

Modified: trunk/app/models/workflow.rb (1929 => 1930)


--- trunk/app/models/workflow.rb	2008-11-07 15:57:20 UTC (rev 1929)
+++ trunk/app/models/workflow.rb	2008-11-07 16:38:04 UTC (rev 1930)
@@ -182,4 +182,23 @@
     words.read
   end
 
+  def get_tag_suggestions()
+
+    ignore = [ "and", "the", "or", "a", "an" ]
+    
+    text = "#{title} #{body} #{get_search_terms(current_version)}"
+
+    words = text.split(/[^a-zA-Z0-9]+/).uniq
+
+    all_tags = Tag.find(:all).select do |t| t.taggings_count > 0 end.map do |t| t.name end
+
+    candidates = words - (words - all_tags)
+
+    candidates = candidates - ignore
+
+    existing = tags.map do |t| t.name end
+
+    (candidates - existing).sort
+  end
+
 end

Modified: trunk/app/views/workflows/_workflow_file_selection_form.rhtml (1929 => 1930)


--- trunk/app/views/workflows/_workflow_file_selection_form.rhtml	2008-11-07 15:57:20 UTC (rev 1929)
+++ trunk/app/views/workflows/_workflow_file_selection_form.rhtml	2008-11-07 16:38:04 UTC (rev 1930)
@@ -1,5 +1,30 @@
 <div class="box_form" style="width: 600px; text-align: center;">
 	<p style="text-align: center;">
+          <div id="upload-form">
 		<input id="workflow_file" name="workflow[file]" size="70" type="file"/>
+          </div>
+
+          <script type="text/_javascript_">
+
+            function multiUploadMode() {
+
+              var max = 10;
+
+              var markup = "<ol>";
+
+              for (var i = 1; i <= max; i++) {
+                markup += '<li><input name="workflow[file' + i + ']" size="70" type="file"/></li>';
+              }
+
+              markup += "</ol>";
+
+              document.getElementById('upload-form').innerHTML = markup;
+            }
+
+          </script>
+
+          <% if multiple == true %>
+            <p>Click <a href=""  to upload multiple workflows.</p>
+          <% end %>
 	</p>
-</div>
\ No newline at end of file
+</div>

Modified: trunk/app/views/workflows/new.rhtml (1929 => 1930)


--- trunk/app/views/workflows/new.rhtml	2008-11-07 15:57:20 UTC (rev 1929)
+++ trunk/app/views/workflows/new.rhtml	2008-11-07 16:38:04 UTC (rev 1930)
@@ -16,7 +16,7 @@
 	<p class="step_text">1. Workflow file/script</p>
 
 	<center>
-	  <%= render :partial => 'workflow_file_selection_form' %>
+	  <%= render :partial => 'workflow_file_selection_form', :locals => { :multiple => true } %>
 	</center>
   
   <br />

Modified: trunk/app/views/workflows/new_version.rhtml (1929 => 1930)


--- trunk/app/views/workflows/new_version.rhtml	2008-11-07 15:57:20 UTC (rev 1929)
+++ trunk/app/views/workflows/new_version.rhtml	2008-11-07 16:38:04 UTC (rev 1930)
@@ -38,7 +38,7 @@
 	<p class="step_text">1. Workflow file/script</p>
 
 	<center>
-	  <%= render :partial => 'workflow_file_selection_form' %>
+	  <%= render :partial => 'workflow_file_selection_form', :locals => { :multiple => false } %>
 	</center>
   
   <br />

Modified: trunk/config/routes.rb (1929 => 1930)


--- trunk/config/routes.rb	2008-11-07 15:57:20 UTC (rev 1929)
+++ trunk/config/routes.rb	2008-11-07 16:38:04 UTC (rev 1930)
@@ -81,7 +81,8 @@
                  :edit_version => :get, 
                  :update_version => :put, 
                  :comments_timeline => :get, 
-                 :comments => :get } do |workflow|
+                 :comments => :get,
+                 :tag_suggestions => :get } do |workflow|
     # workflows have nested citations
     workflow.resources :citations
     workflow.resources :reviews

Added: trunk/public/_javascript_s/tag_suggestions.js (0 => 1930)


--- trunk/public/_javascript_s/tag_suggestions.js	                        (rev 0)
+++ trunk/public/_javascript_s/tag_suggestions.js	2008-11-07 16:38:04 UTC (rev 1930)
@@ -0,0 +1,93 @@
+// tag_suggestions.js
+
+var suggestions = new Array();
+var tagsToAdd   = new Array();
+
+function updateAddBox() {
+}
+
+function addTag(name) {
+
+  if (tagsToAdd.indexOf(name) == -1) {
+
+    tagsToAdd.push(name);
+    updateTagViews();
+  }
+}
+
+function removeTag(name) {
+
+  tagsToAdd.splice(tagsToAdd.indexOf(name), 1);
+  updateTagViews();
+}
+
+function addingTag(name) {
+  alert("Adding tag: " + name);
+}
+
+function tagSuccess(name) {
+  document.getElementById("tag_" + name).innerHTML = "Tag \""+ name + "\" added.";
+  alert("Tag success: " + name);
+}
+
+function defineTag(name) {
+  suggestions.push(name);
+}
+
+function updateTagViews() {
+
+  visibleSuggestions = new Array();
+
+  for (var i = 0; i < suggestions.length; i++) {
+    s = suggestions[i];
+    if (tagsToAdd.indexOf(s) == -1) {
+      visibleSuggestions.push(s);
+    }
+  }
+
+  var separator = ' <span style="color: #999999;">|</span> ';
+
+  // visible suggestions
+
+  var markup = "";
+
+  if (visibleSuggestions.length == 0) {
+
+    markup = "There are no remaining tag suggestions!";
+  } else {
+
+    for (var i = 0; i < visibleSuggestions.length; i++) {
+
+      markup += '<a href=""  + visibleSuggestions[i] +
+        '\'); return false;">' + visibleSuggestions[i] + '</a>';
+
+      if (i != (visibleSuggestions.length - 1))
+        markup += separator;
+    }
+  }
+
+  document.getElementById("suggestions").innerHTML = markup;
+
+  // selected tags
+
+  markup = "";
+
+  if (tagsToAdd.length == 0) {
+
+    markup = "You have not selected any tag suggestions (click on tags below to add).";
+
+  } else {
+
+    for (var i = 0; i < tagsToAdd.length; i++) {
+
+      markup += '<a href=""  + tagsToAdd[i] +
+        '\'); return false;">' + tagsToAdd[i] + '</a>';
+
+      if (i != (tagsToAdd.length - 1))
+        markup += separator;
+    }
+  }
+
+  document.getElementById("to-add").innerHTML = markup;
+}
+

reply via email to

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