Merge branch 'master' of github.com:Vizzuality/cartodb

1.0
Javier Álvarez Medina 14 years ago
commit 671cdd4edb

@ -8,19 +8,11 @@ class Admin::TablesController < ApplicationController
current_page = params[:page].nil? ? 1 : params[:page].to_i
per_page = 10
unless params[:public]
@tags = Tag.fetch("select tags.name, count(*) as count
from tags
where tags.user_id = ?
group by tags.name
order by count desc limit 5", current_user.id).all
@tags = Tag.load_user_tags(current_user.id, :limit => 5)
@tables = Table.filter(:user_id => current_user.id).order(:id).reverse.select(:id,:name,:privacy,:updated_at,:tags).
paginate(current_page, per_page, current_user.tables_count)
paginate(current_page, per_page, current_user.tables_count)
else
@tags = Tag.fetch("select tags.name, count(*) as count
from tags
where tags.user_id != ?
group by tags.name
order by count desc limit 5", current_user.id).all
@tags = Tag.load_public_tags(current_user.id, :limit => 5)
@tables = Table.filter(~{:user_id => current_user.id} & {:privacy => Table::PUBLIC}).order(:id).reverse.
select(:id,:name,:privacy,:updated_at,:tags).paginate(current_page, per_page)
render :template => 'admin/tables/index_public' and return

@ -6,4 +6,23 @@ class Tag < Sequel::Model
# Allowed columns
set_allowed_columns(:name)
def self.load_user_tags(user_id, options = {})
options[:limit] ||= 5
fetch("select tags.name, count(*) as count
from tags
where tags.user_id = ?
group by tags.name
order by count desc limit 5", user_id).all
end
def self.load_public_tags(user_id, options = {})
options[:limit] ||= 5
fetch("select tags.name, count(*) as count
from tags
inner join user_tables on user_tables.id = tags.table_id and user_tables.privacy = #{Table::PUBLIC}
where tags.user_id != ?
group by tags.name
order by count desc limit 5", user_id).all
end
end

@ -184,6 +184,11 @@ feature "Dashboard", %q{
page.should have_content("21 Public tables in cartoDB")
page.should have_content("BROWSE BY TAGS")
page.should have_css("ul li:eq(1) a span", :text => "vodka")
page.should have_css("ul li a span", :text => "restaurants")
page.should have_no_css("ul li a span", :text => "drinking")
within("ul.your_tables li:eq(1)") do
page.should have_link("Favourite restaurants")
page.should have_content("PUBLIC")

@ -0,0 +1,29 @@
require File.expand_path(File.dirname(__FILE__) + '/acceptance_helper')
feature "Tables" do
background do
@user = create_user
@table = create_table :user_id => @user.id, :name => 'Twitter followers', :privacy => Table::PUBLIC
login_as @user
click_link_or_button("Twitter followers")
end
scenario "Toggle the privacy of a table" do
# Toggle to private
click_link_or_button("PUBLIC")
page.find("span.privacy_window ul li.private a").click
page.should have_css("p.status", :text => 'private')
page.find("div.performing_op p.success").text.should == 'The status has been changed'
# Toggle to public
page.find("p.status a").click
page.find("span.privacy_window ul li.public a").click
page.should have_css("p.status", :text => 'public')
page.find("div.performing_op p.success").text.should == 'The status has been changed'
end
end
Loading…
Cancel
Save