Skip to content

Commit

Permalink
bugfix wiki page order on document => now it is fully working
Browse files Browse the repository at this point in the history
  • Loading branch information
vvmruder committed Sep 15, 2016
1 parent 4fd0bfc commit be24978
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
11 changes: 8 additions & 3 deletions app/controllers/doc_pu_wiki_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,21 @@ def edit

# Edit page order
def edit_order
ordered_wikis = @doc_pu.doc_pu_wiki_pages.all
ordered_wikis = @doc_pu.doc_pu_wiki_pages.all.order(wiki_page_order: :asc).to_a
wiki = DocPuWikiPage.find(params[:id])
move_to = params[:doc_pu_wiki][:move_to]
ordered_wikis.delete(wiki)
# $latex_logger.error(move_to)
# $latex_logger.error(ordered_wikis)
case move_to
when 'highest' then ordered_wikis.insert(0, wiki)
when 'lowest' then ordered_wikis.insert(-1, wiki)
when 'higher' then ordered_wikis.insert(wiki.wiki_page_order - 1, wiki)
when 'lower' then ordered_wikis.insert(wiki.wiki_page_order + 1, wiki)
end
end
# $latex_logger.error(ordered_wikis)
reorder_pages(ordered_wikis)
# $latex_logger.error(ordered_wikis)
redirect_to :controller => :doc_pu, :action => :edit, :project_id => @project, :id => @doc_pu
end

Expand Down Expand Up @@ -83,7 +87,8 @@ def reorder_pages(ordered_pages)
page.wiki_page_order = idx
page.save
idx += 1
end
end
$latex_logger.error(page)
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/doc_pu_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def build(filename = nil)

# Get wiki pages
def wiki_pages
self.doc_pu_wiki_pages.all
self.doc_pu_wiki_pages.all.order(wiki_page_order: :asc)
end

def get_flags_from_str
Expand Down
2 changes: 1 addition & 1 deletion app/views/doc_pu_wiki/_list.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</tr></thead>

<tbody>
<% @doc_pu_wikis.all.each do |page| %>
<% @doc_pu_wikis.all.order(wiki_page_order: :asc).each do |page| %>
<tr class="<%= cycle('odd', 'even') %>">
<td><%= link_to page.wiki_page.title, {:controller => :doc_pu_wiki, :action => :edit, :project_id => @project, :doc_pu_id => @doc, :id => page} %></td>
<td><%= page.chapter_name %></td>
Expand Down

0 comments on commit be24978

Please sign in to comment.