调整了具体应用页面评价应用的功能

This commit is contained in:
wanglinchun 2014-04-10 08:33:30 +08:00
parent dfad0448e1
commit be61b9d1ac
9 changed files with 165 additions and 15 deletions

View File

@ -14,7 +14,13 @@ class SoftapplicationsController < ApplicationController
# GET /softapplications/1.json # GET /softapplications/1.json
def show def show
@softapplication = Softapplication.find(params[:id]) @softapplication = Softapplication.find(params[:id])
@jours = @softapplication.journals_for_messages.order('created_on DESC')
@limit = 10
@feedback_count = @jours.count
@feedback_pages = Paginator.new @feedback_count, @limit, params['page']
@offset ||= @feedback_pages.offset
@jour = @jours[@offset, @limit]
@state = false
respond_to do |format| respond_to do |format|
format.html # show.html.erb format.html # show.html.erb
format.json { render json: @softapplication } format.json { render json: @softapplication }
@ -41,6 +47,7 @@ class SoftapplicationsController < ApplicationController
# POST /softapplications.json # POST /softapplications.json
def create def create
@softapplication = Softapplication.new(params[:softapplication]) @softapplication = Softapplication.new(params[:softapplication])
@softapplication.user = User.current
@softapplication.save_attachments(params[:attachments]) @softapplication.save_attachments(params[:attachments])
respond_to do |format| respond_to do |format|
if @softapplication.save if @softapplication.save
@ -86,4 +93,94 @@ class SoftapplicationsController < ApplicationController
format.json { head :no_content } format.json { head :no_content }
end end
end end
#应用评价涉及到的方法
def new_message
@jour = JournalsForMessage.find(params[:journal_id]) if params[:journal_id]
if @jour
user = @jour.user
text = @jour.notes
else
user = @softapplication.user
text = @softapplication.description
end
text = text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]')
@content = "> #{ll(User.current.language, :text_user_wrote, user)}\n> "
@content << text.gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n"
@id = user.id
rescue ActiveRecord::RecordNotFound
render_404
end
#新建评价
def create_message
if params[:softapplication_message][:message].size>0
if params[:reference_content]
message = params[:softapplication_message][:message] + "\n" + params[:reference_content]
else
message = params[:softapplication_message][:message]
end
refer_user_id = params[:softapplication_message][:reference_user_id].to_i
@softapplication = Softapplication.find(params[:id])
@softapplication.add_jour(User.current, message, refer_user_id)
end
@user = @softapplication.user
@jours = @softapplication.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC')
@limit = 10
@feedback_count = @jours.count
@feedback_pages = Paginator.new @feedback_count, @limit, params['page']
@offset ||= @feedback_pages.offset
@jour = @jours[@offset, @limit]
#@softapplication.set_commit(@feedback_count)
respond_to do |format|
format.js
end
end
##删除评价
def destroy_message
@user = @softapplication.user
if User.current.admin? || User.current.id == @user.id
JournalsForMessage.delete_message(params[:object_id])
end
@jours = @softapplication.journals_for_messages.reverse
@limit = 10
@feedback_count = @jours.count
@feedback_pages = Paginator.new @feedback_count, @limit, params['page']
@offset ||= @feedback_pages.offset
@jour = @jours[@offset, @limit]
@softapplication.set_commit(@feedback_count)
respond_to do |format|
format.js
end
end
#
def more
@jour = @softapplication.journals_for_messages
@jour.each_with_index {|j,i| j.indice = i+1}
@state = true
respond_to do |format|
format.html { redirect_to :back }
format.js
#format.api { render_api_ok }
end
end
#
def back
@jour = @softapplication.journals_for_messages
@jour.each_with_index {|j,i| j.indice = i+1}
@state = false
respond_to do |format|
format.html { redirect_to :back }
format.js
#format.api { render_api_ok }
end
end
end end

View File

