修改框架,添加"没有帮助"和"申请成为版主"功能

exceptionHandle
fanqiang 11 years ago
parent e8de48dd24
commit 9af808821d

@ -0,0 +1,2 @@
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.

@ -0,0 +1,2 @@
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.

@ -0,0 +1,4 @@
/*
Place all the styles related to the matching controller here.
They will automatically be included in application.css.
*/

@ -0,0 +1,4 @@
/*
Place all the styles related to the matching controller here.
They will automatically be included in application.css.
*/

@ -0,0 +1,83 @@
class ApplyProjectMastersController < ApplicationController
# GET /apply_project_masters
# GET /apply_project_masters.json
def index
@apply_project_masters = ApplyProjectMaster.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @apply_project_masters }
end
end
# GET /apply_project_masters/1
# GET /apply_project_masters/1.json
def show
@apply_project_master = ApplyProjectMaster.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @apply_project_master }
end
end
# GET /apply_project_masters/new
# GET /apply_project_masters/new.json
def new
@apply_project_master = ApplyProjectMaster.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @apply_project_master }
end
end
# GET /apply_project_masters/1/edit
def edit
@apply_project_master = ApplyProjectMaster.find(params[:id])
end
# POST /apply_project_masters
# POST /apply_project_masters.json
def create
@apply_project_master = ApplyProjectMaster.new(params[:apply_project_master])
respond_to do |format|
if @apply_project_master.save
format.html { redirect_to @apply_project_master, notice: 'Apply project master was successfully created.' }
format.json { render json: @apply_project_master, status: :created, location: @apply_project_master }
else
format.html { render action: "new" }
format.json { render json: @apply_project_master.errors, status: :unprocessable_entity }
end
end
end
# PUT /apply_project_masters/1
# PUT /apply_project_masters/1.json
def update
@apply_project_master = ApplyProjectMaster.find(params[:id])
respond_to do |format|
if @apply_project_master.update_attributes(params[:apply_project_master])
format.html { redirect_to @apply_project_master, notice: 'Apply project master was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @apply_project_master.errors, status: :unprocessable_entity }
end
end
end
# DELETE /apply_project_masters/1
# DELETE /apply_project_masters/1.json
def destroy
@apply_project_master = ApplyProjectMaster.find(params[:id])
@apply_project_master.destroy
respond_to do |format|
format.html { redirect_to apply_project_masters_url }
format.json { head :no_content }
end
end
end

@ -0,0 +1,123 @@
class NoUsesController < ApplicationController
# GET /no_uses
# GET /no_uses.json
def index
@no_uses = NoUse.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @no_uses }
end
end
# GET /no_uses/1
# GET /no_uses/1.json
def show
@no_use = NoUse.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @no_use }
end
end
# GET /no_uses/new
# GET /no_uses/new.json
def new
@no_use = NoUse.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @no_use }
end
end
# GET /no_uses/1/edit
def edit
@no_use = NoUse.find(params[:id])
end
# POST /no_uses
# POST /no_uses.json
def create
@no_use = NoUse.new(params[:no_use])
respond_to do |format|
if @no_use.save
format.html { redirect_to @no_use, notice: 'No use was successfully created.' }
format.json { render json: @no_use, status: :created, location: @no_use }
else
format.html { render action: "new" }
format.json { render json: @no_use.errors, status: :unprocessable_entity }
end
end
end
# PUT /no_uses/1
# PUT /no_uses/1.json
def update
@no_use = NoUse.find(params[:id])
respond_to do |format|
if @no_use.update_attributes(params[:no_use])
format.html { redirect_to @no_use, notice: 'No use was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @no_use.errors, status: :unprocessable_entity }
end
end
end
# DELETE /no_uses/1
# DELETE /no_uses/1.json
def destroy
@no_use = NoUse.find(params[:id])
@no_use.destroy
respond_to do |format|
format.html { redirect_to no_uses_url }
format.json { head :no_content }
end
end
private
def find_no_use
klass = Object.const_get(params[:object_type].camelcase) rescue nil
if klass && klass.respond_to?('watched_by')
@no_use = klass.find_all_by_id(Array.wrap(params[:object_id]))
end
render_404 unless @no_use.present?
end
def set_watcher(watchables, user, watching)
watchables.each do |watchable|
watchable.set_watcher(user, watching)
# @user = watchable # added by william
if watching
# 修改 user和project的状态
if watchable.instance_of?(User)
#写user_statuses表
UserStatus.find_by_user_id(watchable.id).update_watchers_count(1)
elsif watchable.instance_of?(Project)
#写project_statuese表
ProjectStatus.find_by_project_id(watchable.id).update_watchers_count(1)
end
else
# 修改 user和project的状态
if watchable.instance_of?(User)
#写user_statuses表
UserStatus.find_by_user_id(watchable.id).update_watchers_count(-1)
elsif watchable.instance_of?(Project)
#写project_statuese表 :project_status
ProjectStatus.find_by_project_id(watchable.id).update_watchers_count(-1)
end
end
end
respond_to do |format|
format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}}
format.js { render :partial => 'set_watcher', :locals => {:user => user, :watched => watchables} }
end
end
end

