From 3cda9294fde0d4d3a4aa371f27ba4523525d1857 Mon Sep 17 00:00:00 2001 From: z9hang Date: Wed, 16 Jul 2014 09:40:18 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=B3=A8=E9=87=8A=E6=9C=AA=E8=83=BD?= =?UTF-8?q?=E5=AE=89=E8=A3=85=E7=9A=84gem?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gemfile | 2 +- Gemfile.lock | 8 -------- db/schema.rb | 1 + 3 files changed, 2 insertions(+), 9 deletions(-) diff --git a/Gemfile b/Gemfile index 91259aad8..3431ad649 100644 --- a/Gemfile +++ b/Gemfile @@ -43,7 +43,7 @@ group :development, :test do gem 'spork-testunit' gem 'guard-spork' gem 'guard-test', '~> 1.0.0' - gem 'ruby-prof' + #gem 'ruby-prof' gem 'pry' gem 'pry-nav' end diff --git a/Gemfile.lock b/Gemfile.lock index fe06a5e46..5d5f167ca 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -100,7 +100,6 @@ GEM hike (1.2.3) htmlentities (4.3.2) i18n (0.6.1) - iconv (1.0.4) journey (1.0.4) jquery-rails (2.0.3) railties (>= 3.1.0, < 5.0) @@ -190,7 +189,6 @@ GEM sass-rails rmagick (2.13.2) ruby-openid (2.1.8) - ruby-prof (0.15.1) rubyzip (1.1.6) sass (3.3.10) sass-rails (3.2.6) @@ -235,8 +233,6 @@ GEM win32console (1.3.2-x86-mingw32) xpath (1.0.0) nokogiri (~> 1.3) - zip-zip (0.3) - rubyzip (>= 1.0.0) PLATFORMS ruby @@ -257,7 +253,6 @@ DEPENDENCIES guard-test (~> 1.0.0) htmlentities i18n (~> 0.6.0) - iconv jquery-rails (~> 2.0.2) kaminari mocha (~> 0.13.3) @@ -273,12 +268,9 @@ DEPENDENCIES rich (= 1.4.6) rmagick (>= 2.0.0) ruby-openid (~> 2.1.4) - ruby-prof - rubyzip sass-rails (~> 3.2.3) seems_rateable! shoulda (> 3.3.2) spork-testunit therubyracer uglifier (>= 1.0.3) - zip-zip diff --git a/db/schema.rb b/db/schema.rb index f318ff96a..6a732b3ce 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -379,6 +379,7 @@ ActiveRecord::Schema.define(:version => 20140714081030) do t.text "description" t.datetime "created_on" t.integer "user_id", :default => 0 + t.integer "is_public", :default => 1 end add_index "documents", ["category_id"], :name => "index_documents_on_category_id" From cc4bf3b328262c80568b4e90c78d00d141f93d93 Mon Sep 17 00:00:00 2001 From: z9hang Date: Wed, 16 Jul 2014 14:22:12 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=B6=85=E7=BA=A7?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E5=91=98=E6=8E=A7=E5=88=B6=E9=A6=96=E9=A1=B5?= =?UTF-8?q?=E7=83=AD=E9=97=A8=E9=A1=B9=E7=9B=AE=E6=8E=92=E5=BA=8F=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/admin_controller.rb | 1 + app/controllers/welcome_controller.rb | 28 +++++++++++++++++++ app/helpers/welcome_helper.rb | 4 +-- app/models/first_page.rb | 2 +- app/views/admin/first_page_made.html.erb | 8 ++++++ app/views/welcome/index.html.erb | 4 +-- config/locales/zh.yml | 1 + ...0140716021202_add_column_for_first_page.rb | 5 ++++ db/migrate/20140716021558_set_sort_type.rb | 8 ++++++ db/schema.rb | 3 +- 10 files changed, 58 insertions(+), 6 deletions(-) create mode 100644 db/migrate/20140716021202_add_column_for_first_page.rb create mode 100644 db/migrate/20140716021558_set_sort_type.rb diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index fea29759d..171d34377 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -244,6 +244,7 @@ class AdminController < ApplicationController @first_page.web_title = params[:web_title] @first_page.description = params[:description] @first_page.title = params[:title] + @first_page.sort_type = params[:sort_type] if @first_page.save respond_to do |format| flash[:notice] = l(:notice_successful_update) diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index 03bca6162..48c0cf1fb 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -17,12 +17,40 @@ class WelcomeController < ApplicationController include ApplicationHelper + include WelcomeHelper 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 + @hot_projects = find_miracle_project(10, 3) + @hot_projects_ids = [] + @hot_projects.each do |p| + @hot_projects_ids << p + end + @projects_all = Project.active.visible. + joins("LEFT JOIN #{ProjectStatus.table_name} ON #{Project.table_name}.id = #{ProjectStatus.table_name}.project_id"). + where("#{Project.table_name}.project_type = ? and #{Project.table_name}.id in (?)", Project::ProjectType_project,@hot_projects_ids) + + case @first_page.sort_type + when 0 + @projects = @projects_all.order("created_on desc") + when 1 + @projects = @projects_all.order("grade desc") + when 2 + @projects = @projects_all.order("watchers_count desc") + + #gcm + #when '3' + #@projects=desc_sort_course_by_avtivity(@project_activity_count_array,@project_all_array) + # @projects=handle_project @projects_all,@project_activity_count + # @s_type = 3 + # @projects = @projects[@project_pages.offset, @project_pages.per_page] + + else + @projects = @projects_all.order("grade desc") + end end def robots diff --git a/app/helpers/welcome_helper.rb b/app/helpers/welcome_helper.rb index 4ff5a48e4..99357a3d0 100644 --- a/app/helpers/welcome_helper.rb +++ b/app/helpers/welcome_helper.rb @@ -208,7 +208,7 @@ module WelcomeHelper #c1 = find_new_project(sum).to_a.dup #c2 = find_all_hot_project(sum).to_a.dup #(c2.take(sum-max)+c1.take(max)).take(sum) - find_all_hot_project(sum).to_a.dup + find_all_hot_project(sum).dup#.to_a.dup end def find_new_course limit=15 @@ -433,7 +433,7 @@ module WelcomeHelper # FROM projects AS p LEFT OUTER JOIN ( # SELECT project_id,grade FROM project_statuses # WHERE project_type = #{project_type} ORDER BY #{order_by} LIMIT #{limit} ) AS t ON p.id = t.project_id ") - Project.visible.joins(:project_status).where("#{Project.table_name}.project_type = ?", project_type).order(order_by).limit(limit).all + Project.visible.joins(:project_status).where("#{Project.table_name}.project_type = ?", project_type).order(order_by).limit(limit)#.all end def sort_bid_by_hot_rails reward_type, limit = 10 diff --git a/app/models/first_page.rb b/app/models/first_page.rb index 113edc0f8..d1fca531e 100644 --- a/app/models/first_page.rb +++ b/app/models/first_page.rb @@ -1,6 +1,6 @@ class FirstPage < ActiveRecord::Base attr_accessible :description, :title, :web_title,:page_type - validates_presence_of :web_title, :title, :description,:page_type + validates_presence_of :web_title, :title, :description,:page_type,:sort_type validates_length_of :web_title,:title, maximum: 30 validates_length_of :description, maximum: 100 end diff --git a/app/views/admin/first_page_made.html.erb b/app/views/admin/first_page_made.html.erb index d3b7416e4..242b7c689 100644 --- a/app/views/admin/first_page_made.html.erb +++ b/app/views/admin/first_page_made.html.erb @@ -28,6 +28,14 @@ <%= 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 %> diff --git a/app/views/welcome/index.html.erb b/app/views/welcome/index.html.erb index 0cc5c5e2a..8ffbb0469 100644 --- a/app/views/welcome/index.html.erb +++ b/app/views/welcome/index.html.erb @@ -60,8 +60,8 @@ <%= link_to "更多>>", { :controller => 'projects', :action => 'index', :project_type => 0, :host => Setting.project_domain}, :target => "_blank" %>
    - <% projects = find_miracle_project(10, 3) %> - <% projects.map do |project| %> + <% #projects = find_miracle_project(10, 3) %> + <% @projects.map do |project| %>
  • diff --git a/config/locales/zh.yml b/config/locales/zh.yml index 593a73aa6..b1ec95186 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -572,6 +572,7 @@ zh: label_site_title: 网站标题 label_site_description: 网站简介 label_site_image: 简介图片 + label_sort_type: 热门项目排序方式 #by young label_requirement: 需求 label_new_course: 课程列表 diff --git a/db/migrate/20140716021202_add_column_for_first_page.rb b/db/migrate/20140716021202_add_column_for_first_page.rb new file mode 100644 index 000000000..a7cd6854a --- /dev/null +++ b/db/migrate/20140716021202_add_column_for_first_page.rb @@ -0,0 +1,5 @@ +class AddColumnForFirstPage < ActiveRecord::Migration + def change + add_column("first_pages","sort_type",:integer) + end +end diff --git a/db/migrate/20140716021558_set_sort_type.rb b/db/migrate/20140716021558_set_sort_type.rb new file mode 100644 index 000000000..04511ca2b --- /dev/null +++ b/db/migrate/20140716021558_set_sort_type.rb @@ -0,0 +1,8 @@ +class SetSortType < ActiveRecord::Migration + def change + FirstPage.all.each do |fp| + fp.sort_type = 1 + fp.save + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 6a732b3ce..6134f1601 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 => 20140714081030) do +ActiveRecord::Schema.define(:version => 20140716021558) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -415,6 +415,7 @@ ActiveRecord::Schema.define(:version => 20140714081030) do t.datetime "created_at", :null => false t.datetime "updated_at", :null => false t.string "page_type" + t.integer "sort_type" end create_table "forums", :force => true do |t| From 386aa1adc385e3dbe1cd8b8f77887c9565a256c5 Mon Sep 17 00:00:00 2001 From: yanxd Date: Wed, 16 Jul 2014 14:35:54 +0800 Subject: [PATCH 3/3] . --- test/fixtures/courses.yml | 159 ++++++++++++++------- test/fixtures/user_extensions.yml | 43 +++++- test/fixtures/users.yml | 40 +++++- test/functional/courses_controller_test.rb | 50 +++++++ 4 files changed, 235 insertions(+), 57 deletions(-) create mode 100644 test/functional/courses_controller_test.rb diff --git a/test/fixtures/courses.yml b/test/fixtures/courses.yml index 69665d935..c3b7c22a3 100644 --- a/test/fixtures/courses.yml +++ b/test/fixtures/courses.yml @@ -1,69 +1,126 @@ --- -courses_006: - id: 6 - tea_id: 193 - name: - state: 0 +courses_008: + id: 8 + tea_id: 5 + name: 分布式计算环境 + state: code: time: 2013 - extra: course2013-09-30_08-11-15 - created_at: 2013-09-30 08:11:15.000000000 +08:00 - updated_at: 2013-10-11 12:34:29.000000000 +08:00 + extra: course2013-09-30_23-36-00 + created_at: 2013-09-30 15:36:00.000000000 Z + updated_at: 2014-04-19 01:50:41.000000000 Z location: - term: "秋季学期" + term: 春季学期 + string: + password: '1234' + setup_time: + endup_time: '2014-04-18 00:00:00' + class_period: '' + school_id: 117 + description: 介绍分布计算模型,分布计算平台,分布式软件开发环境等分布计算方向的概念、技术和环境,并通过实验提高学生的实践能力。 + status: 1 + attachmenttype: 2 + lft: + rgt: + is_public: 1 + inherit_members: 1 +courses_058: + id: 58 + tea_id: 1168 + name: 软件工程实践 + state: + code: + time: 2014 + extra: course2014-04-17_17-12-17 + created_at: 2014-04-17 09:12:17.000000000 Z + updated_at: 2014-04-17 09:12:17.000000000 Z + location: + term: 春季学期 + string: + password: SEP2014 + setup_time: + endup_time: + class_period: '18' + school_id: 0 + description: 国防科技大学计算机学院工程硕士专业选修课。 + status: 1 + attachmenttype: 2 + lft: + rgt: + is_public: 1 + inherit_members: 1 +courses_059: + id: 59 + tea_id: 193 + name: 软件项目管理 + state: + code: + time: 2014 + extra: course2014-04-18_18-10-46 + created_at: 2014-04-18 10:10:46.000000000 Z + updated_at: 2014-04-18 10:10:46.000000000 Z + location: + term: 春季学期 string: password: software setup_time: endup_time: - class_period: -courses_004: - id: 4 - tea_id: 193 - name: - state: 0 - code: - time: 2013 - extra: course2013-09-27_11-16-11 - created_at: 2013-09-27 11:16:11.000000000 +08:00 - updated_at: 2013-12-21 10:55:20.000000000 +08:00 - location: - term: "秋季学期" - string: - password: '123456' - setup_time: '' - endup_time: '' - class_period: '' -courses_012: - id: 12 - tea_id: 193 - name: + class_period: '30' + school_id: 0 + description: 面向“软件工程”专业的本科生 + status: 1 + attachmenttype: 2 + lft: + rgt: + is_public: 1 + inherit_members: 1 +courses_060: + id: 60 + tea_id: 1179 + name: android开发 state: code: - time: 2013 - extra: course2013-10-08_20-52-10 - created_at: 2013-10-08 20:52:10.000000000 +08:00 - updated_at: 2013-10-08 20:52:10.000000000 +08:00 + time: 2014 + extra: course2014-04-19_15-40-39 + created_at: 2014-04-19 07:40:39.000000000 Z + updated_at: 2014-04-19 07:40:39.000000000 Z location: - term: "秋季学期" + term: 春季学期 string: - password: software + password: trustie740208 setup_time: endup_time: - class_period: -courses_020: - id: 20 - tea_id: 193 - name: + class_period: '48' + school_id: 37 + description: '' + status: 1 + attachmenttype: 2 + lft: + rgt: + is_public: 1 + inherit_members: 1 +courses_061: + id: 61 + tea_id: 29 + name: 测试课程1 state: code: - time: 2013 - extra: course2013-10-21_20-47-58 - created_at: 2013-10-21 20:47:58.000000000 +08:00 - updated_at: 2014-01-08 09:48:56.000000000 +08:00 + time: 2014 + extra: course2014-06-04_14-51-56 + created_at: 2014-06-04 06:51:56.000000000 Z + updated_at: 2014-07-15 01:40:49.000000000 Z location: - term: '秋季学期' + term: 春季学期 string: - password: multi-agent - setup_time: '' - endup_time: '' - class_period: '' + password: '1234' + setup_time: + endup_time: '2014-07-14 00:00:00' + class_period: '23' + school_id: 1579 + description: '233' + status: 1 + attachmenttype: 2 + lft: + rgt: + is_public: 0 + inherit_members: 1 diff --git a/test/fixtures/user_extensions.yml b/test/fixtures/user_extensions.yml index c8f2ebf58..8c19ad7b1 100644 --- a/test/fixtures/user_extensions.yml +++ b/test/fixtures/user_extensions.yml @@ -1,5 +1,3 @@ -# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html - person_one_extra: id: 44 user_id: 29 @@ -36,4 +34,43 @@ person_mao_extra: student_id: nil teacher_realname: nil student_realname: nil - location_city: nil \ No newline at end of file + location_city: nil +ue_lirongzhen: + id: 587 + user_id: 642 + birthday: + brief_introduction: + gender: 0 + location: 河南 + occupation: kylinos-cloud + work_experience: + zip_code: + created_at: 2014-03-18 14:52:55.000000000 Z + updated_at: 2014-03-26 07:19:04.000000000 Z + technical_title: + identity: 1 + student_id: '14066023' + teacher_realname: + student_realname: + location_city: 周口 + school_id: +ue_yingang: + id: 6 + user_id: 5 + birthday: + brief_introduction: 现有功能的精细化! + gender: 0 + location: 湖南 + occupation: 国防科学技术大学计算机学院 + work_experience: + zip_code: + created_at: 2013-09-24 09:36:12.000000000 Z + updated_at: 2014-04-19 08:16:55.000000000 Z + technical_title: 副教授 + identity: 0 + student_id: '' + teacher_realname: + student_realname: + location_city: 长沙 + school_id: 117 + diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml index 587199f62..cf7f6da7c 100644 --- a/test/fixtures/users.yml +++ b/test/fixtures/users.yml @@ -72,7 +72,7 @@ users_003: login: dlopper type: User users_005: - id: 5 + id: 12 created_on: 2006-07-19 19:33:19 +02:00 # Locked status: 3 @@ -165,5 +165,39 @@ groups_011: id: 11 lastname: B Team type: Group - - +users_yingang_teacher: + id: 5 + login: jacknudt + hashed_password: dbbd96684c9a64afe9c4935ce0b517e5e9c08064 + firstname: 刚 + lastname: 尹 + mail: jack_nudt@163.com + admin: false + status: 1 + last_login_on: 2014-04-27 13:49:18.000000000 Z + language: zh + auth_source_id: + created_on: 2013-06-25 05:20:59.000000000 Z + updated_on: 2014-07-16 03:37:51.000000000 Z + type: User + identity_url: + mail_notification: only_my_events + salt: 92944df2ce4dae1a4f01007263c5d8bb +users_lirongzhen_student: + id: 642 + login: lirongzhen + hashed_password: 070922b015398577c3ae0d87a68d5ffa93bf82e9 + firstname: 荣振 + lastname: 李 + mail: lrongzheni@gmail.com + admin: false + status: 1 + last_login_on: 2014-04-16 14:06:07.000000000 Z + language: zh + auth_source_id: + created_on: 2014-03-18 14:52:55.000000000 Z + updated_on: 2014-03-26 07:19:04.000000000 Z + type: User + identity_url: + mail_notification: all + salt: dca66d84fcb88b37de04dd3058f73576 diff --git a/test/functional/courses_controller_test.rb b/test/functional/courses_controller_test.rb new file mode 100644 index 000000000..865a4524d --- /dev/null +++ b/test/functional/courses_controller_test.rb @@ -0,0 +1,50 @@ +require File.expand_path('../../test_helper', __FILE__) + +class CoursesControllerTest < ActionController::TestCase + fixtures :courses, :users, :user_extensions, :roles, :members, :member_roles, :enabled_modules, :boards, :messages + + def setup + @request.session[:user_id] = nil + @request.session[:ctime] = Time.now.to_i + @request.session[:atime] = Time.now.to_i + Setting.default_language = 'en' + end + + def test_index_by_anonymous_should_not_show_private_projects + get :index + assert_response :success + assert_template 'index' + courses = assigns(:courses) + assert_not_nil courses + assert courses.all?(&:is_public?) + end + + test "test_create_courses_anyone_temporary" do + @request.session[:user_id] = 5 + Role.find(2).add_permisstion! :add_course + + + get :new + assert_redirected_to new_course_path + assert_response :success + end + +# test "#index by non-admin user with view_time_entries permission should show overall spent time link" do +# @request.session[:user_id] = 3 +# get :index +# assert_template 'index' +# assert_select 'a[href=?]', '/time_entries' +# end +# +# test "#index by non-admin user without view_time_entries permission should not show overall spent time link" do +# Role.find(2).remove_permission! :view_time_entries +# Role.non_member.remove_permission! :view_time_entries +# Role.anonymous.remove_permission! :view_time_entries +# @request.session[:user_id] = 3 +# +# get :index +# assert_template 'index' +# assert_select 'a[href=?]', '/time_entries', 0 +# end +end +