add first version of the download screen
[opensuse:software-o-o.git] / app / controllers / download_controller.rb
1 class DownloadController < ApplicationController
2
3   verify :params => [:prj, :pkg]
4   before_filter :prepare
5
6   def prepare
7     @prj = params[:prj]
8     @pkg = params[:pkg]
9     @data = Hash.new
10
11     # add fake data for debug purposes
12     ['openSUSE_11.4', 'openSUSE_11.3', 'Fedora_15', 'Fedora_14', 'Mageia_1', 'Mandriva_2011', 'Debian_6.0', 'Ubuntu_11.04', 'CentOS_5', 'RHEL_5', 'SLE_11'].each do |d|
13       @data[d] =
14         { :repo => "http://download.opensuse.org/repositories/#{@prj}/#{d}/",
15           :ymp => "http://software.opensuse.org/ymp/#{@prj}/#{d}/#{@pkg}.ymp",
16           :pkg => {
17             :i586 => "http://download.opensuse.org/repositories/#{@prj}/#{d}/i586/#{@pkg}-2011.04-1.1.i586.rpm",
18             :src => "http://download.opensuse.org/repositories/#{@prj}/#{d}/src/#{@pkg}-2011.04-1.1.src.rpm",
19             :x86_64 => "http://download.opensuse.org/repositories/#{@prj}/#{d}/x86_64/#{@pkg}-2011.04-1.1.x86_64.rpm"
20           }
21         }
22     end
23
24     # collect distro types from data
25     @distros = @data.keys.collect { |i| i.gsub(/_.*$/, '') }.uniq.sort {|x,y| x.downcase <=> y.downcase }
26
27   end
28
29   # /download.html?prj=name&pkg=name
30   def html
31     render :html, :layout => false
32   end
33
34   # /download.js?prj=name&pkg=name
35   def js
36     render :js, :layout => false
37   end
38
39   # /download.json?prj=name&pkg=name
40   def json
41     # needed for rails < 3.0 to support JSONP
42     render_json @data.to_json
43   end
44
45 end