diff --git a/app/controllers/contestnotifications_controller.rb b/app/controllers/contestnotifications_controller.rb
index f2c0fb80f..0f485e65b 100644
--- a/app/controllers/contestnotifications_controller.rb
+++ b/app/controllers/contestnotifications_controller.rb
@@ -41,7 +41,7 @@ class ContestnotificationsController < ApplicationController
@limit = 10
end
- scope = @contest ? @contest.contestnotifications.visible : Contestnotification.visible
+ scope = @contest ? @contest.contestnotifications.visible : Contestnotifications.visible
@contestnotifications_count = scope.count
@contestnotifications_pages = Paginator.new @contestnotifications_count, @limit, params['page']
@@ -80,14 +80,14 @@ class ContestnotificationsController < ApplicationController
# GET /contestnotifications/new
# GET /contestnotifications/new.json
def new
- @contestnotification = Contestnotification.new
-
- respond_to do |format|
- format.html # new.html.erb
- format.json { render json: @contestnotification }
- end
- # @contestnotifications = Contestnotifications.new(:contest => @contest, :author => User.current)
- # render :layout => 'base_contest'
+ # @contestnotification = Contestnotification.new
+#
+ # respond_to do |format|
+ # format.html # new.html.erb
+ # format.json { render json: @contestnotification }
+ # end
+ @contestnotification = Contestnotification.new(:contest => @contest, :author => User.current)
+ render :layout => 'base_newcontest'
end
# GET /contestnotifications/1/edit
@@ -109,15 +109,15 @@ class ContestnotificationsController < ApplicationController
# format.json { render json: @contestnotification.errors, status: :unprocessable_entity }
# end
# end
- @contestnotifications = Contestnotifications.new(:contest => @contest, :author => User.current)
- @contestnotifications.safe_attributes = params[:contestnotifications]
- @news.save_attachments(params[:attachments])
- if @contestnotifications.save
- render_attachment_warning_if_needed(@contestnotifications)
+ @contestnotification = Contestnotification.new(:contest => @contest, :author => User.current)
+ @contestnotification.safe_attributes = params[:contestnotification]
+ @contestnotification.save_attachments(params[:attachments])
+ if @contestnotification.save
+ render_attachment_warning_if_needed(@contestnotification)
flash[:notice] = l(:notice_successful_create)
- redirect_to project_news_index_path(@contest)
+ redirect_to contest_contestnotifications_path(@contest)
else
- layout_file = 'base_contest'
+ layout_file = 'base_newcontest'
render :action => 'new', :layout => layout_file
end
end
diff --git a/app/controllers/previews_controller.rb b/app/controllers/previews_controller.rb
index 0083116d2..2ca2cef9e 100644
--- a/app/controllers/previews_controller.rb
+++ b/app/controllers/previews_controller.rb
@@ -16,10 +16,11 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class PreviewsController < ApplicationController
- before_filter :find_project, :find_attachments
+ before_filter :find_project, :find_attachments, :find_contest
def issue
@issue = @project.issues.find_by_id(params[:id]) unless params[:id].blank?
+ @issue = @contest.issues.find_by_id(params[:id]) unless params[:id].blank?
if @issue
@description = params[:issue] && params[:issue][:description]
if @description && @description.gsub(/(\r?\n|\n\r?)/, "\n") == @issue.description.to_s.gsub(/(\r?\n|\n\r?)/, "\n")
@@ -50,4 +51,20 @@ class PreviewsController < ApplicationController
render_404
end
+ def contestnotifications
+ if params[:id].present? && contestnotifications = Contestnotifications.visible.find_by_id(params[:id])
+ @previewed = contestnotifications
+ end
+ @text = (params[:contestnotifications] ? params[:contestnotifications][:description] : nil)
+ render :partial => 'common/preview'
+ end
+
+ private
+ def find_contest
+ contest_id = (params[:issue] && params[:issue][:contest_id]) || params[:contest_id]
+ @contest = Contest.find(contest_id)
+ rescue ActiveRecord::RecordNotFound
+ render_404
+ end
+
end
diff --git a/app/models/contestnotification.rb b/app/models/contestnotification.rb
index f6b0fd168..b983778e4 100644
--- a/app/models/contestnotification.rb
+++ b/app/models/contestnotification.rb
@@ -19,7 +19,7 @@ class Contestnotification < ActiveRecord::Base
:author_key => :author_id
acts_as_watchable
- after_create :add_author_as_watcher, :reset_counters!
+ after_create :add_author_as_watcher
after_create :act_as_activity
diff --git a/app/views/contestnotifications/_form.html.erb b/app/views/contestnotifications/_form.html.erb
index e69de29bb..acfa20a7c 100644
--- a/app/views/contestnotifications/_form.html.erb
+++ b/app/views/contestnotifications/_form.html.erb
@@ -0,0 +1,11 @@
+<%= error_messages_for @contestnotifications %>
+
+
+
<%= f.text_field :title, :required => true, :size => 60, :style => "width:488px;" %>
+
<%= f.text_area :description, :required => true, :cols => 60, :rows => 11, :class => 'wiki-edit', :style => "width:490px;" %>
+
<%= render :partial => 'attachments/form', :locals => {:container => @contestnotifications} %>
+
+
+<%= wikitoolbar_for 'news_description' %>
diff --git a/app/views/contestnotifications/_contestnotifications.html.erb b/app/views/contestnotifications/_news.html.erb
similarity index 81%
rename from app/views/contestnotifications/_contestnotifications.html.erb
rename to app/views/contestnotifications/_news.html.erb
index 4a062f3b5..1621c5813 100644
--- a/app/views/contestnotifications/_contestnotifications.html.erb
+++ b/app/views/contestnotifications/_news.html.erb
@@ -10,16 +10,16 @@
|
- <%=link_to contestnotifications.author,contestnotifications_path(contestnotifications)%>
- <%= l(:label_project_newshare) %> <%= link_to h(contestnotifications.title), news_path(contestnotifications) %>
+ | <%=link_to contestnotifications.author,contest_contestnotification_path(contestnotifications)%>
+ <%= l(:label_project_newshare) %> <%= link_to h(contestnotifications.title), contest_contestnotification_path(contestnotifications) %>
|
<%=h contestnotifications.description%> |
- <%= contestnotifications.created_on %> |
- <%= link_to l(:label_project_newother),contestnotifications_path(contestnotifications)%>
+ | <%= contestnotifications.created_at %> |
+ <%= link_to l(:label_project_newother),contest_contestnotification_path(contestnotifications)%>
<%= "(#{l(:label_x_comments, :count => contestnotifications.comments_count)})" if contestnotifications.comments_count > 0 %>
|
diff --git a/app/views/contestnotifications/edit.html.erb b/app/views/contestnotifications/edit.html.erb
index 121b15d9a..3d3403818 100644
--- a/app/views/contestnotifications/edit.html.erb
+++ b/app/views/contestnotifications/edit.html.erb
@@ -7,10 +7,10 @@
<%=l(:label_news)%>
-<%= labelled_form_for @contestnotifications, :html => { :id => 'news-form', :multipart => true, :method => :put } do |f| %>
+<%= labelled_form_for @contestnotifications, :html => { :id => 'contestnotifications-form', :multipart => true, :method => :put } do |f| %>
<%= render :partial => 'form', :locals => { :f => f } %>
<%= submit_tag l(:button_save) %>
-<%= preview_link preview_news_path(:project_id => @contest, :id => @contestnotifications), 'news-form' %>
+<%= preview_link preview_news_path(:project_id => @contest, :id => @contestnotifications), 'contestnotifications-form' %>
<% end %>
diff --git a/app/views/contestnotifications/index.html.erb b/app/views/contestnotifications/index.html.erb
index 090b72a36..e114b610c 100644
--- a/app/views/contestnotifications/index.html.erb
+++ b/app/views/contestnotifications/index.html.erb
@@ -1,29 +1,22 @@
-
-
-<%
- btn_tips = l(:label_news_new)
- label_tips = l(:label_news)
-%>
-
- <%= label_tips %>
+ <%= l(:label_news) %>
-<%= link_to(btn_tips,
+<%= link_to(l(:label_news_new),
new_contest_contestnotification_path(@contest),
:class => 'icon icon-add',
- :onclick => 'showAndScrollTo("add-news", "news_title"); return false;') %>
+ :onclick => 'showAndScrollTo("add-contestnotifications", "contestnotifications_title"); return false;') %>
<% if @contest && User.current.allowed_to?(:manage_contestnotifications, @contest) %>
-
- <%= labelled_form_for @contestnotifications, :url => contestnotifications_path(@contest),
- :html => {:id => 'news-form', :multipart => true} do |f| %>
+
+ <%= labelled_form_for @contestnotifications, :url => contest_contestnotifications_path(@contest),
+ :html => {:id => 'contestnotifications-form', :multipart => true} do |f| %>
<%= render :partial => 'contestnotifications/form', :locals => {:f => f} %>
- <%= submit_tag l(:button_create), :class => 'whiteButton m3p10 h30', :name => nil %> |
- <%= preview_link preview_contestnotification_path(:contest_id => @contest), 'news-form', target='preview', {:class => 'whiteButton m3p10'} %>
+ <%= submit_tag l(:button_create), :class => 'whiteButton m3p10 h30', :name => nil %>
+ <%= preview_link preview_contestnotifications_path(:contest_id => @contest), 'contestnotifications-form', target='preview', {:class => 'whiteButton m3p10'} %>
|
- <%= link_to l(:button_cancel), "#", :onclick => '$("#add-news").hide()', :class => 'whiteButton m3p10' %>
+ <%= link_to l(:button_cancel), "#", :onclick => '$("#add-contestnotifications").hide(); return false;', :class => 'whiteButton m3p10' %>
<% end if @contest %>
@@ -44,8 +37,8 @@
- <%= link_to_user(contestnotifications.author) if contestnotifications.respond_to?(:author) %><%= l(:label_project_notice) %><%= link_to h(contestnotifications.title), contestnotification_path(contestnotifications) %>
- <%= delete_link contestnotification_path(contestnotifications) if User.current.allowed_to?(:manage_contestnotification, @contest) %>
+ <%= link_to_user(contestnotifications.author) if contestnotifications.respond_to?(:author) %><%= l(:label_project_notice) %><%= link_to h(contestnotifications.title), contest_contestnotification_path(contestnotifications) %>
+ <%= delete_link contest_contestnotification_path(contestnotifications) if User.current.allowed_to?(:manage_contestnotifications, @contest) %>
|
@@ -55,7 +48,7 @@
<%= l :label_update_time %>
<%= format_time(contestnotifications.created_at) %> |
- <%= link_to l(:label_project_newother), contestnotification_path(contestnotifications) %><%= "(#{l(:label_x_comments, :count => contestnotifications.comments_count)})" if contestnotifications.comments_count >= 0 %> |
+ <%= link_to l(:label_project_newother), contest_contestnotification_path(contestnotifications) %><%= "(#{l(:label_x_comments, :count => contestnotifications.comments_count)})" if contestnotifications.comments_count >= 0 %> |
|
diff --git a/app/views/contestnotifications/new.html.erb b/app/views/contestnotifications/new.html.erb
index 2ad240014..c4e322ec8 100644
--- a/app/views/contestnotifications/new.html.erb
+++ b/app/views/contestnotifications/new.html.erb
@@ -1,6 +1,7 @@
-<%#= labelled_form_for @contestnotifications, :url => contest_contestnotifications_path(@contest), :html => { :id => 'news-form', :multipart => true } do |f| %>
- <%#= render :partial => 'contestnotifications/form', :locals => { :f => f } %>
- <%#= submit_tag l(:button_create), :class => "whiteButton m3p10 h30" %>
-<%# end %>
+<%= labelled_form_for @contestnotification, :url => contest_contestnotifications_path(@contest), :html => { :id => 'contestnotifications-form', :multipart => true } do |f| %>
+ <%= render :partial => 'contestnotifications/form', :locals => { :f => f } %>
+ <%= submit_tag l(:button_create), :class => "whiteButton m3p10 h30" %>
+ <%= preview_link preview_contestnotifications_path(:contest_id => @contest), 'contestnotifications-form' ,target='preview',{:class => 'whiteButton m3p10'}%>
+<% end %>
diff --git a/app/views/contestnotifications/show.html.erb b/app/views/contestnotifications/show.html.erb
index a8069c73c..517f60bca 100644
--- a/app/views/contestnotifications/show.html.erb
+++ b/app/views/contestnotifications/show.html.erb
@@ -50,10 +50,10 @@
<% if authorize_for('contestnotifications', 'edit') %>
<%= labelled_form_for :contestnotifications, @contestnotifications, :url => contestnotifications_path(@contestnotifications),
- :html => { :id => 'news-form', :multipart => true, :method => :put } do |f| %>
+ :html => { :id => 'contestnotifications-form', :multipart => true, :method => :put } do |f| %>
<%= render :partial => 'form', :locals => { :f => f } %>
<%= submit_tag l(:button_save) %>
- <%= preview_link preview_contestnotifications_path(:contest_id => @contest, :id => @contestnotifications), 'news-form',target='preview',{:class => ''} %> |
+ <%= preview_link preview_contestnotifications_path(:contest_id => @contest, :id => @contestnotifications), 'contestnotifications-form',target='preview',{:class => ''} %> |
<%= link_to l(:button_cancel), "#", :onclick => '$("#edit-news").hide(); return false;' %>
<% end %>
diff --git a/config/routes.rb b/config/routes.rb
index 1c707bdb0..aba8b4e32 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -17,7 +17,7 @@
RedmineApp::Application.routes.draw do
-
+
#match '/contests/:id/contestnotifications', :controller => 'contestnotifications', :action => 'index'
resources :homework_users
@@ -70,6 +70,10 @@ RedmineApp::Application.routes.draw do
end
end
+ #resources :contestnotifications, :only => [:index, :show, :edit, :update, :destroy]
+ match '/contestnotifications/:id/comments', :to => 'comments#create', :via => :post
+ match '/contestnotifications/:id/comments/:comment_id', :to => 'comments#destroy', :via => :delete
+ match '/contestnotifications/preview', :controller => 'previews', :action => 'contestnotifications', :as => 'preview_contestnotifications', :via => [:get, :post, :put]
## new added by linchun #新竞赛相关
resources :contests, only: [:index] do
resources :contestnotifications#, except: [:index]
diff --git a/db/schema.rb b/db/schema.rb
index 0e8337b94..f750f247f 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -23,6 +23,11 @@ ActiveRecord::Schema.define(:version => 20140530010015) do
add_index "activities", ["user_id", "act_type"], :name => "index_activities_on_user_id_and_act_type"
add_index "activities", ["user_id"], :name => "index_activities_on_user_id"
+ create_table "applied_projects", :force => true do |t|
+ t.integer "project_id", :null => false
+ t.integer "user_id", :null => false
+ end
+
create_table "apply_project_masters", :force => true do |t|
t.integer "user_id"
t.string "apply_type"