Compare View

switch
from
...
to
 
Commits (5)
src/noosfero-spb/software_communities/controllers/software_communities_plugin_profile_controller.rb
... ... @@ -11,10 +11,15 @@ class SoftwareCommunitiesPluginProfileController < ProfileController
11 11 def download_file
12 12 download = SoftwareCommunitiesPlugin::Download.where(:id => params[:download_id].to_i).detect{ |b| b.download_block.environment.id == environment.id }
13 13  
14   - if download
  14 + if download && (download.link =~ URI::regexp)
15 15 download.total_downloads += 1
16 16 download.save
17 17  
  18 + if profile.software?
  19 + profile.software_info.downloads_count += 1
  20 + profile.software_info.save
  21 + end
  22 +
18 23 redirect_to download.link
19 24 else
20 25 session[:notice] = ERROR_MESSAGES[:not_found]
... ...
src/noosfero-spb/software_communities/db/migrate/20160518173644_adds_downloads_count_to_software.rb 0 → 100644
... ... @@ -0,0 +1,9 @@
  1 +class AddsDownloadsCountToSoftware < ActiveRecord::Migration
  2 + def up
  3 + add_column :software_communities_plugin_software_infos, :downloads_count, :integer, :default => 0
  4 + end
  5 +
  6 + def down
  7 + remove_column :software_communities_plugin_software_infos, :downloads_count
  8 + end
  9 +end
... ...
src/noosfero-spb/software_communities/db/migrate/20160518174439_migrate_software_downloads_count_from_download_block_to_software.rb 0 → 100644
... ... @@ -0,0 +1,18 @@
  1 +class MigrateSoftwareDownloadsCountFromDownloadBlockToSoftware < ActiveRecord::Migration
  2 + def up
  3 + SoftwareCommunitiesPlugin::SoftwareInfo.find_each do |software|
  4 + software.downloads_count = 0
  5 + blocks = SoftwareCommunitiesPlugin::DownloadBlock.joins(:box).where("boxes.owner_id = #{software.community_id}")
  6 + blocks.each do |b|
  7 + b.downloads.map{ |dl|
  8 + software.downloads_count += dl[:total_downloads] if dl.has_key? :total_downloads
  9 + }
  10 + end
  11 + software.save
  12 + end
  13 + end
  14 +
  15 + def down
  16 + say "This migration can't be reverted"
  17 + end
  18 +end
... ...
src/noosfero-spb/software_communities/lib/software_communities_plugin/statistic_block.rb
... ... @@ -14,11 +14,6 @@ class SoftwareCommunitiesPlugin::StatisticBlock &lt; Block
14 14 end
15 15  
16 16 def content(args={})
17   - download_blocks = get_profile_download_blocks(self.owner)
18   - downloads = download_blocks.map do |download_block|
19   - get_downloads_from_block(download_block)
20   - end
21   -
22 17 block = self
23 18 statistics = get_software_statistics
24 19  
... ... @@ -27,7 +22,6 @@ class SoftwareCommunitiesPlugin::StatisticBlock &lt; Block
27 22 :file => 'blocks/software_statistics',
28 23 :locals => {
29 24 :block => block,
30   - :total_downloads => downloads.sum,
31 25 :statistics => statistics
32 26 }
33 27 )
... ... @@ -44,23 +38,17 @@ class SoftwareCommunitiesPlugin::StatisticBlock &lt; Block
44 38 SoftwareCommunitiesPlugin::DownloadBlock.joins(:box).where("boxes.owner_id = ?", profile.id)
45 39 end
46 40  
47   - def get_downloads_from_block download_block
48   - downloads = download_block.download_records.map do |download|
49   - download.total_downloads unless download.total_downloads.nil?
50   - end
51   - downloads.select! {|value| not value.nil? }
52   - downloads.sum
53   - end
54   -
55 41 def get_software_statistics
56 42 statistics = {}
57 43 software = SoftwareCommunitiesPlugin::SoftwareInfo.find_by_community_id(self.owner.id)
58 44 if software.present?
59 45 statistics[:saved_resources] = software.saved_resources
60 46 statistics[:benefited_people] = software.benefited_people
  47 + statistics[:downloads_count] = software.downloads_count
61 48 else
62 49 statistics[:saved_resources] = 0
63 50 statistics[:benefited_people] = 0
  51 + statistics[:downloads_count] = 0
64 52 end
65 53 statistics
66 54 end
... ...
src/noosfero-spb/software_communities/views/blocks/download.html.erb
1 1 <% if block.owner.software_info.nil? %>
2 2 <%= _("This community needs a software to use this block") %>
3 3 <% else %>
4   - <h3 class="block-title"> <%= _("Download") + block.owner.software_info.community.name %> </h3>
  4 + <h3 class="block-title"> <%= block.title.present? ? block.title : _("Download") +" "+ block.owner.software_info.community.name %> </h3>
5 5 <ul class="download-list">
6 6 <% block.download_records.sort_by(&:id).each do |download| %>
7 7 <li id="download-item-<%= download.id %>">
... ...
src/noosfero-spb/software_communities/views/blocks/software_statistics.html.erb
... ... @@ -9,7 +9,7 @@
9 9 <li>
10 10 <span class="downloads-icon"></span>
11 11 <span id="downloads-count">
12   - <%= pluralize(total_downloads, 'download', 'downloads') %>
  12 + <%= pluralize(statistics[:downloads_count], 'download', 'downloads') %>
13 13 </span>
14 14 </li>
15 15 <li>
... ...
src/noosfero-spb/software_communities/views/box_organizer/_download_file.html.erb
1 1 <li class="file-item">
2 2 <a onclick="softwareDownload.selectFile(this)">
3 3 <i class="fa fa-plus"></i><span class="file-name"><%= file.name%></span> - <span class="file-size"><%= number_to_human_size(file.size, precision: 2) %></span>
4   - <%= hidden_field_tag :file_path, "/#{file.profile.identifier}/#{file.path}", :class => "file-path" %>
  4 + <%= hidden_field_tag :file_path, url_for(file.url), :class => "file-path" %>
5 5 </a>
6 6 </li>
... ...