diff --git a/.gitignore b/.gitignore deleted file mode 100644 index de5d954..0000000 --- a/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -.bundle/ -log/*.log -pkg/ -test/dummy/db/*.sqlite3 -test/dummy/db/*.sqlite3-journal -test/dummy/log/*.log -test/dummy/tmp/ -test/dummy/.sass-cache diff --git a/app/controllers/ruling_templates_controller.rb b/app/controllers/ruling_templates_controller.rb index d4b1774..674226a 100644 --- a/app/controllers/ruling_templates_controller.rb +++ b/app/controllers/ruling_templates_controller.rb @@ -1,4 +1,33 @@ class RulingTemplatesController < ApplicationController def index + store_token = params[:store_token] + site_domain = RegisteredSite.find_by(:uid => store_token).site_domain.sub(/(?:(?!\.).)*\./,'') rescue '' + templates = RTemplate.where(allow_domain: site_domain,:git_url.ne=> '').asc(:updated_at).collect do |v| + { + 'install_flag' => v.installed_site_tokens.include?(store_token), + 'uid' => v.uid, + 'title' => v.title, + 'desc' => v.description, + 'images' => v.template_image_files.collect{|v| v.image_file.url} + } + end + render :json => templates.to_json + end + def get_template_zip + template_uid = params[:template_uid] + store_token = params[:store_token] + site_domain = RegisteredSite.find_by(:uid => store_token).site_domain.sub(/(?:(?!\.).)*\./,'') rescue '' + r_template = RTemplate.where(allow_domain: site_domain, uid: template_uid).first + if r_template.nil? + render :json => {}.to_json + else + r_template.installed_site_tokens << store_token + r_template.save + if r_template.git_url.blank? + render :json => {url: r_template.template_zip.url,type: 'zip'}.to_json + else + render :json => {url: r_template.git_url,branch: r_template.git_branch,type: 'git'}.to_json + end + end end end \ No newline at end of file diff --git a/app/models/r_template.rb b/app/models/r_template.rb index 3a62321..2fa8747 100644 --- a/app/models/r_template.rb +++ b/app/models/r_template.rb @@ -16,7 +16,8 @@ class RTemplate field :sold, :type => Boolean, :default => false field :git_url field :git_branch - + field :allow_domain, type: String, default: '' + field :installed_site_tokens, type: Array, default: [] mount_uploader :template_zip, AssetUploader has_many :template_image_files, :autosave => true, :dependent => :destroy diff --git a/app/views/admin/ruling_templates/_form.html.erb b/app/views/admin/ruling_templates/_form.html.erb index f722ceb..e4430ed 100644 --- a/app/views/admin/ruling_templates/_form.html.erb +++ b/app/views/admin/ruling_templates/_form.html.erb @@ -33,6 +33,12 @@ <%= select_category(f, @module_app) %> +