Download Extensions now working

This commit is contained in:
Saurabh Bhatia 2014-01-23 18:27:24 +08:00
parent c0ea38475c
commit 5a9e60174d
3 changed files with 18 additions and 31 deletions

View File

@ -13,18 +13,19 @@ class Admin::ModuleStoreController < OrbitBackendController
def download
#get extension related values
extension = get_extension(params[:id]) rescue nil
download_link = @@store + "/"+ extension["extension"]["extension"]["url"]
downloaded_file_name = extension["extension_filename"]
module_app_name = downloaded_file_name.split(/(.zip)/).first
extension_name = extension["key"].to_s
git_repository_url = extension["git_url"]
version = extension["version"]
module_installed = File.read("downloaded_extensions.rb").include?(extension["key"])
#check if the directory exists or not
@module_status = Dir.exists?("#{Rails.root}/vendor/built_in_modules/#{module_app_name}")
if @module_status.eql?(true)
flash[:notice] = "This module is already installed"
else
download_extension(download_link, downloaded_file_name,module_app_name)
flash[:notice] = "This module has been successfully installed"
if module_installed.eql?(false)
@download_link = "gem '#{extension_name}', '#{version}', :git => '#{git_repository_url}'"
File.open("downloaded_extensions.rb", 'a') do |file|
file.puts @download_link
end
end
%w(bundle install)
site_restart
redirect_to admin_module_store_path
end
@ -37,12 +38,4 @@ class Admin::ModuleStoreController < OrbitBackendController
def get_extension(id)
JSON.parse(open("#{@@store}/api/extensions/#{id}").read)
end
def download_extension(download_link, downloaded_file_name,module_app_name)
puts %x(wget "#{download_link}")
puts %x(unzip "#{downloaded_file_name}")
puts %x(mv #{module_app_name} "#{Rails.root}/vendor/built_in_modules/")
puts %x(rm "#{downloaded_file_name}")
site_restart
end
end

View File

@ -44,18 +44,12 @@
<td>
<%= extension["description"].html_safe%> <%= link_to 'Read More', admin_module_store_show_path(extension["_slugs"][0]) %>
</td>
<!-- <td class="active"><button class="act btn btn-mini" type="button">Uninstall</button></td>
-->
<% download_link = STORE_CONFIG[:store_settings]["url"] + "/"+ extension["extension"]["extension"]["url"]
downloaded_file_name = extension["extension_filename"]
module_app_name = downloaded_file_name.split(/(.zip)/).first
@module_status = Dir.exists?("#{Rails.root}/vendor/built_in_modules/#{module_app_name}")
%>
<% if @module_status.eql?(true)%>
<td class="active">Installed</td>
<% else %>
<td class="active"><%= link_to 'Download', admin_module_store_download_path(:id => extension["_slugs"][0]), :class=>"act btn btn-mini btn-success" %></td>
<% end %>
<% @module_installed = File.read("downloaded_extensions.rb").include?(extension["key"])%>
<% if @module_installed.eql?(true)%>
<td class="active">Installed</td>
<% else %>
<td class="active"><%= link_to 'Download', admin_module_store_download_path(:id => extension["_slugs"][0]), :class=>"act btn btn-mini btn-success" %></td>
<% end %>
</tr>
<% end %>
</tbody>

View File

@ -1,6 +1,6 @@
gem 'archive', '0.0.1', :git => 'git@gitlab.tp.rulingcom.com:root/orbit-archive.git'
gem 'calendar', '0.0.1', :git => 'git@gitlab.tp.rulingcom.com:root/orbit-calendar.git'
gem 'location', '0.0.1', :git => 'git@gitlab.tp.rulingcom.com:root/orbit-location.git'
gem 'ask', '0.0.1', :git => 'git@gitlab.tp.rulingcom.com:root/orbit-ask.git'
gem 'video', '0.0.1', :git => 'git@gitlab.tp.rulingcom.com:root/orbit-video.git'
gem 'faq', '0.0.1', :git => 'git@gitlab.tp.rulingcom.com:root/orbit-faq.git'
gem 'ask', '0.0.1', :git => 'git@gitlab.tp.rulingcom.com:root/orbit-ask.git'