parent
9f29a6c82a
commit
bf71a38608
@ -0,0 +1,2 @@
|
|||||||
|
// Place all the behaviors and hooks related to the matching controller here.
|
||||||
|
// All this logic will automatically be available in application.js.
|
@ -0,0 +1,4 @@
|
|||||||
|
/*
|
||||||
|
Place all the styles related to the matching controller here.
|
||||||
|
They will automatically be included in application.css.
|
||||||
|
*/
|
@ -0,0 +1,161 @@
|
|||||||
|
class ContestnotificationsController < ApplicationController
|
||||||
|
# GET /contestnotifications
|
||||||
|
# GET /contestnotifications.json
|
||||||
|
layout 'base_contest'
|
||||||
|
default_search_scope :contestnotification
|
||||||
|
model_object Contestnotification
|
||||||
|
before_filter :find_model_object_contest, :except => [:new, :create, :index]
|
||||||
|
before_filter :find_contest_from_association, :except => [:new, :create, :index]
|
||||||
|
before_filter :find_contest_by_contest_id, :only => [:new, :create]
|
||||||
|
before_filter :authorize, :except => [:index]
|
||||||
|
before_filter :find_optional_contest, :only => :index
|
||||||
|
accept_rss_auth :index
|
||||||
|
accept_api_auth :index
|
||||||
|
|
||||||
|
def index
|
||||||
|
# @contestnotifications = Contestnotification.all
|
||||||
|
#
|
||||||
|
# respond_to do |format|
|
||||||
|
# format.html # index.html.erb
|
||||||
|
# format.json { render json: @contestnotifications }
|
||||||
|
# end
|
||||||
|
|
||||||
|
### begin ###
|
||||||
|
case params[:format]
|
||||||
|
when 'xml', 'json'
|
||||||
|
@offset, @limit = api_offset_and_limit
|
||||||
|
else
|
||||||
|
@limit = 10
|
||||||
|
end
|
||||||
|
|
||||||
|
scope = @contest ? @contest.contestnotification.visible : Contestnotification.visible
|
||||||
|
|
||||||
|
@contestnotification_count = scope.count
|
||||||
|
@contestnotification_pages = Paginator.new @contestnotification_count, @limit, params['page']
|
||||||
|
@offset ||= @contestnotification_pages.offset
|
||||||
|
@contestnotifications = scope.all(:include => [:author, :contest],
|
||||||
|
:order => "#{Contestnotification.table_name}.created_on DESC",
|
||||||
|
:offset => @offset,
|
||||||
|
:limit => @limit)
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.html {
|
||||||
|
@contestnotification = Contestnotification.new # for adding news inline
|
||||||
|
render :layout => 'base_contest'
|
||||||
|
}
|
||||||
|
format.api
|
||||||
|
format.atom { render_feed(@contestnotifications, :title => (@contest ? @contest.name : Setting.app_title) + ": #{l(:label_contest_notification)}") }
|
||||||
|
end
|
||||||
|
### end ###
|
||||||
|
end
|
||||||
|
|
||||||
|
# GET /contestnotifications/1
|
||||||
|
# GET /contestnotifications/1.json
|
||||||
|
def show
|
||||||
|
# @contestnotification = Contestnotification.find(params[:id])
|
||||||
|
#
|
||||||
|
# respond_to do |format|
|
||||||
|
# format.html # show.html.erb
|
||||||
|
# format.json { render json: @contestnotification }
|
||||||
|
# end
|
||||||
|
@comments = @contestnotification.comments
|
||||||
|
@comments.reverse! if User.current.wants_comments_in_reverse_order?
|
||||||
|
render :layout => 'base_contest'
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
# 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
|
||||||
|
@contestnotification = Contestnotification.new(:contest => @contest, :author => User.current)
|
||||||
|
render :layout => 'base_contest'
|
||||||
|
end
|
||||||
|
|
||||||
|
# GET /contestnotifications/1/edit
|
||||||
|
def edit
|
||||||
|
# @contestnotification = Contestnotification.find(params[:id])
|
||||||
|
end
|
||||||
|
|
||||||
|
# POST /contestnotifications
|
||||||
|
# POST /contestnotifications.json
|
||||||
|
def create
|
||||||
|
# @contestnotification = Contestnotification.new(params[:contestnotification])
|
||||||
|
#
|
||||||
|
# respond_to do |format|
|
||||||
|
# if @contestnotification.save
|
||||||
|
# format.html { redirect_to @contestnotification, notice: 'Contestnotification was successfully created.' }
|
||||||
|
# format.json { render json: @contestnotification, status: :created, location: @contestnotification }
|
||||||
|
# else
|
||||||
|
# format.html { render action: "new" }
|
||||||
|
# format.json { render json: @contestnotification.errors, status: :unprocessable_entity }
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
@contestnotification = Contestnotification.new(:contest => @contest, :author => User.current)
|
||||||
|
@contestnotification.safe_attributes = params[:contestnotification]
|
||||||
|
@news.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)
|
||||||
|
else
|
||||||
|
layout_file = 'base_contest'
|
||||||
|
render :action => 'new', :layout => layout_file
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# PUT /contestnotifications/1
|
||||||
|
# PUT /contestnotifications/1.json
|
||||||
|
def update
|
||||||
|
# @contestnotification = Contestnotification.find(params[:id])
|
||||||
|
#
|
||||||
|
# respond_to do |format|
|
||||||
|
# if @contestnotification.update_attributes(params[:contestnotification])
|
||||||
|
# format.html { redirect_to @contestnotification, notice: 'Contestnotification was successfully updated.' }
|
||||||
|
# format.json { head :no_content }
|
||||||
|
# else
|
||||||
|
# format.html { render action: "edit" }
|
||||||
|
# format.json { render json: @contestnotification.errors, status: :unprocessable_entity }
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
@contestnotification.safe_attributes = params[:contestnotification]
|
||||||
|
@contestnotification.save_attachments(params[:attachments])
|
||||||
|
if @contestnotification.save
|
||||||
|
render_attachment_warning_if_needed(@contestnotification)
|
||||||
|
flash[:notice] = l(:notice_successful_update)
|
||||||
|
redirect_to contestnotification_path(@contestnotification)
|
||||||
|
else
|
||||||
|
render :action => 'edit'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# DELETE /contestnotifications/1
|
||||||
|
# DELETE /contestnotifications/1.json
|
||||||
|
def destroy
|
||||||
|
# @contestnotification = Contestnotification.find(params[:id])
|
||||||
|
# @contestnotification.destroy
|
||||||
|
#
|
||||||
|
# respond_to do |format|
|
||||||
|
# format.html { redirect_to contestnotifications_url }
|
||||||
|
# format.json { head :no_content }
|
||||||
|
# end
|
||||||
|
@contestnotification.destroy
|
||||||
|
redirect_to contest_contestnotification_index_path(@contest)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def find_optional_contest
|
||||||
|
return true unless params[:contest_id]
|
||||||
|
@contest = Contest.find(params[:contest_id])
|
||||||
|
authorize
|
||||||
|
rescue ActiveRecord::RecordNotFound
|
||||||
|
render_404
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
@ -0,0 +1,2 @@
|
|||||||
|
module ContestnotificationsHelper
|
||||||
|
end
|
@ -0,0 +1,61 @@
|
|||||||
|
class Contestnotification < ActiveRecord::Base
|
||||||
|
attr_accessible :author_id, :comments_count, :contest_id, :description, :summary, :title
|
||||||
|
|
||||||
|
include Redmine::SafeAttributes
|
||||||
|
belongs_to :contest
|
||||||
|
belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
|
||||||
|
has_many :comments, :as => :commented, :dependent => :delete_all, :order => "created_at"
|
||||||
|
# fq
|
||||||
|
has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy
|
||||||
|
|
||||||
|
validates_presence_of :title, :description
|
||||||
|
validates_length_of :title, :maximum => 60
|
||||||
|
validates_length_of :summary, :maximum => 255
|
||||||
|
|
||||||
|
acts_as_attachable :delete_permission => :manage_contestnotification
|
||||||
|
acts_as_searchable :columns => ['title', 'summary', "#{table_name}.description"], :include => :contest
|
||||||
|
acts_as_event :url => Proc.new {|o| {:controller => 'contestnotification', :action => 'show', :id => o.id}}
|
||||||
|
acts_as_activity_provider :find_options => {:include => [:contest, :author]},
|
||||||
|
:author_key => :author_id
|
||||||
|
acts_as_watchable
|
||||||
|
|
||||||
|
after_create :add_author_as_watcher, :reset_counters!
|
||||||
|
|
||||||
|
after_create :act_as_activity
|
||||||
|
|
||||||
|
|
||||||
|
# scope :visible, lambda {|*args|
|
||||||
|
# includes(:contest).where(Contest.allowed_to_condition(args.shift || User.current, :view_news, *args))
|
||||||
|
# }
|
||||||
|
|
||||||
|
safe_attributes 'title', 'summary', 'description'
|
||||||
|
|
||||||
|
def visible?(user=User.current)
|
||||||
|
!user.nil? && user.allowed_to?(:view_contestnotification, contest)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Returns true if the news can be commented by user
|
||||||
|
def commentable?(user=User.current)
|
||||||
|
user.allowed_to?(:comment_contestnotification, contest)
|
||||||
|
end
|
||||||
|
|
||||||
|
def recipients
|
||||||
|
contest.users.select {|user| user.notify_about?(self)}.map(&:mail)
|
||||||
|
end
|
||||||
|
|
||||||
|
# returns latest news for contests visible by user
|
||||||
|
def self.latest(user = User.current, count = 5)
|
||||||
|
visible(user).includes([:author, :contest]).order("#{Contestnotification.table_name}.created_on DESC").limit(count).all
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def add_author_as_watcher
|
||||||
|
Watcher.create(:watchable => self, :user => author)
|
||||||
|
end
|
||||||
|
## fq
|
||||||
|
def act_as_activity
|
||||||
|
self.acts << Activity.new(:user_id => self.author_id)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
@ -0,0 +1,41 @@
|
|||||||
|
<%= form_for(@contestnotification) do |f| %>
|
||||||
|
<% if @contestnotification.errors.any? %>
|
||||||
|
<div id="error_explanation">
|
||||||
|
<h2><%= pluralize(@contestnotification.errors.count, "error") %> prohibited this contestnotification from being saved:</h2>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<% @contestnotification.errors.full_messages.each do |msg| %>
|
||||||
|
<li><%= msg %></li>
|
||||||
|
<% end %>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<div class="field">
|
||||||
|
<%= f.label :contest_id %><br />
|
||||||
|
<%= f.number_field :contest_id %>
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<%= f.label :title %><br />
|
||||||
|
<%= f.text_field :title %>
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<%= f.label :summary %><br />
|
||||||
|
<%= f.text_field :summary %>
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<%= f.label :description %><br />
|
||||||
|
<%= f.text_field :description %>
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<%= f.label :author_id %><br />
|
||||||
|
<%= f.number_field :author_id %>
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<%= f.label :comments_count %><br />
|
||||||
|
<%= f.number_field :comments_count %>
|
||||||
|
</div>
|
||||||
|
<div class="actions">
|
||||||
|
<%= f.submit %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
@ -0,0 +1,6 @@
|
|||||||
|
<h1>Editing contestnotification</h1>
|
||||||
|
|
||||||
|
<%= render 'form' %>
|
||||||
|
|
||||||
|
<%= link_to 'Show', @contestnotification %> |
|
||||||
|
<%= link_to 'Back', contestnotifications_path %>
|
@ -0,0 +1,16 @@
|
|||||||
|
<!-- <h1>New contestnotification</h1>
|
||||||
|
|
||||||
|
<%= render 'form' %>
|
||||||
|
|
||||||
|
<%= link_to 'Back', contestnotifications_path %> -->
|
||||||
|
|
||||||
|
|
||||||
|
<!-- <h3><%=l(:label_news_new)%></h3> -->
|
||||||
|
|
||||||
|
<%= labelled_form_for @contestnotification, :url => contest_contestnotification_index_path(@contest),
|
||||||
|
:html => { :id => 'news-form', :multipart => true } do |f| %>
|
||||||
|
<%= render :partial => 'news/form', :locals => { :f => f } %>
|
||||||
|
<%= submit_tag l(:button_create), :class => "whiteButton m3p10 h30" %>
|
||||||
|
<%= preview_link preview_news_path(:project_id => @project), 'news-form' ,target='preview',{:class => 'whiteButton m3p10'}%>
|
||||||
|
<% end %>
|
||||||
|
<div id="preview" class="wiki"></div>
|
@ -0,0 +1,35 @@
|
|||||||
|
<p id="notice"><%= notice %></p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<b>Contest:</b>
|
||||||
|
<%= @contestnotification.contest_id %>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<b>Title:</b>
|
||||||
|
<%= @contestnotification.title %>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<b>Summary:</b>
|
||||||
|
<%= @contestnotification.summary %>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<b>Description:</b>
|
||||||
|
<%= @contestnotification.description %>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<b>Author:</b>
|
||||||
|
<%= @contestnotification.author_id %>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<b>Comments count:</b>
|
||||||
|
<%= @contestnotification.comments_count %>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
|
||||||
|
<%= link_to 'Edit', edit_contestnotification_path(@contestnotification) %> |
|
||||||
|
<%= link_to 'Back', contestnotifications_path %>
|
@ -0,0 +1,14 @@
|
|||||||
|
class CreateContestnotifications < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
create_table :contestnotifications do |t|
|
||||||
|
t.integer :contest_id
|
||||||
|
t.string :title
|
||||||
|
t.string :summary
|
||||||
|
t.string :description
|
||||||
|
t.integer :author_id
|
||||||
|
t.integer :comments_count
|
||||||
|
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,17 @@
|
|||||||
|
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
|
||||||
|
|
||||||
|
one:
|
||||||
|
contest_id: 1
|
||||||
|
title: MyString
|
||||||
|
summary: MyString
|
||||||
|
description: MyString
|
||||||
|
author_id: 1
|
||||||
|
comments_count: 1
|
||||||
|
|
||||||
|
two:
|
||||||
|
contest_id: 1
|
||||||
|
title: MyString
|
||||||
|
summary: MyString
|
||||||
|
description: MyString
|
||||||
|
author_id: 1
|
||||||
|
comments_count: 1
|
@ -0,0 +1,49 @@
|
|||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class ContestnotificationsControllerTest < ActionController::TestCase
|
||||||
|
setup do
|
||||||
|
@contestnotification = contestnotifications(:one)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should get index" do
|
||||||
|
get :index
|
||||||
|
assert_response :success
|
||||||
|
assert_not_nil assigns(:contestnotifications)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should get new" do
|
||||||
|
get :new
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should create contestnotification" do
|
||||||
|
assert_difference('Contestnotification.count') do
|
||||||
|
post :create, contestnotification: { author_id: @contestnotification.author_id, comments_count: @contestnotification.comments_count, contest_id: @contestnotification.contest_id, description: @contestnotification.description, summary: @contestnotification.summary, title: @contestnotification.title }
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_redirected_to contestnotification_path(assigns(:contestnotification))
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should show contestnotification" do
|
||||||
|
get :show, id: @contestnotification
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should get edit" do
|
||||||
|
get :edit, id: @contestnotification
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should update contestnotification" do
|
||||||
|
put :update, id: @contestnotification, contestnotification: { author_id: @contestnotification.author_id, comments_count: @contestnotification.comments_count, contest_id: @contestnotification.contest_id, description: @contestnotification.description, summary: @contestnotification.summary, title: @contestnotification.title }
|
||||||
|
assert_redirected_to contestnotification_path(assigns(:contestnotification))
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should destroy contestnotification" do
|
||||||
|
assert_difference('Contestnotification.count', -1) do
|
||||||
|
delete :destroy, id: @contestnotification
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_redirected_to contestnotifications_path
|
||||||
|
end
|
||||||
|
end
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue