diff --git a/Gemfile b/Gemfile
index a764b91..d2d88c5 100644
--- a/Gemfile
+++ b/Gemfile
@@ -35,7 +35,7 @@ eval(File.read(File.dirname(__FILE__) + '/built_in_extensions.rb'))
eval(File.read(File.dirname(__FILE__) + '/downloaded_extensions.rb'))
#form helpers
-gem 'dynamic_form', '1.0.0', :git => 'git@github.com:rails/dynamic_form.git'
+gem 'dynamic_form', :git => 'git@gitlab.tp.rulingcom.com:saurabh/dynamic-form.git'
gem 'fb_graph'
gem 'rack-gridfs'
diff --git a/app/controllers/admin/designs_controller.rb b/app/controllers/admin/designs_controller.rb
index 4c670a3..08a1776 100644
--- a/app/controllers/admin/designs_controller.rb
+++ b/app/controllers/admin/designs_controller.rb
@@ -31,6 +31,11 @@ class Admin::DesignsController < OrbitBackendController
@design = Design.new
end
+ def design_list
+ @designs = params[:sort] ? get_sorted_and_filtered("designs") : Design.all
+ render :layout => false
+ end
+
def update
@design = Design.find(params[:id])
@design.update_attributes(params[:design])
diff --git a/app/controllers/admin/template_store_controller.rb b/app/controllers/admin/template_store_controller.rb
index 4a24902..5f2344c 100644
--- a/app/controllers/admin/template_store_controller.rb
+++ b/app/controllers/admin/template_store_controller.rb
@@ -1,22 +1,96 @@
+require 'net/http'
+require 'uri'
+require 'fileutils'
+require 'zip/zip'
class Admin::TemplateStoreController < OrbitBackendController
@@store_domain = STORE_CONFIG[:store_settings]["url"]
def index
@store = @@store_domain
+ @design_ids = Design.all.map{|d| d.template_store_id}
@templates = JSON.parse(get_templates)
+ 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
end
def download_theme
- render :json => {"success"=>true}.to_json
+ url = @@store_domain + params["url"]
+ url_base = url.split('/')[2]
+ url_path = '/'+url.split('/')[3..-1].join('/')
+ Net::HTTP.start(url_base) do |http|
+ open("public/#{params['slug']}.zip", "wb") do |file|
+ http.get(url_path) do |str|
+ file.write(str)
+ end
+ end
+ end
+ upload_package("#{params['slug']}.zip", params["id"])
+ File.delete("public/#{params['slug']}.zip")
+ render :json => {"success"=>true,"url"=>@@store_domain + params["url"]}.to_json
end
protected
+ def upload_package(package_name,template_store_id)
+
+ temp_file = Tempfile.new("temp_file")
+ original_file = File.open("#{Rails.root}/public/#{package_name}")
+ temp_file.write(original_file.read.force_encoding('UTF-8'))
+ temp_file.rewind
+ filename = File.basename(original_file,".zip")
+ unzip_design(temp_file, filename, template_store_id)
+ temp_file.close
+
+ end
+
+ def unzip_design(file, zip_name, template_store_id)
+ Zip::ZipFile.open(file) { |zip_file|
+ design = Design.new.from_json(zip_file.read("#{zip_name}/info.json"))
+ design.template_store_id = template_store_id
+ Dir.mktmpdir('f_path') { |dir|
+ themes_entries = []
+ javascripts_entries = []
+ images_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})\/(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
+ end
+ end
+
+ ['themes', 'javascripts', 'images'].each do |type|
+ eval("#{type}_entries").each do |entry|
+ eval("design.#{type}").build(:file => get_temp_file(zip_file, dir, entry))
+ end
+ end
+ }
+ design.save
+ }
+ 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
+
def get_template(id)
uri = URI.parse("#{@@store_domain}/api/templates/#{id}")
http = Net::HTTP.new(uri.host, uri.port)
diff --git a/app/models/design/design.rb b/app/models/design/design.rb
index 6e7a9af..c0105a5 100644
--- a/app/models/design/design.rb
+++ b/app/models/design/design.rb
@@ -7,6 +7,7 @@ class Design
field :intro, :type => String
field :title, :type => String
field :version, :type => String
+ field :template_store_id, :type => String
mount_uploader :zip_file, AssetUploader
diff --git a/app/views/admin/designs/_design.html.erb b/app/views/admin/designs/_design.html.erb
index d0d5add..bcf8e0a 100644
--- a/app/views/admin/designs/_design.html.erb
+++ b/app/views/admin/designs/_design.html.erb
@@ -1,15 +1,20 @@
-
- <%= check_box_tag 'to_delete[]', design.id, false, :class => "checkbox_in_list" %> |
-
- <%= design.title %>
-
-
+
+
+
+ <%= design.title %>
+
+
+ |
+
+ <%= design.author %>
+ |
+
+
+
- <%= link_to t(:edit), edit_admin_design_path(design), :class => 'edit' %>
- <%= link_to t(:delete_), admin_design_path(design), :confirm => t('sure?'), :method => :delete, :class => 'delete' %>
|
- <%= design.intro %> |
- <%= design.author %> |
- <%= radio_button_tag 'design_default', design.id, (@site.design && @site.design.id.to_s.eql?(design.id.to_s) ? true : false), :class => 'design_default toggle-check', :rel => admin_sites_path %> |
+ <%= radio_button_tag 'design_default', design.id, (@site.design && @site.design.id.to_s.eql?(design.id.to_s) ? true : false), :class => 'design_default toggle-check', :rel => admin_sites_path %> |
\ No newline at end of file
diff --git a/app/views/admin/designs/_designs.html.erb b/app/views/admin/designs/_designs.html.erb
index 2ac8ef2..3f805f9 100644
--- a/app/views/admin/designs/_designs.html.erb
+++ b/app/views/admin/designs/_designs.html.erb
@@ -1,25 +1,12 @@
<%= render :partial => 'design', :collection => @designs %>
-
-<% content_for :page_specific_javascript do %>
-
-<% end %>
diff --git a/app/views/admin/designs/design_list.html.erb b/app/views/admin/designs/design_list.html.erb
new file mode 100644
index 0000000..aaa1b19
--- /dev/null
+++ b/app/views/admin/designs/design_list.html.erb
@@ -0,0 +1 @@
+<%= render :partial => 'design', :collection => @designs %>
\ No newline at end of file
diff --git a/app/views/admin/designs/index.html.erb b/app/views/admin/designs/index.html.erb
index 4c92d3d..034fc7f 100644
--- a/app/views/admin/designs/index.html.erb
+++ b/app/views/admin/designs/index.html.erb
@@ -11,17 +11,226 @@
<%= javascript_include_tag 'lib/footable-0.1' %>
<%= javascript_include_tag 'lib/all-list' %>
- <%= javascript_include_tag 'lib/retina' %>
- <%= javascript_include_tag 'lib/mudole_templates_status' %>
+ <%= javascript_include_tag 'lib/retina' %>
+
-<%= render 'filter' %>
-
- <%= render 'designs' %>
+<%#= render 'filter' %>
+<%#= flash[:notice] rescue nil%>
+
+
+ Please wait...
+ Theme changes taking effect
+
+
+
+
+
+
+
+
+ <%= t(:installed_templates) %>
+
+
+
+ <%= render 'designs' %>
+
+
+
+
+
+
+
+
+
+ <%= t(:template_store) %>
+
+
+
+
+
+
+
+ Loading template store...
+ |
+ |
+
+
+
+
+
+
+
+
+
\ No newline at end of file
+
+
+
+
diff --git a/app/views/admin/template_store/_template.html.erb b/app/views/admin/template_store/_template.html.erb
new file mode 100644
index 0000000..970e138
--- /dev/null
+++ b/app/views/admin/template_store/_template.html.erb
@@ -0,0 +1,24 @@
+ |
+
+ ">
+
+
+ |
+
+ ">
+
+ <%= template['title'] %>
+
+
+ |
+
+ Free
+ |
+
+ <% 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"] %>
+ <% else %>
+ <%= link_to "Download", "javascript:void(0);", "data-url" => template['template']['template']['url'], :class=> 'btn btn-primary download-link', "data-name"=>template['title'], "data-slug"=>template["_slugs"][0], "data-id"=>template["_id"]["$oid"] %>
+ <% end %>
+ |
+
\ No newline at end of file
diff --git a/app/views/admin/template_store/index.html.erb b/app/views/admin/template_store/index.html.erb
index 54a01c2..e4c8a61 100644
--- a/app/views/admin/template_store/index.html.erb
+++ b/app/views/admin/template_store/index.html.erb
@@ -1,91 +1,9 @@
-
-
-
-
-
-
- <% @templates.each do |template| %>
- -
- ">
-
-
- <%= template['title'] %>
- Free
-
-
- <%= link_to "Download", "javascript:void(0);", "data-url" => template['template']['template']['url'], :class=> 'btn btn-primary download-link' %>
-
- <% end %>
-
-
-
-
-
-
+
+ Thumbnails |
+ Title |
+ Price |
+ Status |
+
+
+ <%= render :partial => 'template', :collection => @templates %>
+
diff --git a/app/views/admin/template_store/show.html.erb b/app/views/admin/template_store/show.html.erb
index e954303..c730b85 100644
--- a/app/views/admin/template_store/show.html.erb
+++ b/app/views/admin/template_store/show.html.erb
@@ -8,7 +8,11 @@
<%= image_tag "#{@store}#{@template['preview']['preview']['thumb']['url']}", :class => "item-thumb" %>
<%= @template['title'] %>
- <%= link_to "Download", "javascript:void(0);", "data-url" => @template['template']['template']['url'], :class=> 'btn btn-primary download-link' %>
+ <% 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"] %>
+ <% else %>
+ <%= link_to "Download", "javascript:void(0);", "data-url" => @template['template']['template']['url'], :class=> 'btn btn-primary download-link', "data-name"=>@template['title'], "data-slug"=>@template["_slugs"][0], "data-id"=>@template["_id"]["$oid"] %>
+ <% end %>