- template list/show is loaded from central server
- buy a template downloads and creates it in DB - changes in designs index
This commit is contained in:
parent
eb53343bdb
commit
6f1748d2b3
|
@ -287,7 +287,7 @@ header {
|
||||||
}
|
}
|
||||||
#content .main {
|
#content .main {
|
||||||
float: right;
|
float: right;
|
||||||
width: 680px;
|
width: 676px;
|
||||||
}
|
}
|
||||||
#item-info .item-thumb {
|
#item-info .item-thumb {
|
||||||
width: 210px;
|
width: 210px;
|
||||||
|
|
|
@ -9,6 +9,17 @@ class Admin::PurchasesController < ApplicationController
|
||||||
@purchases = Purchase.all.entries
|
@purchases = Purchase.all.entries
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def buy_template
|
||||||
|
original_file, zip_name = download_template(params[:id])
|
||||||
|
temp_file = Tempfile.new("temp_file_zip")
|
||||||
|
temp_file.binmode
|
||||||
|
temp_file.write original_file
|
||||||
|
temp_file.rewind
|
||||||
|
unzip_design(temp_file, zip_name)
|
||||||
|
temp_file.close
|
||||||
|
temp_file.unlink
|
||||||
|
end
|
||||||
|
|
||||||
def download
|
def download
|
||||||
@purchase = Purchase.first(:conditions => {:id => params[:id]})
|
@purchase = Purchase.first(:conditions => {:id => params[:id]})
|
||||||
download_purchase(@purchase, request.env['REQUEST_URI'].split('admin')[0].chop)
|
download_purchase(@purchase, request.env['REQUEST_URI'].split('admin')[0].chop)
|
||||||
|
@ -183,4 +194,66 @@ class Admin::PurchasesController < ApplicationController
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def download_template(id)
|
||||||
|
uri = URI.parse("http://#{APP_CONFIG['store_ip']}/download/design/#{id}")
|
||||||
|
http = Net::HTTP.new(uri.host, uri.port)
|
||||||
|
request = Net::HTTP::Get.new(uri.request_uri)
|
||||||
|
response = http.request(request)
|
||||||
|
[response.body, (response['content-disposition'].split('filename=')[1].gsub(/[\\\"]|.zip/, '') rescue '')]
|
||||||
|
end
|
||||||
|
|
||||||
|
def unzip_design(input_file, zip_name)
|
||||||
|
temp_file = Tempfile.new("temp_file")
|
||||||
|
temp_file.write(input_file.read.force_encoding('UTF-8'))
|
||||||
|
temp_file.rewind
|
||||||
|
Zip::ZipFile.open(temp_file) { |zip_file|
|
||||||
|
design = Design.new.from_json(zip_file.read("#{zip_name}/info.json"))
|
||||||
|
Dir.mktmpdir('f_path') { |dir|
|
||||||
|
themes_entries = []
|
||||||
|
javascripts_entries = []
|
||||||
|
images_entries = []
|
||||||
|
screenshots_entries = []
|
||||||
|
|
||||||
|
zip_file.entries.each do |entry|
|
||||||
|
case (path = entry.to_s)
|
||||||
|
when /\A(#{zip_name})\/(default\.css)\z/ #for default css
|
||||||
|
design.build_css_default(:file => get_temp_file(zip_file, dir, entry))
|
||||||
|
when /\A(#{zip_name})\/(reset\.css)\z/ #for reset css
|
||||||
|
design.build_css_reset(:file => get_temp_file(zip_file, dir, entry))
|
||||||
|
when /\A(#{zip_name})\/(layout\.html)\z/ #for layout html
|
||||||
|
design.build_layout(:file => get_temp_file(zip_file, dir, entry))
|
||||||
|
when /\A(#{zip_name})\/(thumb((\.jpg)|(\.png)|(\.gif)))\z/ #for thumb
|
||||||
|
design.build_thumb(:file => get_temp_file(zip_file, dir, entry))
|
||||||
|
when /\A(#{zip_name})\/(themes)\/.*(\.css)\z/ #for themes css
|
||||||
|
themes_entries << entry
|
||||||
|
when /\A(#{zip_name})\/(javascripts)\/.*(\.js)\z/ #for js
|
||||||
|
javascripts_entries << entry
|
||||||
|
when /\A(#{zip_name})\/(images)\/.*((\.jpg)|(\.png)|(\.gif))\z/ #for img
|
||||||
|
images_entries << entry
|
||||||
|
when /\A(#{zip_name})\/(screenshots)\/.*((\.jpg)|(\.png)|(\.gif))\z/ #for img
|
||||||
|
screenshots_entries << entry
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
['themes', 'javascripts', 'images', 'screenshots'].each do |type|
|
||||||
|
eval("#{type}_entries").each do |entry|
|
||||||
|
eval("design.#{type}").build(:file => get_temp_file(zip_file, dir, entry))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
}
|
||||||
|
design.zip_file = input_file
|
||||||
|
design.save
|
||||||
|
}
|
||||||
|
temp_file.close
|
||||||
|
temp_file.unlink
|
||||||
|
end
|
||||||
|
|
||||||
|
def get_temp_file(zip_file, dir, entry)
|
||||||
|
filename = File.basename(entry.to_s)
|
||||||
|
temp_file = File.new(dir + '/' + filename, 'w+')
|
||||||
|
temp_file.write (zip_file.read entry ).force_encoding('UTF-8')
|
||||||
|
temp_file
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
|
@ -3,9 +3,29 @@ class Admin::TemplateStoreController < ApplicationController
|
||||||
layout "new_admin"
|
layout "new_admin"
|
||||||
|
|
||||||
def index
|
def index
|
||||||
|
@templates = JSON.parse(get_templates)
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
|
@template = JSON.parse(get_template(params[:id]))
|
||||||
|
end
|
||||||
|
|
||||||
|
protected
|
||||||
|
|
||||||
|
def get_template(id)
|
||||||
|
uri = URI.parse("http://#{APP_CONFIG['store_ip']}/store/design/#{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("http://#{APP_CONFIG['store_ip']}/store/designs")
|
||||||
|
http = Net::HTTP.new(uri.host, uri.port)
|
||||||
|
request = Net::HTTP::Get.new(uri.request_uri)
|
||||||
|
response = http.request(request)
|
||||||
|
response.body
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
|
@ -8,63 +8,27 @@ class Design
|
||||||
field :title, :type => String
|
field :title, :type => String
|
||||||
field :version, :type => String
|
field :version, :type => String
|
||||||
|
|
||||||
|
mount_uploader :zip_file, AssetUploader
|
||||||
|
|
||||||
has_one :css_default, as: :css, :autosave => true, :dependent => :destroy
|
has_one :css_default, as: :css, :autosave => true, :dependent => :destroy
|
||||||
has_one :layout, :autosave => true, :dependent => :destroy
|
has_one :layout, :autosave => true, :dependent => :destroy
|
||||||
has_one :css_reset, :autosave => true, :dependent => :destroy
|
has_one :css_reset, :autosave => true, :dependent => :destroy
|
||||||
|
has_one :thumb, :autosave => true, :dependent => :destroy
|
||||||
has_many :images, as: :imgs, :autosave => true, :dependent => :destroy
|
has_many :images, as: :imgs, :autosave => true, :dependent => :destroy
|
||||||
has_many :javascripts, as: :js, :autosave => true, :dependent => :destroy
|
has_many :javascripts, as: :js, :autosave => true, :dependent => :destroy
|
||||||
has_many :pages
|
has_many :pages
|
||||||
|
has_many :screenshots, :autosave => true, :dependent => :destroy
|
||||||
has_many :themes, :autosave => true, :dependent => :destroy
|
has_many :themes, :autosave => true, :dependent => :destroy
|
||||||
|
|
||||||
accepts_nested_attributes_for :images, :allow_destroy => true
|
accepts_nested_attributes_for :images, :allow_destroy => true
|
||||||
accepts_nested_attributes_for :javascripts, :allow_destroy => true
|
accepts_nested_attributes_for :javascripts, :allow_destroy => true
|
||||||
|
accepts_nested_attributes_for :screenshots, :allow_destroy => true
|
||||||
accepts_nested_attributes_for :themes, :allow_destroy => true
|
accepts_nested_attributes_for :themes, :allow_destroy => true
|
||||||
|
|
||||||
validates_presence_of :author, :title
|
validates_presence_of :author, :title
|
||||||
|
|
||||||
after_save :parse_css_for_images
|
after_save :parse_css_for_images
|
||||||
|
|
||||||
|
|
||||||
def new_files=(*attrs)
|
|
||||||
attrs[0].map do |key,items_ary| #Loop by JSs,Themes,Imgs
|
|
||||||
self.files=([items_ary, key])
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# def javascripts=(*attrs)
|
|
||||||
# self.files = (attrs << 'javascripts')
|
|
||||||
# end
|
|
||||||
#
|
|
||||||
# def themes=(*attrs)
|
|
||||||
# self.files = (attrs << 'themes')
|
|
||||||
# end
|
|
||||||
#
|
|
||||||
# def images=(*attrs)
|
|
||||||
# self.files = (attrs << 'images')
|
|
||||||
# end
|
|
||||||
|
|
||||||
# Update or create the attribute records
|
|
||||||
def files=(attrs)
|
|
||||||
case attrs.last
|
|
||||||
when 'layout'
|
|
||||||
files = self.layout.build
|
|
||||||
else
|
|
||||||
files = eval(attrs.last)
|
|
||||||
end
|
|
||||||
attrs[0].each do |a|
|
|
||||||
|
|
||||||
if a[:id].blank? && !a[:file].blank?
|
|
||||||
files.build(:file => a[:file], :to_save => true)
|
|
||||||
else
|
|
||||||
files.each do |file|
|
|
||||||
if file.id.to_s == a[:id]
|
|
||||||
file.to_destroy = a[:to_destroy]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def parse_css_for_images
|
def parse_css_for_images
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
class Screenshot < Image
|
||||||
|
belongs_to :design
|
||||||
|
end
|
|
@ -0,0 +1,3 @@
|
||||||
|
class Thumb < Image
|
||||||
|
belongs_to :design
|
||||||
|
end
|
|
@ -1,6 +1,6 @@
|
||||||
<tr class="with_action">
|
<tr class="with_action">
|
||||||
<td><%= check_box_tag 'to_delete[]', design.id, false, :class => "checkbox_in_list" %></td>
|
<td class="span1"><%= check_box_tag 'to_delete[]', design.id, false, :class => "checkbox_in_list" %></td>
|
||||||
<td>
|
<td class="span2">
|
||||||
<%= design.title %>
|
<%= design.title %>
|
||||||
<div class="quick-edit">
|
<div class="quick-edit">
|
||||||
<ul class="nav nav-pills hide">
|
<ul class="nav nav-pills hide">
|
||||||
|
@ -9,6 +9,6 @@
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td><%= design.author %></td>
|
<td class="span7"><%= design.intro %></td>
|
||||||
<td><%= design.intro %></td>
|
<td class="span2"><%= design.author %></td>
|
||||||
</tr>
|
</tr>
|
|
@ -1,8 +1,8 @@
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th class="span1 strong"></th>
|
<th class="span1 strong"></th>
|
||||||
<th class="span7"></th>
|
|
||||||
<th class="span2"></th>
|
<th class="span2"></th>
|
||||||
|
<th class="span7"></th>
|
||||||
<th class="span2"></th>
|
<th class="span2"></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
<%= render_sort_bar(true, delete_admin_designs_path(:direction => params[:direction], :sort => params[:sort], :sort_options => params[:sort_options]),
|
<%= render_sort_bar(true, delete_admin_designs_path(:direction => params[:direction], :sort => params[:sort], :sort_options => params[:sort_options]),
|
||||||
['title', 'title','span7', :title],
|
['title', 'title','span2', :title],
|
||||||
['author', 'author', 'span2', :author],
|
['intro', 'intro', 'span7', :intro],
|
||||||
['intro', 'intro', 'span2', :intro]).html_safe %>
|
['author', 'author', 'span2', :author]).html_safe %>
|
||||||
|
|
|
@ -76,18 +76,20 @@
|
||||||
</div>
|
</div>
|
||||||
<div id="item-list">
|
<div id="item-list">
|
||||||
<ul class="clearfix">
|
<ul class="clearfix">
|
||||||
<li><a href="template_store/show"><img src="" alt="" class="item-thumb"><span class="item-info"><b class="item-name">Template 1</b><span class="item-price">Free</span></span></a></li>
|
<% @templates.each do |template| %>
|
||||||
<li><a href="template_store/show"><img src="" alt="" class="item-thumb"><span class="item-info"><b class="item-name">Template 2</b><span class="item-price">Free</span></span></a></li>
|
<li>
|
||||||
<li><a href="template_store/show"><img src="" alt="" class="item-thumb"><span class="item-info"><b class="item-name">Template 3</b><span class="item-price">Free</span></span></a></li>
|
<%= link_to admin_template_store_template_path(template['id']) do %>
|
||||||
<li><a href="template_store/show"><img src="" alt="" class="item-thumb"><span class="item-info"><b class="item-name">Template 4</b><span class="item-price">Free</span></span></a></li>
|
<%= image_tag "http://#{APP_CONFIG['store_ip']}#{template['thumb']}", :class => "item-thumb" %>
|
||||||
<li><a href="template_store/show"><img src="" alt="" class="item-thumb"><span class="item-info"><b class="item-name">Template 5</b><span class="item-price">Free</span></span></a></li>
|
<span class="item-info">
|
||||||
<li><a href="template_store/show"><img src="" alt="" class="item-thumb"><span class="item-info"><b class="item-name">Template 6</b><span class="item-price">Free</span></span></a></li>
|
<b class="item-name"><%= template['title'] %></b>
|
||||||
<li><a href="template_store/show"><img src="" alt="" class="item-thumb"><span class="item-info"><b class="item-name">Template 7</b><span class="item-price">Free</span></span></a></li>
|
<span class="item-price">Free</span>
|
||||||
<li><a href="template_store/show"><img src="" alt="" class="item-thumb"><span class="item-info"><b class="item-name">Template 8</b><span class="item-price">Free</span></span></a></li>
|
</span>
|
||||||
<li><a href="template_store/show"><img src="" alt="" class="item-thumb"><span class="item-info"><b class="item-name">Template 9</b><span class="item-price">Free</span></span></a></li>
|
<% end %>
|
||||||
<li><a href="template_store/show"><img src="" alt="" class="item-thumb"><span class="item-info"><b class="item-name">Template 10</b><span class="item-price">Free</template_store/showspan></span></a></li>
|
</li>
|
||||||
<li><a href=""><img src="" alt="" class="item-thumb"><span class="item-info"><b class="item-name">Template 11</b><span class="item-price">Free</template_store/showspan></span></a></li>
|
<% end %>
|
||||||
<li><a href=""><img src="" alt="" class="item-thumb"><span class="item-info"><b class="item-name">Template 12</b><span class="item-price">Free</span></span></a></li>
|
<% (12-@templates.size).times do |i| %>
|
||||||
|
<li><a href="template_store/show"><img src="" alt="" class="item-thumb"><span class="item-info"><b class="item-name">Template <%= i + @templates.size + 1 %></b><span class="item-price">Free</span></span></a></li>
|
||||||
|
<% end %>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -13,35 +13,68 @@
|
||||||
<%= javascript_include_tag "rulingorbit" %>
|
<%= javascript_include_tag "rulingorbit" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<div class="wrapper">
|
<% if @template %>
|
||||||
<div id="toolbar">
|
<div class="wrapper">
|
||||||
<div class="fn"><a class="ui btn" href="/admin/template_store">Back to Store</a></div>
|
<div id="toolbar">
|
||||||
</div>
|
<div class="fn"><a class="ui btn" href="/admin/template_store">Back to Store</a></div>
|
||||||
<div id="content" class="clearfix">
|
|
||||||
<div class="side">
|
|
||||||
<div id="item-info">
|
|
||||||
<img src="" alt="" class="item-thumb">
|
|
||||||
<h2 class="item-name">Template Name</h2>
|
|
||||||
<a id="download" href="">free download</a>
|
|
||||||
<ul class="item-extra-info">
|
|
||||||
<li><span class="title">views</span><span class="count">15,241</span></li>
|
|
||||||
<li><span class="title">color</span><span class="color-tag green"></span></li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="main clearfix">
|
<div id="content" class="clearfix">
|
||||||
<h3>description</h3>
|
<div class="side">
|
||||||
<div id="desc-holder" class="paragraph">Pixel Union’s Jitensha defines storefront minimalism. Japanese for “bicycle,” Jitensha offers clean typography and easy usability, including full color, font, logo, and footer customization. With its painless social media and blog integration, Jitensha gorgeously accomodates every aspect of your business. Any questions before you launch? Don’t hesitate to email us: Support@PixelUnion.net.</div>
|
<div id="item-info">
|
||||||
<h3>screen shot</h3>
|
<%= image_tag "http://#{APP_CONFIG['store_ip']}#{@template['thumb']}", :class => "item-thumb" %>
|
||||||
<div id="screen-shot">
|
<h2 class="item-name"><%= @template['title'] %></h2>
|
||||||
<div class="holder">
|
<%= link_to 'free download', buy_template_admin_purchase_path(@template['id']), :id => "download" %>
|
||||||
<img src="" alt="Thumbnail 1" class="preview item-thumb">
|
<ul class="item-extra-info">
|
||||||
<img src="" alt="Thumbnail 2" class="preview item-thumb">
|
<li><span class="title">views</span><span class="count">15,241</span></li>
|
||||||
<img src="" alt="Thumbnail 3" class="preview item-thumb">
|
<li><span class="title">color</span><span class="color-tag green"></span></li>
|
||||||
<img src="" alt="Thumbnail 4" class="preview item-thumb">
|
</ul>
|
||||||
<img src="" alt="Thumbnail 5" class="preview item-thumb">
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="main clearfix">
|
||||||
|
<h3>description</h3>
|
||||||
|
<div id="desc-holder" class="paragraph"><%= @template['intro'] %></div>
|
||||||
|
<h3>screen shot</h3>
|
||||||
|
<div id="screen-shot">
|
||||||
|
<div class="holder">
|
||||||
|
<% @template['screenshots'].each do |screenshot| %>
|
||||||
|
<%= image_tag "http://#{APP_CONFIG['store_ip']}#{screenshot}", :class => "preview item-thumb" %>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<% else %>
|
||||||
|
<div class="wrapper">
|
||||||
|
<div id="toolbar">
|
||||||
|
<div class="fn"><a class="ui btn" href="/admin/template_store">Back to Store</a></div>
|
||||||
|
</div>
|
||||||
|
<div id="content" class="clearfix">
|
||||||
|
<div class="side">
|
||||||
|
<div id="item-info">
|
||||||
|
<img src="" alt="" class="item-thumb">
|
||||||
|
<h2 class="item-name">Template Name</h2>
|
||||||
|
<a id="download" href="">free download</a>
|
||||||
|
<ul class="item-extra-info">
|
||||||
|
<li><span class="title">views</span><span class="count">15,241</span></li>
|
||||||
|
<li><span class="title">color</span><span class="color-tag green"></span></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="main clearfix">
|
||||||
|
<h3>description</h3>
|
||||||
|
<div id="desc-holder" class="paragraph">Pixel Union’s Jitensha defines storefront minimalism. Japanese for “bicycle,” Jitensha offers clean typography and easy usability, including full color, font, logo, and footer customization. With its painless social media and blog integration, Jitensha gorgeously accomodates every aspect of your business. Any questions before you launch? Don’t hesitate to email us: Support@PixelUnion.net.</div>
|
||||||
|
<h3>screen shot</h3>
|
||||||
|
<div id="screen-shot">
|
||||||
|
<div class="holder">
|
||||||
|
<img src="" alt="Thumbnail 1" class="preview item-thumb">
|
||||||
|
<img src="" alt="Thumbnail 2" class="preview item-thumb">
|
||||||
|
<img src="" alt="Thumbnail 3" class="preview item-thumb">
|
||||||
|
<img src="" alt="Thumbnail 4" class="preview item-thumb">
|
||||||
|
<img src="" alt="Thumbnail 5" class="preview item-thumb">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
|
@ -112,6 +112,7 @@ Orbit::Application.routes.draw do
|
||||||
get 'install_app'
|
get 'install_app'
|
||||||
end
|
end
|
||||||
member do
|
member do
|
||||||
|
get 'buy_template'
|
||||||
get 'download'
|
get 'download'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -137,14 +138,14 @@ Orbit::Application.routes.draw do
|
||||||
end
|
end
|
||||||
|
|
||||||
resources :member_selects do
|
resources :member_selects do
|
||||||
match 'member_select_search' => "member_selects#member_select_search" ,:as => :member_select_search,:via => "post"
|
match 'member_select_search' => "member_selects#member_select_search" ,:as => :member_select_search,:via => "post"
|
||||||
match 'member_select_add' => "member_selects#member_select_add" ,:as => :member_select_add,:via => "post"
|
match 'member_select_add' => "member_selects#member_select_add" ,:as => :member_select_add,:via => "post"
|
||||||
end
|
end
|
||||||
|
|
||||||
match 'module_store' => 'module_store#index'
|
match 'module_store' => 'module_store#index'
|
||||||
match 'module_store/show' => 'module_store#show'
|
match 'module_store/show' => 'module_store#show'
|
||||||
match 'template_store' => 'template_store#index'
|
match 'template_store' => 'template_store#index'
|
||||||
match 'template_store/show' => 'template_store#show'
|
match 'template_store/template/:id' => 'template_store#show', :as => :template_store_template
|
||||||
|
|
||||||
end
|
end
|
||||||
# end admin
|
# end admin
|
||||||
|
|
Reference in New Issue