From adfefdf76d5dd7a6c63c444accfa3fe22ecf489e Mon Sep 17 00:00:00 2001 From: Javier Arce Date: Mon, 28 Apr 2014 11:16:50 +0200 Subject: [PATCH 1/5] CDB-1442 #fixes Sort tags in the public dashboard --- app/controllers/admin/pages_controller.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/admin/pages_controller.rb b/app/controllers/admin/pages_controller.rb index 75566037cc27..cfa43a68c360 100644 --- a/app/controllers/admin/pages_controller.rb +++ b/app/controllers/admin/pages_controller.rb @@ -24,7 +24,7 @@ def datasets viewed_user = User.where(username: user.strip.downcase).first return render_404 if viewed_user.nil? - @tags = viewed_user.map_tags + @tags = viewed_user.map_tags.sort_by{ |m| m.downcase } @username = viewed_user.username @avatar_url = viewed_user.gravatar(128) @@ -52,7 +52,7 @@ def datasets title: dataset.name, description: dataset.description, updated_at: dataset.updated_at, - tags: dataset.tags + tags: dataset.tags.sort_by{ |m| m.downcase } } ) end @@ -71,7 +71,7 @@ def public viewed_user = User.where(username: user.strip.downcase).first return render_404 if viewed_user.nil? - @tags = viewed_user.tags + @tags = viewed_user.map_tags.sort_by{ |m| m.downcase } @username = viewed_user.username @avatar_url = viewed_user.gravatar(128) From 4e9a198b86921a8c9c5c32bdc76951ea0771774e Mon Sep 17 00:00:00 2001 From: Javier Arce Date: Mon, 28 Apr 2014 11:17:23 +0200 Subject: [PATCH 2/5] Sends the sort_by to the backend --- lib/assets/javascripts/cartodb/dashboard/filters/tag_dropdown.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/assets/javascripts/cartodb/dashboard/filters/tag_dropdown.js b/lib/assets/javascripts/cartodb/dashboard/filters/tag_dropdown.js index 61212ab40a73..a411769f7b82 100644 --- a/lib/assets/javascripts/cartodb/dashboard/filters/tag_dropdown.js +++ b/lib/assets/javascripts/cartodb/dashboard/filters/tag_dropdown.js @@ -82,6 +82,7 @@ cdb.admin.TagDropdown = cdb.ui.common.Dropdown.extend({ var self = this; this.tags.fetch({ data: { + sort_by: "name", type: self.model.get("type") }, success: function() { From b016d79871dc641526fc837049b755874498d671 Mon Sep 17 00:00:00 2001 From: Javier Arce Date: Mon, 28 Apr 2014 11:26:10 +0200 Subject: [PATCH 3/5] Changes sort method sent to the back --- .../javascripts/cartodb/dashboard/filters/tag_dropdown.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/assets/javascripts/cartodb/dashboard/filters/tag_dropdown.js b/lib/assets/javascripts/cartodb/dashboard/filters/tag_dropdown.js index a411769f7b82..5b85e186bdb9 100644 --- a/lib/assets/javascripts/cartodb/dashboard/filters/tag_dropdown.js +++ b/lib/assets/javascripts/cartodb/dashboard/filters/tag_dropdown.js @@ -82,7 +82,7 @@ cdb.admin.TagDropdown = cdb.ui.common.Dropdown.extend({ var self = this; this.tags.fetch({ data: { - sort_by: "name", + o: { name: "desc" }, type: self.model.get("type") }, success: function() { From a949e0730fd9bf46027280d20fc9714dd8121ee2 Mon Sep 17 00:00:00 2001 From: Kartones Date: Mon, 28 Apr 2014 15:34:08 +0200 Subject: [PATCH 4/5] CDB-1442 Allowing to specify an order param to change from count to other options --- app/models/visualization/tags.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/models/visualization/tags.rb b/app/models/visualization/tags.rb index 6713f87134f0..0d06c9ebaf94 100644 --- a/app/models/visualization/tags.rb +++ b/app/models/visualization/tags.rb @@ -35,7 +35,7 @@ def count(params={}) SELECT name, count(*) as count FROM tags GROUP BY name - ORDER BY count(*) + #{order_from(params)} }, map_ids_for(user), types_from(params), limit_from(params) ).all.map(&:values) end #count @@ -48,6 +48,11 @@ def map_ids_for(user) user.maps.map(&:id) end #map_ids + def order_from(params={}) + order = params.fetch(:order, nil) + (order.nil? || order.empty?) ? ' ORDER BY count(*) ' : " ORDER BY #{order} " + end #order_from + def privacy_from(params={}) privacy = params.fetch(:privacy, nil) (privacy.nil? || privacy.empty?) ? Member::PRIVACY_VALUES : [privacy] From 450ee7dde2c8373dd7a42d00e27bbfe61e720e67 Mon Sep 17 00:00:00 2001 From: Javier Arce Date: Mon, 28 Apr 2014 15:48:01 +0200 Subject: [PATCH 5/5] CDB-1442 #fixes Sort dropdown tags by name --- .../javascripts/cartodb/dashboard/filters/tag_dropdown.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/assets/javascripts/cartodb/dashboard/filters/tag_dropdown.js b/lib/assets/javascripts/cartodb/dashboard/filters/tag_dropdown.js index 5b85e186bdb9..02f30ba61705 100644 --- a/lib/assets/javascripts/cartodb/dashboard/filters/tag_dropdown.js +++ b/lib/assets/javascripts/cartodb/dashboard/filters/tag_dropdown.js @@ -82,7 +82,7 @@ cdb.admin.TagDropdown = cdb.ui.common.Dropdown.extend({ var self = this; this.tags.fetch({ data: { - o: { name: "desc" }, + order: "name", type: self.model.get("type") }, success: function() {