添加了版主功能
This commit is contained in:
parent
89b668be82
commit
d381423c0e
|
@ -1,5 +1,8 @@
|
|||
class OpenSourceProjectsController < ApplicationController
|
||||
|
||||
before_filter :find_osp, :only => [:master_apply]
|
||||
before_filter :require_master, :only => [:master_apply]
|
||||
|
||||
helper :sort
|
||||
include SortHelper
|
||||
helper :apply_project_masters
|
||||
|
@ -9,6 +12,9 @@ class OpenSourceProjectsController < ApplicationController
|
|||
# GET /open_source_projects
|
||||
# GET /open_source_projects.json
|
||||
def index
|
||||
@app_dir = params[:app_dir]
|
||||
@language = params[:language]
|
||||
@created_at = params[:created_at]
|
||||
per_page_option = 10
|
||||
|
||||
@open_source_projects = OpenSourceProject.all
|
||||
|
@ -24,6 +30,18 @@ class OpenSourceProjectsController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def master_apply
|
||||
@apply = @open_source_project.apply_tips
|
||||
@applicants = @open_source_project.applicants
|
||||
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
render :layout => "base_opensource_p"
|
||||
}
|
||||
format.json { render json: @open_source_project }
|
||||
end
|
||||
end
|
||||
|
||||
# GET /open_source_projects/1
|
||||
# GET /open_source_projects/1.json
|
||||
def show
|
||||
|
@ -127,4 +145,15 @@ class OpenSourceProjectsController < ApplicationController
|
|||
format.json { head :no_content }
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def require_master
|
||||
render_403 unless @open_source_project.admin?(User.current)
|
||||
end
|
||||
|
||||
def find_osp
|
||||
@open_source_project = OpenSourceProject.find(params[:id])
|
||||
render_404 unless @open_source_project.present?
|
||||
end
|
||||
end
|
||||
|
|
|
@ -11,7 +11,7 @@ module ApplyProjectMastersHelper
|
|||
|
||||
css = apply_css(objects) << options[0].to_s
|
||||
|
||||
text = applied ? (allowed ? ("123") : ("123")) : ("231")
|
||||
text = applied ? (allowed ? l(:you_are_master) : l(:cancel_apply)) : l(:apply_master)
|
||||
|
||||
url = apply_project_masters_path(
|
||||
:object_type => objects.first.class.to_s.underscore,
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
class ApplyProjectMaster < ActiveRecord::Base
|
||||
# attr_accessible :title, :body
|
||||
# status 1是申请者,2是版主
|
||||
belongs_to :apply, :polymorphic => true
|
||||
belongs_to :user
|
||||
|
||||
|
|
|
@ -7,6 +7,10 @@ class OpenSourceProject < ActiveRecord::Base
|
|||
has_many :relative_memos, :class_name => 'RelativeMemo', :foreign_key => 'osp_id', :dependent => :destroy
|
||||
has_many :tags, :through => :project_tags, :class_name => 'Tag'
|
||||
has_many :project_tags, :class_name => 'ProjectTags'
|
||||
has_many :masters, :class_name => 'ApplyProjectMaster', :as => :apply, :dependent => :delete_all, :conditions => "#{ApplyProjectMaster.table_name}.status = 2"
|
||||
has_many :admin, :through => :masters, :class_name => 'User'
|
||||
has_many :apply_tips, :class_name => 'ApplyProjectMaster', :as => :apply, :dependent => :delete_all, :conditions => "#{ApplyProjectMaster.table_name}.status = 1"
|
||||
has_many :applicants, :class_name => 'User', :through => :apply_tips, :source => :user
|
||||
|
||||
|
||||
acts_as_taggable
|
||||
|
@ -22,10 +26,20 @@ class OpenSourceProject < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def applied_by?(user)
|
||||
self.applies.each do |apply|
|
||||
if apply.user_id == user.id
|
||||
return true
|
||||
end
|
||||
end
|
||||
false
|
||||
end
|
||||
|
||||
def allowed?(user)
|
||||
self.applies.each do |apply|
|
||||
if apply.user_id == user.id and apply.status == 2
|
||||
return true
|
||||
end
|
||||
end
|
||||
false
|
||||
end
|
||||
|
||||
|
@ -42,6 +56,14 @@ class OpenSourceProject < ActiveRecord::Base
|
|||
ApplyProjectMaster.delete_all "apply_type = '#{self.class}' AND apply_id = #{self.id} AND user_id = #{user.id}"
|
||||
end
|
||||
|
||||
def admin?(user)
|
||||
if user.admin? or ApplyProjectMaster.find(:all, :conditions => ["user_id = ? and apply_type = 'OpenSourceProject' and apply_id = ? and status = ?", user.id, self.id, 2]).present?
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
def reset_counters!
|
||||
self.class.reset_counters!(id)
|
||||
end
|
||||
|
|
|
@ -47,13 +47,14 @@
|
|||
<% @open_source_project = OpenSourceProject.find(params[:id])%>
|
||||
<table>
|
||||
<tr>
|
||||
<td>图片</td>
|
||||
<td><%= image_tag(url_to_avatar(Project.find(2)), :class => 'avatar2') %></td>
|
||||
<td>
|
||||
<div class="info-course">
|
||||
<%= @open_source_project.name %>
|
||||
</div><div>
|
||||
|
||||
</div><div style="margin-left: 20px;">
|
||||
</div>
|
||||
<div style="margin-left: 20px;">
|
||||
<%= apply_super_user(@open_source_project, User.current) %>
|
||||
|
||||
</div></td>
|
||||
|
@ -104,19 +105,35 @@
|
|||
<!-- added by william -for tag -->
|
||||
<div class="user_tags">
|
||||
<div id="tags">
|
||||
<%= render :partial => 'tags/tag', :locals => {:obj => @open_source_project,:object_flag => "7"}%>
|
||||
<%= render :partial => 'tags/tag', :locals => {:obj => @open_source_project, :object_flag => "7"}%>
|
||||
</div>
|
||||
</div>
|
||||
<!-- tag -->
|
||||
</div>
|
||||
|
||||
<!--tool-->
|
||||
<% if @open_source_project.admin?(User.current) %>
|
||||
<div class="user_underline"></div>
|
||||
<div class="font_title_left">
|
||||
管理
|
||||
</div>
|
||||
|
||||
<div class="tools ">
|
||||
<ul>
|
||||
<li>
|
||||
<%= link_to "版主申请" ,master_apply_open_source_project_path(@open_source_project) %>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<!--tool-->
|
||||
<div class="user_underline"></div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div id="content"><%#=
|
||||
<div class="tabs_new">
|
||||
<div id="content">
|
||||
<%#= <div class="tabs_new">
|
||||
|
||||
</div>%>
|
||||
<%= render_flash_messages %>
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
<div class="information">
|
||||
<p class="stats">
|
||||
<strong><span style="font-size: 17px;margin-left: 145px">
|
||||
<%= 1%></span></strong>
|
||||
<%= project.users_count %></span></strong>
|
||||
<%= content_tag('span', l(:label_x_follow_people,:count =>0)) %>
|
||||
</p>
|
||||
<p class="stats">
|
||||
|
@ -21,12 +21,12 @@
|
|||
</p>
|
||||
<p class="stats">
|
||||
<strong><span style="font-size: 17px;margin-left: 145px">
|
||||
<%= 1 %></span></strong>
|
||||
<%= project.commit_count %></span></strong>
|
||||
<%= content_tag('span', l(:label_since_last_commits)) %>
|
||||
</p>
|
||||
<p class="stats">
|
||||
<strong><span style="font-size: 17px;margin-left: 145px">
|
||||
<%= 1 %></span></strong>
|
||||
<%= project.code_line %></span></strong>
|
||||
<%= content_tag('span', "行代码") %>
|
||||
</p>
|
||||
</div>
|
||||
|
|
|
@ -141,16 +141,17 @@ li {
|
|||
<div class="nav-topbar nav-category-group" data-group="nav-topbar">
|
||||
<div class="nav-topbar-content">
|
||||
<ul>
|
||||
<li class="has-arrow">所有分类<span class="nav-topbar-arror"></span>
|
||||
<li class="has-arrow">查找条件><span class="nav-topbar-arror"></span>
|
||||
</li>
|
||||
<li>
|
||||
<span class="topbar-search J_TopbarSearch">
|
||||
<input class="search-input input-placeholder" _default="该条件下查找" placeholder="该条件下查找" accesskey="s">
|
||||
<span class="topbar-submit"></span>
|
||||
<%= @app_dir%>
|
||||
<%= @language%>
|
||||
<%= @created_at%>
|
||||
</span>
|
||||
</li>
|
||||
<li>共 <span class="h">1.61万</span> 个开源项目</li>
|
||||
<li class="related-count"><a href="/search?q=iphone&app=vproduct&vlist=1&from_combo=true">8款相关产品</a></li>
|
||||
<li>共 <span class="h"><%= @os_project_count %></span> 个开源项目</li>
|
||||
<!-- <li class="related-count"><a href="/search?q=iphone&app=vproduct&vlist=1&from_combo=true">8款相关产品</a></li> -->
|
||||
</ul>
|
||||
</div>
|
||||
<div class="nav-category-panel"></div>
|
||||
|
@ -159,14 +160,38 @@ li {
|
|||
<!-- 推荐属性-->
|
||||
<div class="nav-category-group type-line" data-group="type-line">
|
||||
<div class="nav-category ">
|
||||
<h4 title="网络类型">网络类型<span>:</span></h4>
|
||||
<a href="javascript:void(0)" class="nav-more J_More show">更多
|
||||
<h4 title="网络类型">应用方向<span>:</span></h4>
|
||||
<%= link_to "操作系统相关", open_source_projects_path(:app_dir => "操作系统相关", :language => @language, :created_at => @created_at), :class => "nav-more J_More show" %>
|
||||
<%= link_to "管理和监控", open_source_projects_path(:app_dir => "管理和监控", :language => @language, :created_at => @created_at), :class => "nav-more J_More show" %>
|
||||
<%= link_to "游戏/娱乐", open_source_projects_path(:app_dir => "游戏/娱乐", :language => @language, :created_at => @created_at), :class => "nav-more J_More show" %>
|
||||
<%= link_to "应用工具", open_source_projects_path(:app_dir => "应用工具", :language => @language, :created_at => @created_at), :class => "nav-more J_More show" %>
|
||||
<%= link_to "数据库相关", open_source_projects_path(:app_dir => "数据库相关", :language => @language, :created_at => @created_at), :class => "nav-more J_More show" %>
|
||||
<%= link_to "服务器软件", open_source_projects_path(:app_dir => "服务器软件", :language => @language, :created_at => @created_at), :class => "nav-more J_More show" %>
|
||||
<%= link_to "网站系统", open_source_projects_path(:app_dir => "网站系统", :language => @language, :created_at => @created_at), :class => "nav-more J_More show" %>
|
||||
<%= link_to "插件和扩展", open_source_projects_path(:app_dir => "插件和扩展", :language => @language, :created_at => @created_at), :class => "nav-more J_More show" %>
|
||||
<span class="arrow arrow-bottom"></span>
|
||||
</a>
|
||||
</div>
|
||||
<div class="nav-category ">
|
||||
<h4 title="网络类型">网络类型<span>:</span></h4>
|
||||
<a href="javascript:void(0)" class="nav-more J_More show">更多
|
||||
<h4 title="网络类型">开发语言<span>:</span></h4>
|
||||
<%= link_to "java", open_source_projects_path(:language => "java", :app_dir => @app_dir, :created_at => @created_at), :class => "nav-more J_More show" %>
|
||||
<%= link_to "c++", open_source_projects_path(:language => "c++", :app_dir => @app_dir, :created_at => @created_at), :class => "nav-more J_More show" %>
|
||||
<%= link_to "c", open_source_projects_path(:language => "c", :app_dir => @app_dir, :created_at => @created_at), :class => "nav-more J_More show" %>
|
||||
<%= link_to "c#", open_source_projects_path(:language => "c#", :app_dir => @app_dir, :created_at => @created_at), :class => "nav-more J_More show" %>
|
||||
<%= link_to "ruby", open_source_projects_path(:language => "ruby", :app_dir => @app_dir, :created_at => @created_at), :class => "nav-more J_More show" %>
|
||||
<%= link_to "其他", open_source_projects_path(:language => "其他", :app_dir => @app_dir, :created_at => @created_at), :class => "nav-more J_More show" %>
|
||||
|
||||
<span class="arrow arrow-bottom"></span>
|
||||
</a>
|
||||
</div>
|
||||
<div class="nav-category ">
|
||||
<h4 title="网络类型">创立时间<span>:</span></h4>
|
||||
<%= link_to "2013", open_source_projects_path(:app_dir => @app_dir, :language => @language, :created_at => "2013"), :class => "nav-more J_More show" %>
|
||||
<%= link_to "2012", open_source_projects_path(:app_dir => @app_dir, :language => @language, :created_at => "2012"), :class => "nav-more J_More show" %>
|
||||
<%= link_to "2011", open_source_projects_path(:app_dir => @app_dir, :language => @language, :created_at => "2011"), :class => "nav-more J_More show" %>
|
||||
<%= link_to "2010", open_source_projects_path(:app_dir => @app_dir, :language => @language, :created_at => "2010"), :class => "nav-more J_More show" %>
|
||||
<%= link_to "更早", open_source_projects_path(:app_dir => @app_dir, :language => @language, :created_at => "更早"), :class => "nav-more J_More show" %>
|
||||
|
||||
<span class="arrow arrow-bottom"></span>
|
||||
</a>
|
||||
</div>
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
<!-- added by bai -->
|
||||
<div class="autoscroll">
|
||||
<% for user in @applicants -%>
|
||||
<% unless user.id == 1%>
|
||||
<!-- added by bai -->
|
||||
<% messages_count = user.messages.count %>
|
||||
<% messages_score = messages_count * 0.05%>
|
||||
<% finall_messages_score = messages_score %>
|
||||
|
||||
<% journals_count = user.journals.count %>
|
||||
<% journals_score = journals_count * 0.1 %>
|
||||
<% user_changesets_count = user.changesets.count %>
|
||||
<% user_changesets_score = user_changesets_count * 0.3 %>
|
||||
<% finall_user_project_score = journals_score + user_changesets_score %>
|
||||
|
||||
<% journals_for_messages_count = user.journals_for_messages.count %>
|
||||
<% activities_count = user.activities.count %>
|
||||
<% journals_for_messages_score = journals_for_messages_count * 0.05 %>
|
||||
<% activities_score = activities_count * 0.2 %>
|
||||
<% finall_activity_score = journals_for_messages_score + activities_score %>
|
||||
|
||||
<% news_count = user.news.count %>
|
||||
<% news_score = news_count * 0.1 %>
|
||||
<% wiki_contents_count = user.wiki_contents.count %>
|
||||
<% wiki_contents_score = wiki_contents_count * 0.1 %>
|
||||
<% comments_count = user.comments.count %>
|
||||
<% comments_score = comments_count * 0.1 %>
|
||||
<% finall_influence_score = news_score + wiki_contents_score + comments_score %>
|
||||
<% finall_user_score = finall_messages_score + finall_user_project_score + finall_activity_score + finall_influence_score %>
|
||||
<!-- end -->
|
||||
<div class="well">
|
||||
|
||||
<%= content_tag "p", "#{format_date(user.created_on)} #{l(:label_member_since)}", :class => "float_right member_since" %>
|
||||
<%= image_tag "/images/time_member.png", :class => "img_member_time"%>
|
||||
|
||||
<div>
|
||||
<%= image_tag(url_to_avatar(user), :class => 'avatar') %>
|
||||
<%= content_tag "span", link_to_user(user), :class => "nomargin avatar_name" %>
|
||||
|
||||
<!-- modified by bai -->
|
||||
<div style="position:relative;float:left;margin-top:-2px;margin-left: 160px">
|
||||
<%= l(:label_user_grade) %>: <span style="color:#ec6300">
|
||||
<%= link_to( format("%.2f" , finall_user_score).to_f, {:controller => 'users',
|
||||
:action => 'show_score',
|
||||
:remote => true,
|
||||
:id => user.id},
|
||||
:style=>"color: #EC6300;") %></span>
|
||||
</div>
|
||||
<!-- end -->
|
||||
</div>
|
||||
|
||||
<div style="margin-top: 20px;margin-left:66px">
|
||||
<%= l(:label_x_has_fans,:count=>user.watcher_users.count)%>
|
||||
<%= l(:label_has_watchers,:count=>User.watched_by(user.id).count) %>
|
||||
|
||||
</div>
|
||||
<div class="user-bottom">
|
||||
<% unless user.memberships.empty? %>
|
||||
<% cond = Project.visible_condition(User.current) + "AND projects.project_type <> 1" %>
|
||||
<% memberships = user.memberships.all(:conditions => cond) %>
|
||||
<%= l(:label_x_contribute_to, :count => memberships.count) %>
|
||||
<% for member in memberships %>
|
||||
<%= link_to_project(member.project) %><%= (user.memberships.last == member) ? '' : ',' %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<p>
|
||||
<% unless user.memberships.empty? %>
|
||||
<% cond = Project.visible_condition(User.current) + "AND projects.project_type = 1" %>
|
||||
<% memberships = user.memberships.all(:conditions => cond) %>
|
||||
<%= l(:label_x_course_contribute_to, :count => memberships.count) %>
|
||||
<% for member in memberships %>
|
||||
<%= link_to_project(member.project) %><%= (user.memberships.last == member) ? '' : ',' %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</p>
|
||||
|
||||
<%= user.changesets.count == 0 ? '' : "#{l(:label_x_total_commit, :count => user.changesets.count)}" %>
|
||||
</div>
|
||||
</div>
|
||||
<% end -%>
|
||||
<% end -%>
|
||||
</div>
|
|
@ -1808,3 +1808,7 @@ zh:
|
|||
label_sumbit_empty: 搜索内容不能为空
|
||||
no_use: 没有帮助
|
||||
cancel_no_use: 撤销没有帮助
|
||||
cancel_apply: 取消申请
|
||||
apply_master: 申请成为版主
|
||||
you_are_master: 您是该项目的版主
|
||||
|
||||
|
|
|
@ -29,8 +29,9 @@ RedmineApp::Application.routes.draw do
|
|||
collection do
|
||||
match 'search', via: [:get, :post]
|
||||
end
|
||||
resources :relative_memos do
|
||||
|
||||
resources :relative_memos
|
||||
member do
|
||||
match 'master_apply', via: [:get, :post]
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue