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

This commit is contained in:
fanqiang 2014-04-03 20:47:09 +08:00
parent e8de48dd24
commit 9af808821d
39 changed files with 602 additions and 13 deletions

View File

@ -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.

View File

@ -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.

View File

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

View File

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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

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

View File

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

3
app/models/no_use.rb Normal file
View File

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

View File

@ -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

View File

@ -69,6 +69,16 @@ class RelativeMemo < ActiveRecord::Base
# Forum.reset_counters!(forum_id)
# 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

View File

@ -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 %>

View File

@ -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 %>

View File

@ -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 %>

View File

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

View File

@ -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 %>

View File

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

View File

@ -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 %>

View File

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

View File

@ -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 %>

View File

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

View File

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

View File

@ -33,18 +33,18 @@
</tr>
<tr>
<td align="left" colspan="2" ><span class="font_lighter"><%= @open_source_project.url%> </span></td>
<td align="left"><%= no_use_link(topic, User.current) %> </td>
</tr>
<tr><td align="left" colspan="2">
<%= image_tag( "/images/sidebar/tags.png") %>
<%= render :partial => 'tags/tag_name', :locals => {:obj => topic,:object_flag => "9",:non_list_all => true }%>
</td></tr>
<tr>
<td align="left" colspan="2"> <%= image_tag( "/images/sidebar/tags.png") %>
<%= render :partial => 'tags/tag_name', :locals => {:obj => topic,:object_flag => "9",:non_list_all => true }%> </td>
</tr>
</table></td>
</tr>
</table>
<% end %>
<div class="pagination">
<%#= pagination_links_full @topic_pages, @topic_count %>

View File

@ -2,7 +2,7 @@
<div id="add-memo" class='lz' style="display: none; padding: 20px;">
<h3><%=l(:label_memo_new)%></h3>
<% if User.current.logged? %>
<%= labelled_form_for(@memo, :url => forum_memos_path(@forum), :html => {:multipart => true} ) do |f| %>
<%#= labelled_form_for(@memo, :url => forum_memos_path(1), :html => {:multipart => true} ) do |f| %>
<% if @memo.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@memo.errors.count, "error") %> prohibited this memo from being saved:</h2>
@ -13,7 +13,7 @@
<% end %>
</ul>
</div>
<% end %>
<% #end %>
<div class="actions" style="max-width:680px">
<p><%= f.text_field :subject, :required => true%></p>
<p style="max-width:680px"><%= f.text_area :content, :required => true, :id => 'editor02' %></p>
@ -23,7 +23,7 @@
<%= l(:label_attachment_plural) %><br />
<%= render :partial => 'attachments/form', :locals => {:container => @memo} %>
</p>
<%= f.submit :value => l(:label_memo_create) %>
<%#= f.submit :value => l(:label_memo_create) %>
<%= link_to l(:button_cancel), "#", :onclick => '$("#add-memo").hide(); return false;' %>
</div>
<% end %>
@ -32,7 +32,7 @@
<!--modified by huang-->
<% #= link_to '发布帖子', new_forum_memo_path(@forum), :class => 'icon icon-add' %>
<span>
<%= link_to l(:label_memo_new_from_forum), new_forum_memo_path(@forum), :class => 'icon icon-add',
<%#= link_to l(:label_memo_new_from_forum), new_forum_memo_path(@forum), :class => 'icon icon-add',
:onclick => 'showAndScrollTo("add-memo", "memo_subject"); return false;' if User.current.logged? %>
</span>

View File

@ -16,6 +16,12 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
RedmineApp::Application.routes.draw do
resources :no_uses
resources :apply_project_masters
resources :open_source_projects do
collection do
match 'search', via: [:get, :post]

View File

@ -0,0 +1,12 @@
class CreateApplyProjectMasters < ActiveRecord::Migration
def change
create_table :apply_project_masters do |t|
t.integer :user_id
t.string :apply_type
t.integer :apply_id
t.integer :status
t.timestamps
end
end
end

View File

