Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added BDD feature management / Basic PDF export #3

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Export_Example.pdf
Binary file not shown.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# TODO There is a mechanism that automatically scans this file. Which is it?
# source "http://rubygems.org"
gem "pdfkit", "0.6.2"
group :test do
#gem 'ZenTest', "4.8.3" // is not used at the moment (27 feb 2014)
end
8 changes: 8 additions & 0 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ You can find an online demo of Redmine RE here: http://redmine-re.korem.de:8080.

You can find information about how to install the Redmine RE here: http://redmine-re.korem.de/projects/redmine-re/wiki/Installing_Redmine_RE.

== Export Function

The export functionality relies on the {pdfkit}[https://github.com/pdfkit/pdfkit] library which uses {wkhtmltopdf}[https://github.com/wkhtmltopdf/wkhtmltopdf] to generate PDF files from pure HTML.
Currently the export function is very basic. The following things could be added in the future: Revision Table, Meta Information, Table of Contents, Page Numbers.

It is recommended to install wkhtmltopdf from a package distributed via the {project page}[http://wkhtmltopdf.org/downloads.html] instead of using your OS package manager, because the distributed packages are newer and should work without big configuration effort out of the box.
The function was tested with a fresh installed ubuntu 12.04 server using the described way.

== Acknowledgments

* This project relies heavily on Redmine.
Expand Down
51 changes: 50 additions & 1 deletion app/controllers/re_artifact_properties_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def create
def show
@re_artifact_properties = ReArtifactProperties.find(params[:id])
@artifact_type = @re_artifact_properties.artifact_type

session[:visualization_type]=params[:visualization_type]

if @artifact_type == "Project"
Expand Down Expand Up @@ -452,6 +452,55 @@ def autocomplete_parent
list << '</ul>'
render :text => list
end

def download
#@todo only allow for BDD Features, not for all other artifacts
@re_artifact_properties = ReArtifactProperties.find(params[:id])
feature = ActiveSupport::JSON.decode(@re_artifact_properties.description)

file_content = 'Feature: ' + feature['name'] + "\n"

feature['description'].each do |line|
file_content = file_content + "\s\s"+ line + "\n"
end

file_content = file_content + "\n"

if feature['background'] != nil

if feature['background']['steps'].length > 0
file_content = file_content + ' Background:' + "\n"

feature['background']['steps'].each do |step|
step_chunks = step.split('#')

spaces = 11 - step_chunks[0].length

file_content = file_content + (' '*spaces) + step_chunks[0] + ' ' + step_chunks[1] + "\n"
end

file_content = file_content + "\n"

end
end

feature['scenarios'].each do |scenario|
file_content = file_content + ' Scenario: ' + scenario['name'] + "\n"

scenario['steps'].each do |step|

step_chunks = step.split('#')

spaces = 11 - step_chunks[0].length

file_content = file_content + (' '*spaces) + step_chunks[0] + ' ' + step_chunks[1] + "\n"

end

end

send_data file_content, :filename => "test.feature"
end

private

Expand Down
16 changes: 14 additions & 2 deletions app/controllers/requirements_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
include ReApplicationHelper

require 'exporter'
class RequirementsController < RedmineReController
unloadable
menu_item :re
Expand Down Expand Up @@ -131,7 +131,19 @@ def add_relation
redirect_to @re_artifact_properties
end
end


def export
# For testing purposes ignore from which node the export attempt was started.
# Allow flexible export later, e.g. only sub-tree or re-arrange on the fly (visual editor)
root_node = ReArtifactProperties.find_by_project_id_and_artifact_type(@project.id, "Project")

u = url_for(:controller => 're_artifact_properties', :action => 'show', :id => "XX")

exporter = Exporter.new(root_node, u)

send_data exporter.get_pdf, :filename => "export.pdf"
end

#######
private
#######
Expand Down
2 changes: 1 addition & 1 deletion app/models/re_artifact_properties.rb
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def attributes=(attributes = {})
validates :updated_by, :presence => true
validates :parent, :presence => true, :unless => Proc.new { |a| a.artifact_type == "Project" }
validates :artifact_type, :presence => true, :inclusion => {
:in => %w(ReGoal ReSection ReVision ReTask ReSubtask ReVision ReWorkarea ReUserProfile ReSection ReRequirement ReScenario ReProcessword ReRational ReUseCase ReRationale Project)}
:in => %w(ReGoal ReSection ReVision ReTask ReSubtask ReVision ReWorkarea ReUserProfile ReSection ReRequirement ReScenario ReProcessword ReRational ReUseCase ReRationale ReFeature Project)}

#TODO
#validates_associated :parent_relation
Expand Down
8 changes: 8 additions & 0 deletions app/models/re_feature.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class ReFeature < ActiveRecord::Base
unloadable

INITIAL_COLOR="#00ccff"

acts_as_re_artifact

end
23 changes: 18 additions & 5 deletions app/views/re_artifact_properties/_action_menu.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
<div class="contextual">
<%= link_to_if_authorized(t(:button_update), {
:controller => 're_artifact_properties',
:action => 'edit', :id => @re_artifact_properties },
:onclick => 'showAndScrollTo("update", "re_artifact_properties_description"); scrollContentPaneTo("update"); return false;',
:class => 'icon icon-edit', :accesskey => accesskey(:edit) ) %>

<% if @re_artifact_properties.artifact_type == 'ReFeature' %>
<%= link_to 'Download', 'download/'+@re_artifact_properties.id.to_s, { :class => 'icon icon-download' } %>
<% end %>

<% if @re_artifact_properties.artifact_type == 'ReFeature' %>
<%= link_to_if_authorized(t(:button_update), {
:controller => 're_artifact_properties',
:action => 'edit', :id => @re_artifact_properties },
:class => 'icon icon-edit', :accesskey => accesskey(:edit) ) %>
<% else %>
<%= link_to_if_authorized(t(:button_update), {
:controller => 're_artifact_properties',
:action => 'edit', :id => @re_artifact_properties },
:onclick => 'showAndScrollTo("update", "re_artifact_properties_description"); scrollContentPaneTo("update"); return false;',
:class => 'icon icon-edit', :accesskey => accesskey(:edit) ) %>
<% end %>

<%= watcher_tag(@re_artifact_properties, User.current) %>

<span class="icon icon-add">
Expand Down
143 changes: 143 additions & 0 deletions app/views/re_artifact_properties/_bdd_feature.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
<div id="bdd_feature_form">

<input id="bdd_feature_serialized" type="hidden" name="re_artifact_properties[description]">

<strong class="bdd_keyword">Feature:</strong>
<input id="bdd_feature_name" class="bbd_feature_name_input" type="text" value="<%=t :bdd_feature_description %>" data-touched="0" onblur="handleInputBlurEvent(this)" onfocus="handleInputFocusEvent(this)"/>

<%= image_tag 'icons/add.png', :onclick => 'addFeatureOutline()', :class => 'bdd_click_image', :plugin => 'redmine_re' %>
<%= image_tag 'icons/delete.png', :onclick => 'removeFeatureOutline()', :class => 'bdd_click_image', :plugin => 'redmine_re' %>

<!--
<%= image_tag 'icons/information.png', :plugin => 'redmine_re' %>
-->
<br/>
<div id="bdd_feature_outline">
<input class="bdd_feature_outline" name="bdd_feature_outline_1" type="text" value="<%=t :bdd_feature_outline_hint_1 %>" data-touched="0" onblur="handleInputBlurEvent(this)" onfocus="handleInputFocusEvent(this)"/> <br />
<input class="bdd_feature_outline" name="bdd_feature_outline_2" type="text" value="<%=t :bdd_feature_outline_hint_2 %>" data-touched="0" onblur="handleInputBlurEvent(this)" onfocus="handleInputFocusEvent(this)"/> <br />
<input class="bdd_feature_outline" name="bdd_feature_outline_3" type="text" value="<%=t :bdd_feature_outline_hint_3 %>" data-touched="0" onblur="handleInputBlurEvent(this)" onfocus="handleInputFocusEvent(this)"/> <br />
<input class="bdd_feature_outline" name="bdd_feature_outline_4" type="text" value="<%=t :bdd_feature_outline_hint_4 %>" data-touched="0" onblur="handleInputBlurEvent(this)" onfocus="handleInputFocusEvent(this)"/> <br />
<br/>
</div>
<button onclick="addScenario(event)"><%=t :bdd_feature_add_scenario_btn %></button>
<button onclick="removeScenario(event)"><%=t :bdd_feature_remove_scenario_btn %></button>
<button id="toggleBackgroundBoxBtn" onclick="toggleScenarioBackgroundBox(event)"><%=t :bdd_background_toggle_btn %></button>
<br/>
<br/>
<!-- Optional Background Form for Scenario(s) -->
<div id="bdd_scenario_background_box" class="bdd_scenario_background_container" data-toggle="0">

<strong class="bdd_keyword">Background:</strong>
<%= image_tag 'icons/add.png', :onclick => 'addScenarioStep(this)', :class => 'bdd_click_image_dis', :plugin => 'redmine_re' %>
<%= image_tag 'icons/delete.png', :onclick => 'removeScenarioStep(this)', :class => 'bdd_click_image_dis', :plugin => 'redmine_re' %>
<br />

<div class="bdd_scenario_outline_step">
<select disabled class="bdd_keyword">
<option>Given</option>
<option>When</option>
<option>Then</option>
<option>And</option>
<option>But</option>
</select>

<input disabled class="bdd_scenario_outline" type="text" value="<%=t :bdd_feature_scenario_outline_hint_1 %>" data-touched="0" onblur="handleInputBlurEvent(this)" onfocus="handleInputFocusEvent(this)"/>
</div>

<div class="bdd_scenario_outline_step">
<select disabled class="bdd_keyword">
<option>Given</option>
<option selected>When</option>
<option>Then</option>
<option>And</option>
<option>But</option>
</select>

<input disabled class="bdd_scenario_outline" type="text" value="<%=t :bdd_feature_scenario_outline_hint_2 %>" data-touched="0" onblur="handleInputBlurEvent(this)" onfocus="handleInputFocusEvent(this)"/>
</div>

<div class="bdd_scenario_outline_step">
<select disabled class="bdd_keyword">
<option>Given</option>
<option>When</option>
<option selected>Then</option>
<option>And</option>
<option>But</option>
</select>

<input disabled class="bdd_scenario_outline" type="text" value="<%=t :bdd_feature_scenario_outline_hint_3 %>" data-touched="0" onblur="handleInputBlurEvent(this)" onfocus="handleInputFocusEvent(this)"/>
</div>

<div class="bdd_scenario_outline_step">
<select disabled class="bdd_keyword">
<option>Given</option>
<option>When</option>
<option>Then</option>
<option selected>And</option>
<option>But</option>
</select>

<input disabled class="bdd_scenario_outline" type="text" value="<%=t :bdd_feature_scenario_outline_hint_4 %>" data-touched="0" onblur="handleInputBlurEvent(this)" onfocus="handleInputFocusEvent(this)"/>
</div>

</div>



<div id="bdd_scenario_box" class="bdd_scenario_container">

<strong class="bdd_keyword">Scenario:</strong> <input class="bbd_scenario_name_input" type="text" value="<%=t :bdd_feature_scenario_description %>" data-touched="0" onblur="handleInputBlurEvent(this)" onfocus="handleInputFocusEvent(this)"/>
<%= image_tag 'icons/add.png', :onclick => 'addScenarioStep(this)', :class => 'bdd_click_image', :plugin => 'redmine_re' %>
<%= image_tag 'icons/delete.png', :onclick => 'removeScenarioStep(this)', :class => 'bdd_click_image', :plugin => 'redmine_re' %>
<br />

<div class="bdd_scenario_outline_step">
<select class="bdd_keyword">
<option>Given</option>
<option>When</option>
<option>Then</option>
<option>And</option>
<option>But</option>
</select>

<input class="bdd_scenario_outline" type="text" value="<%=t :bdd_feature_scenario_outline_hint_1 %>" data-touched="0" onblur="handleInputBlurEvent(this)" onfocus="handleInputFocusEvent(this)"/>
</div>

<div class="bdd_scenario_outline_step">
<select class="bdd_keyword">
<option>Given</option>
<option selected>When</option>
<option>Then</option>
<option>And</option>
<option>But</option>
</select>

<input class="bdd_scenario_outline" type="text" value="<%=t :bdd_feature_scenario_outline_hint_2 %>" data-touched="0" onblur="handleInputBlurEvent(this)" onfocus="handleInputFocusEvent(this)"/>
</div>

<div class="bdd_scenario_outline_step">
<select class="bdd_keyword">
<option>Given</option>
<option>When</option>
<option selected>Then</option>
<option>And</option>
<option>But</option>
</select>

<input class="bdd_scenario_outline" type="text" value="<%=t :bdd_feature_scenario_outline_hint_3 %>" data-touched="0" onblur="handleInputBlurEvent(this)" onfocus="handleInputFocusEvent(this)"/>
</div>

<div class="bdd_scenario_outline_step">
<select class="bdd_keyword">
<option>Given</option>
<option>When</option>
<option>Then</option>
<option selected>And</option>
<option>But</option>
</select>

<input class="bdd_scenario_outline" type="text" value="<%=t :bdd_feature_scenario_outline_hint_4 %>" data-touched="0" onblur="handleInputBlurEvent(this)" onfocus="handleInputFocusEvent(this)"/>
</div>

</div>
</div>
37 changes: 21 additions & 16 deletions app/views/re_artifact_properties/_common_attributes.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,25 @@
<%= f.label :responsible_id, t(:re_artifact_responsible) %>
<%= f.select :responsible_id, options_for_select(selectable_users, select_user_id), :include_blank => true %>
</p>
<p>
<%= f.label :description %>
<span id='update-description'>
<%= f.text_area :description,
:cols => 60,
:rows => (@re_artifact_properties.description.blank? ? 10 : [[10, @re_artifact_properties.description.length / 50].max, 100].min),
:accesskey => accesskey(:edit),
:class => 'wiki-edit' %>
<%= wikitoolbar_for ('re_artifact_properties_description').html_safe %>
<%= javascript_tag do %>
$j(document).ready(function() {
$j("textarea.wiki-edit").autoGrow();
});
<% end %>
</span>
</p>

<% if @re_artifact_properties.artifact_type == 'ReFeature' %>
<%= render :partial => 'bdd_feature' %>
<% else %>
<p>
<%= f.label :description %>
<span id='update-description'>
<%= f.text_area :description,
:cols => 60,
:rows => (@re_artifact_properties.description.blank? ? 10 : [[10, @re_artifact_properties.description.length / 50].max, 100].min),
:accesskey => accesskey(:edit),
:class => 'wiki-edit' %>
<%= wikitoolbar_for ('re_artifact_properties_description').html_safe %>
<%= javascript_tag do %>
$j(document).ready(function() {
$j("textarea.wiki-edit").autoGrow();
});
<% end %>
</span>
</p>
<% end %>
</fieldset>
19 changes: 18 additions & 1 deletion app/views/re_artifact_properties/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,24 @@
<% end %>

initRelationSuggestibles('<%= suggest_artifacts_re_queries_path(@project.id) %>',exceptRelationIDs);



<% if @re_artifact_properties.artifact_type == 'ReFeature' and !@re_artifact_properties.new_record? %>
// Add pre-send hook for proper serialization
addHookToForm('edit');

// Code for generation of BDD Feature View upon page load
var feature_data = '<%= (textilizable @re_artifact_properties, :description) %>';

// Strip unwanted html tags from rails sanitization
feature_data = feature_data.replace('<p>','');
feature_data = feature_data.replace('</p>','');

// Create View
createFeatureViewFormFromJSON(feature_data);
<% else %>
addHookToForm('new');
<% end %>
});
})(jQuery);
<% end %>
10 changes: 10 additions & 0 deletions app/views/re_artifact_properties/_infobar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,15 @@ $j(document).ready(function () {
var easttoggler = $j("div.ui-layout-toggler-east-closed > span.content-closed");
var eastspan = easttoggler.first()
eastspan.html('<%= watchers %><%= image_tag(watcher_image) %><br/><%= comments %><%= image_tag('comments.png')%>');

// Code for generation of BDD Feature View upon page load
var feature_data = '<%= (textilizable @re_artifact_properties, :description) %>';

// Strip unwanted html tags from rails sanitization
feature_data = feature_data.replace('<p>','');
feature_data = feature_data.replace('</p>','');

// Create View
createFeatureViewFromJSON(feature_data);
});
<% end %>
Loading