From d0a675f2b8a489d8048a2898676743301d63a8a3 Mon Sep 17 00:00:00 2001 From: huang Date: Fri, 30 Jan 2015 14:11:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=81=E4=B8=9A=E7=89=88=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/assets/javascripts/enterprises.js.coffee | 3 + app/assets/stylesheets/enterprises.css.scss | 3 + app/controllers/enterprises_controller.rb | 6 + app/controllers/welcome_controller.rb | 11 + app/helpers/enterprises_helper.rb | 2 + app/helpers/projects_helper.rb | 6 +- app/models/course.rb | 2 +- app/models/project.rb | 4 +- app/views/enterprises/index.html.erb | 25 ++ app/views/projects/_form.html.erb | 2 +- app/views/welcome/_hot_projects_list.html.erb | 23 ++ app/views/welcome/_no_course_title.html.erb | 2 +- app/views/welcome/index.html.erb | 297 ++++++++---------- config/locales/zh.yml | 10 + config/routes.rb | 5 +- ...8032421_add_enterprise_name_to_projects.rb | 5 + db/schema.rb | 41 ++- public/stylesheets/application.css | 3 + .../enterprises_controller_spec.rb | 12 + 19 files changed, 294 insertions(+), 168 deletions(-) create mode 100644 app/assets/javascripts/enterprises.js.coffee create mode 100644 app/assets/stylesheets/enterprises.css.scss create mode 100644 app/controllers/enterprises_controller.rb create mode 100644 app/helpers/enterprises_helper.rb create mode 100644 app/views/enterprises/index.html.erb create mode 100644 app/views/welcome/_hot_projects_list.html.erb create mode 100644 db/migrate/20150128032421_add_enterprise_name_to_projects.rb create mode 100644 spec/controllers/enterprises_controller_spec.rb diff --git a/app/assets/javascripts/enterprises.js.coffee b/app/assets/javascripts/enterprises.js.coffee new file mode 100644 index 000000000..761567942 --- /dev/null +++ b/app/assets/javascripts/enterprises.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/assets/stylesheets/enterprises.css.scss b/app/assets/stylesheets/enterprises.css.scss new file mode 100644 index 000000000..174f3a2ec --- /dev/null +++ b/app/assets/stylesheets/enterprises.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Enterprises controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/enterprises_controller.rb b/app/controllers/enterprises_controller.rb new file mode 100644 index 000000000..c15b6dc8f --- /dev/null +++ b/app/controllers/enterprises_controller.rb @@ -0,0 +1,6 @@ +class EnterprisesController < ApplicationController + layout 'project_base' + def index + @enterprises = Project.find_by_sql("select enterprise_name from projects") + end +end diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index 8e11bceb5..6c28ec502 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -25,6 +25,17 @@ class WelcomeController < ApplicationController before_filter :entry_select, :only => [:index] def index + unless params[:enterprise].nil? + @enterprise = params[:enterprise] + @enterprise_projects = Project.find_by_sql(["select * from projects where enterprise_name =? ", @enterprise]) + @e_count = @enterprise_projects.count + if @e_count < 10 + part_count = 10 -@e_count + # @part_projects = find_all_hot_project part_count, order + @part_projects = find_miracle_project(part_count, 3,"score desc") + limit = 10 - @e_count + end + end if @first_page.nil? || @first_page.sort_type.nil? @projects = find_miracle_project(10, 3,"score desc") else diff --git a/app/helpers/enterprises_helper.rb b/app/helpers/enterprises_helper.rb new file mode 100644 index 000000000..10321ba16 --- /dev/null +++ b/app/helpers/enterprises_helper.rb @@ -0,0 +1,2 @@ +module EnterprisesHelper +end diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 5df3644ad..6b6127979 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -367,7 +367,7 @@ module ProjectsHelper return true end end - + def find_project_repository project unless project.repositories.nil? project.repositories.each do |repository| @@ -375,4 +375,8 @@ module ProjectsHelper end end end + + def get_part_projects e_count, t_count + + end end diff --git a/app/models/course.rb b/app/models/course.rb index a5de93cf7..c986597b3 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -6,7 +6,7 @@ class Course < ActiveRecord::Base STATUS_CLOSED = 5 STATUS_ARCHIVED = 9 - attr_accessible :code, :extra, :name, :state, :tea_id, :time , :location, :state, :term, :password,:is_public,:description,:class_period, :open_student + attr_accessible :code, :extra, :name, :state, :tea_id, :time , :location, :state, :term, :password,:is_public,:description,:class_period, :open_student, :enterprise_name #belongs_to :project, :class_name => 'Course', :foreign_key => :extra, primary_key: :identifier belongs_to :teacher, :class_name => 'User', :foreign_key => :tea_id # 定义一个方法teacher,该方法通过tea_id来调用User表 belongs_to :school, :class_name => 'School', :foreign_key => :school_id #定义一个方法school,该方法通过school_id来调用School表 diff --git a/app/models/project.rb b/app/models/project.rb index 14763347f..d5f3e381e 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -116,6 +116,7 @@ class Project < ActiveRecord::Base validates_associated :repository, :wiki # validates_length_of :description, :maximum => 255 validates_length_of :name, :maximum => 255 + validates_length_of :enterprise_name, :maximum => 255 validates_length_of :homepage, :maximum => 255 validates_length_of :identifier, :in => 1..IDENTIFIER_MAX_LENGTH # donwcase letters, digits, dashes but not digits only @@ -760,7 +761,8 @@ class Project < ActiveRecord::Base 'issue_custom_field_ids', 'project_type', 'dts_test', - 'attachmenttype' + 'attachmenttype', + 'enterprise_name' diff --git a/app/views/enterprises/index.html.erb b/app/views/enterprises/index.html.erb new file mode 100644 index 000000000..9db8d99ab --- /dev/null +++ b/app/views/enterprises/index.html.erb @@ -0,0 +1,25 @@ +
+