@ -2,6 +2,10 @@ class OpenSourceProjectsController < ApplicationController
helper :sort
include SortHelper
helper :apply_project_masters
include ApplyProjectMastersHelper
helper :no_uses
include NoUsesHelper
# GET /open_source_projects
# GET /open_source_projects.json
def index

@ -0,0 +1,23 @@
module ApplyProjectMastersHelper
def apply_super_user(objects, user, options=[])
return '' unless user && user.logged?
objects = Array.wrap(objects)
applied = objects.any? {|object| object.applied_by?(user)}
allowed = objects.any? {|object| object.allowed?(user)}
# @watch_flag = (objects.first.instance_of?(User) or objects.first.instance_of?(Project) or (objects.first.instance_of?(Bid)))
# css = @watch_flag ? ([watcher_css(objects), watched ? 'icon ' : 'icon '].join(' ') << options[0].to_s) :
# ([watcher_css(objects), watched ? 'icon icon-fav ' : 'icon icon-fav-off '].join(' ') << options[0].to_s)
text = applied ? (allowed ? ("123") : ("123")) : ("231")
url = apply_project_master_path(
:object_type => objects.first.class.to_s.underscore,
:object_id => (objects.size == 1 ? objects.first.id : objects.map(&:id).sort)
)
method = applied ? 'delete' : 'post'
link_to text, url, :remote => true, :method => method
#, :class => css
end
end

@ -0,0 +1,22 @@
module NoUsesHelper
def no_use_link(objects, user, options=[])
return '' unless user && user.logged?
objects = Array.wrap(objects)
clicked = objects.any? {|object| object.no_use_for?(user)}
# @watch_flag = (objects.first.instance_of?(User) or objects.first.instance_of?(Project) or (objects.first.instance_of?(Bid)))
# css = @watch_flag ? ([watcher_css(objects), watched ? 'icon ' : 'icon '].join(' ') << options[0].to_s) :
# ([watcher_css(objects), watched ? 'icon icon-fav ' : 'icon icon-fav-off '].join(' ') << options[0].to_s)
text = clicked ? ("123") : ("231")
url = apply_project_master_path(
:object_type => objects.first.class.to_s.underscore,
:object_id => (objects.size == 1 ? objects.first.id : objects.map(&:id).sort)
)
method = clicked ? 'delete' : 'post'
link_to text, url, :remote => true, :method => method
#, :class => css
end
end

@ -11,4 +11,5 @@ module OpenSourceProjectsHelper
end
s << "</ul>"
end
end

@ -0,0 +1,3 @@
class ApplyProjectMaster < ActiveRecord::Base
# attr_accessible :title, :body
end

