Class: Wiki::PagesController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Wiki::PagesController
- Defined in:
- app/controllers/wiki/pages_controller.rb
Instance Method Summary collapse
- #add_tag ⇒ Object
- #attach ⇒ Object
- #combined ⇒ Object
- #compare ⇒ Object
- #create ⇒ Object
- #destroy ⇒ Object
- #history ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #remove_tag ⇒ Object
- #reorder ⇒ Object
- #show ⇒ Object
- #star ⇒ Object
- #subpages_dropdown ⇒ Object
- #update ⇒ Object
Instance Method Details
#add_tag ⇒ Object
132 133 134 135 136 137 |
# File 'app/controllers/wiki/pages_controller.rb', line 132 def add_tag @page.tag_list.add(params[:tag]) @page.save @page.__elasticsearch__.index_document render json: {} end |
#attach ⇒ Object
106 107 108 109 110 111 112 113 |
# File 'app/controllers/wiki/pages_controller.rb', line 106 def attach @attachment = Attachment.create_from_uploaded_file(params[:file], current_user, attachable: @page) if @attachment.errors.none? @activity = @page.create_activity key: "page.attachment", owner: current_user, recipient: @attachment end end |
#combined ⇒ Object
57 58 59 60 |
# File 'app/controllers/wiki/pages_controller.rb', line 57 def combined @subtree = @page.subtree.arrange render layout: "minimal" end |
#compare ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'app/controllers/wiki/pages_controller.rb', line 33 def compare version = @page.versions.select{|x| x.sha == params[:version]}.first filename = version.show.first.b_path #TODO: should cache the diffs (store on save page in delayed job) @old_html = version.repo.git.show({}, "#{version.sha}~1:#{filename}").force_encoding('UTF-8') @new_html = version.repo.git.show({}, "#{version.sha}:#{filename}").force_encoding('UTF-8') giri = Nokogiri::HTML(DaisyDiff.strings(@old_html, @new_html)) @diff_html = giri.css("body") @diff_html.css(".diffpage-html-firstlast").remove @diff_html.css("script").remove @diff_html.xpath('//@onclick').remove @diff_html.xpath('//@onload').remove @diff_html.xpath('//@onerror').remove @diff_html.xpath('//@onabort').remove @diff_html.css("[changeid][id], img[changetype]").each do |element| element['data-toggle'] = "tooltip" element['data-title'] = "Here!" element['data-trigger'] = "manual" end end |
#create ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/controllers/wiki/pages_controller.rb', line 9 def create create_params = page_params if params[:markdown_body].present? create_params[:body] = redcarpet(params[:markdown_body]) end @page = Page.new create_params.merge( creator: current_user, parent_id: params[:parent_id] ) if @page.save @page.update_to_gollum(current_user) @page.create_activity key: "page.created", owner: current_user end end |
#destroy ⇒ Object
146 147 148 149 150 151 152 153 154 |
# File 'app/controllers/wiki/pages_controller.rb', line 146 def destroy parent = @page.parent @page.save_and_destroy(current_user) link = root_url link = wiki_page_path(parent) if parent redirect_to link, notice: "Page was deleted.", status: :see_other end |
#history ⇒ Object
30 31 |
# File 'app/controllers/wiki/pages_controller.rb', line 30 def history end |
#index ⇒ Object
5 6 7 |
# File 'app/controllers/wiki/pages_controller.rb', line 5 def index @roots = Page.roots end |
#new ⇒ Object
82 83 84 |
# File 'app/controllers/wiki/pages_controller.rb', line 82 def new @page = Page.new creator: current_user end |
#remove_tag ⇒ Object
139 140 141 142 143 144 |
# File 'app/controllers/wiki/pages_controller.rb', line 139 def remove_tag @page.tag_list.remove(params[:tag]) @page.save @page.__elasticsearch__.index_document render json: {} end |
#reorder ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'app/controllers/wiki/pages_controller.rb', line 86 def reorder old_parent_id = @page.parent_id old_position = @page.position if @page.reorder!( parent_id: params[:parent_id], position: params[:position] ) @activity = @page.create_activity key: "page.reorder", owner: current_user, parameters: { from_parent_id: old_parent_id, old_position: old_position, parent_id: params[:parent_id], position: params[:position] } end render json: {} end |
#show ⇒ Object
24 25 26 27 28 |
# File 'app/controllers/wiki/pages_controller.rb', line 24 def show @space = @page.root @subtree = @page.subtree.group_by(&:parent_id) @last_updated = @page.last_updated end |
#star ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'app/controllers/wiki/pages_controller.rb', line 119 def star starred = Starred.where(user_id: current_user.id, starrable_id: @page, starrable_type: @page.class).first if starred && params[:to_star] == "false" starred.destroy end if !starred && params[:to_star] == "true" Starred.create(user: current_user, starrable: @page) end render json: {} end |
#subpages_dropdown ⇒ Object
115 116 117 |
# File 'app/controllers/wiki/pages_controller.rb', line 115 def subpages_dropdown render partial: 'subpages_dropdown' end |
#update ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'app/controllers/wiki/pages_controller.rb', line 62 def update update_params = params.require(params[:type]).permit( :title, :body, ) if params[:markdown_body].present? update_params[:body] = redcarpet(params[:markdown_body]) end if (params[:timestamp].present? && @page.last_updated.present?) && ((params[:timestamp].present? && !@page.last_updated.present?) || @page.last_updated.try(:created_at) != Time.parse(params[:timestamp])) @page.errors.add(:base, "This page was edited by someone. Please refresh to get the updated changes. Refreshing the page will remove the your changes.") end if @page.errors.none? && @page.update_attributes(update_params) @page.update_to_gollum(current_user) @last_updated = @page.create_activity key: "page.update_details", owner: current_user end end |