Skip to content

Commit

Permalink
Wiki Route working fine
Browse files Browse the repository at this point in the history
  • Loading branch information
SidharthBansal committed Jan 25, 2018
1 parent ceb7d05 commit 73375f6
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 58 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ DEPENDENCIES
mustermann (~> 0.4)
mysql2 (~> 0.3.20)
nifty-generators
paperclip (< 4.2.0)
paperclip (~> 4.2.2)
passenger
php-serialize
progress_bar
Expand Down
51 changes: 41 additions & 10 deletions app/controllers/tag_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ def show
.references(:term_data)
.where('term_data.name = ?', params[:id])
@length = Tag.contributor_count(params[:id]) || 0

@tagnames = [params[:id]]
@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 @@ -132,36 +135,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
42 changes: 26 additions & 16 deletions app/views/tag/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@
<%= render :partial => "tag/graph", locals: { tags: @tags } %>
<% end %>

<% if params[:action] == 'show' %>
<h3><%= raw t('tag.show.notes_tagged', tag: params[:id]) %>
<% elsif %>
<h3> Notes on <%= params[:id] %> by <%= link_to(@user.name,"/profile/"+@user.name) %> </h3>
<% if params[:action] == 'show'&& @node_type=="contributors" %>
<h3><%= raw t('tag.contributors.contributors_for', :tag_name => params[:id]) %></h3>
<% elsif params[:action] == 'show' %>
<h3><%= raw t('tag.show.notes_tagged', tag: params[:id]) %></h3>
<% else %>
<h3> Notes on <%= params[:id] %> by <%= link_to(@user.name,"/profile/@user.name") %> </h3>
<% end %>
<% unless @tags.try(:first).try(:parent).nil? %> <small>parent: <%= @tags.first.parent %></small><% end %></h3>

<h3><% unless @tags.try(:first).try(:parent).nil? %><small>parent: <%= @tags.first.parent %></small><% end %></h3>
<%= render :partial => "notes/format_toggle" if @node_type == "note" %>

<% if current_user %>
Expand All @@ -47,11 +50,11 @@
<a class="btn btn-default btn-sm" href="/feed/tag/<%= params[:id] %>.rss"><i class="fa fa-rss"></i> RSS</a>
<% unless @wildcard %>
<% if current_user.following(params[:id]) %>
<a rel="tooltip" title="<%= t('tag.show.unfollow') %>" class="btn btn-default btn-sm active" href="/unsubscribe/tag/<%= params[:id] %>" data-method="delete"><i class="fa fa-eye"></i> <%= t('tag.show.following') %> <b><%= params[:id] %></b></a>
<a rel="tooltip" title="<%= t('tag.show.unfollow') %>" class="btn btn-default btn-sm active" href="/unsubscribe/tag/<%= params[:id] %>" data-method="delete"><i class="fa fa-eye"></i> <%= t('tag.show.following') %> <b><%= params[:id] %></b></a>
<% else %>
<a class="btn btn-default btn-sm" href="/subscribe/tag/<%= params[:id] %>"><i class="fa fa-eye"></i> <%= t('tag.show.follow') %> <b><%= params[:id] %></b></a>
<a class="btn btn-default btn-sm" href="/subscribe/tag/<%= params[:id] %>"><i class="fa fa-eye"></i> <%= t('tag.show.follow') %> <b><%= params[:id] %></b></a>
<% end %>
<a class="btn btn-default btn-sm" rel="popover" data-placement="bottom" data-html="true" data-title="<%= t('tag.show.users_following_tag') %>" data-content="<% Tag.followers(params[:id]).each do |user| %><i class='fa fa-star-o'></i> <a href='/profile/<%= user.username %>'><%= user.username %></a><br /><% end %><% if Tag.follower_count(params[:id]) == 0 %><i><%= t('tag.show.none') %></i><% end %>"><%= Tag.follower_count(params[:id]) %> <i class="fa fa-user"></i> <span class="caret"></span></a>
<a class="btn btn-default btn-sm" rel="popover" data-placement="bottom" data-html="true" data-title="<%= t('tag.show.users_following_tag') %>" data-content="<% Tag.followers(params[:id]).each do |user| %><i class='fa fa-star-o'></i> <a href='/profile/<%= user.username %>'><%= user.username %></a><br /><% end %><% if Tag.follower_count(params[:id]) == 0 %><i><%= t('tag.show.none') %></i><% end %>"><%= Tag.follower_count(params[:id]) %> <i class="fa fa-user"></i> <span class="caret"></span></a>
<% end %>
</div>
<!-- AJAXify -->
Expand All @@ -65,15 +68,11 @@
<li<% if @node_type == "questions" %> class="active"<% end %>><a href="/questions/tag/<%= params[:id] %>"><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] %>"><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] %>"><i class="fa fa-map-marker"></i> <%= t('tag.show.maps') %></a></li>
<% if !@wildcard %>
<li<% if @node_type == "contributors" %> class="active"<% end %>><a href="/contributors/<%= 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 == "contributors" %> class="active"<% end %>><a href="#" rel="tooltip" title="Contributors cannot be listed for wildcard tag searches" ><i class="fa fa-user"></i> <%= raw t('tag.show.contributors') %></a></li>
<% end %>
<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 Expand Up @@ -113,7 +112,18 @@
</div>
<% end %>

<% if @node_type == "contributors" %>
<div class="tab-pane active" id="contributors">
<div class="row">
<div class="col-md-9" style="padding-left: 46px">
<%= render :partial => "tag/contributors" %>
</div>
</div>
</div>
<% end %>
<br />
<hr />

</div>

</div>
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,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

0 comments on commit 73375f6

Please sign in to comment.