Fixed Store for templates and modules

This commit is contained in:
Saurabh Bhatia 2014-02-14 20:06:32 +08:00
parent ce5b35239f
commit bf532bfea9
9 changed files with 46 additions and 22 deletions

View File

@ -1,5 +1,5 @@
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"]
def index
@ -85,7 +85,7 @@ class Admin::ModuleStoreController < OrbitBackendController
protected
def get_extensions
extensions = JSON.parse(open("#{@@store}/extensions").read)
extensions = store_session.extensions
exist_exts = []
ext_file = File.new("#{Rails.root}/downloaded_extensions.rb", "r")
@ -112,7 +112,7 @@ class Admin::ModuleStoreController < OrbitBackendController
end
def get_extension(id)
JSON.parse(open("#{@@store}/extensions/#{id}").read)
store_session.get_extension(id)
end
def get_downloaded_extension
@ -142,4 +142,10 @@ class Admin::ModuleStoreController < OrbitBackendController
end
end
private
def get_site
@site ||= Site.first
end
end

View File

@ -3,20 +3,20 @@ require 'uri'
require 'fileutils'
require 'zip/zip'
class Admin::TemplateStoreController < OrbitBackendController
before_filter :check_central_server_connection, :only => [:get_extensions]
@@store_domain = STORE_CONFIG[:store_settings]["url"]
def index
@store = @@store_domain
@store_url = @@store_domain
@design_ids = Design.all.map{|d| d.template_store_id}
@templates = JSON.parse(get_templates)
@templates = get_templates.parsed_response
render :layout => false
end
def show
@store = @@store_domain
@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
def download_theme
@ -92,19 +92,21 @@ class Admin::TemplateStoreController < OrbitBackendController
end
def get_template(id)
uri = URI.parse("#{@@store_domain}/api/templates/#{id}")
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Get.new(uri.request_uri)
response = http.request(request)
response.body
store_session.get_template(id)
# uri = URI.parse("#{@@store_domain}/api/templates/#{id}")
# http = Net::HTTP.new(uri.host, uri.port)
# request = Net::HTTP::Get.new(uri.request_uri)
# response = http.request(request)
# response.body
end
def get_templates
uri = URI.parse("#{@@store_domain}/api/templates")
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Get.new(uri.request_uri)
response = http.request(request)
response.body
extensions = store_session.templates
# uri = URI.parse("#{@@store_domain}/api/templates")
# http = Net::HTTP.new(uri.host, uri.port)
# request = Net::HTTP::Get.new(uri.request_uri)
# response = http.request(request)
# response.body
end
end

View File

@ -488,4 +488,9 @@ class ApplicationController < ActionController::Base
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

View File

@ -184,7 +184,6 @@
<div class="panel">
<div class="panel-heading"><i class="icon-shopping-cart"></i><span class="break"></span><%= t(:module_store) %></div>
<div class="pannel-body">
<table id="mt-list" class="table main-list">
<thead>
<tr class="sort-header">

View File

@ -1,7 +1,7 @@
<tr>
<td>
<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>
</td>
<td>

View File

@ -5,5 +5,6 @@
<th class="span1">Status</th>
</thead>
<tbody>
<%= render :partial => 'template', :collection => @templates %>
</tbody>

View File

@ -6,7 +6,7 @@
<div id="content" class="clearfix">
<div class="side">
<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>
<% 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"] %>

View File

@ -1,3 +1,4 @@
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"'

View File

@ -3,7 +3,7 @@ class Store
include HTTParty
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)
@options_for_get = {
@ -30,11 +30,21 @@ class Store
self.class.get('/templates', options)
end
def get_template(id)
options = @options_for_get
self.class.get("/templates/#{id}", options)
end
def extensions(options={})
options = @options_for_get
self.class.get('/extensions', options)
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)
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 )