@ -192,6 +192,8 @@ class WordsController < ApplicationController
obj = Bid.find_by_id(obj_id) obj = Bid.find_by_id(obj_id)
elsif ( referer.match(/contests/) || referer.match(/contests/) ) #new added elsif ( referer.match(/contests/) || referer.match(/contests/) ) #new added
obj = Contest.find_by_id(obj_id) obj = Contest.find_by_id(obj_id)
elsif ( referer.match(/softapplications/) || referer.match(/softapplications/) ) #new added
obj = Softapplication.find_by_id(obj_id)
else else
raise 'create reply obj unknow type.' raise 'create reply obj unknow type.'
end end
@ -208,6 +210,8 @@ class WordsController < ApplicationController
obj.add_jour(nil, nil, nil, options) obj.add_jour(nil, nil, nil, options)
elsif obj.kind_of? Contest elsif obj.kind_of? Contest
obj.add_jour(nil, nil, obj.id, options) #new added obj.add_jour(nil, nil, obj.id, options) #new added
elsif obj.kind_of? Softapplication
obj.add_jour(nil, nil, obj.id, options) #new added
else else
raise 'create reply obj unknow type.' raise 'create reply obj unknow type.'
end end

View File

@ -1,4 +1,21 @@
class Softapplication < ActiveRecord::Base class Softapplication < ActiveRecord::Base
attr_accessible :android_min_version_available, :app_type_id, :app_type_name, :description, :name, :user_id attr_accessible :android_min_version_available, :app_type_id, :app_type_name, :description, :name, :user_id
acts_as_attachable acts_as_attachable
has_many :journals_for_messages, :as => :jour, :dependent => :destroy
belongs_to :user
def add_jour(user, notes, reference_user_id = 0, options = {})
if options.count == 0
self.journals_for_messages << JournalsForMessage.new(:user_id => user.id, :notes => notes, :reply_id => reference_user_id)
else
jfm = self.journals_for_messages.build(options)
jfm.save
jfm
end
end
def set_commit(commit)
self.update_attribute(:commit, commit)
end
end end

View File

@ -79,12 +79,14 @@ class User < Principal
## added by xianbo for delete ## added by xianbo for delete
has_many :biding_projects, :dependent => :destroy has_many :biding_projects, :dependent => :destroy
has_many :contesting_projects, :dependent => :destroy has_many :contesting_projects, :dependent => :destroy
belongs_to :softapplication, :foreign_key => 'id', :dependent => :destroy
##ended by xianbo ##ended by xianbo
#####fq #####fq
has_many :jours, :class_name => 'JournalsForMessage', :dependent => :destroy has_many :jours, :class_name => 'JournalsForMessage', :dependent => :destroy
has_many :bids, :foreign_key => 'author_id', :dependent => :destroy has_many :bids, :foreign_key => 'author_id', :dependent => :destroy
has_many :contests, :foreign_key => 'author_id', :dependent => :destroy has_many :contests, :foreign_key => 'author_id', :dependent => :destroy
has_many :softapplications, :foreign_key => 'user_id', :dependent => :destroy
has_many :journals_for_messages, :as => :jour, :dependent => :destroy has_many :journals_for_messages, :as => :jour, :dependent => :destroy
has_many :new_jours, :as => :jour, :class_name => 'JournalsForMessage', :conditions => "status=1" has_many :new_jours, :as => :jour, :class_name => 'JournalsForMessage', :conditions => "status=1"
has_many :journal_replies, :dependent => :destroy has_many :journal_replies, :dependent => :destroy

View File

