diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb
index 2a3ce15d8..d87644e43 100644
--- a/app/controllers/admin_controller.rb
+++ b/app/controllers/admin_controller.rb
@@ -234,4 +234,96 @@ class AdminController < ApplicationController
format.api
end
end
+
+ #首页定制
+ def first_page_made
+ if request.get?
+ @first_page = FirstPage.where("page_type = 'project'").first
+ elsif request.post?
+ @first_page = FirstPage.where("page_type = 'project'").first
+ @first_page.web_title = params[:web_title]
+ @first_page.description = params[:description]
+ @first_page.title = params[:title]
+ if @first_page.save
+ respond_to do |format|
+ format.html {
+ flash[:notice] = l(:notice_successful_update)
+ redirect_to admin_first_page_made_path
+ }
+ format.api { render_api_ok }
+ end
+ else
+ respond_to do |format|
+ format.html {
+ first_page_made
+ render :action => 'first_page_made'
+ }
+ format.api { render_validation_errors(@first_page) }
+ end
+ end
+ end
+ end
+
+ def course_page_made
+ if request.get?
+ @course_page = FirstPage.where("page_type = 'course'").first
+ @first_page = FirstPage.where("page_type = 'project'").first
+ elsif request.post?
+ @first_page = FirstPage.where("page_type = 'project'").first
+ @course_page = FirstPage.where("page_type = 'course'").first
+ @first_page.web_title = params[:web_title]
+ @course_page.title = params[:course_title]
+ @course_page.description = params[:course_description]
+ if @first_page.save && @course_page.save
+ respond_to do |format|
+ format.html {
+ flash[:notice] = l(:notice_successful_update)
+ redirect_to admin_course_page_made_path
+ }
+ format.api { render_api_ok }
+ end
+ else
+ respond_to do |format|
+ format.html {
+ course_page_made
+ render :action => 'course_page_made'
+ }
+ format.api { render_validation_errors(@first_page) }
+ format.api { render_validation_errors(@course_page) }
+ end
+ end
+ end
+ end
+
+ def contest_page_made
+ if request.get?
+ @contest_page = FirstPage.where("page_type = 'contest'").first
+ @first_page = FirstPage.where("page_type = 'project'").first
+ elsif request.post?
+ @first_page = FirstPage.where("page_type = 'project'").first
+ @contest_page = FirstPage.where("page_type = 'contest'").first
+ @first_page.web_title = params[:web_title]
+ @contest_page.title = params[:contest_title]
+ @contest_page.description = params[:contest_description]
+ if @first_page.save && @contest_page.save
+ respond_to do |format|
+ format.html {
+ flash[:notice] = l(:notice_successful_update)
+ redirect_to admin_contest_page_made_path
+ }
+ format.api { render_api_ok }
+ end
+ else
+ respond_to do |format|
+ format.html {
+ contest_page_made
+ render :action => 'contest_page_made'
+ }
+ format.api { render_validation_errors(@first_page) }
+ format.api { render_validation_errors(@contest_page) }
+ end
+ end
+ end
+ end
+
end
diff --git a/app/controllers/bids_controller.rb b/app/controllers/bids_controller.rb
index a728ee6e2..b9f9245c8 100644
--- a/app/controllers/bids_controller.rb
+++ b/app/controllers/bids_controller.rb
@@ -449,7 +449,7 @@ class BidsController < ApplicationController
# 显示作业课程
# add by nwb
def show_courseEx
- if (User.current.logged? && User.current.member_of_course?(@bid.courses.first))
+ if (User.current.logged? && (User.current.member_of_course?(@bid.courses.first) || User.current.admin?))
# flash[:notice] = ""
@membership = User.current.coursememberships.all(:conditions => Course.visible_condition(User.current))
diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb
index bf18332df..03bca6162 100644
--- a/app/controllers/welcome_controller.rb
+++ b/app/controllers/welcome_controller.rb
@@ -16,12 +16,13 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class WelcomeController < ApplicationController
+ include ApplicationHelper
caches_action :robots
# before_filter :fake, :only => [:index, :course]
before_filter :entry_select, :only => [:index]
def index
-
+ @first_page = FirstPage.where("page_type = 'project'").first
end
def robots
@@ -30,6 +31,7 @@ class WelcomeController < ApplicationController
end
def course
+ @course_page = FirstPage.where("page_type = 'course'").first
if params[:school_id]
@school_id = params[:school_id]
elsif User.current.logged? && User.current.user_extensions.school
@@ -41,13 +43,24 @@ class WelcomeController < ApplicationController
def logolink()
+ @course_page = FirstPage.where("page_type = 'course'").first
+ logo = get_avatar?(@course_page)
id = params[:school_id]
logo_link = ""
- if id.nil? and User.current.user_extensions.school.nil?
- logo_link = '/images/transparent.png'
+ if id.nil? && User.current.user_extensions.school.nil?
+ if logo
+ logo_link = url_to_avatar(@course_page)
+ else
+ logo_link = '/images/transparent.png'
+ end
+
else
if id == "0"
- logo_link = '/images/transparent.png'
+ if logo
+ logo_link = url_to_avatar(@course_page)
+ else
+ logo_link = '/images/transparent.png'
+ end
else
if id.nil?
if School.find(User.current.user_extensions.school.id).logo_link.nil?
@@ -66,7 +79,7 @@ class WelcomeController < ApplicationController
def contest
-
+ @contest_page = FirstPage.where("page_type = 'contest'").first
end
def search
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index e6bbf6ed6..4f6cb3e95 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -256,8 +256,8 @@ module ApplicationHelper
end
def format_activity_description(text)
- h(truncate(text.to_s, :length => 120).gsub(%r{[\r\n]*<(pre|code)>.*$}m, '...')
- ).gsub(/[\r\n]+/, "
").html_safe
+ h(truncate(text.to_s, :length => 120).gsub(%r{[\r\n]*<(pre|code)>.*$}m, '...')).gsub(/[\r\n]+/, "
").html_safe
+ #h(truncate(text.to_s, :length => 120).gsub(/<\/?.*?>/,"")).html_safe
end
def format_version_name(version)
@@ -625,10 +625,15 @@ module ApplicationHelper
end
def html_title(*args)
+ first_page = FirstPage.where("page_type = 'project'").first
if args.empty?
title = @html_title || []
title << @project.name if @project
- title << Setting.app_title unless Setting.app_title == title.last
+ if first_page.nil? || first_page.web_title.nil?
+ title << Setting.app_title unless Setting.app_title == title.last
+ else
+ title << first_page.web_title unless first_page.web_title == title.last
+ end
title.select {|t| !t.blank? }.join(' - ')
else
@html_title ||= []
diff --git a/app/models/course.rb b/app/models/course.rb
index b6974eed0..248f80e0b 100644
--- a/app/models/course.rb
+++ b/app/models/course.rb
@@ -104,7 +104,19 @@ class Course < ActiveRecord::Base
# 课程的短描述信息
def short_description(length = 255)
- description.gsub(/^(.{#{length}}[^\n\r]*).*$/m, '\1...').strip if description
+ description.gsub(/<\/?.*?>/,"").html_safe if description
+ #description.gsub(/^(.{#{length}}[^\n\r]*).*$/m, '\1...').strip if description
+ end
+
+ def strip_html(html)
+ return html if html.empty? || !html.include?('<')
+ output = ""
+ tokenizer = HTML::Tokenizer.new(html)
+ while token = tokenizer.next
+ node = HTML::Node.parse(nil, 0, 0, token, false)
+ output += token unless (node.kind_of? HTML::Tag) or (token =~ /^/,"").html_safe if description
+ #description.gsub(/^(.{#{length}}[^\n\r]*).*$/m, '\1...').strip if description
+ end
+
private :workflow_rule_by_attribute
def done_ratio
@@ -1513,4 +1519,6 @@ class Issue < ActiveRecord::Base
def be_user_score_new_issue
UserScore.project(:post_issue, User.current,self, { issue_id: self.id })
end
+
+
end
diff --git a/app/models/news.rb b/app/models/news.rb
index 9a0f8b75c..66e339291 100644
--- a/app/models/news.rb
+++ b/app/models/news.rb
@@ -74,6 +74,12 @@ class News < ActiveRecord::Base
visible(user).includes([:author, :project]).order("#{News.table_name}.created_on DESC").limit(count).all
end
+ # 新闻的短描述信息
+ def short_description(length = 255)
+ description.gsub(/<\/?.*?>/,"").html_safe if description
+ #description.gsub(/^(.{#{length}}[^\n\r]*).*$/m, '\1...').strip if description
+ end
+
private
def add_author_as_watcher
diff --git a/app/models/open_source_project.rb b/app/models/open_source_project.rb
index e3556ce55..2de5966bb 100644
--- a/app/models/open_source_project.rb
+++ b/app/models/open_source_project.rb
@@ -84,7 +84,8 @@ class OpenSourceProject < ActiveRecord::Base
# end
def short_description(length = 255)
- description.gsub(/^(.{#{length}}[^\n\r]*).*$/m, '\1...').strip if description
+ #description.gsub(/^(.{#{length}}[^\n\r]*).*$/m, '\1...').strip if description
+ description.gsub(/<\/?.*?>/,"").html_safe if description
end
def applied_by?(user)
diff --git a/app/models/project.rb b/app/models/project.rb
index 37ca8f20b..698b1f26a 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -629,7 +629,8 @@ class Project < ActiveRecord::Base
# Returns a short description of the projects (first lines)
def short_description(length = 255)
- description.gsub(/^(.{#{length}}[^\n\r]*).*$/m, '\1...').strip if description
+ #description.gsub(/^(.{#{length}}[^\n\r]*).*$/m, '\1...').strip if description
+ description.gsub(/<\/?.*?>/,"").html_safe if description
end
def css_classes
diff --git a/app/views/admin/contest_page_made.html.erb b/app/views/admin/contest_page_made.html.erb
new file mode 100644
index 000000000..b8a86fa4d
--- /dev/null
+++ b/app/views/admin/contest_page_made.html.erb
@@ -0,0 +1,39 @@
+
+ + <%= text_field_tag 'web_title', params[:wbe_title],:value => @first_page.web_title, :size => 30,:style => "font-size:small;width:490px;margin-left:10px;" %> +
++ +
++ + <%= text_field_tag 'contest_title', params[:label_site_title], :value => @contest_page.title,:size => 30,:style => "font-size:small;width:490px;margin-left:10px;" %> +
+ ++ + <%= text_area_tag 'contest_description',@contest_page.description,:rows => 8, :size => 30,:style => "font-size:small;width:490px;margin-left:10px;" %> +
+ + <%= submit_tag l(:button_save), :class => "small", :name => nil %> +<% end %> ++ + <%= text_field_tag 'web_title', params[:wbe_title],:value => @first_page.web_title, :size => 30,:style => "font-size:small;width:490px;margin-left:10px;" %> +
++ +
++ + <%= text_field_tag 'course_title', params[:label_site_title], :value => @course_page.title,:size => 30,:style => "font-size:small;width:490px;margin-left:10px;" %> +
++ + <%= text_area_tag 'course_description',@course_page.description,:rows => 8, :size => 30,:style => "font-size:small;width:490px;margin-left:10px;" %> +
+ + <%= submit_tag l(:button_save), :class => "small", :name => nil %> +<% end %> ++ + <%= text_field_tag 'web_title', params[:wbe_title],:value => @first_page.web_title, :size => 30,:style => "font-size:small;width:490px;margin-left:10px;" %> +
++ +
++ + <%= text_field_tag 'title', params[:label_site_title], :value => @first_page.title,:size => 30,:style => "font-size:small;width:490px;margin-left:10px;" %> +
++ + <%= text_area_tag 'description',@first_page.description,:rows => 8, :size => 30,:style => "font-size:small;width:490px;margin-left:10px;" %> +
+ + <%= submit_tag l(:button_save), :class => "small", :name => nil %> +<% end %> ++ + <%= text_field_tag 'web_title', params[:wbe_title],:value => @first_page.web_title, :size => 30,:style => "font-size:small;width:490px;margin-left:10px;" %> +
++ +
++ + <%= text_field_tag 'title', params[:label_site_title], :value => @first_page.title,:size => 30,:style => "font-size:small;width:490px;margin-left:10px;" %> +
++ + <%= text_area_tag 'description',@first_page.description,:rows => 8, :size => 30,:style => "font-size:small;width:490px;margin-left:10px;" %> +
+ + <%= submit_tag l(:button_save), :class => "small", :name => nil %> +<% end %> +<%= link_to(image_tag(url_to_avatar(contest.author), :class => 'avatar'), user_path(contest.author), :class => "avatar") %> | ++ <% unless contest.author.nil? %> + <%= link_to(image_tag(url_to_avatar(contest.author), :class => 'avatar'), user_path(contest.author), :class => "avatar") %> + <% end %> + |
|
- <%= membership.project.description%> + <%= membership.project.short_description%>