diff --git a/lib/cms_helper.rb b/lib/cms_helper.rb index c581afe..2dd6fb6 100644 --- a/lib/cms_helper.rb +++ b/lib/cms_helper.rb @@ -10,7 +10,11 @@ module CmsHelper image_tag(icon_for_article(article)) + link_to(article_name, article.url) else if "ProposalsDiscussionPlugin::Proposal".eql? article.type - link_to article.abstract, article.url, :class => icon_for_article(article) + if article.children_count > 0 + link_to article.abstract, {:action => 'view', :id => article.id}, :class => 'icon icon-replyied-article' + else + link_to article.abstract, article.url, :class => icon_for_article(article) + end else link_to article_name, article.url, :class => icon_for_article(article) end diff --git a/lib/proposals_discussion_plugin/api_new_relic_instrumenter.rb b/lib/proposals_discussion_plugin/api_new_relic_instrumenter.rb new file mode 100644 index 0000000..1b43c7f --- /dev/null +++ b/lib/proposals_discussion_plugin/api_new_relic_instrumenter.rb @@ -0,0 +1,46 @@ +class ProposalsDiscussionPlugin::ApiNewRelicInstrumenter < Grape::Middleware::Base + include NewRelic::Agent::Instrumentation::ControllerInstrumentation + + def call_with_newrelic(&block) + trace_options = { + :category => :rack, + :path => "#{route_path}\##{route_method}", + :request => Grape::Request.new(@env) + } + + perform_action_with_newrelic_trace(trace_options) do + result = yield + MetricFrame.abort_transaction! if result.first == 404 # ignore cascaded calls + result + end + end + + def call(env) + @env = env + if ENV['NEW_RELIC_ID'] + call_with_newrelic do + super + end + else + super + end + end + + def env + @env + end + + def route + env['api.endpoint'].routes.first + end + + def route_method + route.route_method.downcase + end + + def route_path + path = route.route_path.gsub(/^.+:version\/|^\/|:|\(.+\)/, '').tr('/', '-') + "api.#{route.route_version}.#{path}" + end + +end diff --git a/lib/proposals_discussion_plugin/response.rb b/lib/proposals_discussion_plugin/response.rb index 9913560..b6fde32 100644 --- a/lib/proposals_discussion_plugin/response.rb +++ b/lib/proposals_discussion_plugin/response.rb @@ -12,16 +12,16 @@ class ProposalsDiscussionPlugin::Response < TinyMceArticle _("The response of a Proposal") end + def icon_name + 'response' + end + protected def check_parent_type unless parent.is_a? ProposalsDiscussionPlugin::Proposal errors.add(:parent, N_('of Response needs be a Proposal')) end - - # if self.body_changed? && (self.changed & attrs_validators).any? - # errors.add(:response, N_('only have "body" field')) - # end end end diff --git a/public/images/replyied-article.png b/public/images/replyied-article.png new file mode 100644 index 0000000..6b83000 Binary files /dev/null and b/public/images/replyied-article.png differ diff --git a/public/images/response-article.png b/public/images/response-article.png new file mode 100644 index 0000000..c45d94f Binary files /dev/null and b/public/images/response-article.png differ diff --git a/public/style.css b/public/style.css index 33fbb40..0cabca5 100644 --- a/public/style.css +++ b/public/style.css @@ -406,3 +406,11 @@ div.confirm_evaluation_button a.disabled { .icon-child-article { background-image: url('/plugins/proposals_discussion/images/reply.png'); } + +.icon-response { + background: url('/plugins/proposals_discussion/images/response-article.png') no-repeat; +} + +.icon-replyied-article { + background: url('/plugins/proposals_discussion/images/replyied-article.png') no-repeat; +} diff --git a/test/unit/proposal_test.rb b/test/unit/proposal_test.rb index e9dad70..755e081 100644 --- a/test/unit/proposal_test.rb +++ b/test/unit/proposal_test.rb @@ -156,4 +156,20 @@ class ProposalTest < ActiveSupport::TestCase assert_match "Body can't be blank", err.message end + should 'not add a response to a article that isnt a proposal' do + article = create(Article, :name => 'test article', :profile => @profile) + data = { + :name => 'Response', + :abstract => 'Test', + :parent => article, + :profile => profile + } + + err = assert_raises ActiveRecord::RecordInvalid do + response = create(ProposalsDiscussionPlugin::Response, data) + end + + assert_match "Parent of Response needs be a Proposal", err.message + end + end diff --git a/views/cms/proposals_discussion_plugin/_response.html.erb b/views/cms/proposals_discussion_plugin/_response.html.erb index 0ab4ad7..8d3d75c 100644 --- a/views/cms/proposals_discussion_plugin/_response.html.erb +++ b/views/cms/proposals_discussion_plugin/_response.html.erb @@ -10,14 +10,16 @@
<%= required labelled_form_field _('Title'), limited_text_area(:article, :name, title_limit, 'title_textarea', :rows => 1) %>
- - <%= select_profile_folder(_('Parent folder:'), 'article[parent_id]', profile, @article.parent_id, {},{},{},:include_articles => true) %> + <% if @article.parent_id.nil? %> + <%= select_profile_folder(_('Parent folder:'), 'article[parent_id]', profile, @article.parent_id, {},{},{},:include_articles => true) %> + <% else %> + <%= hidden_field(:article, :parent_id) %> + <% end %>
<%= labelled_form_field(_('Response'), text_area(:article, :body, :class => 'mceEditor')) %>
- <%= hidden_field(:article, :parent_id) %>