Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#63 reopened; #64

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/views/issues/_didyoumean_injected.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
};
</script>

<%= javascript_tag "observeIssueSubjectField('#{@project.id}', #{@issue.id or '\'\''}, '#{issues_didyoumean_event_type}');" %>
<%= javascript_tag "observeIssueSubjectField('#{@project.id}', #{@issue.id or '\'\''}, '#{Setting.plugin_redmine_didyoumean['start_search_when'] == "1" ? "keyup" : "change"}');" %>
29 changes: 22 additions & 7 deletions assets/javascripts/didyoumean.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
function observeIssueSubjectField(project_id, issue_id, event_type) {

if (window.jQuery) {
$(document).ready(moveSimilarIssuesRoot)
$(document).ready(moveSimilarIssuesRoot);
} else {
document.observe("dom:loaded", moveSimilarIssuesRoot)
document.observe("dom:loaded", moveSimilarIssuesRoot);
}

var handleUpdate = function(event) {
Expand All @@ -29,18 +29,33 @@ function observeIssueSubjectField(project_id, issue_id, event_type) {
evalJSON: true
});
}
}
};

if (window.jQuery) {
getElem('issue_subject').bind(event_type, handleUpdate);
if(event_type === 'keyup'){
function throttle(f, delay){
var timer = null;
return function(){
var context = this, args = arguments;
clearTimeout(timer);
timer = window.setTimeout(function(){
f.apply(context, args);
},
delay || 500);
};
}
getElem('issue_subject').bind(event_type, throttle(handleUpdate));
}else{
getElem('issue_subject').bind(event_type, handleUpdate);
}
} else {
getElem('issue_subject').observe(event_type, handleUpdate);
}
}

function updateSimilarIssuesBlock(data) {
var items = data.issues;
if(items.length == 0) {
if(items.length === 0) {
getElem('similar_issues').hide();
} else {
var items_html = '';
Expand All @@ -50,8 +65,8 @@ function updateSimilarIssuesBlock(data) {

if (data.total > data.issues.length) {
var more = data.total - data.issues.length;
var more_text = '<li>' + more + ' ' + dym.label_more + '</li>'
items_html += more_text
var more_text = '<li>' + more + ' ' + dym.label_more + '</li>';
items_html += more_text;
}

setHtml(getElem('similar_issues_list'), items_html);
Expand Down
9 changes: 9 additions & 0 deletions db/migrate/001_issue_subject_index.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class IssueSubjectIndex < ActiveRecord::Migration
def self.up
add_index :issues, :subject
end

def self.down
remove_index :issues, :subject
end
end
5 changes: 1 addition & 4 deletions init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,4 @@
settings(:default => default_settings, :partial => 'settings/didyoumean_settings')
end

ActionDispatch::Callbacks.to_prepare do
require 'redmine_didyoumean/hooks/didyoumean_hooks'
IssuesHelper.send :include, RedmineDidyoumean::Patches::SearchIssuesHelperPatch
end
require 'redmine_didyoumean/hooks/didyoumean_hooks'
13 changes: 0 additions & 13 deletions lib/redmine_didyoumean/patches/search_issues_helper_patch.rb

This file was deleted.