@ -0,0 +1,3 @@
class NoUse < ActiveRecord::Base
# attr_accessible :title, :body
end

@ -11,6 +11,14 @@ class OpenSourceProject < ActiveRecord::Base
description.gsub(/^(.{#{length}}[^\n\r]*).*$/m, '\1...').strip if description
end
def applied_by?(user)
false
end
def allowed?(user)
false
end
def reset_counters!
self.class.reset_counters!(id)
end

@ -70,6 +70,16 @@ class RelativeMemo < ActiveRecord::Base
# end
# end
scope :no_use_for, lambda { |user_id|
{ :include => :no_uses,
:conditions => ["#{NoUse.table_name}.user_id = ?", user_id] }
}
def no_use_for?(user)
false
end
def reset_counters!
if parent && parent.id
RelativeMemo.update_all({:last_reply_id => parent.children.maximum(:id)}, {:id => parent.id})

@ -0,0 +1,17 @@
<%= form_for(@apply_project_master) do |f| %>
<% if @apply_project_master.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@apply_project_master.errors.count, "error") %> prohibited this apply_project_master from being saved:</h2>
<ul>
<% @apply_project_master.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="actions">
<%= f.submit %>
</div>
<% end %>

@ -0,0 +1,6 @@
<h1>Editing apply_project_master</h1>
<%= render 'form' %>
<%= link_to 'Show', @apply_project_master %> |
<%= link_to 'Back', apply_project_masters_path %>

@ -0,0 +1,21 @@
<h1>Listing apply_project_masters</h1>
<table>
<tr>
<th></th>
<th></th>
<th></th>
</tr>
<% @apply_project_masters.each do |apply_project_master| %>
<tr>
<td><%= link_to 'Show', apply_project_master %></td>
<td><%= link_to 'Edit', edit_apply_project_master_path(apply_project_master) %></td>
<td><%= link_to 'Destroy', apply_project_master, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</table>
<br />
<%= link_to 'New Apply project master', new_apply_project_master_path %>

@ -0,0 +1,5 @@
<h1>New apply_project_master</h1>
<%= render 'form' %>
<%= link_to 'Back', apply_project_masters_path %>

@ -0,0 +1,5 @@
<p id="notice"><%= notice %></p>
<%= link_to 'Edit', edit_apply_project_master_path(@apply_project_master) %> |
<%= link_to 'Back', apply_project_masters_path %>

@ -54,6 +54,7 @@
</div><div>
</div><div style="margin-left: 20px;">
<%= apply_super_user(@open_source_project, User.current) %>
</div></td>
</tr>

@ -0,0 +1,17 @@
<%= form_for(@no_use) do |f| %>
<% if @no_use.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@no_use.errors.count, "error") %> prohibited this no_use from being saved:</h2>
<ul>
<% @no_use.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="actions">
<%= f.submit %>
</div>
<% end %>

@ -0,0 +1,6 @@
<h1>Editing no_use</h1>
<%= render 'form' %>
<%= link_to 'Show', @no_use %> |
<%= link_to 'Back', no_uses_path %>

@ -0,0 +1,21 @@
<h1>Listing no_uses</h1>
<table>
<tr>
<th></th>
<th></th>
<th></th>
</tr>
<% @no_uses.each do |no_use| %>
<tr>
<td><%= link_to 'Show', no_use %></td>
<td><%= link_to 'Edit', edit_no_use_path(no_use) %></td>
<td><%= link_to 'Destroy', no_use, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</table>
<br />
<%= link_to 'New No use', new_no_use_path %>

@ -0,0 +1,5 @@
<h1>New no_use</h1>
<%= render 'form' %>
<%= link_to 'Back', no_uses_path %>

@ -0,0 +1,5 @@
<p id="notice"><%= notice %></p>
<%= link_to 'Edit', edit_no_use_path(@no_use) %> |
<%= link_to 'Back', no_uses_path %>

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save