增加参赛应用页面的打分细节--初级版

This commit is contained in:
wanglinchun 2014-04-30 08:07:08 +08:00
parent 3da6d5cd37
commit e48edac988
3 changed files with 31 additions and 2 deletions

View File

@ -40,8 +40,25 @@ class SoftapplicationsController < ApplicationController
# GET /softapplications/1
# GET /softapplications/1.json
def percent_of(num, percent)
num.to_f / percent.to_f * 100.0
end
def show
@softapplication = Softapplication.find(params[:id])
# 打分统计
stars_reates = @softapplication.
rates(:quality)
stars_reates_count = stars_reates.count == 0 ? 1 : stars_reates.count
stars_status = stars_reates.select("stars, count(*) as scount").
group("stars")
@stars_status_map = Hash.new(0.0)
stars_status.each do |star_status|
@stars_status_map["star#{star_status.stars.to_i}".to_sym] =
percent_of(star_status.scount, stars_reates_count).to_s + "%"
end
@jours = @softapplication.journals_for_messages.order('created_on DESC')
@image_results = []
@softapplication.attachments.each do |f|

View File

@ -49,7 +49,8 @@
<div class="avatar-4"; style="float: left; margin-top: 7px "><%= image_tag('/images/app1.png')%></div>
<div style="float: left; width: 600px; padding-top: 6px; margin-left: 8px"><%= softapplication.description.truncate(95, omission: '...') %></div>
<div style="float: left; width: 200px; margin-left: 70px; margin-top: -3px; line-height: 0.5em">
<p>所属竞赛:<%#= contest ? link_to(contest.name, show_softapplication_contest_path()) : '尚未加入竞赛'%></p>
<%contest = softapplication.contests.first%>
<p>所属竞赛:<%= contest ? link_to(contest.name, show_softapplication_contest_path(contest) ) : '尚未加入竞赛'%></p>
<p>所属类别:<%= softapplication.app_type_name %></p>
<p>系统支持:<%= softapplication.android_min_version_available %></p>
</div>

View File

@ -72,7 +72,18 @@
</div>
<div class="underline-contests_one"></div>
<div style="margin-left: 22%;">
<% 100.step(20,-20) do |star| %>
<div data-kls="Softapplication" data-id="2" data-dimension="quality" data-average="3.25" class="rateable div_inline jDisabled" style="height: 20px; width: 115px; overflow: hidden; z-index: 1; position: relative;">
<div class="jRatingColor" style="width: <%=star%>%;"></div>
<div class="jRatingAverage" style="width: 0px; top: -20px;"></div>
<div class="jStar" style="width: 115px; height: 20px; top: -40px; background: url(&quot;/images/seems_rateable/stars.png&quot;) repeat-x scroll 0% 0% transparent;">
</div>
</div>
<%= @stars_status_map["star#{(star/20).to_s}".to_sym] %>
<br>
<% end %>
</div>
<div style="height: 50px">
<div style="font-size: 15px"><strong>软件评论:</strong></div>
<div style="padding-left: 210px">评分: <%= rating_for @softapplication, dimension: :quality, class: 'rateable div_inline' %></div>