diff --git a/app/controllers/admin/imports_controller.rb b/app/controllers/admin/imports_controller.rb index be6fe2a2..02959f96 100644 --- a/app/controllers/admin/imports_controller.rb +++ b/app/controllers/admin/imports_controller.rb @@ -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 diff --git a/app/views/admin/imports/show.html.haml b/app/views/admin/imports/show.html.haml index e5d37652..016278ee 100644 --- a/app/views/admin/imports/show.html.haml +++ b/app/views/admin/imports/show.html.haml @@ -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 diff --git a/config/application.rb b/config/application.rb index 88d63d5c..75741f29 100644 --- a/config/application.rb +++ b/config/application.rb @@ -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 diff --git a/config/environments/development.rb b/config/environments/development.rb index 384d8225..15590651 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -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 diff --git a/config/locales/admin_ui_en.yml b/config/locales/admin_ui_en.yml index 6e68b5c4..86278234 100644 --- a/config/locales/admin_ui_en.yml +++ b/config/locales/admin_ui_en.yml @@ -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: diff --git a/config/locales/admin_ui_fr.yml b/config/locales/admin_ui_fr.yml index 9890b787..882e073d 100644 --- a/config/locales/admin_ui_fr.yml +++ b/config/locales/admin_ui_fr.yml @@ -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: diff --git a/config/locales/flash.en.yml b/config/locales/flash.en.yml index ac4ed5b0..ddeb76ac 100644 --- a/config/locales/flash.en.yml +++ b/config/locales/flash.en.yml @@ -111,5 +111,5 @@ en: imports: create: - notice: "Your site is being updated" - alert: "Import was not done" \ No newline at end of file + notice: "Your site is being updated." + alert: "The import was not done." \ No newline at end of file diff --git a/doc/TODO b/doc/TODO index 48d55ea7..e3015a84 100644 --- a/doc/TODO +++ b/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 diff --git a/lib/locomotive/import/asset_collections.rb b/lib/locomotive/import/asset_collections.rb index 7319f6ff..7aa6a2a1 100644 --- a/lib/locomotive/import/asset_collections.rb +++ b/lib/locomotive/import/asset_collections.rb @@ -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] } diff --git a/lib/locomotive/import/assets.rb b/lib/locomotive/import/assets.rb index 04c15fda..d7d39c1f 100644 --- a/lib/locomotive/import/assets.rb +++ b/lib/locomotive/import/assets.rb @@ -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) diff --git a/lib/locomotive/import/content_types.rb b/lib/locomotive/import/content_types.rb index 8ebccc33..12ce4fbb 100644 --- a/lib/locomotive/import/content_types.rb +++ b/lib/locomotive/import/content_types.rb @@ -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] } diff --git a/lib/locomotive/import/job.rb b/lib/locomotive/import/job.rb index 19fc7c77..87bafcb7 100644 --- a/lib/locomotive/import/job.rb +++ b/lib/locomotive/import/job.rb @@ -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 diff --git a/lib/locomotive/liquid/drops/theme_assets.rb b/lib/locomotive/liquid/drops/theme_assets.rb deleted file mode 100644 index 218663bb..00000000 --- a/lib/locomotive/liquid/drops/theme_assets.rb +++ /dev/null @@ -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 diff --git a/lib/locomotive/render.rb b/lib/locomotive/render.rb index c3c94372..f44e5417 100644 --- a/lib/locomotive/render.rb +++ b/lib/locomotive/render.rb @@ -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] } diff --git a/public/javascripts/admin/application.js b/public/javascripts/admin/application.js index 9201f744..06a13b06 100644 --- a/public/javascripts/admin/application.js +++ b/public/javascripts/admin/application.js @@ -1,4 +1,3 @@ -var foo = null; var I18nLocale = null; var CodeMirrorEditors = []; diff --git a/public/javascripts/admin/import.js b/public/javascripts/admin/import.js index 59a4a531..4b700eb0 100644 --- a/public/javascripts/admin/import.js +++ b/public/javascripts/admin/import.js @@ -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) state = 'done'; + if (i == currentIndex + 1 && data.failed) state = 'failed'; - if (i == currentIndex && data.failed) state = 'failed'; - - $('#import-steps li:eq(' + i + ')').addClass(state); + 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(); }); }); \ No newline at end of file