diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index aab9d7b69..1efbb665f 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -322,4 +322,11 @@ class AdminController < ApplicationController end end + #组织 + def organization + @organizations = Organization.all + respond_to do |format| + format.html + end + end end diff --git a/app/controllers/organization_controller.rb b/app/controllers/organization_controller.rb new file mode 100644 index 000000000..db8295e44 --- /dev/null +++ b/app/controllers/organization_controller.rb @@ -0,0 +1,55 @@ +class OrganizationController < ApplicationController + layout 'project_base' + before_filter :require_admin, :except => [:index] + + def index + #@projects = Project.find_by_sql("SELECT * FROM projects WHERE id IN (select MAX(id) from projects GROUP BY enterprise_name)") + @organizations = Organization.all + respond_to do |format| + format.html + end + end + + def new + @organizations = Organization.new + respond_to do |format| + format.html + end + end + + def create + @organizations = Organization.new + @organizations.name = params[:organization][:name] + if @organizations.save + redirect_to admin_organization_url + end + end + + def edit + @organization = Organization.find params[:id] + respond_to do |format| + format.html + end + rescue Exception => e + render_404 + end + + def update + @organization = Organization.find params[:id] + @organization.name = params[:organization][:name] + if @organization.save + redirect_to admin_organization_url + end + rescue Exception => e + render_404 + end + + def destroy + @organization = Organization.find params[:id] + if @organization.destroy + redirect_to admin_organization_url + end + rescue Exception => e + render_404 + end +end diff --git a/app/controllers/organizations_controller.rb b/app/controllers/organizations_controller.rb deleted file mode 100644 index c9cce5752..000000000 --- a/app/controllers/organizations_controller.rb +++ /dev/null @@ -1,6 +0,0 @@ -class OrganizationsController < ApplicationController - layout 'project_base' - def index - @projects = Project.find_by_sql("SELECT * FROM projects WHERE id IN (select MAX(id) from projects GROUP BY enterprise_name)") - end -end diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index dfdcf6576..88ebbb1c1 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -179,6 +179,7 @@ class ProjectsController < ApplicationController @trackers = Tracker.sorted.all @project = Project.new @project.safe_attributes = params[:project] + @project.organization_id = params[:organization_id] if validate_parent_id && @project.save @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id') # Add current user as a project member if he is not admin @@ -412,6 +413,7 @@ class ProjectsController < ApplicationController def update @project.safe_attributes = params[:project] + @project.organization_id = params[:organization_id] #@project.dts_test = params[:project][:dts_test] if validate_parent_id && @project.save @course = Course.find_by_extra(@project.identifier) diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index db2f287eb..290af0068 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -27,28 +27,31 @@ class WelcomeController < ApplicationController def index # 企业版定制: params[:project]为传过来的参数 unless params[:organization].nil? - @cur_projects = Project.find(params[:organization]) - @organization = @cur_projects.enterprise_name - @organization_projects = (current_user.admin? || User.current.member_of?(@cur_projects)) ? Project.where("enterprise_name =? ", @organization) : Project.all_public.where("enterprise_name =? ", @organization) - @e_count = @organization_projects.count - @part_projects = [] - # 取十个 - @organization_projects.each do |obj| - break if(@organization_projects[10] == obj) - @part_projects << Project.visible.find_by_id("#{obj.id}") unless obj.id.nil? - end - # 不够十个的用最火项目替代 - @e_count < 9 ? @part_projects = find_miracle_project( 9 - @e_count, 3,"score desc") : @part_projects - # 配置文件首页定制 + @organization = Organization.find params[:organization] + @organization_projects = Project.visible.joins(:project_status).joins("LEFT JOIN project_scores ON projects.id = project_scores.project_id").where("projects.organization_id = ?", @organization.id).order("score DESC").limit(10).all + @part_projects = @organization_projects.count < 9 ? find_miracle_project( 9 - @organization_projects.count, 3,"score desc") : [] + # @cur_projects = Project.find(params[:organization]) + # @organization = @cur_projects.enterprise_name + # @organization_projects = (current_user.admin? || User.current.member_of?(@cur_projects)) ? Project.where("enterprise_name =? ", @organization) : Project.all_public.where("enterprise_name =? ", @organization) + # @e_count = @organization_projects.count + # @part_projects = [] + # # 取十个 + # @organization_projects.each do |obj| + # break if(@organization_projects[10] == obj) + # @part_projects << Project.visible.find_by_id("#{obj.id}") unless obj.id.nil? + # end + # # 不够十个的用最火项目替代 + # @e_count < 9 ? @part_projects = find_miracle_project( 9 - @e_count, 3,"score desc") : @part_projects + # # 配置文件首页定制 @enterprise_page = FirstPage.find_by_page_type('enterprise') if @enterprise_page.nil? @enterprise_page = FirstPage.new @enterprise_page.page_type = 'enterprise' end - # 主页配置部分结束 - + # 主页配置部分结束 end # end 企业版定制结束 + if @first_page.nil? || @first_page.sort_type.nil? @projects = find_miracle_project(10, 3,"score desc") else @@ -74,7 +77,8 @@ class WelcomeController < ApplicationController @projects = @projects_all.order("score desc") end end - + rescue Exception => e + render_404 end def robots diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 5579fe79b..1ac0a5bbf 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1841,7 +1841,7 @@ module ApplicationHelper # course_all_course_link = link_to l(:label_course_all), {:controller => 'courses', :action => 'index'} course_teacher_all_link = link_to l(:label_teacher_all), {:controller => 'users', :action => 'index', :role => 'teacher', :host => Setting.course_domain} # courses_link = link_to l(:label_course_practice), {:controller => 'courses', :action => 'index'} - users_link = link_to l(:label_software_user), {:controller => 'users', :action => 'index', :host => Setting.user_domain} + #users_link = link_to l(:label_software_user), {:controller => 'users', :action => 'index', :host => Setting.user_domain} # contest_link = link_to l(:label_contest_innovate), {:controller => 'contests', :action => 'index'} bids_link = link_to l(:label_requirement_enterprise), {:controller => 'bids', :action => 'index'} forum_link = link_to l(:label_forum_all), {:controller => "forums", :action => "index"} @@ -1860,7 +1860,7 @@ module ApplicationHelper nav_list.push(courses_link) if @nav_dispaly_course_label && @show_course == 1 # nav_list.push(projects_link) if @nav_dispaly_project_label - nav_list.push(users_link) if @nav_dispaly_user_label + #nav_list.push(users_link) if @nav_dispaly_user_label # nav_list.push(contest_link) if @nav_dispaly_contest_label && @show_contest == 1 nav_list.push(bids_link) if @nav_dispaly_bid_label nav_list.push(forum_link) if @nav_dispaly_forum_label diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index fe6714186..3c1663fcb 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -371,4 +371,19 @@ module ProjectsHelper return projects end + + def project_organizations_id_option + type = [] + option1 = [] + option1 << l(:label_organization_choose) + option1 << 0 + type << option1 + Organization.all.each do |org| + option = [] + option << org.name + option << org.id + type << option + end + type + end end diff --git a/app/models/organization.rb b/app/models/organization.rb new file mode 100644 index 000000000..5f52dee98 --- /dev/null +++ b/app/models/organization.rb @@ -0,0 +1,5 @@ +class Organization < ActiveRecord::Base + attr_accessible :logo_link, :name + + has_many :projects +end diff --git a/app/models/project.rb b/app/models/project.rb index c8364f132..099870bc7 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -89,7 +89,9 @@ class Project < ActiveRecord::Base :association_foreign_key => 'custom_field_id' has_many :tags, :through => :project_tags, :class_name => 'Tag' - has_many :project_tags, :class_name => 'ProjectTags' + has_many :project_tags, :class_name => 'ProjectTags' + + belongs_to :organization # has_many :journals diff --git a/app/views/admin/organization.html.erb b/app/views/admin/organization.html.erb new file mode 100644 index 000000000..582b8b44a --- /dev/null +++ b/app/views/admin/organization.html.erb @@ -0,0 +1,43 @@ +
+ <%= link_to l(:label_organization_new), new_organization_path, :class => 'icon icon-add' %> +
+ +

