ruling_template/app/controllers/ruling_templates_controller.rb

37 lines
1.7 KiB
Ruby
Raw Permalink Normal View History

2017-08-02 09:07:55 +00:00
class RulingTemplatesController < ApplicationController
def index
2021-04-11 15:09:25 +00:00
store_token = params[:store_token]
2021-04-19 01:42:09 +00:00
site_domain = RegisteredSite.find_by(:uid => store_token).site_domain
root_domain = site_domain.sub(/(?:(?!\.).)*\./,'') rescue ''
2021-04-20 08:22:56 +00:00
root_domain2 = root_domain.sub(/(?:(?!\.).)*\./,'') rescue ''
templates = RTemplate.where(:allow_domain.in => [site_domain,root_domain,root_domain2,'',nil]).asc(:updated_at).collect do |v|
2021-04-11 15:09:25 +00:00
{
'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]
2021-04-19 01:42:09 +00:00
site_domain = RegisteredSite.find_by(:uid => store_token).site_domain
root_domain = site_domain.sub(/(?:(?!\.).)*\./,'') rescue ''
2021-04-20 08:22:56 +00:00
root_domain2 = root_domain.sub(/(?:(?!\.).)*\./,'') rescue ''
r_template = RTemplate.where(:allow_domain.in => [site_domain,root_domain,root_domain2,'',nil], uid: template_uid).first
2021-04-11 15:09:25 +00:00
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
2021-04-20 08:51:26 +00:00
render :json => {url: r_template.git_url+'.git',branch: r_template.git_branch,type: 'git'}.to_json
2021-04-11 15:09:25 +00:00
end
end
2017-08-02 09:07:55 +00:00
end
end