Class: DcManualRenderer
- Inherits:
-
Object
- Object
- DcManualRenderer
- Includes:
- DcApplicationHelper
- Defined in:
- app/helpers/dc_manual_renderer.rb
Instance Method Summary collapse
-
#default ⇒ Object
Render manual data.
-
#find_document ⇒ Object
Find document.
-
#initialize(parent, opts = {}) ⇒ DcManualRenderer
constructor
A new instance of DcManualRenderer.
-
#list ⇒ Object
List all manuals.
-
#manual_menu ⇒ Object
Create menu.
-
#menu_link_for(menu, parent_path) ⇒ Object
Create link for one page.
- #render_css ⇒ Object
- #render_html ⇒ Object
-
#submenu(menu_item, menu, parent_path) ⇒ Object
Create submenus for a menu.
Constructor Details
#initialize(parent, opts = {}) ⇒ DcManualRenderer
Returns a new instance of DcManualRenderer.
34 35 36 37 38 |
# File 'app/helpers/dc_manual_renderer.rb', line 34 def initialize( parent, opts={} ) @parent = parent @opts = opts self end |
Instance Method Details
#default ⇒ Object
Render manual data
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'app/helpers/dc_manual_renderer.rb', line 131 def default @path = @opts[:path] return list if @path.size == 1 # link for manual settings on the page edit_html = '' if dc_edit_mode? edit_html << @parent.dc_link_for_edit(table: 'dc_memory', title: 'dc_manual.settings', form_name: 'dc_manual_settings', icon: 'book lg', location: @parent.page.class.to_s, field_name: 'params', id: @parent.page.id, action: 'new', element: 'manual' ) end find_document() return "ERROR! #{@parent.params[:path]} #{edit_html}" if @manual.nil? or @manual_page.nil? # if dc_edit_mode? opts = { action: 'edit', table: 'dc_manual', id: @manual._id, title: 'dc_manual.edit' } edit_html << dc_link_for_edit(opts) end # html = %Q[ <div class="wrap"> <div class="row manual"> <div class="column small-12 medium-3 large-4"> #{edit_html}#{()} </div> <div class="column small-12 medium-9 large-8 body">] # # ;add dc_manual_pages no_subsections = @manual_ids.split(';').size table = 'dc_manual' + ';dc_manual_page'*no_subsections form_name = @manual_ids.blank? ? 'dc_manual' : 'dc_manual_page' if dc_edit_mode? unless @manual_ids.blank? opts = { action: 'edit', form_name: form_name, table: table, ids: @manual_ids, 'id' => @manual_page.id, title: I18n.t('dc_manual.edit_chapter', title: @manual_page.title) } html << dc_link_for_edit(opts) + '<br>'.html_safe end # Add new subchapter ids = @manual_ids + (@manual_ids.blank? ? '' : ';') + @manual_page.id.to_s table = 'dc_manual' + ';dc_manual_page'*(no_subsections+1) opts = { controller: 'cmsedit', action: 'new', form_name: 'dc_manual_page', table: table, ids: ids, title: I18n.t('dc_manual.new_chapter', title: @manual_page.title) } html << dc_link_for_create(opts) + '<br>'.html_safe end # can_view, msg = dc_user_can_view(@parent, @manual_page) html << if can_view %Q[<h1>#{@manual_page.title}</h1>#{@manual_page.body}<br> <div class='updated'> #{t('dc_manual.updated')} <b>#{@manual_page.updated_at.strftime('%d.%m.%Y')}</b> </div>] else msg end html << '</div></div></div>' end |
#find_document ⇒ Object
Find document.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'app/helpers/dc_manual_renderer.rb', line 56 def find_document # found bookname in path link book_name_ix = @path.index(@parent.page.link) @manual = DcManual.find_by(link: @path[book_name_ix+1]) if @manual @prepand_path = @path.shift(book_name_ix+2) else # manual_id should be set in page settings manual_id = @opts.dig(:settings, 'manual', 'manual_id') @prepand_path = @path.shift(book_name_ix+1) @manual = DcManual.find(manual_id) if manual_id end return if @manual.nil? # ids for editing manual page @manual_ids = '' # Determine selected page @manual_page = @manual while (link_page = @path.shift) != nil do @manual_ids << (@manual_ids.blank? ? '' : ';') + "#{@manual_page.id}" @manual_page = @manual_page.dc_manual_pages.find_by(link: link_page) if @manual_page.nil? # select first page if path is in error @manual_page = @manual break end end end |
#list ⇒ Object
List all manuals
43 44 45 46 47 48 49 50 51 |
# File 'app/helpers/dc_manual_renderer.rb', line 43 def list html = "<div class='#{@opts[:div] || 'list-manuals'}'>" if @opts[:edit_mode] > 1 html << dc_link_for_create({ controller: 'cmsedit', table: 'dc_manual', title: t('dc_manual.new') }) end manuals = DcManual.where(active: true).sort(title: 1).to_a html << @parent.render( partial: 'dc_manual/list', locals: { manuals: manuals }, formats: [:html] ) html << '</div>' end |
#manual_menu ⇒ Object
Create menu
119 120 121 122 123 124 125 126 |
# File 'app/helpers/dc_manual_renderer.rb', line 119 def = @manual.choices4_all_as_tree html = "<div class=\"title\">#{(.first,[])}</div>" html << (.first, , []) %Q[<ul id="manual-menu" class="is-active menu multilevel-accordion-menu " data-accordion-menu data-submenu-toggle="true"> #{html} </ul>] end |
#menu_link_for(menu, parent_path) ⇒ Object
Create link for one page
87 88 89 90 91 92 |
# File 'app/helpers/dc_manual_renderer.rb', line 87 def (, parent_path) document_link = parent_path + [[4]] document_link.shift # remove link to document name link = "/#{@prepand_path.join('/')}/#{document_link.join('/')}" @parent.link_to([0],link) end |
#render_css ⇒ Object
205 206 207 |
# File 'app/helpers/dc_manual_renderer.rb', line 205 def render_css @manual.try :css end |
#render_html ⇒ Object
195 196 197 198 199 200 |
# File 'app/helpers/dc_manual_renderer.rb', line 195 def render_html method = @opts[:method] || 'default' return "#{self.class}. Method #{method} not defined!" unless method send method end |
#submenu(menu_item, menu, parent_path) ⇒ Object
Create submenus for a menu
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'app/helpers/dc_manual_renderer.rb', line 97 def (, , parent_path) # is active when ids path matches parent path or last (my id) matches manual_page last_item = [1].split(';').last is_active = (@manual_ids.match([1]) or last_item.match(@manual_page.id.to_s)) ? ' is-active' : '' html = parent_path.blank? ? '' : "<li class=\"#{is_active}\">#{(, parent_path)}" # select subpages sub_pages = .select {|e| e[2] == [1]} return html if sub_pages.size == 0 # sub_pages.sort! {|a,b| a[3] <=> b[3]} sub_pages.each do |page| html << %Q[<ul class="menu vertical nested #{is_active}" >] html << (page, , parent_path + [[4]] ) html << '</ul>' end html << '</li>' end |