修改osp的show界面,建立框架

This commit is contained in:
fanqiang 2014-04-03 14:41:04 +08:00
parent cfa5532598
commit e8de48dd24
12 changed files with 463 additions and 47 deletions

View File

@ -1,4 +1,7 @@
class OpenSourceProjectsController < ApplicationController
helper :sort
include SortHelper
# GET /open_source_projects
# GET /open_source_projects.json
def index
@ -22,6 +25,33 @@ class OpenSourceProjectsController < ApplicationController
def show
@open_source_project = OpenSourceProject.find(params[:id])
sort_init 'updated_at', 'desc'
sort_update 'created_at' => "#{RelativeMemo.table_name}.created_at",
'replies' => "#{RelativeMemo.table_name}.replies_count",
'updated_at' => "COALESCE (last_replies_relative_memos.created_at, #{RelativeMemo.table_name}.created_at)"
@memo = RelativeMemo.new(:open_source_project => @open_source_project)
@topic_count = @open_source_project.topics.count
@topic_pages = Paginator.new @topic_count, per_page_option, params['page']
@memos = @open_source_project.topics.
reorder("#{RelativeMemo.table_name}.sticky DESC").
includes(:last_reply).
limit(@topic_pages.per_page).
offset(@topic_pages.offset).
order(sort_clause).
all
# @offset, @limit = api_offset_and_limit({:limit => 10})
# @forum = Forum.find(params[:id])
# @memos_all = @forum.topics
# @topic_count = @memos_all.count
# @topic_pages = Paginator.new @topic_count, @limit, params['page']
# @offset ||= @topic_pages.offset
# @memos = @memos_all.offset(@offset).limit(@limit).all
respond_to do |format|
format.html {
render :layout => "base_opensource_p"

View File

@ -0,0 +1,123 @@
class RelativeMemosController < ApplicationController
helper :sort
include SortHelper
# GET /open_source_projects
# GET /open_source_projects.json
def index
# per_page_option = 10
#
# @open_source_projects = OpenSourceProject.all
#
# @os_project_count = @open_source_projects.count
# @os_project_pages = Paginator.new @os_project_count, per_page_option, params['page']
#
# @open_source_projects = OpenSourceProject.all
#
# respond_to do |format|
# format.html # index.html.erb
# format.json { render json: @open_source_projects }
# end
end
# GET /open_source_projects/1
# GET /open_source_projects/1.json
def show
# @open_source_project = OpenSourceProject.find(params[:id])
#
# sort_init 'updated_at', 'desc'
# sort_update 'created_at' => "#{RelativeMemo.table_name}.created_at",
# 'replies' => "#{RelativeMemo.table_name}.replies_count",
# 'updated_at' => "COALESCE (last_replies_relative_memos.created_at, #{RelativeMemo.table_name}.created_at)"
#
# @memo = RelativeMemo.new(:open_source_project => @open_source_project)
# @topic_count = @open_source_project.topics.count
# @topic_pages = Paginator.new @topic_count, per_page_option, params['page']
# @memos = @open_source_project.topics.
# reorder("#{RelativeMemo.table_name}.sticky DESC").
# includes(:last_reply).
# limit(@topic_pages.per_page).
# offset(@topic_pages.offset).
# order(sort_clause).
# all
# @offset, @limit = api_offset_and_limit({:limit => 10})
# @forum = Forum.find(params[:id])
# @memos_all = @forum.topics
# @topic_count = @memos_all.count
# @topic_pages = Paginator.new @topic_count, @limit, params['page']
# @offset ||= @topic_pages.offset
# @memos = @memos_all.offset(@offset).limit(@limit).all
# respond_to do |format|
# format.html {
# render :layout => "base_opensource_p"
# }
# format.json { render json: @open_source_project }
# end
end
# GET /open_source_projects/new
# GET /open_source_projects/new.json
def new
@open_source_project = OpenSourceProject.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @open_source_project }
end
end
# GET /open_source_projects/1/edit
def edit
@open_source_project = OpenSourceProject.find(params[:id])
end
# POST /open_source_projects
# POST /open_source_projects.json
def create
@open_source_project = OpenSourceProject.new(params[:open_source_project])
respond_to do |format|
if @open_source_project.save
format.html { redirect_to @open_source_project, notice: 'Open source project was successfully created.'}
format.json { render json: @open_source_project, status: :created, location: @open_source_project }
else
format.html { render action: "new" }
format.json { render json: @open_source_project.errors, status: :unprocessable_entity }
end
end
end
# PUT /open_source_projects/1
# PUT /open_source_projects/1.json
def update
@open_source_project = OpenSourceProject.find(params[:id])
respond_to do |format|
if @open_source_project.update_attributes(params[:open_source_project])
format.html { redirect_to @open_source_project, notice: 'Open source project was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @open_source_project.errors, status: :unprocessable_entity }
end
end
end
# DELETE /open_source_projects/1
# DELETE /open_source_projects/1.json
def destroy
@open_source_project = OpenSourceProject.find(params[:id])
@open_source_project.destroy
respond_to do |format|
format.html { redirect_to open_source_projects_url }
format.json { head :no_content }
end
end
end

View File

@ -1,10 +1,25 @@
class OpenSourceProject < ActiveRecord::Base
attr_accessible :String
include Redmine::SafeAttributes
has_many :topics, :class_name => 'RelativeMemo', :foreign_key => 'osp_id', :conditions => "#{RelativeMemo.table_name}.parent_id IS NULL", :order => "#{RelativeMemo.table_name}.created_at DESC", :dependent => :destroy
has_many :relative_memos, :dependent => :destroy
has_many :tags, :through => :project_tags, :class_name => 'Tag'
has_many :project_tags, :class_name => 'ProjectTags'
acts_as_taggable
def short_description(length = 255)
description.gsub(/^(.{#{length}}[^\n\r]*).*$/m, '\1...').strip if description
end
def reset_counters!
self.class.reset_counters!(id)
end
def self.reset_counters!(id)
osp_id = id.to_i
update_all("topic_count = (SELECT COUNT(*) FROM #{RelativeMemo.table_name} WHERE osp_id=#{osp_id} AND parent_id IS NULL)," +
" memo_count = (SELECT COUNT(*) FROM #{RelativeMemo.table_name} WHERE osp_id=#{osp_id} AND parent_id IS NOT NULL)," +
" last_memo_id = (SELECT MAX(id) FROM #{RelativeMemo.table_name} WHERE osp_id=#{osp_id})",
["id = ?", osp_id])
end
end

View File

@ -1,3 +1,152 @@
class RelativeMemo < ActiveRecord::Base
# attr_accessible :title, :body
include Redmine::SafeAttributes
belongs_to :open_source_project, :class_name => "OpenSourceProject", :foreign_key => 'osp_id'
belongs_to :author, :class_name => "User", :foreign_key => 'author_id'
has_many :tags, :through => :project_tags, :class_name => 'Tag'
has_many :project_tags, :class_name => 'ProjectTags'
acts_as_taggable
validates_presence_of :osp_id, :subject
#validates :content, presence: true
# validates_length_of :subject, maximum: 50
#validates_length_of :content, maximum: 3072
validate :cannot_reply_to_locked_topic, :on => :create
acts_as_tree :counter_cache => :replies_count, :order => "#{RelativeMemo.table_name}.created_at ASC"
acts_as_attachable
belongs_to :last_reply, :class_name => 'RelativeMemo', :foreign_key => 'last_reply_id'
# acts_as_searchable :column => ['subject', 'content'],
# #:include => { :forum => :p}
# #:project_key => "#{Forum.table_name}.project_id"
# :date_column => "#{table_name}.created_at"
# acts_as_event :title => Proc.new {|o| "#{o.forum.name}: #{o.subject}"},
# :datetime => :updated_at,
# # :datetime => :created_at,
# :description => :content,
# :author => :author,
# :type => Proc.new {|o| o.parent_id.nil? ? 'Memo' : 'Reply'},
# :url => Proc.new {|o| {:controller => 'memos', :action => 'show', :forum_id => o.forum_id}.merge(o.parent_id.nil? ? {:id => o.id} : {:id => o.parent_id, :r => o.id, :anchor => "reply-#{o.id}"})}
# acts_as_activity_provider :author_key => :author_id,
# :func => 'memos',
# :timestamp => 'created_at'
# :find_options => {:type => 'memos'}
# acts_as_watchable
safe_attributes "author_id",
"subject",
"content",
"osp_id",
"last_memo_id",
"lock",
"sticky",
"parent_id",
"replies_count",
"is_quote"
after_create :add_author_as_watcher, :reset_counters!
# after_update :update_memos_forum
after_destroy :reset_counters!
# after_create :send_notification
# after_save :plusParentAndForum
# after_destroy :minusParentAndForum
# scope :visible, lambda { |*args|
# includes(:forum => ).where()
# }
def cannot_reply_to_locked_topic
errors.add :base, l(:label_memo_locked) if root.locked? && self != root
end
# def update_memos_forum
# if forum_id_changed?
# Message.update_all({:board_id => board_id}, ["id = ? OR parent_id = ?", root.id, root.id ])
# Forum.reset_counters!(forum_id_was)
# Forum.reset_counters!(forum_id)
# end
# end
def reset_counters!
if parent && parent.id
RelativeMemo.update_all({:last_reply_id => parent.children.maximum(:id)}, {:id => parent.id})
parent.update_attribute(:updated_at, Time.now)
end
forum.reset_counters!
end
def sticky?
sticky == 1
end
def replies
RelativeMemo.where("parent_id = ?", id)
end
def locked?
self.lock
end
def editable_by? user
# user && user.logged? || (self.author == usr && usr.allowed_to?(:edit_own_messages, project))
user.admin?
end
# def destroyable_by? user
# (user && user.logged? && (Forum.find(self.forum_id).creator_id == user.id) ) || user.admin?
# #self.author == user || user.admin?
# end
def deleted_attach_able_by? user
(user && user.logged? && (self.author == user) ) || user.admin?
end
private
def add_author_as_watcher
Watcher.create(:watchable => self.root, :user => author)
end
def send_notification
if Setting.notified_events.include?('message_posted')
Mailer.message_posted(self).deliver
end
end
# def plusParentAndForum
# @forum = Forum.find(self.forum_id)
# @forum.memo_count = @forum.memo_count.to_int + 1
# @forum.last_memo_id = self.id
# if self.parent_id
# @parent_memo = Memo.find_by_id(self.parent_id)
# @parent_memo.last_reply_id = self
# @parent_memo.replies_count = @parent_memo.replies_count.to_int + 1
# @parent_memo.save
# else
# @forum.topic_count = @forum.topic_count.to_int + 1
# end
# @forum.save
# end
# def minusParentAndForum
# @forum = Forum.find(self.forum_id)
# @forum.memo_count = @forum.memo_count.to_int - 1
# @forum.memo_count = 0 if @forum.memo_count.to_int < 0
# # @forum.last_memo_id = Memo.reorder('created_at ASC').find_all_by_forum_id(self.forum_id).last.id
# if self.parent_id
# @parent_memo = Memo.find_by_id(self.parent_id)
# # @parent_memo.last_reply_id = Memo.reorder('created_at ASC').find_all_by_parent_id(self.parent_id).last.id
# @parent_memo.replies_count = @parent_memo.replies_count.to_int - 1
# @parent_memo.replies_count = 0 if @parent_memo.replies_count.to_int < 0
# @parent_memo.save
# else
# @forum.topic_count = @forum.topic_count.to_int - 1
# @forum.topic_count = 0 if @forum.topic_count.to_int < 0
# end
# @forum.save
# end
end

View File

@ -5,7 +5,7 @@
<% if memos.any? %>
<% memos.each do |topic| %>
<table class="content-text-list">
<tr><td colspan="2" valign="top" width="50" ><%= link_to image_tag(url_to_avatar(topic.author), :class => "avatar"), user_path(topic.author) %></td>
<tr><td colspan="2" valign="top" width="50" ><%= link_to image_tag(url_to_avatar(topic.author), :class => "avatar"), user_path(topic.author) if topic.author%></td>
<td>
<table width="630px" border="0">
<tr>

View File

@ -103,7 +103,7 @@
<!-- added by william -for tag -->
<div class="user_tags">
<div id="tags">
<%= render :partial => 'tags/tag', :locals => {:obj => @open_source_project,:object_flag => "2"}%>
<%= render :partial => 'tags/tag', :locals => {:obj => @open_source_project,:object_flag => "7"}%>
</div>
</div>
<!-- tag -->
@ -114,10 +114,10 @@
</div>
</div>
<div id="content">
<div id="content"><%#=
<div class="tabs_new">
</div>
</div>%>
<%= render_flash_messages %>
<%= yield %>
<%= call_hook :view_layouts_base_content %>

View File

@ -51,7 +51,7 @@
<div class="licences">
<%= content_tag('span', "数据更新时间") %><%= content_tag('span', format_time(project.created_at)) %>
</div>
</div>
</div>
<div class="tags">
<div id="tags">
<%= image_tag( "/images/sidebar/tags.png") %>

View File

@ -0,0 +1,57 @@
<!-- added by fq -->
<!--display the board-->
<div class="borad-topic-count">
共有 <%= link_to memos.count %> 个贴子
</div>
<div style="padding-top: 10px">
<% if memos.any? %>
<% memos.each do |topic| %>
<table class="content-text-list">
<tr>
<td colspan="2" valign="top" width="50" ><%= link_to image_tag(url_to_avatar(topic.author), :class => "avatar"), user_path(topic.author) if topic.author%></td>
<td>
<table width="630px" border="0">
<tr>
<td valign="top" width="500px" class="<%= topic.sticky ? 'sticky' : '' %> <%= topic.locked? ? 'locked' : '' %>"><%= link_to h(topic.subject), open_source_project_relative_memo_path(topic.open_source_project, topic) %></td>
<td align="right" rowspan="3">
<table class="borad-count">
<tr>
<td align="center" class="borad-count-digit"><%= link_to (topic.replies_count), forum_memo_path(topic.open_source_project, topic) %></td>
</tr>
<tr>
<td align="center">回答</td>
</tr>
</table></td>
</tr>
<tr>
<td colspan="2" ><span class="font_description"> </span></td>
</tr>
<tr>
<td align="left" colspan="2" ><span class="font_lighter"><%#= authoring topic.created_at, topic.author %>
<br />
</span></td>
</tr>
<tr>
<td align="left" colspan="2" ><span class="font_lighter"><%= @open_source_project.url%> </span></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 %>
</div>
<% else %>
<p class="nodata">
<%= l(:label_no_data) %>
</p>
<% end %>
</div>

View File

@ -1,10 +1,54 @@
<p id="notice"><%= notice %></p>
<!-- added by fq -->
<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| %>
<% if @memo.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@memo.errors.count, "error") %> prohibited this memo from being saved:</h2>
<p>
<b>String:</b>
<%= @open_source_project.name %>
</p>
<ul>
<% @memo.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% 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>
<script type="text/javascript">var ckeditor=CKEDITOR.replace('editor02');</script>
<br/>
<p>
<%= l(:label_attachment_plural) %><br />
<%= render :partial => 'attachments/form', :locals => {:container => @memo} %>
</p>
<%= f.submit :value => l(:label_memo_create) %>
<%= link_to l(:button_cancel), "#", :onclick => '$("#add-memo").hide(); return false;' %>
</div>
<% end %>
<% end %>
</div>
<!--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',
:onclick => 'showAndScrollTo("add-memo", "memo_subject"); return false;' if User.current.logged? %>
</span>
<%= link_to 'Edit', edit_open_source_project_path(@open_source_project) %> |
<%= link_to 'Back', open_source_projects_path %>
<div class="contextual-borad">
<%#= link_to(
image_tag('edit.png')+l(:label_forum_edit),
{:action => 'edit', :id => @forum},
:method => 'get',
:title => l(:button_edit)
) if @forum.editable_by?(User.current) %>
<%#= link_to(
image_tag('delete.png')+'删除讨论区',
{:action => 'destroy', :id => @forum},
:method => :delete,
:data => {:confirm => l(:text_are_you_sure)},
:title => l(:button_delete)
) if @forum.destroyable_by?(User.current) %>
</div>
<%= render :partial => 'open_source_projects/show_topics', :locals => {:memos => @memos} %>

View File

View File

@ -6,6 +6,8 @@
4 代表是bid类型
5 代表是forum类型
6 代表是Attachment类型
7 代表是OpenSourceProject类型
8 代表是RelativeMemo类型
#end%>
<!-- 3 代表的是issue 当是issue是 处理方式与前2个对象不同 -->
<% if object_flag == '3' %>

View File

@ -20,8 +20,10 @@ RedmineApp::Application.routes.draw do
collection do
match 'search', via: [:get, :post]
end
end
resources :relative_memos do
end
end
match 'course', :to => 'welcome#course', :via => :get
resources :stores do
@ -44,7 +46,6 @@ RedmineApp::Application.routes.draw do
end
end
resources :shares
#added by william
@ -103,7 +104,6 @@ RedmineApp::Application.routes.draw do
match '/journals/edit/:id', :to => 'journals#edit', :id => /\d+/, :via => [:get, :post]
match '/journals/destroy/:id', :to => 'journals#destroy', :id => /\d+/, :via => [:get, :post]
get '/projects/:project_id/issues/gantt', :to => 'gantts#show', :as => 'project_gantt'
get '/issues/gantt', :to => 'gantts#show'
@ -204,7 +204,6 @@ RedmineApp::Application.routes.draw do
match 'copy', :via => [:get, :post]
end
#by young
match '/member', :controller => 'projects', :action => 'member', :as => 'member', :via => :get
match '/file', :controller => 'projects', :action => 'file', :as => 'file', :via => :get
@ -212,7 +211,6 @@ RedmineApp::Application.routes.draw do
# match '/investor', :controller => 'projects', :action => 'investor', :as => 'investor', :via => :get
match '/homework', :controller => 'projects', :action => 'homework', :as => 'homework', :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
@ -448,8 +446,6 @@ RedmineApp::Application.routes.draw do
end
end
match 'workflows', :controller => 'workflows', :action => 'index', :via => :get
match 'workflows/edit', :controller => 'workflows', :action => 'edit', :via => [:get, :post]
match 'workflows/permissions', :controller => 'workflows', :action => 'permissions', :via => [:get, :post]