Skip to content

Commit

Permalink
[webui] Add helper for toggling and slice texts. Also replace extende…
Browse files Browse the repository at this point in the history
…r calls with it
  • Loading branch information
Moises Deniz Aleman committed Jan 24, 2017
1 parent 5b98c83 commit fa670c8
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
14 changes: 14 additions & 0 deletions src/api/app/helpers/webui/webui_helper.rb
Expand Up @@ -411,4 +411,18 @@ def word_break(string, length)
# adds a <wbr> tag after an amount of given characters
safe_join(string.scan(/.{1,#{length}}/), "<wbr>".html_safe)
end

def toggle_sliced_text(text, slice_length = 50, id = "toggle_sliced_text_#{Time.now.to_f.to_s.delete('.')}")
return text if text.length < slice_length
javascript_toggle_code = "$(\"[data-toggle-id='".html_safe + id + "']\").toggle();".html_safe
short = content_tag(:span, 'data-toggle-id' => id) do
content_tag(:span, text.slice(0, slice_length) + ' ') +
link_to('[+]', '#', onclick: javascript_toggle_code)
end
long = content_tag(:span, 'data-toggle-id' => id, :style => 'display: none;') do
content_tag(:span, text + ' ') +
link_to('[-]', '#', onclick: javascript_toggle_code)
end
short + long
end
end
6 changes: 1 addition & 5 deletions src/api/app/views/webui/request/_issues_table.html.erb
@@ -1,8 +1,4 @@
<% if issues.present? %>
<% content_for :ready_function do %>
$('.expandable_issue_description').expander({slicePoint: 50, sliceEarlierAt: '<br>', expandText: '[+]', expandPrefix: ' ', userCollapseText: '[-]',});
<% end %>

<table>
<tbody>
<% issues.each do |long_name, issue| %>
Expand All @@ -23,7 +19,7 @@
<% end %>
<% if issue[:summary] %>
<tr class="odd">
<td colspan="3" class="expandable_issue_description"><%= issue[:summary] %></td>
<td colspan="3"><%= toggle_sliced_text(issue[:summary]) %></td>
</tr>
<% end %>
<% end %>
Expand Down
8 changes: 2 additions & 6 deletions src/api/app/views/webui/request/_recent_events_table.html.erb
@@ -1,7 +1,3 @@
<%= content_for :ready_function do %>
$('.expandable_event_comment').expander({slicePoint: 48, sliceEarlierAt: '<br>', expandText: '[+]', expandPrefix: ' ', userCollapseText: '[-]',});
<% end %>

<table>
<tbody>
<!-- add a history item based on the request creation information -->
Expand All @@ -18,7 +14,7 @@
</td>
</tr>
<tr class="odd">
<td colspan="3" class="expandable_event_comment"><pre class="plain"><%= @bsreq.description %></pre></td>
<td colspan="3" class="expandable_event_comment"><pre class="plain"><%= toggle_sliced_text(@bsreq.description, 48) %></pre></td>
</tr>
<!-- and now everything from the history log -->
<% @history.each do |element| %>
Expand All @@ -40,7 +36,7 @@
</tr>
<% unless element.comment.blank? %>
<tr class="odd">
<td colspan="3" class="expandable_event_comment"><pre class="plain"><%= element.comment %></pre></td>
<td colspan="3" class="expandable_event_comment"><pre class="plain"><%= toggle_sliced_text(element.comment, 48) %></pre></td>
</tr>
<% end %>
<% end %>
Expand Down
6 changes: 1 addition & 5 deletions src/api/app/views/webui/request/show.html.erb
Expand Up @@ -2,10 +2,6 @@
<% @layouttype = 'custom' %>
<% @crumb_list = ["Request #{@number}"] %>

<%= content_for :ready_function do %>
$('#description-text').expander({slicePoint: 300, expandText: '[+]', expandPrefix: ' ', userCollapseText: '[-]',});
<% end %>

<div id="request_navigation_box" style="position: absolute; right: 0.3em;">
<% if @request_before -%>
<%= link_to '<<', request_show_path(@request_before), data: { keybinding: "h" } %>
Expand All @@ -19,7 +15,7 @@
<%= render :partial => 'tabs' %>
<div class="grid_10 alpha">
<h3><%= @pagetitle %> (<%= @state %>)</h3>
<%= description_wrapper(@req['description']) %>
<%= description_wrapper(toggle_sliced_text(@req['description'], 300)) %>

<div class="grid_16 alpha omega">

Expand Down

0 comments on commit fa670c8

Please sign in to comment.