summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dzaporozhets@sphereconsultinginc.com>2012-06-12 11:31:38 +0300
committerDmitriy Zaporozhets <dzaporozhets@sphereconsultinginc.com>2012-06-12 11:31:38 +0300
commit0e33bf6eb0883259af4b258532b948e5798e7d1d (patch)
tree1deccc68e821a0f8ced37ebe67aa376f5f49b81f /app
parent3a2d7a6604372ce1ab98982709c9d851376879da (diff)
downloadgitlab-ce-0e33bf6eb0883259af4b258532b948e5798e7d1d.tar.gz
Refactored IssuesController
Diffstat (limited to 'app')
-rw-r--r--app/assets/javascripts/issues.js26
-rw-r--r--app/controllers/issues_controller.rb32
-rw-r--r--app/views/issues/index.html.haml37
3 files changed, 50 insertions, 45 deletions
diff --git a/app/assets/javascripts/issues.js b/app/assets/javascripts/issues.js
index 19de614fd62..5f49567f709 100644
--- a/app/assets/javascripts/issues.js
+++ b/app/assets/javascripts/issues.js
@@ -35,3 +35,29 @@ function backToIssues(){
});
});
}
+
+function initIssuesSearch() {
+ var href = $('.issue_search').parent().attr('action');
+ var last_terms = '';
+
+ $('.issue_search').keyup(function() {
+ var terms = $(this).val();
+ var milestone_id = $('#milestone_id').val();
+ var status = $('#status').val();
+
+ if (terms != last_terms) {
+ last_terms = terms;
+
+ if (terms.length >= 2 || terms.length == 0) {
+ $.get(href, { 'f': status, 'terms': terms, 'milestone_id': milestone_id }, function(response) {
+ $('#issues-table').html(response);
+ setSortable();
+ });
+ }
+ }
+ });
+
+ $('.delete-issue').live('ajax:success', function() {
+ $(this).closest('tr').fadeOut(); updatePage();
+ });
+}
diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb
index 64be20ff503..0e31f04deb5 100644
--- a/app/controllers/issues_controller.rb
+++ b/app/controllers/issues_controller.rb
@@ -23,16 +23,9 @@ class IssuesController < ApplicationController
respond_to :js, :html
def index
- @issues = case params[:f].to_i
- when 1 then @project.issues
- when 2 then @project.issues.closed
- when 3 then @project.issues.opened.assigned(current_user)
- else @project.issues.opened
- end
+ @issues = issues_filtered
- @issues = @issues.where(:milestone_id => params[:milestone_id]) if params[:milestone_id].present?
@issues = @issues.page(params[:page]).per(20)
- @issues = @issues.includes(:author, :project).order("critical, updated_at")
respond_to do |format|
format.html # index.html.erb
@@ -111,15 +104,9 @@ class IssuesController < ApplicationController
def search
terms = params['terms']
- @project = Project.find(params['project'])
- @issues = case params[:status].to_i
- when 1 then @project.issues
- when 2 then @project.issues.closed
- when 3 then @project.issues.opened.assigned(current_user)
- else @project.issues.opened
- end.page(params[:page]).per(100)
-
+ @issues = issues_filtered
@issues = @issues.where("title LIKE ?", "%#{terms}%") unless terms.blank?
+ @issues = @issues.page(params[:page]).per(100)
render :partial => 'issues'
end
@@ -141,4 +128,17 @@ class IssuesController < ApplicationController
def module_enabled
return render_404 unless @project.issues_enabled
end
+
+ def issues_filtered
+ @issues = case params[:f].to_i
+ when 1 then @project.issues
+ when 2 then @project.issues.closed
+ when 3 then @project.issues.opened.assigned(current_user)
+ else @project.issues.opened
+ end
+
+ @issues = @issues.where(:milestone_id => params[:milestone_id]) if params[:milestone_id].present?
+ @issues = @issues.includes(:author, :project).order("critical, updated_at")
+ @issues
+ end
end
diff --git a/app/views/issues/index.html.haml b/app/views/issues/index.html.haml
index 511957325e0..98cbb7d2eef 100644
--- a/app/views/issues/index.html.haml
+++ b/app/views/issues/index.html.haml
@@ -41,27 +41,14 @@
= render "issues"
:javascript
- var href = $('.issue_search').parent().attr('action');
- var last_terms = '';
-
- $('.issue_search').keyup(function() {
- var terms = $(this).val();
- var project_id = $('#project_id').val();
- var status = $('#status').val();
- if (terms != last_terms) {
- last_terms = terms;
-
- if (terms.length >= 2 || terms.length == 0) {
- $.get(href, { 'status': status, 'terms': terms, project: project_id }, function(response) {
- $('#issues-table').html(response);
- setSortable();
- });
- }
- }
- });
-
- $('.delete-issue').live('ajax:success', function() {
- $(this).closest('tr').fadeOut(); updatePage();});
+ $(function(){
+ initIssuesSearch();
+ setSortable();
+ $("#milestone_id").chosen();
+ $("#milestone_id").live("change", function(){
+ $(this).closest("form").submit();
+ });
+ })
function setSortable(){
$('#issues-table').sortable({
@@ -83,11 +70,3 @@
}
});
}
-
- $(function(){
- setSortable();
- $("#milestone_id").chosen();
- $("#milestone_id").live("change", function(){
- $(this).closest("form").submit();
- });
- });