Commit a276b09278141e223db3e703eab513efaa08a562

Authored by Filipe Ribeiro
1 parent 78f4af08
Exists in temp_ratings

temp

plugins/communities_ratings/db/migrate/20150716143312_ratings_block.rb 0 → 100644
... ... @@ -0,0 +1,7 @@
  1 +class RatingsBlock < ActiveRecord::Migration
  2 + def up
  3 + end
  4 +
  5 + def down
  6 + end
  7 +end
... ...
plugins/communities_ratings/lib/ratings_block.rb 0 → 100644
... ... @@ -0,0 +1,68 @@
  1 +class RatingsBlock < Block
  2 +
  3 + attr_accessible :ratings, :order
  4 +
  5 + settings_items :order, :type => string
  6 + settings_items :ratings, :type => Array, :default => []
  7 + before_save :get_ratings
  8 +
  9 + def self.description
  10 + _('Community Ratings')
  11 + end
  12 +
  13 + def help
  14 + _('This block displays the community ratings.')
  15 + end
  16 +
  17 + def content(args = {})
  18 + block = self
  19 + block.ratings = get_ratings
  20 + s = show_name
  21 + lambda do |object|
  22 + render(
  23 + :file => 'blocks/download',
  24 + :locals => {
  25 + :block => block,
  26 + :show_name => s
  27 + }
  28 + )
  29 + end
  30 + end
  31 +
  32 + def get_ratings
  33 + self.ratings = CommunityRating.where(community_id: owner.id)
  34 + end
  35 +
  36 + def limit_number_of_downloads
  37 + if default_release
  38 + ratings = default_release.count
  39 + ratings > 3 ? 3 : ratings
  40 + end
  41 + end
  42 +
  43 + def release
  44 + if self.current_release.downcase == "use last release"
  45 + self.owner.software_info.releases.last
  46 + else
  47 + self.owner.software_info.releases.find_by_id(self.current_release.to_i)
  48 + end
  49 + end
  50 +
  51 + def cacheable?
  52 + false
  53 + end
  54 +
  55 + def software_releases
  56 + releases_options_to_select = []
  57 + releases = self.owner.software_info.releases
  58 + return [] if releases.blank?
  59 + releases.each_with_index do |release, index|
  60 + sub_list = []
  61 + release_index = release.name
  62 + sub_list << release_index
  63 + sub_list << release.id
  64 + releases_options_to_select << sub_list
  65 + end
  66 + releases_options_to_select
  67 + end
  68 +end
... ...
plugins/communities_ratings/views/blocks/ratings.html.erb 0 → 100644
plugins/communities_ratings/views/box_organizer/_ratings_block.html.erb 0 → 100644
... ... @@ -0,0 +1,6 @@
  1 +<div class='edit-ratings-block'>
  2 +
  3 + <%= label_tag "block_current_release", _('Choose the ratings order') %>
  4 + <%= select_tag("block[current_release]",options_for_select(["Use last release"] + @block.software_releases, @block.current_release)) %>
  5 +
  6 +</div>
0 7 \ No newline at end of file
... ...