@ -1,9 +1,9 @@
<h3><%= l(:label_release_softapplication)%></h3> <!-- <%= render 'form' %> <h3 style="font-size: 18px"><%= l(:label_release_softapplication)%></h3> <!-- <%= render 'form' %>
<%= link_to 'Back', softapplications_path %> --> <%= link_to 'Back', softapplications_path %> -->
<div id="put-bid-form" style=""> <div id="put-bid-form">
<%= form_for Softapplication.new, :url => {:controller => 'softapplications', :action => 'create'}, :update => "bidding_project_list", :complete => '$("#put-bid-form").hide();', :html => {:multipart => true, :id => 'add_homework_form'} do |f| %> <%= form_for Softapplication.new, :url => {:controller => 'softapplications', :action => 'create'}, :update => "bidding_project_list", :complete => '$("#put-bid-form").hide();', :html => {:multipart => true, :id => 'add_homework_form'} do |f| %>
<fieldset> <fieldset>
<legend> <legend>
@ -41,12 +41,18 @@
</tr></ br> </tr></ br>
<br /> <br />
<br /> <br />
<fieldset style="width: 500px">
<legend>上传应用软件包或应用截图</legend>
<%= render_flash_messages %> <%= render_flash_messages %>
<p id="put-bid-form-partial"> <p id="put-bid-form-partial">
<%= render :partial => 'attachments/form' %> <%= render :partial => 'attachments/form' %>
</p> </p>
<p style="font-size: 10px">(<%=l(:label_upload_softapplication_photo_condition)%>)</p>
</fieldset> </fieldset>
<%= submit_tag l(:button_create), :onclick => "return true" %> </fieldset></br>
<div class="align-center"><%= submit_tag l(:button_create), :onclick => "return true" %></div>
<script type="text/javascript"> <script type="text/javascript">
function j_submit () { function j_submit () {
alert('start') alert('start')

View File

@ -13,7 +13,7 @@
<td>发布时间:<%=@softapplication.created_at %></span></td> <td>发布时间:<%=@softapplication.created_at %></span></td>
</tr> </tr>
<tr> <tr>
<td>开发者:<%= @softapplication.user_id %></td> <td>开发者:<%= @softapplication.user.name %></td>
<td>系统支持:<%= @softapplication.android_min_version_available %></td> <td>系统支持:<%= @softapplication.android_min_version_available %></td>
</tr> </tr>
@ -40,7 +40,20 @@
<div></div> <div></div>
</div> </div>
<!--提示登录后对应用进行评价-->
<div id="history">
<%= render :partial => 'message_history', :locals => { :contest => @softapplication, :journals => @jour, :state => false} %>
</div>
<!--分页-->
<div class="pagination" style="float:left;">
<ul>
<%= pagination_links_full @feedback_pages %>
</ul>
</div>
<div>
<%= link_to 'Edit', edit_softapplication_path(@softapplication) %> | <%= link_to 'Edit', edit_softapplication_path(@softapplication) %> |
<%= link_to 'Back', softapplications_path %> <%= link_to 'Back', softapplications_path %>
</div>

View File

@ -1,6 +1,6 @@
<% if @journal_destroyed.nil? %> <% if @journal_destroyed.nil? %>
alert('<%=l(:notice_failed_delete)%>'); alert('<%=l(:notice_failed_delete)%>');
<% elsif (['Principal','Project', 'Bid', 'Contest'].include? @journal_destroyed.jour_type)%> <% elsif (['Principal','Project', 'Bid', 'Contest', 'Softapplication'].include? @journal_destroyed.jour_type)%>
var destroyedItem = $('#word_li_<%=@journal_destroyed.id%>') var destroyedItem = $('#word_li_<%=@journal_destroyed.id%>')
destroyedItem.fadeOut(600,function(){ destroyedItem.fadeOut(600,function(){
destroyedItem.remove(); destroyedItem.remove();

View File

@ -1829,10 +1829,11 @@ zh:
label_release_softapplication: 发布应用 label_release_softapplication: 发布应用
label_upload_softapplication_packets: 上传应用软件包 label_upload_softapplication_packets: 上传应用软件包
label_upload_softapplication_photo: 上传产品截图 label_upload_softapplication_photo: 上传产品截图
label_upload_softapplication_photo_condition: 至少上传2张截图至多4张格式为gif/jpg/png 尺寸480*800, 每张小于2M label_upload_softapplication_photo_condition: 截图至少上传2张至多4张格式为gif/jpg/png 尺寸480*800, 每张小于2M
label_softapplication_name: 应用名称 label_softapplication_name: 应用名称
label_softapplication_description: 应用简介 label_softapplication_description: 应用简介
label_softapplication_type: 应用分类 label_softapplication_type: 应用分类
label_softapplication_version_available: 适配版本 label_softapplication_version_available: 适配版本
label_softapplication_developer: 开发者 label_softapplication_developer: 开发者
label_softapplication_name_condition: 25个汉字以内50个字符 label_softapplication_name_condition: 25个汉字以内50个字符
label_user_login_softapplication_board: 您还没有登录,请登录后参与应用评价。

View File

@ -16,7 +16,17 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
RedmineApp::Application.routes.draw do RedmineApp::Application.routes.draw do
resources :softapplications
resources :softapplications do
collection do
match 'new_message', via: :get
end
member do
match 'create_message' , via: :post
end
end
## new added by linchun #新竞赛相关 ## new added by linchun #新竞赛相关
resources :contests, only: [:index] do resources :contests, only: [:index] do
collection do collection do