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]
|
|
|
|
site_domain = RegisteredSite.find_by(:uid => store_token).site_domain.sub(/(?:(?!\.).)*\./,'') rescue ''
|
2021-04-12 06:39:11 +00:00
|
|
|
templates = RTemplate.where(:allow_domain.in => [site_domain,'',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]
|
|
|
|
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
|
2017-08-02 09:07:55 +00:00
|
|
|
end
|
|
|
|
end
|