Commit 5f356d69284850603893b8a82141e44d27eec89e
1 parent
50fdb2e7
Exists in
master
and in
4 other branches
Issues tags: refactoring
Showing
3 changed files
with
39 additions
and
20 deletions
Show diff stats
app/assets/javascripts/issues.js
| @@ -61,3 +61,18 @@ function initIssuesSearch() { | @@ -61,3 +61,18 @@ function initIssuesSearch() { | ||
| 61 | $(this).closest('tr').fadeOut(); updatePage(); | 61 | $(this).closest('tr').fadeOut(); updatePage(); |
| 62 | }); | 62 | }); |
| 63 | } | 63 | } |
| 64 | + | ||
| 65 | +/** | ||
| 66 | + * Init issues page | ||
| 67 | + * | ||
| 68 | + */ | ||
| 69 | +function issuesPage(){ | ||
| 70 | + initIssuesSearch(); | ||
| 71 | + setSortable(); | ||
| 72 | + $("#label_name").chosen(); | ||
| 73 | + $("#assignee_id").chosen(); | ||
| 74 | + $("#milestone_id").chosen(); | ||
| 75 | + $("#milestone_id, #assignee_id, #label_name").on("change", function(){ | ||
| 76 | + $(this).closest("form").submit(); | ||
| 77 | + }); | ||
| 78 | +} |
app/controllers/issues_controller.rb
| @@ -3,6 +3,8 @@ class IssuesController < ApplicationController | @@ -3,6 +3,8 @@ class IssuesController < ApplicationController | ||
| 3 | before_filter :project | 3 | before_filter :project |
| 4 | before_filter :module_enabled | 4 | before_filter :module_enabled |
| 5 | before_filter :issue, :only => [:edit, :update, :destroy, :show] | 5 | before_filter :issue, :only => [:edit, :update, :destroy, :show] |
| 6 | + helper_method :issues_filter | ||
| 7 | + | ||
| 6 | layout "project" | 8 | layout "project" |
| 7 | 9 | ||
| 8 | # Authorize | 10 | # Authorize |
| @@ -130,10 +132,10 @@ class IssuesController < ApplicationController | @@ -130,10 +132,10 @@ class IssuesController < ApplicationController | ||
| 130 | end | 132 | end |
| 131 | 133 | ||
| 132 | def issues_filtered | 134 | def issues_filtered |
| 133 | - @issues = case params[:f].to_i | ||
| 134 | - when 1 then @project.issues | ||
| 135 | - when 2 then @project.issues.closed | ||
| 136 | - when 3 then @project.issues.opened.assigned(current_user) | 135 | + @issues = case params[:f] |
| 136 | + when issues_filter[:all] then @project.issues | ||
| 137 | + when issues_filter[:closed] then @project.issues.closed | ||
| 138 | + when issues_filter[:to_me] then @project.issues.opened.assigned(current_user) | ||
| 137 | else @project.issues.opened | 139 | else @project.issues.opened |
| 138 | end | 140 | end |
| 139 | 141 | ||
| @@ -143,4 +145,13 @@ class IssuesController < ApplicationController | @@ -143,4 +145,13 @@ class IssuesController < ApplicationController | ||
| 143 | @issues = @issues.includes(:author, :project).order("updated_at") | 145 | @issues = @issues.includes(:author, :project).order("updated_at") |
| 144 | @issues | 146 | @issues |
| 145 | end | 147 | end |
| 148 | + | ||
| 149 | + def issues_filter | ||
| 150 | + { | ||
| 151 | + all: "1", | ||
| 152 | + closed: "2", | ||
| 153 | + to_me: "3", | ||
| 154 | + open: "0" | ||
| 155 | + } | ||
| 156 | + end | ||
| 146 | end | 157 | end |
app/views/issues/index.html.haml
| @@ -18,17 +18,17 @@ | @@ -18,17 +18,17 @@ | ||
| 18 | .title | 18 | .title |
| 19 | .left | 19 | .left |
| 20 | %ul.nav.nav-pills.left | 20 | %ul.nav.nav-pills.left |
| 21 | - %li{:class => ("active" if (params[:f] == "0" || !params[:f]))} | ||
| 22 | - = link_to project_issues_path(@project, :f => 0, :milestone_id => params[:milestone_id]) do | 21 | + %li{:class => ("active" if (params[:f] == issues_filter[:open] || !params[:f]))} |
| 22 | + = link_to project_issues_path(@project, :f => issues_filter[:open], :milestone_id => params[:milestone_id]) do | ||
| 23 | Open | 23 | Open |
| 24 | - %li{:class => ("active" if params[:f] == "2")} | ||
| 25 | - = link_to project_issues_path(@project, :f => 2, :milestone_id => params[:milestone_id]) do | 24 | + %li{:class => ("active" if params[:f] == issues_filter[:closed])} |
| 25 | + = link_to project_issues_path(@project, :f => issues_filter[:closed], :milestone_id => params[:milestone_id]) do | ||
| 26 | Closed | 26 | Closed |
| 27 | - %li{:class => ("active" if params[:f] == "3")} | ||
| 28 | - = link_to project_issues_path(@project, :f => 3, :milestone_id => params[:milestone_id]) do | 27 | + %li{:class => ("active" if params[:f] == issues_filter[:to_me])} |
| 28 | + = link_to project_issues_path(@project, :f => issues_filter[:to_me], :milestone_id => params[:milestone_id]) do | ||
| 29 | To Me | 29 | To Me |
| 30 | - %li{:class => ("active" if params[:f] == "1")} | ||
| 31 | - = link_to project_issues_path(@project, :f => 1, :milestone_id => params[:milestone_id]) do | 30 | + %li{:class => ("active" if params[:f] == issues_filter[:all])} |
| 31 | + = link_to project_issues_path(@project, :f => issues_filter[:all], :milestone_id => params[:milestone_id]) do | ||
| 32 | All | 32 | All |
| 33 | 33 | ||
| 34 | .right | 34 | .right |
| @@ -44,14 +44,7 @@ | @@ -44,14 +44,7 @@ | ||
| 44 | 44 | ||
| 45 | :javascript | 45 | :javascript |
| 46 | $(function(){ | 46 | $(function(){ |
| 47 | - initIssuesSearch(); | ||
| 48 | - setSortable(); | ||
| 49 | - $("#label_name").chosen(); | ||
| 50 | - $("#assignee_id").chosen(); | ||
| 51 | - $("#milestone_id").chosen(); | ||
| 52 | - $("#milestone_id, #assignee_id, #label_name").live("change", function(){ | ||
| 53 | - $(this).closest("form").submit(); | ||
| 54 | - }); | 47 | + issuesPage(); |
| 55 | }) | 48 | }) |
| 56 | 49 | ||
| 57 | function setSortable(){ | 50 | function setSortable(){ |