Fixed Store for templates and modules
This commit is contained in:
parent
ce5b35239f
commit
bf532bfea9
|
@ -1,5 +1,5 @@
|
||||||
class Admin::ModuleStoreController < OrbitBackendController
|
class Admin::ModuleStoreController < OrbitBackendController
|
||||||
before_filter :check_central_server_connection
|
before_filter :check_central_server_connection, :only => [:get_extensions]
|
||||||
@@store = STORE_CONFIG[:store_settings]["url"]
|
@@store = STORE_CONFIG[:store_settings]["url"]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
|
@ -85,7 +85,7 @@ class Admin::ModuleStoreController < OrbitBackendController
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def get_extensions
|
def get_extensions
|
||||||
extensions = JSON.parse(open("#{@@store}/extensions").read)
|
extensions = store_session.extensions
|
||||||
|
|
||||||
exist_exts = []
|
exist_exts = []
|
||||||
ext_file = File.new("#{Rails.root}/downloaded_extensions.rb", "r")
|
ext_file = File.new("#{Rails.root}/downloaded_extensions.rb", "r")
|
||||||
|
@ -112,7 +112,7 @@ class Admin::ModuleStoreController < OrbitBackendController
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_extension(id)
|
def get_extension(id)
|
||||||
JSON.parse(open("#{@@store}/extensions/#{id}").read)
|
store_session.get_extension(id)
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_downloaded_extension
|
def get_downloaded_extension
|
||||||
|
@ -142,4 +142,10 @@ class Admin::ModuleStoreController < OrbitBackendController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def get_site
|
||||||
|
@site ||= Site.first
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
|
@ -3,20 +3,20 @@ require 'uri'
|
||||||
require 'fileutils'
|
require 'fileutils'
|
||||||
require 'zip/zip'
|
require 'zip/zip'
|
||||||
class Admin::TemplateStoreController < OrbitBackendController
|
class Admin::TemplateStoreController < OrbitBackendController
|
||||||
|
before_filter :check_central_server_connection, :only => [:get_extensions]
|
||||||
|
|
||||||
@@store_domain = STORE_CONFIG[:store_settings]["url"]
|
@@store_domain = STORE_CONFIG[:store_settings]["url"]
|
||||||
def index
|
def index
|
||||||
@store = @@store_domain
|
@store_url = @@store_domain
|
||||||
@design_ids = Design.all.map{|d| d.template_store_id}
|
@design_ids = Design.all.map{|d| d.template_store_id}
|
||||||
@templates = JSON.parse(get_templates)
|
@templates = get_templates.parsed_response
|
||||||
render :layout => false
|
render :layout => false
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@store = @@store_domain
|
@store = @@store_domain
|
||||||
@design_ids = Design.all.map{|d| d.template_store_id}
|
@design_ids = Design.all.map{|d| d.template_store_id}
|
||||||
@template = JSON.parse(get_template(params[:id])) rescue nil
|
@template = get_template(params[:id]).parsed_response rescue nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def download_theme
|
def download_theme
|
||||||
|
@ -92,19 +92,21 @@ class Admin::TemplateStoreController < OrbitBackendController
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_template(id)
|
def get_template(id)
|
||||||
uri = URI.parse("#{@@store_domain}/api/templates/#{id}")
|
store_session.get_template(id)
|
||||||
http = Net::HTTP.new(uri.host, uri.port)
|
# uri = URI.parse("#{@@store_domain}/api/templates/#{id}")
|
||||||
request = Net::HTTP::Get.new(uri.request_uri)
|
# http = Net::HTTP.new(uri.host, uri.port)
|
||||||
response = http.request(request)
|
# request = Net::HTTP::Get.new(uri.request_uri)
|
||||||
response.body
|
# response = http.request(request)
|
||||||
|
# response.body
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_templates
|
def get_templates
|
||||||
uri = URI.parse("#{@@store_domain}/api/templates")
|
extensions = store_session.templates
|
||||||
http = Net::HTTP.new(uri.host, uri.port)
|
# uri = URI.parse("#{@@store_domain}/api/templates")
|
||||||
request = Net::HTTP::Get.new(uri.request_uri)
|
# http = Net::HTTP.new(uri.host, uri.port)
|
||||||
response = http.request(request)
|
# request = Net::HTTP::Get.new(uri.request_uri)
|
||||||
response.body
|
# response = http.request(request)
|
||||||
|
# response.body
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
|
@ -488,4 +488,9 @@ class ApplicationController < ActionController::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def store_session
|
||||||
|
api_key = STORE_CONFIG[:store_settings]["api_key"]
|
||||||
|
@store = Store.new(@site.id.to_s,@site.site_token,api_key) if @site.site_token
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -184,7 +184,6 @@
|
||||||
<div class="panel">
|
<div class="panel">
|
||||||
<div class="panel-heading"><i class="icon-shopping-cart"></i><span class="break"></span><%= t(:module_store) %></div>
|
<div class="panel-heading"><i class="icon-shopping-cart"></i><span class="break"></span><%= t(:module_store) %></div>
|
||||||
<div class="pannel-body">
|
<div class="pannel-body">
|
||||||
|
|
||||||
<table id="mt-list" class="table main-list">
|
<table id="mt-list" class="table main-list">
|
||||||
<thead>
|
<thead>
|
||||||
<tr class="sort-header">
|
<tr class="sort-header">
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<a href="<%= admin_template_store_template_path(template["_slugs"][0]) %>">
|
<a href="<%= admin_template_store_template_path(template["_slugs"][0]) %>">
|
||||||
<img src="<%= @store + template['preview']['preview']['thumb']['url'] %>" class="item-thumb" />
|
<img src="<%= @store_url + template['preview']['preview']['thumb']['url'] %>" class="item-thumb" />
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
|
|
|
@ -5,5 +5,6 @@
|
||||||
<th class="span1">Status</th>
|
<th class="span1">Status</th>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
|
||||||
<%= render :partial => 'template', :collection => @templates %>
|
<%= render :partial => 'template', :collection => @templates %>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
<div id="content" class="clearfix">
|
<div id="content" class="clearfix">
|
||||||
<div class="side">
|
<div class="side">
|
||||||
<div id="item-info">
|
<div id="item-info">
|
||||||
<%= image_tag "#{@store}#{@template['preview']['preview']['thumb']['url']}", :class => "item-thumb" %>
|
<%= image_tag "#{@store_url}/#{@template['preview']['preview']['thumb']['url']}", :class => "item-thumb" %>
|
||||||
<h2 class="item-name"><%= @template['title'] %></h2>
|
<h2 class="item-name"><%= @template['title'] %></h2>
|
||||||
<% if @design_ids.include?(@template["_id"]["$oid"]) %>
|
<% if @design_ids.include?(@template["_id"]["$oid"]) %>
|
||||||
<%= link_to "Installed", "javascript:void(0);", "data-url" => @template['template']['template']['url'], :class=> 'btn btn-success download-link', "disabled"=>"disabled", "data-name"=>@template['title'], "data-slug"=>@template["_slugs"][0], "data-id"=>@template["_id"]["$oid"] %>
|
<%= link_to "Installed", "javascript:void(0);", "data-url" => @template['template']['template']['url'], :class=> 'btn btn-success download-link', "disabled"=>"disabled", "data-name"=>@template['title'], "data-slug"=>@template["_slugs"][0], "data-id"=>@template["_id"]["$oid"] %>
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
store_settings:
|
store_settings:
|
||||||
url: "http://store.tp.rulingcom.com/api"
|
url: "http://store.tp.rulingcom.com"
|
||||||
|
api_url: "http://store.tp.rulingcom.com/api"
|
||||||
api_key: 'Token token="2870f77e59168dbe3fbdffba466c7c8d"'
|
api_key: 'Token token="2870f77e59168dbe3fbdffba466c7c8d"'
|
||||||
|
|
12
lib/store.rb
12
lib/store.rb
|
@ -3,7 +3,7 @@ class Store
|
||||||
include HTTParty
|
include HTTParty
|
||||||
|
|
||||||
format :json
|
format :json
|
||||||
base_uri STORE_CONFIG[:store_settings]["url"]
|
base_uri STORE_CONFIG[:store_settings]["api_url"]
|
||||||
|
|
||||||
def initialize(site_id,site_token,api_key)
|
def initialize(site_id,site_token,api_key)
|
||||||
@options_for_get = {
|
@options_for_get = {
|
||||||
|
@ -30,11 +30,21 @@ class Store
|
||||||
self.class.get('/templates', options)
|
self.class.get('/templates', options)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get_template(id)
|
||||||
|
options = @options_for_get
|
||||||
|
self.class.get("/templates/#{id}", options)
|
||||||
|
end
|
||||||
|
|
||||||
def extensions(options={})
|
def extensions(options={})
|
||||||
options = @options_for_get
|
options = @options_for_get
|
||||||
self.class.get('/extensions', options)
|
self.class.get('/extensions', options)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get_extension(id)
|
||||||
|
options = @options_for_get
|
||||||
|
self.class.get("/extensions/#{id}", options)
|
||||||
|
end
|
||||||
|
|
||||||
def post_client(site_id,site_token,site_name)
|
def post_client(site_id,site_token,site_name)
|
||||||
options = @options_for_client.merge({ :body => {:site_name => site_name, :site_id => site_id, :site_token => site_token}.to_json })
|
options = @options_for_client.merge({ :body => {:site_name => site_name, :site_id => site_id, :site_token => site_token}.to_json })
|
||||||
self.class.post('/clients', options )
|
self.class.post('/clients', options )
|
||||||
|
|
Loading…
Reference in New Issue