+ <%= link_to l(:label_all_enterprises) %> +

+

+ <% if @enterprises.count == 0 %> +

<%= l(:label_enterprise_nil) %>

+ <% else %> + <% @enterprises.each do |enterprise| %> + <% unless enterprise.enterprise_name.blank? %> + + <% end %> + <% end %> + <% end %> +

+
+
+
+ +
+<% html_title(l(:label_school_all)) -%> diff --git a/app/views/projects/_form.html.erb b/app/views/projects/_form.html.erb index 512c2df82..636aadf43 100644 --- a/app/views/projects/_form.html.erb +++ b/app/views/projects/_form.html.erb @@ -8,7 +8,7 @@

<%= f.text_area :description, :rows => 8, :class => 'wiki-edit', :style => "font-size:small;width:490px;margin-left:10px;" %>

- +

<%= f.text_field :enterprise_name, :size => 60, :style => "width:490px;" %>

<%= f.text_field :identifier, :required => true, :size => 60, :style => "width:488px;", :disabled => @project.identifier_frozen?, :maxlength => Project::IDENTIFIER_MAX_LENGTH, value:"#{User.current.id.to_s + '_' +Time.now.to_s.gsub(' ','_').gsub(':','').gsub('+','')}" %> <% unless @project.identifier_frozen? %> diff --git a/app/views/welcome/_hot_projects_list.html.erb b/app/views/welcome/_hot_projects_list.html.erb new file mode 100644 index 000000000..9b941f420 --- /dev/null +++ b/app/views/welcome/_hot_projects_list.html.erb @@ -0,0 +1,23 @@ +

  • +
    + <%= image_tag(get_project_avatar(project), :class => "avatar-4") %> +
    + +
    + <% unless project.is_public %> + <%= l(:label_private) %> + <% end %> + <%= link_to( project.name, project_path(project.id), :class => "d-g-blue d-p-project-name",:title => "#{project.name}" )%> + (<%= link_to "#{projectCount(project)}人", project_member_path(project) ,:course =>'0' %>) +
    +
    + <%=project.description.truncate(90, omission: '...')%> +
    +
    + <%= content_tag "span", l(:label_project_score)+ ":" + red_project_scores(project).to_i.to_s, + :style => "cursor: pointer; display: inline-block; float: right; color: #ec6300;", + :title => "项目得分,综合考虑了项目的各项活动,反映了该项目的活跃程度", + :class => "tooltip", + :id => "tooltip-#{project.id}" %> +
    +
  • \ No newline at end of file diff --git a/app/views/welcome/_no_course_title.html.erb b/app/views/welcome/_no_course_title.html.erb index f16b91dba..3b3849e4e 100644 --- a/app/views/welcome/_no_course_title.html.erb +++ b/app/views/welcome/_no_course_title.html.erb @@ -1,5 +1,5 @@

    - <%= course_title%> + <%= course_title %>

    \ No newline at end of file diff --git a/app/views/welcome/index.html.erb b/app/views/welcome/index.html.erb index 3e341bd27..5dd8c2f86 100644 --- a/app/views/welcome/index.html.erb +++ b/app/views/welcome/index.html.erb @@ -2,197 +2,172 @@ <%= stylesheet_link_tag 'welcome' %> <%= javascript_include_tag 'welcome' %>
    - <%#= render partial: 'wei_xin' %> + <%#= render partial: 'wei_xin' %>
    - - <% if get_avatar?(@first_page) %> - <%= image_tag(url_to_avatar(@first_page), width:@first_page.image_width,height: @first_page.image_height) %> - <% else %> - <%= image_tag '/images/transparent.png', width:@first_page.image_width,height: @first_page.image_height %> - <% end %> - + + <% if @enterprise.nil? %> + <% if get_avatar?(@first_page) %> + <%= image_tag(url_to_avatar(@first_page), width:@first_page.image_width,height: @first_page.image_height) %> + <% else %> + <%= image_tag '/images/transparent.png', width:@first_page.image_width,height: @first_page.image_height %> + <% end %> + <% else %> + <%= image_tag '/images/avatars/Project/0', width:@first_page.image_width,height: @first_page.image_height %> + <% end %>
    -
    - <% unless @first_page.nil? %> - <%= @first_page.description.html_safe %> - <% end %> -
    - -
    +
    + <% if @enterprise.nil? %> + <% unless @first_page.nil? %> + <%= @first_page.description.html_safe %> + <% end %> + <% else %> + + <%= link_to @enterprise, options={:action => 'index', :enterprise => @enterprise}, html_options={ :method => 'get', :style => "color: #E8770D"} %> +
    + <%= @first_page.title %> + <% end %> +
    + +
    -
    +
    -

    - - <%= l(:lable_hot_projects)%> - -

    - - <% if User.current.logged? %> - <%= link_to(l(:label_project_new), {:controller => 'projects', - :action => 'new', - :course => 0, - :project_type =>( @project_type||=0)}, - :class => 'icon icon-add') if User.current.allowed_to?(:add_project, nil, :global => true) %> -      - <%= link_to l(:label_join_project), join_project_projects_path ,:remote => true, :class => 'icon icon-add' %> -      - <% end %> - +

    <%= l(:lable_hot_projects)%>

    + <% if User.current.logged? %> + <%= link_to(l(:label_project_new), {:controller => 'projects', + :action => 'new', + :course => 0, + :project_type =>( @project_type||=0)}, + :class => 'icon icon-add') if User.current.allowed_to?(:add_project, nil, :global => true) %> +      + <%= link_to l(:label_join_project), join_project_projects_path ,:remote => true, :class => 'icon icon-add' %> +      + <% end %>
      - <% @projects.map do |project| %> -
    • -
      - <%= image_tag(get_project_avatar(project), :class => "avatar-4") %> -
      - -
      - <% unless project.is_public %> - - <%= l(:label_private) %> - - <% end %> - <%= link_to( project.name, project_path(project.id), :class => "d-g-blue d-p-project-name",:title => "#{project.name}" )%> - (<%= link_to "#{projectCount(project)}人", project_member_path(project) ,:course =>'0' %>) -
      -
      - - <%=project.description.truncate(90, omission: '...')%> - -
      -
      - <%= content_tag "span", l(:label_project_score)+ ":" + red_project_scores(project).to_i.to_s, - :style => "cursor: pointer; display: inline-block; float: right; color: #ec6300;", - :title => "项目得分,综合考虑了项目的各项活动,反映了该项目的活跃程度", - :class => "tooltip", - :id => "tooltip-#{project.id}" %> -
      -
    • - - <% end; reset_cycle %> + + <% if @enterprise.nil? %> + <% @projects.map do |project| %> + <%= render :partial => 'hot_projects_list', :locals => {:project => project} %> + <% end; reset_cycle %> + + <% else %> + <% if @e_count == 0 %> +

      <%= l(:label_enterprise_tips) %>

      + <% @projects.map do |project| %> + <%= render :partial => 'hot_projects_list', :locals => {:project => project} %> + <% end; reset_cycle %> + <% elsif @e_count < 10 %> + <% @enterprise_projects.map do |project| %> + <%= render :partial => 'hot_projects_list', :locals => {:project => project} %> + <% end %> +

      <%= l(:label_part_enterprise_tips) %>

      + <% @part_projects.map do |project| %> + <%= render :partial => 'hot_projects_list', :locals => {:project => project} %> + <% end %> + <% else %> + <% @part_projects.map do |project| %> + <%= render :partial => 'hot_projects_list', :locals => {:project => project} %> + <% end %> + <% end; reset_cycle %> + <% end; reset_cycle %>
    - -
    + + -
    +
      - +
      -

      - - <%= l(:lable_bar_active)%> - - <%= link_to l(:label_my_question) , newbie_send_path, {:class => 'orangeButton idea_btn', :style => "color: #EEEEEE" }%> - <%= link_to l(:label_my_feedback) , suggestion_send_path, {:class => 'orangeButton idea_btn', :style => "color: #EEEEEE" }%> -

      - - <%= link_to l(:label_more), forums_path %> - +

      <%= l(:lable_bar_active)%> <%= link_to l(:label_my_question) , newbie_send_path, {:class => 'orangeButton idea_btn', :style => "color: #EEEEEE" }%> + <%= link_to l(:label_my_feedback) , suggestion_send_path, {:class => 'orangeButton idea_btn', :style => "color: #EEEEEE" }%>

      + <%= link_to l(:label_more), forums_path %>
      <% topics = find_new_forum_topics(6) %> - <% topics.includes(:forum, :last_reply, :author).each do |topic|%> - -
    • -
      - <%= link_to '['+topic.forum.name + ']',forum_path(topic.forum),:class => 'memo_Bar_title' %> - <%= link_to topic.subject.truncate(30, omission: '...'), topic.event_url,title: topic.subject %> -
      -
      - - <%= "#{l(:label_updated_time, value: time_tag_welcome(topic_last_time topic))}".html_safe %> - - - <%= l(:label_question_sponsor)%>: - <%= link_to topic.author.login.truncate(10, omission: '...'),user_path(topic.author),title: topic.author.login %> - - - <% unless (topic.last_reply.nil? || topic.last_reply.author.nil?) %> - <%= l(:label_final_reply)%>: - <%=link_to topic.last_reply.author.login.truncate(10, omission: '...'),user_path(topic.last_reply.author),title: topic.last_reply.author.login%> - <% end %> - - - <%= l(:label_reply)%> - (<%= link_to topic.try(:replies_count), topic.event_url %>) - -
      -
    • - - <% end %> + <% topics.includes(:forum, :last_reply, :author).each do |topic|%> + +
    • +
      + <%= link_to '['+topic.forum.name + ']',forum_path(topic.forum),:class => 'memo_Bar_title' %> + <%= link_to topic.subject.truncate(30, omission: '...'), topic.event_url,title: topic.subject %> +
      +
      + <%= "#{l(:label_updated_time, value: time_tag_welcome(topic_last_time topic))}".html_safe %> + <%= l(:label_question_sponsor)%>: + <%= link_to topic.author.login.truncate(10, omission: '...'),user_path(topic.author),title: topic.author.login %> + <% unless (topic.last_reply.nil? || topic.last_reply.author.nil?) %> + <%= l(:label_final_reply)%>: + <%= link_to topic.last_reply.author.login.truncate(10, omission: '...'),user_path(topic.last_reply.author),title: topic.last_reply.author.login%> + <% end %> + <%= l(:label_reply)%> + (<%= link_to topic.try(:replies_count), topic.event_url %>) +
      +
    • + + + <% end %>
    -
    +
    <%= render partial: 'link_to_another' %> \ No newline at end of file diff --git a/config/locales/zh.yml b/config/locales/zh.yml index d058a6c1b..d6ecec369 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -275,6 +275,7 @@ zh: label_course_closed_tips: "确定要%{desc}课程?" # end field_name: 名称 + field_enterprise_name: 企业名 #added by huang field_tea_name: 教师 field_couurse_time: 学时 @@ -2313,3 +2314,12 @@ zh: label_technical_support: 技术支持: label_feedback: 意见反馈 + + # 项目企业模块 + label_all_enterprises: 所有企业 + label_my_enterprise: 我的企业 + label_enterprise_tips: 暂时还没有该企业对应的项目,系统的其它项目您可能会感兴趣! + label_part_enterprise_tips: 系统的其它项目您可能也会感兴趣! + label_enterprise_nil: 改模块为最新上线模块,目前还未有项目关联到企业! + label_enterprises: 名企 + diff --git a/config/routes.rb b/config/routes.rb index 122481d38..6fc78fd49 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -26,6 +26,8 @@ # Example: :via => :get ====> :via => :get RedmineApp::Application.routes.draw do + get "enterprises/index" + #match '/contests/:id/contestnotifications', :controller => 'contestnotifications', :action => 'index' mount Mobile::API => '/api' @@ -388,7 +390,8 @@ RedmineApp::Application.routes.draw do match '/statistics', :to => 'projects#statistics', :as => 'statistics', :via => :get # match '/investor', :controller => 'projects', :action => 'investor', :as => 'investor', :via => :get match '/homework', :to => 'projects#homework', :as => 'homework', :via => :get - + match 'enterprise', :to => 'enterprises#index', :as => 'index', :via => :get + # match '/activity', :controller => 'activities', :action => 'index', :as => 'activity', :via => :get # match '/repository', :controller => 'repositories', :action => 'show', :repository_id => nil, :path => nil, :rev => nil, :as => 'repository', :via => :get # match '/', :controller => 'projects', :action => 'show', :as => 'project_show', :via => :get diff --git a/db/migrate/20150128032421_add_enterprise_name_to_projects.rb b/db/migrate/20150128032421_add_enterprise_name_to_projects.rb new file mode 100644 index 000000000..8ec2b25a3 --- /dev/null +++ b/db/migrate/20150128032421_add_enterprise_name_to_projects.rb @@ -0,0 +1,5 @@ +class AddEnterpriseNameToProjects < ActiveRecord::Migration + def change + add_column :projects, :enterprise_name, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 98476f9dd..7c9e6d556 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 => 20150123020615) do +ActiveRecord::Schema.define(:version => 20150128032421) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -925,6 +925,7 @@ ActiveRecord::Schema.define(:version => 20150123020615) do t.integer "attachmenttype", :default => 1 t.integer "user_id" t.integer "dts_test", :default => 0 + t.string "enterprise_name" end add_index "projects", ["lft"], :name => "index_projects_on_lft" @@ -1069,6 +1070,14 @@ ActiveRecord::Schema.define(:version => 20150123020615) do t.string "description" end + create_table "social_groups", :force => true do |t| + t.string "name" + t.text "description" + t.integer "user_id" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + create_table "softapplications", :force => true do |t| t.string "name" t.text "description" @@ -1284,6 +1293,36 @@ ActiveRecord::Schema.define(:version => 20150123020615) do add_index "versions", ["project_id"], :name => "versions_project_id" add_index "versions", ["sharing"], :name => "index_versions_on_sharing" + create_table "voting_choices", :force => true do |t| + t.integer "poll_id", :null => false + t.string "text", :null => false + t.datetime "created_on", :null => false + t.integer "position", :default => 1 + end + + add_index "voting_choices", ["poll_id"], :name => "choices_poll_id" + + create_table "voting_polls", :force => true do |t| + t.integer "project_id", :null => false + t.string "question", :null => false + t.datetime "created_on", :null => false + t.boolean "revote" + end + + add_index "voting_polls", ["project_id"], :name => "polls_project_id" + + create_table "voting_votes", :force => true do |t| + t.integer "user_id", :null => false + t.integer "poll_id", :null => false + t.integer "choice_id", :null => false + t.datetime "created_on", :null => false + end + + add_index "voting_votes", ["choice_id"], :name => "votes_choice_id" + add_index "voting_votes", ["poll_id"], :name => "votes_poll_id" + add_index "voting_votes", ["user_id", "poll_id"], :name => "votes_user_poll_unique", :unique => true + add_index "voting_votes", ["user_id"], :name => "votes_user_id" + create_table "watchers", :force => true do |t| t.string "watchable_type", :default => "", :null => false t.integer "watchable_id", :default => 0, :null => false diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index db57596bc..9c8471315 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -9,6 +9,9 @@ h4, .wiki h3 {font-size: 13px;} h4 {border-bottom: 1px dotted #bbb;} /*huang*/ /*current position*/ +.enterprise_all{ + padding-left: 20px; +} .course_ad{ position:absolute; visibility:visible; diff --git a/spec/controllers/enterprises_controller_spec.rb b/spec/controllers/enterprises_controller_spec.rb new file mode 100644 index 000000000..49ca325bf --- /dev/null +++ b/spec/controllers/enterprises_controller_spec.rb @@ -0,0 +1,12 @@ +require 'spec_helper' + +describe EnterprisesController do + + describe "GET 'index'" do + it "returns http success" do + get 'index' + response.should be_success + end + end + +end