+ <%=l(:label_organization_list)%> +

+ +
+ + + + + + + + + + <% @organizations.each do |org|%> + "> + + + + + <% end%> + +
+ <%=l(:label_organization)%> + + <%=l(:field_created_on)%> +
+ + <%= link_to org.name,home_path(:organization => org.id) %> + + + <%= format_date(org.created_at) %> + + <%= link_to(l(:button_change), edit_organization_path(org.id), :class => 'icon icon-copy') %> + <%= link_to(l(:button_delete), organization_path(org.id), :method => :delete,:confirm => l(:text_are_you_sure), :class => 'icon icon-del') %> +
+
+ +<% html_title(l(:label_project_plural)) -%> diff --git a/app/views/admin/projects.html.erb b/app/views/admin/projects.html.erb index 762ceae9e..4c9479a6d 100644 --- a/app/views/admin/projects.html.erb +++ b/app/views/admin/projects.html.erb @@ -2,16 +2,25 @@ <%= link_to l(:label_project_new), {:controller => 'projects', :action => 'new'}, :class => 'icon icon-add' %> -

<%=l(:label_project_plural)%>

+

+ <%=l(:label_project_plural)%> +

<%= form_tag({}, :method => :get) do %> -
<%= l(:label_filter_plural) %> - -<%= select_tag 'status', project_status_options_for_select(@status), :class => "small", :onchange => "this.form.submit(); return false;" %> - -<%= text_field_tag 'name', params[:name], :size => 30 %> -<%= submit_tag l(:button_apply), :class => "small", :name => nil %> -<%= link_to l(:button_clear), {:controller => 'admin', :action => 'projects'}, :class => 'icon icon-reload' %> +
+ + <%= l(:label_filter_plural) %> + + + <%= select_tag 'status', project_status_options_for_select(@status), :class => "small", :onchange => "this.form.submit(); return false;" %> + + <%= text_field_tag 'name', params[:name], :size => 30 %> + <%= submit_tag l(:button_apply), :class => "small", :name => nil %> + <%= link_to l(:button_clear), {:controller => 'admin', :action => 'projects'}, :class => 'icon icon-reload' %>
<% end %>   @@ -19,17 +28,31 @@
- - - + + + <% project_tree(@projects) do |project, level| %> <%= project.css_classes %> <%= level > 0 ? "idnt idnt-#{level}" : nil %>"> - - - + + +
<%=l(:label_project)%><%=l(:field_is_public)%><%=l(:field_created_on)%> + <%=l(:label_project)%> + + <%=l(:field_is_public)%> + + <%=l(:field_created_on)%> +
<%= link_to_project_settings(project, {}) %><%= checked_image project.is_public? %><%= format_date(project.created_on) %> + + <%= link_to_project_settings(project, {}) %> + + + <%= checked_image project.is_public? %> + + <%= format_date(project.created_on) %> + <%= link_to(l(:button_archive), { :controller => 'projects', :action => 'archive', :id => project, :status => params[:status] }, :data => {:confirm => l(:text_are_you_sure)}, :method => :post, :class => 'icon icon-lock') unless project.archived? %> <%= link_to(l(:button_unarchive), { :controller => 'projects', :action => 'unarchive', :id => project, :status => params[:status] }, :method => :post, :class => 'icon icon-unlock') if project.archived? && (project.parent.nil? || !project.parent.archived?) %> diff --git a/app/views/organization/_form.html.erb b/app/views/organization/_form.html.erb new file mode 100644 index 000000000..80cc76850 --- /dev/null +++ b/app/views/organization/_form.html.erb @@ -0,0 +1,21 @@ +<%= error_messages_for 'project' %> + +<% unless @organizations.new_record? %> +

