Commit 20e322c5799e77ab6629f30a017d1a96eb809ee3
Committed by
Leandro Santos
1 parent
2905bc6e
Exists in
staging
and in
7 other branches
Added filter by tags in tasks list
Showing
3 changed files
with
93 additions
and
40 deletions
Show diff stats
app/controllers/my_profile/tasks_controller.rb
@@ -7,10 +7,14 @@ class TasksController < MyProfileController | @@ -7,10 +7,14 @@ class TasksController < MyProfileController | ||
7 | @filter_type = params[:filter_type].presence | 7 | @filter_type = params[:filter_type].presence |
8 | @filter_text = params[:filter_text].presence | 8 | @filter_text = params[:filter_text].presence |
9 | @filter_responsible = params[:filter_responsible] | 9 | @filter_responsible = params[:filter_responsible] |
10 | + @filter_tags = params[:filter_tags] | ||
11 | + | ||
10 | @task_types = Task.pending_types_for(profile) | 12 | @task_types = Task.pending_types_for(profile) |
13 | + @task_tags = [OpenStruct.new(:name => _('All'), :id => nil) ] + Task.all_tags | ||
11 | 14 | ||
12 | @tasks = Task.pending_all(profile, @filter_type, @filter_text).order_by('created_at', 'asc') | 15 | @tasks = Task.pending_all(profile, @filter_type, @filter_text).order_by('created_at', 'asc') |
13 | @tasks = @tasks.where(:responsible_id => @filter_responsible.to_i != -1 ? @filter_responsible : nil) if @filter_responsible.present? | 16 | @tasks = @tasks.where(:responsible_id => @filter_responsible.to_i != -1 ? @filter_responsible : nil) if @filter_responsible.present? |
17 | + @tasks = @tasks.tagged_with(@filter_tags, any: true) if @filter_tags.present? | ||
14 | @tasks = @tasks.paginate(:per_page => Task.per_page, :page => params[:page]) | 18 | @tasks = @tasks.paginate(:per_page => Task.per_page, :page => params[:page]) |
15 | 19 | ||
16 | @failed = params ? params[:failed] : {} | 20 | @failed = params ? params[:failed] : {} |
app/views/tasks/index.html.erb
@@ -35,6 +35,11 @@ | @@ -35,6 +35,11 @@ | ||
35 | </p> | 35 | </p> |
36 | <% end %> | 36 | <% end %> |
37 | <p> | 37 | <p> |
38 | + <%= labelled_select(_('Tags')+': ', :filter_tags, :id, :name, @filter_tags, @task_tags, {:id => 'filter-add-tag'}) %> | ||
39 | + <%= text_field_tag( :filter_tags, @filter_tags, :size => 36, :class => 'filter-tags' ) %> | ||
40 | + </p> | ||
41 | + | ||
42 | + <p> | ||
38 | <%= submit_button(:search, _('Search')) %> | 43 | <%= submit_button(:search, _('Search')) %> |
39 | </p> | 44 | </p> |
40 | <% end %> | 45 | <% end %> |
@@ -72,46 +77,6 @@ | @@ -72,46 +77,6 @@ | ||
72 | <% end %> | 77 | <% end %> |
73 | </ul> | 78 | </ul> |
74 | 79 | ||
75 | - <script> | ||
76 | - jQuery('.tag-list').inputosaurus({ | ||
77 | - autoCompleteSource: <%= "'/myprofile/#{profile.identifier}/cms/search_tags'," %> | ||
78 | - activateFinalResult: true, | ||
79 | - submitTags: { | ||
80 | - url: <%= "'/myprofile/#{profile.identifier}/tasks/save_tags'" %>, | ||
81 | - beforeSend: function(){ | ||
82 | - this.element.parents('.task_box') | ||
83 | - .prev('.fg-state-error') | ||
84 | - .remove(); | ||
85 | - }, | ||
86 | - success: function(response){ | ||
87 | - | ||
88 | - this.element.parents('.task_box') | ||
89 | - .prev('.fg-state-error') | ||
90 | - .remove(); | ||
91 | - | ||
92 | - if(!response.success){ | ||
93 | - | ||
94 | - var errorIcon = $('<span/>',{ | ||
95 | - 'class':'ui-icon ui-icon-alert', | ||
96 | - style:'float: left; margin-right: .3em;' | ||
97 | - }); | ||
98 | - | ||
99 | - var content = $('<p/>',{ | ||
100 | - html:'<strong>'+response.message+'</strong>' | ||
101 | - }).prepend(errorIcon); | ||
102 | - | ||
103 | - var div = $('<div/>',{ | ||
104 | - 'class':'alert fg-state-error ui-state-error' | ||
105 | - }).append(content); | ||
106 | - | ||
107 | - this.element.parents('.task_box').before(div); | ||
108 | - } | ||
109 | - | ||
110 | - } | ||
111 | - } | ||
112 | - }) | ||
113 | - </script> | ||
114 | - | ||
115 | <%= pagination_links(@tasks)%> | 80 | <%= pagination_links(@tasks)%> |
116 | 81 | ||
117 | <% button_bar(:class => 'task-actions') do %> | 82 | <% button_bar(:class => 'task-actions') do %> |
@@ -127,3 +92,55 @@ | @@ -127,3 +92,55 @@ | ||
127 | 92 | ||
128 | 93 | ||
129 | <%= javascript_include_tag 'tasks' %> | 94 | <%= javascript_include_tag 'tasks' %> |
95 | + | ||
96 | +<script type="text/javascript"> | ||
97 | + | ||
98 | + jQuery('.filter-tags').inputosaurus({ | ||
99 | + hideInput: true | ||
100 | + }); | ||
101 | + | ||
102 | + $('#filter-add-tag').change(function(){ | ||
103 | + | ||
104 | + if($(this).val() != ''){ | ||
105 | + jQuery('.filter-tags').inputosaurus('addTags',$(this).children(':selected').text()); | ||
106 | + } | ||
107 | + }); | ||
108 | + | ||
109 | + jQuery('.tag-list').inputosaurus({ | ||
110 | + autoCompleteSource: <%= "'/myprofile/#{profile.identifier}/cms/search_tags'," %> | ||
111 | + activateFinalResult: true, | ||
112 | + submitTags: { | ||
113 | + url: <%= "'/myprofile/#{profile.identifier}/tasks/save_tags'" %>, | ||
114 | + beforeSend: function(){ | ||
115 | + this.element.parents('.task_box') | ||
116 | + .prev('.fg-state-error') | ||
117 | + .remove(); | ||
118 | + }, | ||
119 | + success: function(response){ | ||
120 | + | ||
121 | + this.element.parents('.task_box') | ||
122 | + .prev('.fg-state-error') | ||
123 | + .remove(); | ||
124 | + | ||
125 | + if(!response.success){ | ||
126 | + | ||
127 | + var errorIcon = $('<span/>',{ | ||
128 | + 'class':'ui-icon ui-icon-alert', | ||
129 | + style:'float: left; margin-right: .3em;' | ||
130 | + }); | ||
131 | + | ||
132 | + var content = $('<p/>',{ | ||
133 | + html:'<strong>'+response.message+'</strong>' | ||
134 | + }).prepend(errorIcon); | ||
135 | + | ||
136 | + var div = $('<div/>',{ | ||
137 | + 'class':'alert fg-state-error ui-state-error' | ||
138 | + }).append(content); | ||
139 | + | ||
140 | + this.element.parents('.task_box').before(div); | ||
141 | + } | ||
142 | + | ||
143 | + } | ||
144 | + } | ||
145 | + }) | ||
146 | +</script> |
public/javascripts/inputosaurus.js
@@ -63,6 +63,9 @@ | @@ -63,6 +63,9 @@ | ||
63 | // when you check for duplicates it check for the case | 63 | // when you check for duplicates it check for the case |
64 | caseSensitiveDuplicates: false, | 64 | caseSensitiveDuplicates: false, |
65 | 65 | ||
66 | + //Hide input to inform tags. This is cool when you create tags from another way | ||
67 | + hideInput: false, | ||
68 | + | ||
66 | //Ajax options to send tags | 69 | //Ajax options to send tags |
67 | submitTags: null | 70 | submitTags: null |
68 | }, | 71 | }, |
@@ -204,6 +207,31 @@ | @@ -204,6 +207,31 @@ | ||
204 | widget._resetPlaceholder(); | 207 | widget._resetPlaceholder(); |
205 | }, | 208 | }, |
206 | 209 | ||
210 | + addTags: function(list){ | ||
211 | + | ||
212 | + if(arguments.length == 1){ | ||
213 | + list = [list]; | ||
214 | + } | ||
215 | + | ||
216 | + if(arguments[1]){ | ||
217 | + list = Array.prototype.slice.call(arguments); | ||
218 | + } | ||
219 | + | ||
220 | + if(!$.isArray(list)){ | ||
221 | + var msg = 'Tag list needs be an Array'; | ||
222 | + | ||
223 | + if(console){ | ||
224 | + console.error(msg); | ||
225 | + | ||
226 | + return false; | ||
227 | + }else{ | ||
228 | + throw new Error(msg); | ||
229 | + } | ||
230 | + | ||
231 | + } | ||
232 | + this._setChosen(list); | ||
233 | + }, | ||
234 | + | ||
207 | _inputFocus : function(ev) { | 235 | _inputFocus : function(ev) { |
208 | var widget = ev.data.widget || this; | 236 | var widget = ev.data.widget || this; |
209 | 237 | ||
@@ -399,6 +427,10 @@ | @@ -399,6 +427,10 @@ | ||
399 | } | 427 | } |
400 | }); | 428 | }); |
401 | self._setValue(self._buildValue()); | 429 | self._setValue(self._buildValue()); |
430 | + | ||
431 | + if(this.options.hideInput){ | ||
432 | + this.elements.input.parent().hide(); | ||
433 | + } | ||
402 | }, | 434 | }, |
403 | 435 | ||
404 | _buildValue : function() { | 436 | _buildValue : function() { |