@ -0,0 +1,11 @@
class CreateNoUses < ActiveRecord::Migration
def change
create_table :no_uses do |t|
t.integer :user_id, :null => false
t.string :no_use_type
t.integer :no_use_id
t.timestamps
end
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20140401004102) do
ActiveRecord::Schema.define(:version => 20140403113341) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false
@ -23,6 +23,15 @@ ActiveRecord::Schema.define(:version => 20140401004102) do
add_index "activities", ["user_id", "act_type"], :name => "index_activities_on_user_id_and_act_type"
add_index "activities", ["user_id"], :name => "index_activities_on_user_id"
create_table "apply_project_masters", :force => true do |t|
t.integer "user_id"
t.string "apply_type"
t.integer "apply_id"
t.integer "status"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "attachments", :force => true do |t|
t.integer "container_id"
t.string "container_type", :limit => 30
@ -636,6 +645,14 @@ ActiveRecord::Schema.define(:version => 20140401004102) do
add_index "news", ["created_on"], :name => "index_news_on_created_on"
add_index "news", ["project_id"], :name => "news_project_id"
create_table "no_uses", :force => true do |t|
t.integer "user_id", :null => false
t.string "no_use_type"
t.integer "no_use_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "ohloh_tagged", :force => true do |t|
t.integer "proj_id", :default => 0, :null => false
t.string "description", :limit => 100, :null => false

11
test/fixtures/apply_project_masters.yml vendored Normal file
View File

@ -0,0 +1,11 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
# This model initially had no columns defined. If you add columns to the
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value

11
test/fixtures/no_uses.yml vendored Normal file
View File

@ -0,0 +1,11 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
# This model initially had no columns defined. If you add columns to the
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value

View File

@ -0,0 +1,49 @@
require 'test_helper'
class ApplyProjectMastersControllerTest < ActionController::TestCase
setup do
@apply_project_master = apply_project_masters(:one)
end
test "should get index" do
get :index
assert_response :success
assert_not_nil assigns(:apply_project_masters)
end
test "should get new" do
get :new
assert_response :success
end
test "should create apply_project_master" do
assert_difference('ApplyProjectMaster.count') do
post :create, apply_project_master: { }
end
assert_redirected_to apply_project_master_path(assigns(:apply_project_master))
end
test "should show apply_project_master" do
get :show, id: @apply_project_master
assert_response :success
end
test "should get edit" do
get :edit, id: @apply_project_master
assert_response :success
end
test "should update apply_project_master" do
put :update, id: @apply_project_master, apply_project_master: { }
assert_redirected_to apply_project_master_path(assigns(:apply_project_master))
end
test "should destroy apply_project_master" do
assert_difference('ApplyProjectMaster.count', -1) do
delete :destroy, id: @apply_project_master
end
assert_redirected_to apply_project_masters_path
end
end

View File

@ -0,0 +1,49 @@
require 'test_helper'
class NoUsesControllerTest < ActionController::TestCase
setup do
@no_use = no_uses(:one)
end
test "should get index" do
get :index
assert_response :success
assert_not_nil assigns(:no_uses)
end
test "should get new" do
get :new
assert_response :success
end
test "should create no_use" do
assert_difference('NoUse.count') do
post :create, no_use: { }
end
assert_redirected_to no_use_path(assigns(:no_use))
end
test "should show no_use" do
get :show, id: @no_use
assert_response :success
end
test "should get edit" do
get :edit, id: @no_use
assert_response :success
end
test "should update no_use" do
put :update, id: @no_use, no_use: { }
assert_redirected_to no_use_path(assigns(:no_use))
end
test "should destroy no_use" do
assert_difference('NoUse.count', -1) do
delete :destroy, id: @no_use
end
assert_redirected_to no_uses_path
end
end

View File

@ -0,0 +1,7 @@
require 'test_helper'
class ApplyProjectMasterTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

View File

@ -0,0 +1,4 @@
require 'test_helper'
class ApplyProjectMastersHelperTest < ActionView::TestCase
end

View File

@ -0,0 +1,4 @@
require 'test_helper'
class NoUsesHelperTest < ActionView::TestCase
end

7
test/unit/no_use_test.rb Normal file
View File

@ -0,0 +1,7 @@
require 'test_helper'
class NoUseTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end