From 20e322c5799e77ab6629f30a017d1a96eb809ee3 Mon Sep 17 00:00:00 2001
From: Michel Felipe
Date: Mon, 1 Jun 2015 00:29:45 -0300
Subject: [PATCH] Added filter by tags in tasks list
---
app/controllers/my_profile/tasks_controller.rb | 4 ++++
app/views/tasks/index.html.erb | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------
public/javascripts/inputosaurus.js | 32 ++++++++++++++++++++++++++++++++
3 files changed, 93 insertions(+), 40 deletions(-)
diff --git a/app/controllers/my_profile/tasks_controller.rb b/app/controllers/my_profile/tasks_controller.rb
index 74ae666..61f3b16 100644
--- a/app/controllers/my_profile/tasks_controller.rb
+++ b/app/controllers/my_profile/tasks_controller.rb
@@ -7,10 +7,14 @@ class TasksController < MyProfileController
@filter_type = params[:filter_type].presence
@filter_text = params[:filter_text].presence
@filter_responsible = params[:filter_responsible]
+ @filter_tags = params[:filter_tags]
+
@task_types = Task.pending_types_for(profile)
+ @task_tags = [OpenStruct.new(:name => _('All'), :id => nil) ] + Task.all_tags
@tasks = Task.pending_all(profile, @filter_type, @filter_text).order_by('created_at', 'asc')
@tasks = @tasks.where(:responsible_id => @filter_responsible.to_i != -1 ? @filter_responsible : nil) if @filter_responsible.present?
+ @tasks = @tasks.tagged_with(@filter_tags, any: true) if @filter_tags.present?
@tasks = @tasks.paginate(:per_page => Task.per_page, :page => params[:page])
@failed = params ? params[:failed] : {}
diff --git a/app/views/tasks/index.html.erb b/app/views/tasks/index.html.erb
index e6ee5c4..ae43ecc 100644
--- a/app/views/tasks/index.html.erb
+++ b/app/views/tasks/index.html.erb
@@ -35,6 +35,11 @@
<% end %>
+ <%= labelled_select(_('Tags')+': ', :filter_tags, :id, :name, @filter_tags, @task_tags, {:id => 'filter-add-tag'}) %>
+ <%= text_field_tag( :filter_tags, @filter_tags, :size => 36, :class => 'filter-tags' ) %>
+
+
+
<%= submit_button(:search, _('Search')) %>
<% end %>
@@ -72,46 +77,6 @@
<% end %>
-
-
<%= pagination_links(@tasks)%>
<% button_bar(:class => 'task-actions') do %>
@@ -127,3 +92,55 @@
<%= javascript_include_tag 'tasks' %>
+
+
diff --git a/public/javascripts/inputosaurus.js b/public/javascripts/inputosaurus.js
index c38c20e..d1d2b6c 100644
--- a/public/javascripts/inputosaurus.js
+++ b/public/javascripts/inputosaurus.js
@@ -63,6 +63,9 @@
// when you check for duplicates it check for the case
caseSensitiveDuplicates: false,
+ //Hide input to inform tags. This is cool when you create tags from another way
+ hideInput: false,
+
//Ajax options to send tags
submitTags: null
},
@@ -204,6 +207,31 @@
widget._resetPlaceholder();
},
+ addTags: function(list){
+
+ if(arguments.length == 1){
+ list = [list];
+ }
+
+ if(arguments[1]){
+ list = Array.prototype.slice.call(arguments);
+ }
+
+ if(!$.isArray(list)){
+ var msg = 'Tag list needs be an Array';
+
+ if(console){
+ console.error(msg);
+
+ return false;
+ }else{
+ throw new Error(msg);
+ }
+
+ }
+ this._setChosen(list);
+ },
+
_inputFocus : function(ev) {
var widget = ev.data.widget || this;
@@ -399,6 +427,10 @@
}
});
self._setValue(self._buildValue());
+
+ if(this.options.hideInput){
+ this.elements.input.parent().hide();
+ }
},
_buildValue : function() {
--
libgit2 0.21.2