+ <%= render :partial=>"avatar/avatar_form",:locals=> {source:@organizations} %> +

+<% end %> +

+ + <%= f.text_field :name, :required => true, :size => 60, :style => "width:290px;" %> +

+ + + <%#= l(:field_description)%> + + + + diff --git a/app/views/organization/edit.html.erb b/app/views/organization/edit.html.erb new file mode 100644 index 000000000..60b7c06a0 --- /dev/null +++ b/app/views/organization/edit.html.erb @@ -0,0 +1,25 @@ +<%= form_for(@organization) do |f|%> +

+ <%=l(:label_organization_edit)%> +

+
+ <%= error_messages_for 'project' %> +

+ <%= render :partial=>"avatar/avatar_form",:locals=> {source:@organization} %> +

+

+ + <%= f.text_field :name, :required => true, :size => 60, :style => "width:290px;" %> +

+ + <%= submit_tag l(:button_create), :class => "enterprise"%> + +
+ <%#= submit_tag l(:button_create_and_continue), :name => 'continue' %> + <%= javascript_tag "$('#project_name').focus();" %> +<% end %> + +<% html_title(l(:label_organization_edit)) -%> \ No newline at end of file diff --git a/app/views/organization/index.html.erb b/app/views/organization/index.html.erb new file mode 100644 index 000000000..f1c50d6ab --- /dev/null +++ b/app/views/organization/index.html.erb @@ -0,0 +1,31 @@ + + <%= l(:label_all_enterprises) %> + +
+
+ <%= l(:label_all_enterprises) %> +
+
+ <% if @organizations.empty? %> +

