Date: Fri, 25 Jul 2014 16:05:33 +0800
Subject: [PATCH 4/4] =?UTF-8?q?=E9=A6=96=E9=A1=B5=E5=AE=9A=E5=88=B6?=
=?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=89=82=E4=BF=AE=E6=94=B9=E5=9B=BE=E7=89=87?=
=?UTF-8?q?=E5=A4=A7=E5=B0=8F=E5=8A=9F=E8=83=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/controllers/admin_controller.rb | 6 +++++
app/models/first_page.rb | 2 ++
app/views/admin/contest_page_made.html.erb | 8 +++++++
app/views/admin/course_page_made.html.erb | 8 +++++++
app/views/admin/first_page_made.html.erb | 9 +++++++-
app/views/welcome/contest.html.erb | 6 ++---
app/views/welcome/course.html.erb | 4 ++--
app/views/welcome/index.html.erb | 4 ++--
config/locales/zh.yml | 4 ++++
db/migrate/20140725062302_add_column.rb | 6 +++++
db/schema.rb | 8 ++++---
lib/tasks/first_page.rake | 26 ++++++++++++++++++++++
lib/tasks/first_page_ros.rake | 0
13 files changed, 80 insertions(+), 11 deletions(-)
create mode 100644 db/migrate/20140725062302_add_column.rb
create mode 100644 lib/tasks/first_page.rake
delete mode 100644 lib/tasks/first_page_ros.rake
diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb
index a76a78dcb..36b7e8598 100644
--- a/app/controllers/admin_controller.rb
+++ b/app/controllers/admin_controller.rb
@@ -150,6 +150,8 @@ class AdminController < ApplicationController
@first_page.web_title = params[:web_title]
@first_page.description = params[:first_page][:description]
#@first_page.title = params[:title]
+ @first_page.image_width = params[:image_width]
+ @first_page.image_height = params[:image_height]
@first_page.sort_type = params[:sort_type]
if @first_page.save
respond_to do |format|
@@ -183,6 +185,8 @@ class AdminController < ApplicationController
@first_page.web_title = params[:web_title]
@course_page.web_title = params[:web_title]
@course_page.title = params[:course_title]
+ @course_page.image_width = params[:image_width]
+ @course_page.image_height = params[:image_height]
@course_page.description = params[:course_description]
if @first_page.save && @course_page.save
respond_to do |format|
@@ -219,6 +223,8 @@ class AdminController < ApplicationController
@first_page.web_title = params[:web_title]
@contest_page.web_title = params[:web_title]
@contest_page.title = params[:contest_title]
+ @contest_page.image_width = params[:image_width]
+ @contest_page.image_height = params[:image_height]
@contest_page.description = params[:contest_description]
@notification.title = params[:contest_notification_title]
@notification.content = params[:contest_notification][:content]
diff --git a/app/models/first_page.rb b/app/models/first_page.rb
index 58d20901e..e7ecfd518 100644
--- a/app/models/first_page.rb
+++ b/app/models/first_page.rb
@@ -2,5 +2,7 @@ class FirstPage < ActiveRecord::Base
attr_accessible :description, :title, :web_title,:page_type,:sort_type
validates_presence_of :web_title, :title, :description,:page_type
validates_length_of :web_title,:title, maximum: 30
+ validates_inclusion_of :image_width,:in => 50..120, :message => l(:image_width_error_message)
+ validates_inclusion_of :image_height,:in => 50..80, :message => l(:image_height_error_message)
#validates_length_of :description, maximum: 100
end
diff --git a/app/views/admin/contest_page_made.html.erb b/app/views/admin/contest_page_made.html.erb
index 7f054324d..c1bccb122 100644
--- a/app/views/admin/contest_page_made.html.erb
+++ b/app/views/admin/contest_page_made.html.erb
@@ -20,6 +20,14 @@
<%= render :partial=>"avatar/avatar_form",:style => "display:inline",:locals=> {source:@contest_page} %>
+
+
+ <%= text_field_tag 'image_width', params[:label_image_width],:value => @contest_page.image_width,:size => 30,:style => "font-size:small;width:490px;margin-left:10px;" %>
+
+
+
+ <%= text_field_tag 'image_height', params[:label_imgae_height], :value => @contest_page.image_height,: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;" %>
diff --git a/app/views/admin/course_page_made.html.erb b/app/views/admin/course_page_made.html.erb
index 7d73c7c6e..15a99bc6a 100644
--- a/app/views/admin/course_page_made.html.erb
+++ b/app/views/admin/course_page_made.html.erb
@@ -19,6 +19,14 @@
<%= render :partial=>"avatar/avatar_form",:style => "display:inline",:locals=> {source:@course_page} %>
+
+
+ <%= text_field_tag 'image_width', params[:label_image_width],:value => @course_page.image_width,:size => 30,:style => "font-size:small;width:490px;margin-left:10px;" %>
+
+
+
+ <%= text_field_tag 'image_height', params[:label_imgae_height], :value => @course_page.image_height,: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;" %>
diff --git a/app/views/admin/first_page_made.html.erb b/app/views/admin/first_page_made.html.erb
index e4a5119d3..b83e54db1 100644
--- a/app/views/admin/first_page_made.html.erb
+++ b/app/views/admin/first_page_made.html.erb
@@ -19,7 +19,14 @@
<%= render :partial=>"avatar/avatar_form",:style => "display:inline",:locals=> {source:@first_page} %>
-
+
+
+ <%= text_field_tag 'image_width', params[:label_image_width],:value => @first_page.image_width,:size => 30,:style => "font-size:small;width:490px;margin-left:10px;" %>
+
+
+
+ <%= text_field_tag 'image_height', params[:label_imgae_height], :value => @first_page.image_height,:size => 30,:style => "font-size:small;width:490px;margin-left:10px;" %>
+
-
+
<% if get_avatar?(@contest_page) %>
- <%= image_tag(url_to_avatar(@contest_page), size: "75x75") %>
+ <%= image_tag(url_to_avatar(@contest_page), width:@contest_page.image_width,height: @contest_page.image_height) %>
<% else %>
- <%= image_tag '/images/transparent.png', size: "75x75" %>
+ <%= image_tag '/images/transparent.png', width:@contest_page.image_width,height: @contest_page.image_height %>
<% end %>
diff --git a/app/views/welcome/course.html.erb b/app/views/welcome/course.html.erb
index 6ddc64899..dae00f50e 100644
--- a/app/views/welcome/course.html.erb
+++ b/app/views/welcome/course.html.erb
@@ -37,8 +37,8 @@
微信扫码
-
- <%= image_tag(@logoLink, size: '75x75') %>
+
+ <%= image_tag(@logoLink, width:@course_page.image_width,height: @course_page.image_height) %>
diff --git a/app/views/welcome/index.html.erb b/app/views/welcome/index.html.erb
index b2bc1657e..7dd1e751d 100644
--- a/app/views/welcome/index.html.erb
+++ b/app/views/welcome/index.html.erb
@@ -37,9 +37,9 @@
<% if get_avatar?(@first_page) %>
- <%= image_tag(url_to_avatar(@first_page), size: "107x63") %>
+ <%= image_tag(url_to_avatar(@first_page), width:@first_page.image_width,height: @first_page.image_height) %>
<% else %>
- <%= image_tag '/images/transparent.png', size: "107x63" %>
+ <%= image_tag '/images/transparent.png', width:@first_page.image_width,height: @first_page.image_height %>
<% end %>
diff --git a/config/locales/zh.yml b/config/locales/zh.yml
index 439661a27..bb4c445e8 100644
--- a/config/locales/zh.yml
+++ b/config/locales/zh.yml
@@ -572,6 +572,10 @@ zh:
label_site_title: 网站标题
label_site_description: 网站简介
label_site_image: 简介图片
+ label_image_width: 图片宽度
+ label_imgae_height: 图片高度
+ image_width_error_message: 图片宽度只能是50至120之间的整数
+ image_height_error_message: 图片高度只能是50至80之间的整数
label_sort_type: 热门项目排序方式
label_contest_notification_title: 竞赛通知标题
label_contest_notification_content: 竞赛通知内容
diff --git a/db/migrate/20140725062302_add_column.rb b/db/migrate/20140725062302_add_column.rb
new file mode 100644
index 000000000..995ccde3a
--- /dev/null
+++ b/db/migrate/20140725062302_add_column.rb
@@ -0,0 +1,6 @@
+class AddColumn < ActiveRecord::Migration
+ def change
+ add_column("first_pages","image_width",:integer,default: 107)
+ add_column("first_pages","image_height",:integer,default: 63)
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index fe80b7d6f..9191e78ce 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20140725013735) do
+ActiveRecord::Schema.define(:version => 20140725062302) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false
@@ -419,10 +419,12 @@ ActiveRecord::Schema.define(:version => 20140725013735) do
t.string "web_title"
t.string "title"
t.text "description"
- t.datetime "created_at", :null => false
- t.datetime "updated_at", :null => false
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
t.string "page_type"
t.integer "sort_type"
+ t.integer "image_width", :default => 107
+ t.integer "image_height", :default => 63
end
create_table "forums", :force => true do |t|
diff --git a/lib/tasks/first_page.rake b/lib/tasks/first_page.rake
new file mode 100644
index 000000000..762eea5d6
--- /dev/null
+++ b/lib/tasks/first_page.rake
@@ -0,0 +1,26 @@
+# -*coding:utf-8 -*-
+desc "First Page Initialize"
+task :first_page do
+ puts "first_page sync."
+end
+
+namespace :first_page do
+ desc "initialize first page"
+ task :initialize => :environment do
+ first_page = FirstPage.where("page_type = 'project'").first
+ first_page.description = "
micROS多态智能集群机器人操作系统
+中国开源社区
"
+ first_page.image_width = 107;
+ first_page.image_height = 63;
+ course_page = FirstPage.where("page_type = 'course'").first
+ course_page.image_width = 75
+ course_page.image_height = 75
+ contest_page = FirstPage.where("page_type = 'contest'").first
+ contest_page.image_width = 75
+ contest_page.image_height = 75
+ first_page.save
+ course_page.save
+ contest_page.save
+ puts "initialized Successfully"
+ end
+end
\ No newline at end of file
diff --git a/lib/tasks/first_page_ros.rake b/lib/tasks/first_page_ros.rake
deleted file mode 100644
index e69de29bb..000000000