diff --git a/Gemfile b/Gemfile index fd3868a..dda513e 100644 --- a/Gemfile +++ b/Gemfile @@ -34,7 +34,7 @@ gem 'mongoid', github: "mongoid/mongoid" gem "mini_magick", "3.5.0" gem 'carrierwave' gem 'carrierwave-mongoid', :require => 'carrierwave/mongoid' - +gem 'zip-zip' gem 'kaminari' gem "impressionist" gem "chartkick" diff --git a/app/assets/javascripts/validator.js b/app/assets/javascripts/validator.js index 847a6d4..89c653a 100644 --- a/app/assets/javascripts/validator.js +++ b/app/assets/javascripts/validator.js @@ -25,7 +25,10 @@ var FormValidator = function(form){ nospace : function(value){ return (/\s/.test(value) ? false : true); }, - email : function(value){ + lowercase : function(value){ + return (value == value.toLowerCase() ? true : false); + }, + email : function(){ var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; return re.test(value); } @@ -40,35 +43,39 @@ var FormValidator = function(form){ var _attachSubmitHandler = function(){ fv.form.on("submit",function(){ - failed_elements = []; - $.each(elements_data,function(key,element){ - var validators = element.validators, - messages = element.messages, - el = fv.form.find("#" + key); - for(i = 0; i < validators.length; i++){ - var error_span = (fv.form.find("div[for=" + key + "]").length ? $("div[for=" + key + "]") : $("
")); - if(typeof fv.validate_functions[validators[i]] == "function"){ - if(!fv.validate_functions[validators[i]](el.val(),el)){ - error_span.text(messages[i]); - el.after(error_span); - failed_elements.push(el); - break; - }else{ - error_span.remove(); - } + return fv.isFormValidated(); + }) + } + + this.isFormValidated = function(){ + failed_elements = []; + $.each(elements_data,function(key,element){ + var validators = element.validators, + messages = element.messages, + el = fv.form.find("#" + key); + for(i = 0; i < validators.length; i++){ + var error_span = (fv.form.find("div[for=" + key + "]").length ? $("div[for=" + key + "]") : $("
")); + if(typeof fv.validate_functions[validators[i]] == "function"){ + if(!fv.validate_functions[validators[i]](el.val(),el)){ + error_span.text(messages[i]); + el.after(error_span); + failed_elements.push(el); + break; }else{ - console.info("Not validating for " + validators[i] + ". Skipping."); + error_span.remove(); } + }else{ + console.info("Not validating for " + validators[i] + ". Skipping."); } - }) - if(failed_elements.length){ - var offset = failed_elements[0].offset().top - fv.form.offset().top + fv.form.scrollTop(); - fv.form.parent().animate({scrollTop:offset-50}, '300', 'swing'); - return false; - }else{ - return true; } }) + if(failed_elements.length){ + var offset = failed_elements[0].offset().top - fv.form.offset().top + fv.form.scrollTop(); + fv.form.parent().animate({scrollTop:offset-50}, '300', 'swing'); + return false; + }else{ + return true; + } } var _putFieldsValidatorAndMessage = function(){ diff --git a/app/controllers/admin/sites_controller.rb b/app/controllers/admin/sites_controller.rb index 87175db..eb9c299 100644 --- a/app/controllers/admin/sites_controller.rb +++ b/app/controllers/admin/sites_controller.rb @@ -106,7 +106,9 @@ class Admin::SitesController < OrbitAdminController else result = "success" # Bundler.with_clean_env { `cd #{Rails.root} && bundle update` } - Bundler.with_clean_env { `cd #{Rails.root} && BUNDLE_GEMFILE=built_in_extensions.rb bundle update && bundle` } + Bundler.with_clean_env { `cd #{Rails.root} && BUNDLE_GEMFILE=built_in_extensions.rb bundle update && bundle` } + Bundler.with_clean_env { `cd #{Rails.root} && BUNDLE_GEMFILE=downloaded_extensions.rb bundle update && bundle` } + end render :text => result diff --git a/app/controllers/store_api_controller.rb b/app/controllers/store_api_controller.rb index 50eb645..b526e54 100644 --- a/app/controllers/store_api_controller.rb +++ b/app/controllers/store_api_controller.rb @@ -1,3 +1,6 @@ +require "net/http" +require 'open-uri' +require 'zip/zip' class StoreApiController < ApplicationController def confirmation site_token = params[:site_token] @@ -11,4 +14,49 @@ class StoreApiController < ApplicationController render :json => {"success" => false}.to_json end end + + def install_module + file = File.join(Rails.root,"downloaded_extensions.rb") + g = "gem '#{params[:module_key]}', git: '#{params[:git_path]}'" + File.open(file,"a+") { |f| f.puts(g) } + if !directory_exists?(File.join(Rails.root,"app","templates","#{Site.first.template}","modules","#{params[:module_key]}")) + download_template(params[:template],params[:template_filename]) + end + bundle_install + render :json => {"success" => true} .to_json + end + + private + def bundle_install + Bundler.with_clean_env { `cd #{Rails.root} && BUNDLE_GEMFILE=downloaded_extensions.rb bundle update && bundle` } + %x(kill -s USR2 `cat tmp/pids/unicorn.pid`) + sleep 5 + end + + def download_template(url,name) + dir = File.join(Rails.root,"public","template_cache") + destination = File.join(Rails.root,"app","templates","#{Site.first.template}","modules") + if !directory_exists?(dir) + Dir.mkdir dir + end + zipfile = File.join(Rails.root, "public" , "template_cache", name) + open(zipfile, 'wb') do |fo| + fo.print open(url).read + end + unzip_file(zipfile,destination) + end + + def directory_exists?(directory) + File.directory?(directory) + end + + def unzip_file (file, destination) + Zip::ZipFile.open(file) { |zip_file| + zip_file.each { |f| + f_path=File.join(destination, f.name) + FileUtils.mkdir_p(File.dirname(f_path)) + zip_file.extract(f, f_path) unless File.exist?(f_path) + } + } + end end \ No newline at end of file diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 624d2f5..7d1f857 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -64,6 +64,8 @@ module ApplicationHelper end site_footer = site_footer.nil? ? "" : site_footer html = html.gsub("{{footer-data}}",site_footer) + counter = Page.root.view_count.to_s rescue "" + html = html.gsub("{{site-counter}}",counter) html.html_safe end diff --git a/app/templates/orbit_bootstrap/home/footer.html.erb b/app/templates/orbit_bootstrap/home/footer.html.erb index 76aa7cc..110eb8f 100644 --- a/app/templates/orbit_bootstrap/home/footer.html.erb +++ b/app/templates/orbit_bootstrap/home/footer.html.erb @@ -1,5 +1,6 @@ \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index cd62b5e..2da0372 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -27,6 +27,7 @@ Orbit::Application.routes.draw do get "/module/:name" => "home#index" get "/module/:name/show" => "home#show" post "/store/confirmation" => "store_api#confirmation" + post "/store/install_module" => "store_api#install_module" # The priority is based upon order of creation: first created -> highest priority. # See how all your routes lay out with "rake routes".