+ <%= l(:label_enterprise_nil) %> +

+ <% else %> + <% @organizations.each do |organization| %> + <% unless organization.name.blank? %> +
    +
  • + <%= organization.name%> + <%= link_to organization.name, home_path(:organization => organization.id) %> +
  • +
+ <% end %> + <% end %> + <% end %> +
+
+
+
+
    +
    +<% html_title(l(:label_enterprise_all)) -%> diff --git a/app/views/organization/new.html.erb b/app/views/organization/new.html.erb new file mode 100644 index 000000000..163f4a5f5 --- /dev/null +++ b/app/views/organization/new.html.erb @@ -0,0 +1,18 @@ +<%= form_for(@organizations, :method => :post, + :name => 'new_form', + :url => {:controller => 'organization', + :action => 'create'}) do |f|%> +

    + <%=l(:label_organization_new)%> +

    +
    + <%= render :partial => 'form', :locals => { :f => f } %> + + <%= submit_tag l(:button_create), :class => "enterprise"%> + +
    + <%#= submit_tag l(:button_create_and_continue), :name => 'continue' %> + <%= javascript_tag "$('#project_name').focus();" %> +<% end %> + +<% html_title(l(:label_organization_new)) -%> \ No newline at end of file diff --git a/app/views/organizations/index.html.erb b/app/views/organizations/index.html.erb deleted file mode 100644 index 45813ced5..000000000 --- a/app/views/organizations/index.html.erb +++ /dev/null @@ -1,23 +0,0 @@ -<%= l(:label_all_enterprises) %> -
    -
    <%= l(:label_all_enterprises) %>
    -
    - <% if @projects.count == 0 %> -

    <%= l(:label_enterprise_nil) %>

    - <% else %> - <% @projects.each do |organization| %> - <% unless organization.enterprise_name.blank? %> -
      -
    • #{project.enterprise_name} - <%= link_to organization.enterprise_name, home_path(:organization => organization) %>
    • -
    - <% end %> - <% end %> - <% end %> -
    -
    -
    -
    -
      -
      -<% html_title(l(:label_enterprise_all)) -%> diff --git a/app/views/poll/_edit_head.html.erb b/app/views/poll/_edit_head.html.erb index dfa5b5cfc..c74453f6d 100644 --- a/app/views/poll/_edit_head.html.erb +++ b/app/views/poll/_edit_head.html.erb @@ -4,9 +4,14 @@
      - +
      + <%= @poll.polls_description.nil? ? "" : @poll.polls_description.html_safe%> +
      +
      -