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 @@ <%= extension["description"].html_safe%> <%= link_to 'Read More', admin_module_store_show_path(extension["_slugs"][0]) %> - - <% 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)%> - Installed - <% else %> - <%= link_to 'Download', admin_module_store_download_path(:id => extension["_slugs"][0]), :class=>"act btn btn-mini btn-success" %> - <% end %> + <% @module_installed = File.read("downloaded_extensions.rb").include?(extension["key"])%> + <% if @module_installed.eql?(true)%> + Installed + <% else %> + <%= link_to 'Download', admin_module_store_download_path(:id => extension["_slugs"][0]), :class=>"act btn btn-mini btn-success" %> + <% end %> <% end %> diff --git a/downloaded_extensions.rb b/downloaded_extensions.rb index d071428..43e1541 100644 --- a/downloaded_extensions.rb +++ b/downloaded_extensions.rb @@ -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'