diff --git a/app/controllers/packages_controller.rb b/app/controllers/packages_controller.rb index 66f4b7d..16f1919 100644 --- a/app/controllers/packages_controller.rb +++ b/app/controllers/packages_controller.rb @@ -199,18 +199,11 @@ class PackagesController < ApplicationController # Show an HTML partial with reviews of this package from the Ubuntu API def reviews expires_in 1.day, public: true - @reviews = Package.find_by_name!(params[:name]).ubuntu_reviews + # @reviews = Package.find_by_name!(params[:name]).ubuntu_reviews + @reviews = get_ubuntu_reviews :name render '_reviews', layout: false end - def my_uploads - # @current_users_screenshots gets filled in ApplicationController - # - # Get packages that the uploaded screenshots belong to. - @packages = Package.joins(:screenshots).where( - 'screenshots.id' => @current_users_screenshots) - end - private # Send a dummy thumbnail reading "No screenshot available. Sorry." @@ -264,4 +257,19 @@ class PackagesController < ApplicationController session[:ip] ||= request.remote_ip end + + # Get reviews of this package from the Ubuntu API + def get_ubuntu_reviews(packagename) + # Use the URL defined in the configuration to get a JSON string + json = open(Rails.configuration.ubuntu_reviews_api_url % packagename).read + # Turn JSON into a Ruby data structure + json = JSON.parse(json) + # Only show english reviews + # TODO: Support further languages + json = json.select {|x| x['language']=='en'} + # Sort by 'usefulness_total' (how many people found this review useful) + json = json.sort { |x,y| y['usefulness_total'].to_i <=> x['usefulness_total'].to_i} + return json + end + end diff --git a/app/models/package.rb b/app/models/package.rb index b0e26d5..5e9edc1 100644 --- a/app/models/package.rb +++ b/app/models/package.rb @@ -66,20 +66,6 @@ class Package < ApplicationRecord self.screenshots.to_a.sort { |x,y| version_compare(x.version,y.version) } end - # Get reviews of this package from the Ubuntu API - def ubuntu_reviews - # Use the URL defined in the configuration to get a JSON string - json = open(Rails.configuration.ubuntu_reviews_api_url % self.name).read - # Turn JSON into a Ruby data structure - json = JSON.parse(json) - # Only show english reviews - # TODO: Support further languages - json = json.select {|x| x['language']=='en'} - # Sort by 'usefulness_total' (how many people found this review useful) - json = json.sort { |x,y| y['usefulness_total'].to_i <=> x['usefulness_total'].to_i} - return json - end - # Return the newest screenshot that is not newer than the given version. # This algorithm collects all image # versions of a package and determines the (second) newest version.