polish the import module + some code refactoring / cleaning
This commit is contained in:
parent
54063d6b46
commit
1c86db05f8
@ -12,7 +12,10 @@ module Admin
|
||||
format.html do
|
||||
redirect_to new_admin_import_url if @job.nil?
|
||||
end
|
||||
format.json { render :json => { :step => @job.nil? ? 'done' : @job.step, :failed => @job.try(:failed?) } }
|
||||
format.json { render :json => {
|
||||
:step => @job.nil? ? 'done' : @job.step,
|
||||
:failed => @job && @job.last_error.present?
|
||||
} }
|
||||
end
|
||||
|
||||
end
|
||||
@ -22,7 +25,7 @@ module Admin
|
||||
def create
|
||||
if params[:zipfile].blank?
|
||||
@error = t('errors.messages.blank')
|
||||
flash[:alert] = t('flash.admin.imports.create.error')
|
||||
flash[:alert] = t('flash.admin.imports.create.alert')
|
||||
render 'new'
|
||||
else
|
||||
path = self.store_zipfile!
|
||||
@ -30,7 +33,7 @@ module Admin
|
||||
job = Locomotive::Import::Job.new(path, current_site)
|
||||
Delayed::Job.enqueue job, { :site => current_site, :job_type => 'import' }
|
||||
|
||||
flash[:notice] = t('flash.admin.imports.create.alert')
|
||||
flash[:notice] = t('flash.admin.imports.create.notice')
|
||||
|
||||
redirect_to admin_import_url
|
||||
end
|
||||
|
@ -8,8 +8,8 @@
|
||||
|
||||
%p!= t('.help')
|
||||
|
||||
%ul{ :id => 'import-steps', :class => 'list', 'data-url' => admin_import_url(:json) }
|
||||
- %w(site content_types assets snippets pages).each do |step|
|
||||
%ul{ :id => 'import-steps', :class => 'list', :'data-url' => admin_import_url(:json), :'data-success-message' => t('.message.success'), :'data-failure-message' => t('.message.failure') }
|
||||
- %w(site content_types assets asset_collections snippets pages).each do |step|
|
||||
%li{ :id => "#{step}-step" }
|
||||
%em
|
||||
%strong
|
||||
|
@ -48,6 +48,5 @@ module Locomotive
|
||||
config.filter_parameters << :password
|
||||
|
||||
config.middleware.insert_after ::ActionDispatch::Static, '::Locomotive::Middlewares::Fonts', :path => %r{^/fonts}
|
||||
# config.middleware.insert_after 'Rack::Lock', 'Dragonfly::Middleware'
|
||||
end
|
||||
end
|
||||
|
@ -4,14 +4,14 @@ Locomotive::Application.configure do
|
||||
# In the development environment your application's code is reloaded on
|
||||
# every request. This slows down response time but is perfect for development
|
||||
# since you don't have to restart the webserver when you make code changes.
|
||||
config.cache_classes = true # false
|
||||
config.cache_classes = false
|
||||
|
||||
# Log error messages when you accidentally call methods on nil.
|
||||
config.whiny_nils = true
|
||||
|
||||
# Show full error reports and disable caching
|
||||
config.consider_all_requests_local = true
|
||||
config.action_controller.perform_caching = true #false
|
||||
config.action_controller.perform_caching = false
|
||||
|
||||
# Don't care if the mailer can't send
|
||||
config.action_mailer.raise_delivery_errors = false
|
||||
|
@ -259,8 +259,12 @@ en:
|
||||
site: Site information
|
||||
content_types: Custom content types
|
||||
assets: Theme files
|
||||
asset_collections: Asset collections
|
||||
snippets: Snippets
|
||||
pages: Pages
|
||||
messages:
|
||||
success: "Your site was successfully updated."
|
||||
failure: "The import did not work."
|
||||
|
||||
formtastic:
|
||||
titles:
|
||||
|
@ -258,8 +258,12 @@ fr:
|
||||
site: Informations sur le site
|
||||
content_types: Modèles de données personnalisés
|
||||
assets: Fichiers du thème
|
||||
asset_collections: Collections de média
|
||||
snippets: Snippets
|
||||
pages: Pages
|
||||
messages:
|
||||
success: "Votre site a été mis à jour avec succès."
|
||||
failure: "L'import n'a pas fonctionné."
|
||||
|
||||
formtastic:
|
||||
titles:
|
||||
|
@ -111,5 +111,5 @@ en:
|
||||
|
||||
imports:
|
||||
create:
|
||||
notice: "Your site is being updated"
|
||||
alert: "Import was not done"
|
||||
notice: "Your site is being updated."
|
||||
alert: "The import was not done."
|
2
doc/TODO
2
doc/TODO
@ -40,8 +40,8 @@ x refactor ui for the theme assets page
|
||||
x fix assets liquid tags / filters
|
||||
x upload and insert new images in a css or js from the ui is broken
|
||||
x proxy for fonts (http://markevans.github.com/dragonfly/file.Rails3.html)
|
||||
- fix tests
|
||||
- order yaml file (http://www.ruby-forum.com/topic/120295)
|
||||
- fix tests
|
||||
- global regions: keyword in editable element (http://www.mongodb.org/display/DOCS/Updating)
|
||||
- write my first tutorial about locomotive
|
||||
|
||||
|
@ -33,8 +33,10 @@ module Locomotive
|
||||
end
|
||||
|
||||
def self.add_or_update_fields(asset_collection, fields)
|
||||
fields.each do |name, data|
|
||||
attributes = { :_alias => name, :label => name.humanize, :kind => 'string' }.merge(data).symbolize_keys
|
||||
fields.each_with_index do |data, position|
|
||||
name, data = data.keys.first, data.values.first
|
||||
|
||||
attributes = { :_alias => name, :label => name.humanize, :kind => 'string', :position => position }.merge(data).symbolize_keys
|
||||
|
||||
field = asset_collection.asset_custom_fields.detect { |f| f._alias == attributes[:_alias] }
|
||||
|
||||
|
@ -7,12 +7,8 @@ module Locomotive
|
||||
|
||||
whitelist = self.build_regexps_in_withlist(context[:database]['site']['assets']['whitelist']) rescue nil
|
||||
|
||||
puts "whitelist = #{whitelist.inspect}"
|
||||
|
||||
self.add_theme_assets(site, theme_path, whitelist)
|
||||
|
||||
# self.add_font_assets(site, theme_path)
|
||||
|
||||
self.add_other_assets(site, theme_path)
|
||||
end
|
||||
|
||||
@ -25,46 +21,19 @@ module Locomotive
|
||||
visible = self.check_against_whitelist(whitelist, asset_path.gsub(File.join(theme_path, 'public'), ''))
|
||||
|
||||
folder = asset_path.gsub(File.join(theme_path, 'public'), '').gsub(File.basename(asset_path), '').gsub(/^\//, '').gsub(/\/$/, '')
|
||||
# folder = nil if folder.blank? || folder == kind
|
||||
|
||||
puts "folder = #{folder} / #{visible.inspect} / #{asset_path.gsub(File.join(theme_path, 'public'), '')} / local_path = #{File.join(folder, File.basename(asset_path))}"
|
||||
|
||||
# slug = File.basename(asset_path, File.extname(asset_path)).parameterize('_')
|
||||
|
||||
# asset = site.theme_assets.where(:content_type => kind.singularize, :folder => folder, :slug => slug).first
|
||||
|
||||
asset = site.theme_assets.where(:local_path => File.join(folder, File.basename(asset_path))).first
|
||||
|
||||
puts "found asset ! #{!asset.nil?} / #{File.join(folder, File.basename(asset_path))} / #{kind.singularize}"
|
||||
|
||||
asset ||= site.theme_assets.build(:folder => folder)
|
||||
|
||||
asset.attributes = { :source => File.open(asset_path), :performing_plain_text => false, :hidden => !visible }
|
||||
asset.save!
|
||||
|
||||
puts "--------------------"
|
||||
|
||||
site.reload
|
||||
# asset.reload
|
||||
#
|
||||
# puts "asset.url = #{asset.source.url}"
|
||||
#
|
||||
# # asset = site.theme_assets.create! :source => File.open(asset_path), :performing_plain_text => false
|
||||
# # puts "#{asset.source.inspect} / #{asset.inspect}\n--------\n"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# def self.add_font_assets(site, theme_path)
|
||||
# uploader = FontUploader.new(site)
|
||||
#
|
||||
# Dir[File.join(theme_path, 'public', 'fonts', '*')].each do |asset_path|
|
||||
# next if File.directory?(asset_path)
|
||||
# puts "font file = #{asset_path}"
|
||||
# uploader.store!(File.open(asset_path))
|
||||
# end
|
||||
# end
|
||||
|
||||
def self.add_other_assets(site, theme_path)
|
||||
collection = AssetCollection.find_or_create_internal(site)
|
||||
|
||||
|
@ -39,8 +39,10 @@ module Locomotive
|
||||
end
|
||||
|
||||
def self.add_or_update_fields(content_type, fields)
|
||||
fields.each do |name, data|
|
||||
attributes = { :_alias => name, :label => name.humanize, :kind => 'string' }.merge(data).symbolize_keys
|
||||
fields.each_with_index do |data, position|
|
||||
name, data = data.keys.first, data.values.first
|
||||
|
||||
attributes = { :_alias => name, :label => name.humanize, :kind => 'string', :position => position }.merge(data).symbolize_keys
|
||||
|
||||
field = content_type.content_custom_fields.detect { |f| f._alias == attributes[:_alias] }
|
||||
|
||||
|
@ -33,29 +33,12 @@ module Locomotive
|
||||
|
||||
%w(site content_types assets asset_collections snippets pages).each do |step|
|
||||
if @enabled[step] != false
|
||||
@worker.update_attributes :step => step if @worker
|
||||
# puts "@worker...#{@worker.failed_at.inspect} / #{@worker.failed?.inspect}"
|
||||
"Locomotive::Import::#{step.camelize}".constantize.process(context)
|
||||
@worker.update_attributes :step => step if @worker
|
||||
else
|
||||
puts "skipping #{step}"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# rescue Exception => e
|
||||
# context[:error] = e.message
|
||||
# end
|
||||
#
|
||||
# context
|
||||
# # Locomotive::Import::Site.process(context)
|
||||
# #
|
||||
# # Locomotive::Import::ContentTypes.process(context)
|
||||
# #
|
||||
# # Locomotive::Import::Assets.process(context)
|
||||
# #
|
||||
# # Locomotive::Import::Snippets.process(context)
|
||||
# #
|
||||
# # Locomotive::Import::Pages.process(context)
|
||||
end
|
||||
|
||||
protected
|
||||
|
@ -1,28 +0,0 @@
|
||||
module Locomotive
|
||||
module Liquid
|
||||
module Drops
|
||||
module ThemeAssets
|
||||
|
||||
class Base < ::Liquid::Drop
|
||||
|
||||
def before_method(meth)
|
||||
content_type = self.class.name.demodulize.underscore #.singularize
|
||||
|
||||
asset = ThemeAsset.new(:site => @context.registers[:site], :folder => content_type)
|
||||
|
||||
'/' + ThemeAssetUploader.new(asset).store_path(meth.gsub('__', '.'))
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Images < Base; end
|
||||
|
||||
class Javascripts < Base; end
|
||||
|
||||
class Stylesheets < Base; end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
@ -54,9 +54,6 @@ module Locomotive
|
||||
'site' => current_site,
|
||||
'page' => @page,
|
||||
'asset_collections' => Locomotive::Liquid::Drops::AssetCollections.new,
|
||||
'stylesheets' => Locomotive::Liquid::Drops::ThemeAssets::Stylesheets.new,
|
||||
'javascripts' => Locomotive::Liquid::Drops::ThemeAssets::Javascripts.new,
|
||||
'theme_images' => Locomotive::Liquid::Drops::ThemeAssets::Images.new,
|
||||
'contents' => Locomotive::Liquid::Drops::Contents.new,
|
||||
'current_page' => self.params[:page]
|
||||
}
|
||||
|
@ -1,4 +1,3 @@
|
||||
var foo = null;
|
||||
var I18nLocale = null;
|
||||
var CodeMirrorEditors = [];
|
||||
|
||||
|
@ -5,21 +5,28 @@ $(document).ready(function() {
|
||||
dataType: 'json',
|
||||
minTimeout: 100
|
||||
}, function(data) {
|
||||
var steps = ['site', 'content_types', 'assets', 'snippets', 'pages'];
|
||||
var steps = ['site', 'content_types', 'assets', 'asset_collections', 'snippets', 'pages'];
|
||||
|
||||
var currentIndex = data.step == 'done' ? steps.length - 1 : steps.indexOf(data.step);
|
||||
|
||||
// console.log('data.step = ' + data.step + ', ' + currentIndex + ', ' + data.failed);
|
||||
for (var i = 0; i < steps.length; i++) {
|
||||
var state = null;
|
||||
|
||||
for (var i = 0; i <= currentIndex; i++) {
|
||||
var state = 'done';
|
||||
|
||||
if (i == currentIndex && data.failed) state = 'failed';
|
||||
if (i <= currentIndex) state = 'done';
|
||||
if (i == currentIndex + 1 && data.failed) state = 'failed';
|
||||
|
||||
if (state != null)
|
||||
$('#import-steps li:eq(' + i + ')').addClass(state);
|
||||
}
|
||||
|
||||
// if (state == 'failed' || currentIndex == steps.length) # TODO
|
||||
if (data.step == 'done')
|
||||
$.growl('notice', $('#import-steps').attr('data-success-message'));
|
||||
|
||||
if (data.failed)
|
||||
$.growl('alert', $('#import-steps').attr('data-failure-message'));
|
||||
|
||||
if (data.step == 'done' || data.failed)
|
||||
$('#import-steps').smartupdaterStop();
|
||||
});
|
||||
|
||||
});
|
Loading…
Reference in New Issue
Block a user