diff --git a/app/controllers/admin/module_store_controller.rb b/app/controllers/admin/module_store_controller.rb index d5ef07b..bd4adc3 100644 --- a/app/controllers/admin/module_store_controller.rb +++ b/app/controllers/admin/module_store_controller.rb @@ -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 \ No newline at end of file diff --git a/app/views/admin/module_store/index.html.erb b/app/views/admin/module_store/index.html.erb index b7ae9d3..15e9699 100644 --- a/app/views/admin/module_store/index.html.erb +++ b/app/views/admin/module_store/index.html.erb @@ -44,18 +44,12 @@