Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various pages for tagname and authorname #2108

Merged
merged 3 commits into from
Jan 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 38 additions & 10 deletions app/controllers/tag_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def show
@tag = Tag.find_by(name: params[:id])
@noteCount = Tag.taggedNodeCount(params[:id]) || 0
@users = Tag.contributors(@tagnames[0])

respond_with(nodes) do |format|
format.html { render 'tag/show' }
format.xml { render xml: nodes }
Expand All @@ -138,36 +138,64 @@ def show
end

def show_for_author
@wiki = Node.where(path: "/wiki/#{params[:id]}").try(:first) || Node.where(path: "/#{params[:id]}").try(:first)
@wiki = Node.find(@wiki.power_tag('redirect')) if @wiki && @wiki.has_power_tag('redirect')
if params[:id][-1..-1] == '*' # wildcard tags
@wildcard = true
@tags = Tag.where('name LIKE (?)', params[:id][0..-2] + '%')
else
@tags = Tag.where(name: params[:id])
end
@tagname = params[:id]
default_type = if params[:id].match('question:')
'questions'
else
'note'
end

# params[:node_type] - this is an optional param
# if params[:node_type] is nil - use @default_type
@node_type = params[:node_type] || default_type
@user = User.find_by(name: params[:author])
@title = "'" + @tagname.to_s + "' by " + params[:author]
@notes = Tag.tagged_nodes_by_author(@tagname, @user)
.paginate(page: params[:page], per_page: 24)

qids = Node.questions.where(status: 1).collect(&:nid)
nodes = Tag.tagged_nodes_by_author(@tagname, @user)
.paginate(page: params[:page], per_page: 24)

@notes = nodes.where('node.nid NOT IN (?)', qids) if @node_type == 'note'
@unpaginated = true
@node_type = 'note'
@wiki = nil
respond_with(@notes) do |format|
node_type = 'note' if @node_type == 'questions' || @node_type == 'note'
node_type = 'page' if @node_type == 'wiki'
node_type = 'map' if @node_type == 'maps'
@questions = nodes.where('node.nid IN (?)', qids) if @node_type == 'questions'
@wikis = nodes if @node_type == 'wiki'
@nodes = nodes if @node_type == 'maps'
# the following could be refactored into a Tag.contributor_count method:
notes = Node.where(status: 1, type: 'note')
.select('node.nid, node.type, node.uid, node.status, term_data.*, community_tags.*')
.includes(:tag)
.references(:term_data)
.where('term_data.name = ?', params[:id])
@length = Tag.contributor_count(params[:id]) || 0
respond_with(nodes) do |format|
format.html { render 'tag/show' }
format.xml { render xml: @notes }
format.xml { render xml: nodes }
format.json do
json = []
@notes.each do |node|
nodes.each do |node|
json << node.as_json(except: %i[path tags])
json.last['path'] = 'https://' + request.host.to_s + node.path
json.last['path'] = 'https://' + request.host.
to_s + node.path
json.last['preview'] = node.body_preview(500)
json.last['image'] = node.main_image.path(:large) if node.main_image
json.last['tags'] = Node.find(node.id).tags.collect(&:name) if node.tags
end
render json: json
end
end
end
end


def widget
num = params[:n] || 4
Expand Down
6 changes: 3 additions & 3 deletions app/views/tag/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@
<li<% if @node_type == "maps" %> class="active"<% end %>><a href="/maps/tag/<%= params[:id] %>"><i class="fa fa-map-marker"></i> <%= t('tag.show.maps') %></a></li>
<li<% if @node_type == "contributors" %> class="active"<% end %>><a href="/contributors/tag/<%= params[:id] %>"><i class="fa fa-user"></i> <%= raw t('tag.show.contributors') %> <span class="badge"><%=@length %></span></a></li>
<% else %>
<li class="disabled"<% if @node_type == "questions" %> class="active"<% end %>><a href="#" rel="tooltip" title="Questions can't be listed for tag searches with Author"><i class="fa fa-question-circle"></i> <%= t('tag.show.questions') %></a></li>
<li class="disabled"<% if @node_type == "wiki" %> class="active"<% end %>><a href="#" rel="tooltip" title="Wikis can't be listed for tag searches with Authors"><i class="fa fa-book"></i> <%= raw t('tag.show.wiki_pages') %></a></li>
<li class="disabled"<% if @node_type == "maps" %> class="active"<% end %>><a href="#" rel="tooltip" title="Maps can't be listed for tag searches with Authors"><i class="fa fa-map-marker"></i> <%= t('tag.show.maps') %></a></li>
<li<% if @node_type == "questions" %> class="active"<% end %>><a href="/questions/tag/<%= params[:id] %>/author/<%= params[:author] %>" ><i class="fa fa-question-circle"></i> <%= t('tag.show.questions') %></a></li>
<li<% if @node_type == "wiki" %> class="active"<% end %>><a href="/wiki/tag/<%= params[:id] %>/author/<%= params[:author] %>" ><i class="fa fa-book"></i> <%= raw t('tag.show.wiki_pages') %></a></li>
<li<% if @node_type == "maps" %> class="active"<% end %>><a href="/maps/tag/<%= params[:id] %>/author/<%= params[:author] %>" ><i class="fa fa-map-marker"></i> <%= t('tag.show.maps') %></a></li>
<li class="disabled"<% if @node_type == "contributors" %> class="active"<% end %>><a href="#" rel="tooltip" title="Contributors can't be listed for tag searches with Authors" ><i class="fa fa-user"></i> <%= raw t('tag.show.contributors') %></a></li> <% end %>
</ul>

Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
put 'tag/remove_all_tags' => 'tag#remove_all_tags'
get 'tag/:id' => 'tag#show'
get 'tag/:id/author/:author' => 'tag#show_for_author'

