2012-01-30 20:39:34 +00:00
|
|
|
# -*- encoding : utf-8 -*-
|
2011-03-09 19:27:51 +00:00
|
|
|
class PlatformsController < ApplicationController
|
2011-10-27 12:02:25 +01:00
|
|
|
before_filter :authenticate_user!, :except => :easy_urpmi
|
2011-10-31 21:55:56 +00:00
|
|
|
before_filter :find_platform, :only => [:freeze, :unfreeze, :clone, :edit, :destroy]
|
2011-11-03 12:49:14 +00:00
|
|
|
before_filter :get_paths, :only => [:new, :create, :clone]
|
2011-11-16 18:45:01 +00:00
|
|
|
|
2011-11-24 21:46:19 +00:00
|
|
|
load_and_authorize_resource
|
2011-12-01 09:29:04 +00:00
|
|
|
autocomplete :user, :uname
|
2011-10-28 18:55:40 +01:00
|
|
|
|
2011-11-30 14:48:16 +00:00
|
|
|
def build_all
|
2012-02-23 18:32:56 +00:00
|
|
|
@platform.delay.build_all(current_user)
|
2011-11-30 14:48:16 +00:00
|
|
|
|
|
|
|
redirect_to(platform_path(@platform), :notice => t("flash.platform.build_all_success"))
|
|
|
|
end
|
|
|
|
|
2011-03-09 19:27:51 +00:00
|
|
|
def index
|
2012-03-11 23:08:50 +00:00
|
|
|
@platforms = @platforms.paginate(:page => params[:page], :per_page => 20)
|
2011-10-27 12:02:25 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def easy_urpmi
|
2011-10-31 15:19:55 +00:00
|
|
|
@platforms = Platform.where(:distrib_type => APP_CONFIG['distr_types'].first, :visibility => 'open', :platform_type => 'main')
|
2011-10-20 21:23:38 +01:00
|
|
|
respond_to do |format|
|
|
|
|
format.json do
|
|
|
|
render :json => {
|
|
|
|
:platforms => @platforms.map do |p|
|
2011-11-28 15:41:42 +00:00
|
|
|
{:name => p.name,
|
2011-10-20 21:23:38 +01:00
|
|
|
:architectures => ['i586', 'x86_64'],
|
2011-11-28 15:41:42 +00:00
|
|
|
:repositories => p.repositories.map(&:name),
|
2011-12-21 14:01:50 +00:00
|
|
|
:url => p.public_downloads_url(request.host_with_port)}
|
2011-10-20 21:23:38 +01:00
|
|
|
end
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
2011-03-09 19:27:51 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
2011-03-11 16:08:41 +00:00
|
|
|
@platform = Platform.find params[:id], :include => :repositories
|
2012-03-11 23:08:50 +00:00
|
|
|
#@repositories = @platform.repositories
|
|
|
|
#@members = @platform.members.uniq
|
2011-03-09 19:27:51 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@platform = Platform.new
|
2011-12-12 15:37:28 +00:00
|
|
|
@admin_uname = current_user.uname
|
|
|
|
@admin_id = current_user.id
|
2011-03-09 19:27:51 +00:00
|
|
|
end
|
2012-03-11 23:08:50 +00:00
|
|
|
|
2011-10-25 14:07:19 +01:00
|
|
|
def edit
|
2011-12-13 13:27:27 +00:00
|
|
|
@admin_id = @platform.owner.id
|
|
|
|
@admin_uname = @platform.owner.uname
|
2011-10-25 14:07:19 +01:00
|
|
|
end
|
2011-03-09 19:27:51 +00:00
|
|
|
|
|
|
|
def create
|
2011-10-17 15:27:07 +01:00
|
|
|
@platform = Platform.new params[:platform]
|
2011-12-12 14:10:39 +00:00
|
|
|
@admin_id = params[:admin_id]
|
2011-12-12 15:37:28 +00:00
|
|
|
@admin_uname = params[:admin_uname]
|
|
|
|
@platform.owner = @admin_id.blank? ? get_owner : User.find(@admin_id)
|
2011-10-17 15:27:07 +01:00
|
|
|
|
2011-12-13 21:48:25 +00:00
|
|
|
if @platform.save
|
2011-10-17 15:27:07 +01:00
|
|
|
flash[:notice] = I18n.t("flash.platform.saved")
|
2011-12-13 13:27:27 +00:00
|
|
|
redirect_to @platform
|
|
|
|
else
|
2011-12-28 02:57:42 +00:00
|
|
|
flash[:error] = I18n.t("flash.platform.save_error")
|
2011-12-13 13:27:27 +00:00
|
|
|
render :action => :new
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
@admin_id = params[:admin_id]
|
|
|
|
@admin_uname = params[:admin_uname]
|
|
|
|
|
|
|
|
if @platform.update_attributes(
|
|
|
|
:owner => @admin_id.blank? ? get_owner : User.find(@admin_id),
|
|
|
|
:description => params[:platform][:description],
|
|
|
|
:released => params[:platform][:released]
|
|
|
|
)
|
|
|
|
flash[:notice] = I18n.t("flash.platform.saved")
|
2011-10-17 15:27:07 +01:00
|
|
|
redirect_to @platform
|
|
|
|
else
|
2011-12-28 02:57:42 +00:00
|
|
|
flash[:error] = I18n.t("flash.platform.save_error")
|
2011-10-17 15:27:07 +01:00
|
|
|
render :action => :new
|
|
|
|
end
|
2011-03-09 19:27:51 +00:00
|
|
|
end
|
|
|
|
|
2011-03-17 14:47:16 +00:00
|
|
|
def freeze
|
|
|
|
@platform.released = true
|
|
|
|
if @platform.save
|
|
|
|
flash[:notice] = I18n.t("flash.platform.freezed")
|
|
|
|
else
|
|
|
|
flash[:notice] = I18n.t("flash.platform.freeze_error")
|
|
|
|
end
|
2011-03-17 12:35:42 +00:00
|
|
|
|
2011-03-17 14:47:16 +00:00
|
|
|
redirect_to @platform
|
|
|
|
end
|
|
|
|
|
|
|
|
def unfreeze
|
|
|
|
@platform.released = false
|
|
|
|
if @platform.save
|
|
|
|
flash[:notice] = I18n.t("flash.platform.unfreezed")
|
|
|
|
else
|
|
|
|
flash[:notice] = I18n.t("flash.platform.unfreeze_error")
|
|
|
|
end
|
|
|
|
|
|
|
|
redirect_to @platform
|
|
|
|
end
|
2011-03-17 12:35:42 +00:00
|
|
|
|
2011-05-30 10:04:32 +01:00
|
|
|
def clone
|
2012-02-21 21:27:11 +00:00
|
|
|
@cloned = Platform.new
|
|
|
|
@cloned.name = @platform.name + "_clone"
|
|
|
|
@cloned.description = @platform.description + "_clone"
|
|
|
|
end
|
|
|
|
|
|
|
|
def make_clone
|
2012-02-22 20:24:29 +00:00
|
|
|
@cloned = @platform.full_clone params[:platform].merge(:owner => current_user)
|
|
|
|
if @cloned.persisted?
|
2012-02-21 21:27:11 +00:00
|
|
|
flash[:notice] = I18n.t("flash.platform.clone_success")
|
|
|
|
redirect_to @cloned
|
2011-05-30 10:04:32 +01:00
|
|
|
else
|
2012-02-21 21:27:11 +00:00
|
|
|
flash[:error] = @cloned.errors.full_messages.join('. ')
|
|
|
|
render 'clone'
|
2011-05-30 10:04:32 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-03-09 19:27:51 +00:00
|
|
|
def destroy
|
2012-02-22 12:35:40 +00:00
|
|
|
@platform.delay.destroy if @platform
|
2011-03-31 03:00:21 +01:00
|
|
|
|
|
|
|
flash[:notice] = t("flash.platform.destroyed")
|
2011-03-09 19:27:51 +00:00
|
|
|
redirect_to root_path
|
|
|
|
end
|
2011-11-16 18:45:01 +00:00
|
|
|
|
|
|
|
def forbidden
|
|
|
|
end
|
2011-03-17 14:47:16 +00:00
|
|
|
|
|
|
|
protected
|
2011-10-17 15:27:07 +01:00
|
|
|
def get_paths
|
|
|
|
if params[:user_id]
|
|
|
|
@user = User.find params[:user_id]
|
|
|
|
@platforms_path = user_platforms_path @user
|
|
|
|
@new_platform_path = new_user_platform_path @user
|
|
|
|
elsif params[:group_id]
|
|
|
|
@group = Group.find params[:group_id]
|
|
|
|
@platforms_path = group_platforms_path @group
|
|
|
|
@new_platform_path = new_group_platform_path @group
|
|
|
|
else
|
|
|
|
@platforms_path = platforms_path
|
|
|
|
@new_platform_path = new_platform_path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-03-17 14:47:16 +00:00
|
|
|
def find_platform
|
|
|
|
@platform = Platform.find params[:id]
|
|
|
|
end
|
2011-03-09 19:27:51 +00:00
|
|
|
end
|