diff --git a/controllers/myprofile/proposals_discussion_plugin_myprofile_controller.rb b/controllers/myprofile/proposals_discussion_plugin_myprofile_controller.rb new file mode 100644 index 0000000..5f08665 --- /dev/null +++ b/controllers/myprofile/proposals_discussion_plugin_myprofile_controller.rb @@ -0,0 +1,12 @@ +class ProposalsDiscussionPluginMyprofileController < MyProfileController + + def select_topic + @discussion = profile.articles.find(params[:parent_id]) + render :file => 'select_topic' + end + + def new_proposal + redirect_to :controller => 'cms', :action => 'new', :type => "ProposalsDiscussionPlugin::Proposal", :parent_id => params[:discussion][:topic] + end + +end diff --git a/lib/proposals_discussion_plugin.rb b/lib/proposals_discussion_plugin.rb index 6b2c097..23b2d3a 100644 --- a/lib/proposals_discussion_plugin.rb +++ b/lib/proposals_discussion_plugin.rb @@ -18,19 +18,26 @@ class ProposalsDiscussionPlugin < Noosfero::Plugin parent_id = context.params[:parent_id] parent = parent_id ? context.profile.articles.find(parent_id) : nil types << ProposalsDiscussionPlugin::Discussion unless parent - types << ProposalsDiscussionPlugin::Proposal if parent.kind_of?(ProposalsDiscussionPlugin::Discussion) + types << ProposalsDiscussionPlugin::Topic if parent.kind_of?(ProposalsDiscussionPlugin::Discussion) + types << ProposalsDiscussionPlugin::Proposal if parent.kind_of?(ProposalsDiscussionPlugin::Topic) types else - [ProposalsDiscussionPlugin::Discussion, ProposalsDiscussionPlugin::Proposal] + [ProposalsDiscussionPlugin::Discussion, + ProposalsDiscussionPlugin::Topic, + ProposalsDiscussionPlugin::Proposal] end end def content_remove_new(page) - page.kind_of?(ProposalsDiscussionPlugin::Discussion) || page.kind_of?(ProposalsDiscussionPlugin::Proposal) + page.kind_of?(ProposalsDiscussionPlugin::Discussion) || + page.kind_of?(ProposalsDiscussionPlugin::Topic) || + page.kind_of?(ProposalsDiscussionPlugin::Proposal) end def content_remove_upload(page) - page.kind_of?(ProposalsDiscussionPlugin::Discussion) || page.kind_of?(ProposalsDiscussionPlugin::Proposal) + page.kind_of?(ProposalsDiscussionPlugin::Discussion) || + page.kind_of?(ProposalsDiscussionPlugin::Topic) || + page.kind_of?(ProposalsDiscussionPlugin::Proposal) end end diff --git a/lib/proposals_discussion_plugin/discussion.rb b/lib/proposals_discussion_plugin/discussion.rb index daeb514..9c4421f 100644 --- a/lib/proposals_discussion_plugin/discussion.rb +++ b/lib/proposals_discussion_plugin/discussion.rb @@ -1,17 +1,20 @@ class ProposalsDiscussionPlugin::Discussion < Folder + alias :topics :children + + has_many :proposals, :class_name => 'ProposalsDiscussionPlugin::Proposal', :through => :children, :source => :children + def self.short_description _("Discussion") end def self.description - _('Container for proposals.') + _('Container for topics.') end def to_html(options = {}) - discussion = self proc do - render :file => 'content_viewer/discussion', :locals => {:discussion => discussion} + render :file => 'content_viewer/discussion' end end diff --git a/lib/proposals_discussion_plugin/proposal.rb b/lib/proposals_discussion_plugin/proposal.rb index 3863246..6b3028f 100644 --- a/lib/proposals_discussion_plugin/proposal.rb +++ b/lib/proposals_discussion_plugin/proposal.rb @@ -1,5 +1,7 @@ class ProposalsDiscussionPlugin::Proposal < TinyMceArticle + alias :topic :parent + def self.short_description _("Proposal") end @@ -10,4 +12,11 @@ class ProposalsDiscussionPlugin::Proposal < TinyMceArticle validates_presence_of :abstract + + def to_html(options = {}) + proc do + render :file => 'content_viewer/proposal' + end + end + end diff --git a/lib/proposals_discussion_plugin/topic.rb b/lib/proposals_discussion_plugin/topic.rb new file mode 100644 index 0000000..297e343 --- /dev/null +++ b/lib/proposals_discussion_plugin/topic.rb @@ -0,0 +1,27 @@ +class ProposalsDiscussionPlugin::Topic < Folder + + alias :discussion :parent + alias :proposals :children + + has_many :proposals_comments, :class_name => 'Comment', :through => :children, :source => :comments + has_many :proposals_authors, :class_name => 'Person', :through => :children, :source => :created_by + + def self.short_description + _("Discussion topic") + end + + def self.description + _('Container for proposals.') + end + + def most_active_participants + proposals_authors.group('profiles.id').order('count(articles.id) DESC').includes(:environment, :preferred_domain, :image) + end + + def to_html(options = {}) + proc do + render :file => 'content_viewer/topic' + end + end + +end diff --git a/public/style.css b/public/style.css index 1d2d44f..3a22bc3 100644 --- a/public/style.css +++ b/public/style.css @@ -1,19 +1,39 @@ .proposal { background: rgb(236, 236, 236); - width: 31%; + width: 100%; min-width: 272px; - display: inline-block; + display: table; vertical-align: top; - margin: 5px 13px 5px 0; + margin: 12px 13px 12px 0; box-shadow: 5px 5px 5px -2px #ddd; + padding: 5px; } -.proposal:hover { +.article-body-proposals-discussion-plugin_discussion .actions, +.article-body-proposals-discussion-plugin_topic .actions { + margin: 10px 0 25px 0; +} + +.proposal .content, .proposal .score, .proposal .topic { + display: table-cell; + border-right: 1px solid; + border-color: rgb(201, 201, 201); +} +.proposal .topic { + border-right: 0; + text-align: center; + width: 30%; +} +.proposal .score { + width: 8%; + text-align: center; +} + +.proposal .content:hover, .proposal .topic:hover { background: rgb(223, 223, 223); } .proposal .title { - background: rgba(0, 0, 0, 0.1); font-weight: bold; font-size: 15px; } @@ -25,16 +45,12 @@ display: inline-block; } -#article .proposal .title { - padding: 0px 5px; -} - #article .proposal .title a { padding: 8px 0px; } .proposal .content { - padding: 5px; + width: 60%; color: rgb(83, 83, 83); } @@ -42,31 +58,6 @@ padding-top: 8px; } -.proposal .info { - float: left; -} - -.proposal .info .comments { - background: url('/plugins/proposals_discussion/images/comments.gif') no-repeat left/15px; - padding-left: 18px; - display: inline; - font-size: 10px; - color: rgb(82, 82, 82); - opacity: 0.6; -} - -.proposal .actions { - float: right; -} - -.proposal .actions .vote-actions { - position: static; -} - -.proposal .actions .vote-actions .vote-action a { - opacity: 0.6; -} - form .proposals-discussion-plugin textarea { width: 98%; } diff --git a/views/content_viewer/_proposal_card.html.erb b/views/content_viewer/_proposal_card.html.erb index 9f05d64..8c39f8a 100644 --- a/views/content_viewer/_proposal_card.html.erb +++ b/views/content_viewer/_proposal_card.html.erb @@ -1,16 +1,16 @@
-
- <%= link_to proposal_card.name, proposal_card.view_url %> -
-
-
<%= proposal_card.comments_count %>
-
-
- <%= @plugins.dispatch(:article_header_extra_contents, proposal_card).collect { |content| instance_exec(&content) }.join("") %> +
+ <%= link_to proposal_card.name, proposal_card.view_url %>
<%= link_to strip_tags(proposal_card.lead), proposal_card.view_url %>
+
+ <%= proposal_card.comments_count %> +
+
+ <%= link_to proposal_card.topic.title, proposal_card.topic.view_url %> +
diff --git a/views/content_viewer/_proposals_list.html.erb b/views/content_viewer/_proposals_list.html.erb new file mode 100644 index 0000000..57f5cd0 --- /dev/null +++ b/views/content_viewer/_proposals_list.html.erb @@ -0,0 +1,4 @@ +
+ <%= render :partial => 'content_viewer/proposal_card', :collection => holder.proposals.includes(:parent, :profile) %> +
+
diff --git a/views/content_viewer/discussion.html.erb b/views/content_viewer/discussion.html.erb index ac3787a..c5777b2 100644 --- a/views/content_viewer/discussion.html.erb +++ b/views/content_viewer/discussion.html.erb @@ -2,11 +2,26 @@ <%= @page.body %>
-<%= link_to url_for({:controller => 'cms', :action => 'new', :type => "ProposalsDiscussionPlugin::Proposal", :parent_id => @page.id}), :class => 'button with-text icon-add' do %> - <%= _("New Proposal") %> +<% if @page.allow_create?(user) %> +
+ <%= link_to url_for({:controller => 'cms', :action => 'new', :type => "ProposalsDiscussionPlugin::Topic", :parent_id => @page.id}), :class => 'button with-text icon-add' do %> + <%= _("New Topic") %> + <% end %> +
<% end %> -
- <%= render :partial => 'content_viewer/proposal_card', :collection => discussion.children %> +
+

<%= _('Discussion Topics') %>

+ <% @page.topics.includes(:profile).each do |topic| %> +
<%= link_to topic.title, topic.view_url %>
+ <% end %>
+ +
+ <%= link_to url_for({:controller => 'proposals_discussion_plugin_myprofile', :action => 'select_topic', :parent_id => @page.id}), :class => 'button with-text icon-add' do %> + <%= _("Send my proposal") %> + <% end %> +
+ +<%= render :partial => 'content_viewer/proposals_list', :locals => {:holder => @page} %> diff --git a/views/content_viewer/proposal.html.erb b/views/content_viewer/proposal.html.erb new file mode 100644 index 0000000..46697cb --- /dev/null +++ b/views/content_viewer/proposal.html.erb @@ -0,0 +1,19 @@ +
+
<%= _('Discussion Topic') %>
+
<%= @page.topic.title %>
+
+ +
+
<%= _('Title') %>
+
<%= @page.title %>
+
+ +
+
<%= _('Abstract') %>
+
<%= @page.abstract %>
+
+ +
+
<%= _('Body') %>
+
<%= @page.body %>
+
diff --git a/views/content_viewer/topic.html.erb b/views/content_viewer/topic.html.erb new file mode 100644 index 0000000..a326e6d --- /dev/null +++ b/views/content_viewer/topic.html.erb @@ -0,0 +1,32 @@ +
+ <%= @page.body %> +
+

<%= @page.discussion.title %>

+ +
+ <%= _('Number of Proposals: ') %> + <%= @page.proposals.count %> +
+
+ <%= _('Number of Participants: ') %> + <%= @page.proposals_authors.count %> +
+
+ <%= _('Number of Comments: ') %> + <%= @page.proposals_comments.count %> +
+
+ <%= _('Most active: ') %> + + <% @page.most_active_participants.each do |author| %> + <%= link_to profile_image(author, :icon), author.url, :title => author.name %> + <% end %> + +
+ +<%= render :partial => 'content_viewer/proposals_list', :locals => {:holder => @page} %> + +
+ <%= render :partial => 'content_viewer/proposal_card', :collection => @page.proposals.includes(:parent, :profile) %> +
+
diff --git a/views/select_topic.html.erb b/views/select_topic.html.erb new file mode 100644 index 0000000..9532280 --- /dev/null +++ b/views/select_topic.html.erb @@ -0,0 +1,37 @@ + + +
+

<%= @discussion.title %>

+ <%= form_for :discussion, :url => {:controller => 'proposals_discussion_plugin_myprofile', :action => 'new_proposal'} do %> + +

<%= _('Select topic') %>

+
+ + <% @discussion.children.each do |topic| %> +

+ <%= radio_button_tag('discussion[topic]', topic.id) %> + <%= topic.title %> +

+
+ <%= topic.body %> +
+ <% end %> + +
+
+ +
+ <%= submit_button(:next, _('Next')) %> + <%= button :cancel, _('Cancel'), @discussion.view_url %> +
+ <% end %> +
-- libgit2 0.21.2