get ':node_type/tag/:id/author/:author' => 'tag#show_for_author'
get 'locations/form' => 'tag#location'
get 'locations/modal' => 'tag#location_modal'
get 'embed/grid/:tagname' => 'tag#gridsEmbed'
Expand Down
87 changes: 57 additions & 30 deletions test/functional/tag_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,35 @@ def setup
assert_select '#note-graph', 0
end

test "wildcard tag show wiki pages with author" do
get :show_for_author, node_type: 'wiki', id: 'activity:*', author: 'jeff'
assert :success
assert_not_nil :tags
assert :wildcard
assert :wikis
assert assigns(:wikis).length > 0
assigns['wikis'].each do |node|
assert_equal 2, node.uid
assert node.has_tag('activity:*')
end
assert_select '#note-graph', 0
assert_template 'tag/show'
end

test "tag show wiki pages with author" do
get :show_for_author, node_type: 'wiki', id: 'activity:spectrometer', author: 'jeff'
assert :success
assert_not_nil :tags
assert :wildcard
assert :wikis
assert assigns(:wikis).length > 0
assigns['wikis'].each do |node|
assert_equal 2, node.uid
assert node.has_tag('activity:spectrometer')
end
assert_template 'tag/show'
end

test "wildcard does not show wiki" do
get :show, id: 'question:*', node_type: 'wiki'
assert_equal true, assigns(:wikis).empty?
Expand All @@ -185,36 +214,34 @@ def setup
end

test 'show note with author and tagname without wildcard' do
get :show_for_author, id: 'test', author: 'jeff'
assert_response :success
assert_not_nil :tags
assert_not_nil :authors
assert_not_nil :notes
assert_nil assigns(:wildcard)
assert assigns['notes'].include?(nodes(:one))
assert assigns['notes'].include?(nodes(:question))
assigns['notes'].each do |node|
assert_equal 2, node.uid
assert node.has_tag('test')
end
assert_template 'tag/show'
end

test 'show note with author and tagname with wildcard' do
get :show_for_author, id: 'test*', author: 'jeff'
assert_response :success
assert_not_nil :tags
assert_not_nil :authors
assert_not_nil :notes
assert assigns(:wildcard)
assert assigns['notes'].include?(nodes(:one))
assert assigns['notes'].include?(nodes(:question))
assert assigns['notes'].include?(nodes(:blog))
assigns['notes'].each do |node|
assert_equal 2, node.uid
assert node.has_tag('test*')
end
assert_template 'tag/show'
get :show_for_author, id: 'test', author: 'jeff'
assert_response :success
assert_not_nil :tags
assert_not_nil :authors
assert_not_nil :notes
assert_nil assigns(:wildcard)
assert assigns['notes'].include?(nodes(:one))
assigns['notes'].each do |node|
assert_equal 2, node.uid
assert node.has_tag('test')
end
assert_template 'tag/show'
end

test 'show note with author and tagname with wildcard' do
get :show_for_author, id: 'test*', author: 'jeff'
assert_response :success
assert_not_nil :tags
assert_not_nil :authors
assert_not_nil :notes
assert assigns(:wildcard)
assert assigns['notes'].include?(nodes(:one))
assert assigns['notes'].include?(nodes(:blog))
assigns['notes'].each do |node|
assert_equal 2, node.uid
assert node.has_tag('test*')
end
assert_template 'tag/show'
end

test 'tag widget' do
Expand Down