diff --git a/Gemfile b/Gemfile index 5cb5d8e76..22b946224 100644 --- a/Gemfile +++ b/Gemfile @@ -16,4 +16,4 @@ group :development, :test do gem 'codeclimate-test-reporter', require: nil gem 'figaro' gem 'appraisal' -end \ No newline at end of file +end diff --git a/app/assets/javascripts/spina/admin/spina.infinite_scroll.coffee b/app/assets/javascripts/spina/admin/spina.infinite_scroll.coffee index f8657afe2..311203e41 100644 --- a/app/assets/javascripts/spina/admin/spina.infinite_scroll.coffee +++ b/app/assets/javascripts/spina/admin/spina.infinite_scroll.coffee @@ -1,15 +1,18 @@ class Spina.InfiniteScroll @init: (link) -> $(window).off('scroll.infiniteScroll') + $('#main, #overlay section').off('scroll.infiniteScroll') $link = $(link) if (url = $link.find('a').attr('href')) $(window).on 'scroll.infiniteScroll', => @loadNextPage($link) - $(window).scroll() + $('#main, #overlay section').on('scroll.infiniteScroll', -> $(window).trigger 'scroll.infiniteScroll') + $(window).trigger('scroll.infiniteScroll') @loadNextPage: ($link) -> if ($(window).scrollTop() > $link.offset().top - $(window).height() - 500) $(window).off('scroll.infiniteScroll') + $('#main, #overlay section').off('scroll.infiniteScroll') $.rails.disableElement($link.find('a')) $.getScript($link.find('a').attr('href')) @@ -18,3 +21,4 @@ $.fn.infiniteScroll = () -> $(document).on 'page:change', -> $(window).off('scroll.infiniteScroll') + $('#main, #overlay section').off('scroll.infiniteScroll') diff --git a/app/assets/javascripts/spina/admin/spina.trix.js.coffee b/app/assets/javascripts/spina/admin/spina.trix.js.coffee.erb similarity index 90% rename from app/assets/javascripts/spina/admin/spina.trix.js.coffee rename to app/assets/javascripts/spina/admin/spina.trix.js.coffee.erb index 837e2435e..00b71bf69 100644 --- a/app/assets/javascripts/spina/admin/spina.trix.js.coffee +++ b/app/assets/javascripts/spina/admin/spina.trix.js.coffee.erb @@ -30,7 +30,7 @@ Trix.config.blockAttributes = $.extend Trix.config.blockAttributes, { class Spina.TrixAttachment @photoSelect: (e) -> editor_id = $(this).closest('trix-toolbar').data('editor-id') - $.get("/admin/photos/wysihtml5_select/#{editor_id}") + $.get("<%= Spina::Engine.routes.url_helpers.wysihtml5_select_admin_photos_path('') %>/#{editor_id}") @photoInsert: (e, url) -> length = this.editor.getDocument().toString().length diff --git a/app/assets/stylesheets/spina/admin/application.sass b/app/assets/stylesheets/spina/admin/application.sass index ca39dfad4..58b9e4066 100755 --- a/app/assets/stylesheets/spina/admin/application.sass +++ b/app/assets/stylesheets/spina/admin/application.sass @@ -1 +1,4 @@ @import spina + +.infinite-scroll + @include clearfix diff --git a/app/controllers/spina/admin/attachments_controller.rb b/app/controllers/spina/admin/attachments_controller.rb index 3e8c7556d..b319134a8 100644 --- a/app/controllers/spina/admin/attachments_controller.rb +++ b/app/controllers/spina/admin/attachments_controller.rb @@ -24,7 +24,8 @@ def destroy end def select - @attachments = Attachment.file_attached.sorted + @selected_attachment_id = Attachment.find_by(id: params[:selected_attachment_id]).try(:id) + @attachments = Attachment.order_by_ids(@selected_attachment_id).file_attached.sorted @attachment = Attachment.new end @@ -33,12 +34,13 @@ def insert end def select_collection - @attachments = Attachment.file_attached.sorted + @selected_attachment_ids = Attachment.where(id: params[:selected_attachment_ids]).ids + @attachments = Attachment.order_by_ids(@selected_attachment_ids).file_attached.sorted @attachment = Attachment.new end def insert_collection - @attachments = Attachment.find(params[:attachment_ids]) + @attachments = Attachment.where(id: params[:attachment_ids]) end private diff --git a/app/controllers/spina/admin/photos_controller.rb b/app/controllers/spina/admin/photos_controller.rb index 2ba5f286e..b12073462 100644 --- a/app/controllers/spina/admin/photos_controller.rb +++ b/app/controllers/spina/admin/photos_controller.rb @@ -42,10 +42,9 @@ def link end def photo_select - selected = params[:selected_photo_id] || Array.new + @selected_photo_id = Photo.find_by(id: params[:selected_photo_id]).try(:id) hidden_field_id = params[:hidden_field_id] - @photos = Photo.order_by_ids(selected).sorted.page(params[:page]) - @selected_photo = Photo.find(selected) + @photos = Photo.order_by_ids(@selected_photo_id).sorted.page(params[:page]) @photo = Photo.new if params[:page].present? @@ -56,9 +55,8 @@ def photo_select end def photo_collection_select - selected = params[:selected_photo_ids] || Array.new - @photos = Photo.order_by_ids(selected).sorted.page(params[:page]) - @selected_photos = Photo.where(id: selected) + @selected_photo_ids = Photo.where(id: params[:selected_photo_ids]).ids + @photos = Photo.order_by_ids(@selected_photo_ids).sorted.page(params[:page]) @photo = Photo.new if params[:page].present? diff --git a/app/helpers/spina/admin/pages_helper.rb b/app/helpers/spina/admin/pages_helper.rb index f689dc542..d646cbb24 100644 --- a/app/helpers/spina/admin/pages_helper.rb +++ b/app/helpers/spina/admin/pages_helper.rb @@ -37,6 +37,21 @@ def partable_type_partial_namespace(partable_type) partable_type.tableize.sub(/\Aspina\//, '') end + def flatten_nested_hash(hash) + hash.flat_map{|k, v| [k, *flatten_nested_hash(v)]} + end + + def page_ancestry_options(page) + pages = Spina::Page.active + pages = pages.where.not(id: page.subtree.ids) unless page.new_record? + + flatten_nested_hash(pages.arrange(order: :position)).map do |page| + next if page.depth >= Spina.config.max_page_depth - 1 + page_menu_title = page.depth.zero? ? page.menu_title : " #{page.menu_title}".indent(page.depth, '-') + [page_menu_title, page.ancestry] + end.compact + end + end end end diff --git a/app/models/spina/attachment.rb b/app/models/spina/attachment.rb index 12e83c561..5433cb950 100644 --- a/app/models/spina/attachment.rb +++ b/app/models/spina/attachment.rb @@ -24,5 +24,10 @@ def update_attributes(attributes) end end + def self.order_by_ids(ids) + sql = sanitize_sql_for_conditions({id: ids}) + order("CASE WHEN #{sql} THEN 0 ELSE 1 END") + end + end end diff --git a/app/models/spina/page.rb b/app/models/spina/page.rb index 4d56b24a0..63597c640 100644 --- a/app/models/spina/page.rb +++ b/app/models/spina/page.rb @@ -109,7 +109,7 @@ def generate_materialized_path name == 'homepage' ? '' : "#{url_title}" else ancestors.collect(&:url_title).append(url_title).join('/') - end + end end def ancestry_is_nil diff --git a/app/views/spina/admin/attachments/_select.html.haml b/app/views/spina/admin/attachments/_select.html.haml index e52c4f986..3d469b3fd 100644 --- a/app/views/spina/admin/attachments/_select.html.haml +++ b/app/views/spina/admin/attachments/_select.html.haml @@ -17,7 +17,7 @@ %tbody - @attachments.each do |attachment| %tr - %td= radio_button_tag :attachment_id, attachment.id + %td= radio_button_tag :attachment_id, attachment.id, attachment.id == @selected_attachment_id %td= attachment.name %footer diff --git a/app/views/spina/admin/attachments/_select_collection.html.haml b/app/views/spina/admin/attachments/_select_collection.html.haml index b4eba3db5..29ac83fc7 100644 --- a/app/views/spina/admin/attachments/_select_collection.html.haml +++ b/app/views/spina/admin/attachments/_select_collection.html.haml @@ -17,7 +17,7 @@ %tbody - @attachments.each do |attachment| %tr - %td= check_box_tag 'attachment_ids[]', attachment.id + %td= check_box_tag 'attachment_ids[]', attachment.id, attachment.id.in?(@selected_attachment_ids) %td= attachment.name %footer diff --git a/app/views/spina/admin/attachments/insert.js.coffee b/app/views/spina/admin/attachments/insert.js.coffee new file mode 100644 index 000000000..045362dda --- /dev/null +++ b/app/views/spina/admin/attachments/insert.js.coffee @@ -0,0 +1,5 @@ +hidden_input = $("input[name='<%= j params[:page_part_id] %>[page_partable_id]']") +hidden_input.parents('.media_picker').find('.attachment').remove() +hidden_input.parents('.media_picker').append("
") +hidden_input.val("<%= @attachment.id %>") +$.hideModal() diff --git a/app/views/spina/admin/attachments/insert.js.erb b/app/views/spina/admin/attachments/insert.js.erb deleted file mode 100644 index 25df42ba4..000000000 --- a/app/views/spina/admin/attachments/insert.js.erb +++ /dev/null @@ -1,5 +0,0 @@ -var hidden_input = $("input[name='<%= j params[:page_part_id] %>[page_partable_id]']"); -hidden_input.parents('td').find('a .attachment, a .placeholder').remove(); -hidden_input.parents('td').find('a').prepend(" "); -hidden_input.val("<%= @attachment.id %>"); -$.hideModal(); diff --git a/app/views/spina/admin/attachments/insert_collection.js.coffee b/app/views/spina/admin/attachments/insert_collection.js.coffee new file mode 100644 index 000000000..e6310782d --- /dev/null +++ b/app/views/spina/admin/attachments/insert_collection.js.coffee @@ -0,0 +1,7 @@ +hidden_input = $("input[name='<%= j params[:page_part_id] %>[attachment_tokens]']") +attachment_collection = $("<%= j render partial: 'attachment_collection', locals: {attachments: @attachments} %>") + +hidden_input.parents('.media_picker').find('.attachment').remove() +hidden_input.parents('.media_picker').append(attachment_collection) +hidden_input.val("<%= @attachments.map(&:id).join(',') %>") +$.hideModal() diff --git a/app/views/spina/admin/attachments/insert_collection.js.erb b/app/views/spina/admin/attachments/insert_collection.js.erb deleted file mode 100644 index f66663a3f..000000000 --- a/app/views/spina/admin/attachments/insert_collection.js.erb +++ /dev/null @@ -1,7 +0,0 @@ -var hidden_input = $("input[name='<%= j params[:page_part_id] %>[attachment_tokens]']"); -var attachment_collection = $("<%= j render partial: 'attachment_collection', locals: {attachments: @attachments} %>"); - -hidden_input.parents('td').find('.attachment, .placeholder').remove(); -hidden_input.parents('td a').append(attachment_collection); -hidden_input.val("<%= @attachments.map(&:id).join(',') %>"); -$.hideModal(); diff --git a/app/views/spina/admin/page_partables/attachment_collections/_form.html.haml b/app/views/spina/admin/page_partables/attachment_collections/_form.html.haml index fd804876b..08a5038e1 100644 --- a/app/views/spina/admin/page_partables/attachment_collections/_form.html.haml +++ b/app/views/spina/admin/page_partables/attachment_collections/_form.html.haml @@ -2,14 +2,13 @@ = f.object.title .horizontal-form-content = f.fields_for :page_partable, f.object.page_partable do |ff| - = link_to select_collection_admin_attachments_path(ff.object_name), remote: true, class: "media_picker" do - .clearfix - .placeholder.pull-right - %span.button.button-small.button-round - %i.icon.icon-dots - = t('spina.choose_from_library') - - if ff.object.attachments.any? - - ff.object.attachments.each do |attachment| - .attachment= attachment.name + = link_to select_collection_admin_attachments_path(ff.object_name, selected_attachment_ids: ff.object.attachment_ids), remote: true, class: 'media_picker clearfix' do + .placeholder.pull-right + %span.button.button-small.button-round + %i.icon.icon-dots + = t('spina.choose_from_library') + - if ff.object.attachments.any? + - ff.object.attachments.each do |attachment| + .attachment= attachment.name = ff.hidden_field :attachment_tokens, value: ff.object.attachment_ids.join(",") diff --git a/app/views/spina/admin/page_partables/attachments/_form.html.haml b/app/views/spina/admin/page_partables/attachments/_form.html.haml index e3d99810b..1ede20f94 100644 --- a/app/views/spina/admin/page_partables/attachments/_form.html.haml +++ b/app/views/spina/admin/page_partables/attachments/_form.html.haml @@ -1,14 +1,13 @@ .horizontal-form-label = f.object.title .horizontal-form-content - = link_to select_admin_attachments_path(f.object_name), remote: true, class: "media_picker" do - .clearfix - .placeholder.pull-right - %span.button.button-small.button-round - %i.icon.icon-dots - = t('spina.choose_from_library') + = link_to select_admin_attachments_path(f.object_name, selected_attachment_id: f.object.page_partable.id), remote: true, class: 'media_picker clearfix' do + .placeholder.pull-right + %span.button.button-small.button-round + %i.icon.icon-dots + = t('spina.choose_from_library') - - if f.object.page_partable && f.object.page_partable.file.present? - .attachment= f.object.page_partable.name + - if f.object.page_partable && f.object.page_partable.file.present? + .attachment= f.object.page_partable.name = f.hidden_field :page_partable_id diff --git a/app/views/spina/admin/page_partables/photo_collections/_form.html.haml b/app/views/spina/admin/page_partables/photo_collections/_form.html.haml index 9d501ef0d..647a26f23 100644 --- a/app/views/spina/admin/page_partables/photo_collections/_form.html.haml +++ b/app/views/spina/admin/page_partables/photo_collections/_form.html.haml @@ -2,8 +2,8 @@ = f.object.title .horizontal-form-content = f.fields_for :page_partable, f.object.page_partable do |ff| - = link_to spina.photo_collection_select_admin_photos_path(ff.object_name, selected_photo_ids: (ff.object.photo_ids if ff.object.photos.any?)), remote: true, class: "media_picker" do - .placeholder{class: ('pull-right' if ff.object.photos.any?)} + = link_to spina.photo_collection_select_admin_photos_path(ff.object_name, selected_photo_ids: ff.object.photo_ids), remote: true, class: 'media_picker clearfix' do + .placeholder.pull-right %span.button.button-small.button-round %i.icon.icon-dots =t 'spina.pages.photos_picker' diff --git a/app/views/spina/admin/page_partables/photos/_form.html.haml b/app/views/spina/admin/page_partables/photos/_form.html.haml index caf8fd5d4..2ade89959 100644 --- a/app/views/spina/admin/page_partables/photos/_form.html.haml +++ b/app/views/spina/admin/page_partables/photos/_form.html.haml @@ -1,18 +1,14 @@ .horizontal-form-label = f.object.title .horizontal-form-content - = link_to spina.photo_select_admin_photos_path(f.object_name, selected_photo_id: (f.object.page_partable.id if f.object.page_partable.present?)), remote: true, class: "media_picker" do + = link_to spina.photo_select_admin_photos_path(f.object_name, selected_photo_id: f.object.page_partable.id), remote: true, class: 'media_picker clearfix' do + .placeholder.pull-right + %span.button.button-small.button-round + %i.icon.icon-dots + =t 'spina.pages.photo_picker' + - if f.object.page_partable && f.object.page_partable.file.present? - .placeholder.pull-right - %span.button.button-small.button-round - %i.icon.icon-dots - =t 'spina.pages.photo_picker' .image = image_tag f.object.page_partable.file.thumb - - else - .placeholder - %span.button.button-small.button-round - %i.icon.icon-dots - =t 'spina.pages.photo_picker' = f.hidden_field :page_partable_id diff --git a/app/views/spina/admin/pages/_form_advanced.html.haml b/app/views/spina/admin/pages/_form_advanced.html.haml index cc4ae553e..cff8e746a 100644 --- a/app/views/spina/admin/pages/_form_advanced.html.haml +++ b/app/views/spina/admin/pages/_form_advanced.html.haml @@ -44,4 +44,4 @@ = Spina::Page.human_attribute_name :ancestry %td .select-dropdown.ancestry - = f.select :ancestry, options_from_collection_for_select(Spina::Page.active.sorted.roots, 'id', 'menu_title', @page.ancestry.to_i), include_blank: Spina::Page.human_attribute_name(:no_parent) + = f.select :ancestry, page_ancestry_options(f.object), include_blank: Spina::Page.human_attribute_name(:no_parent) diff --git a/app/views/spina/admin/photos/_photo_collection_select.html.haml b/app/views/spina/admin/photos/_photo_collection_select.html.haml index 189ab5466..f7bf935cc 100644 --- a/app/views/spina/admin/photos/_photo_collection_select.html.haml +++ b/app/views/spina/admin/photos/_photo_collection_select.html.haml @@ -5,12 +5,12 @@ = form_for [spina, :admin, @photo], html: {multipart: true} do |f| = f.label :file, t('spina.photos.upload_image') = f.file_field :file, data: {customfileinput: true} - + = form_tag spina.insert_photo_collection_admin_photos_path(params[:page_part_id]), remote: true, class: 'gallery-prepend-image' do .infinite-scroll = render partial: 'spina/admin/photos/photo_multi_picker', collection: @photos - .infinite-pagination= link_to_next_page @photos, 'Next', params: {selected_photo_ids: @selected_photos.ids}, remote: true + .infinite-pagination= link_to_next_page @photos, 'Next', params: params.slice(:selected_photo_ids), remote: true .gallery-select-action-bar .pull-right @@ -19,5 +19,5 @@ = icon('plus') = t('spina.photos.choose_images') %span.gallery-select-counter - - if @selected_photos.any? - (#{@selected_photos.count}) \ No newline at end of file + - if @selected_photo_ids.any? + (#{ @selected_photo_ids.count }) diff --git a/app/views/spina/admin/photos/_photo_multi_picker.html.haml b/app/views/spina/admin/photos/_photo_multi_picker.html.haml index 2742e4b89..64727ca08 100644 --- a/app/views/spina/admin/photos/_photo_multi_picker.html.haml +++ b/app/views/spina/admin/photos/_photo_multi_picker.html.haml @@ -1,3 +1,3 @@ -.item{class: ('selected' if @selected_photos.include?(photo_multi_picker))} - = check_box_tag 'photo_ids[]', photo_multi_picker.id, @selected_photos.include?(photo_multi_picker) +.item{class: ('selected' if photo_multi_picker.id.in?(@selected_photo_ids)) } + = check_box_tag 'photo_ids[]', photo_multi_picker.id, photo_multi_picker.id.in?(@selected_photo_ids) = image_tag photo_multi_picker.file.thumb.url, id: "photo_#{photo_multi_picker.id}" diff --git a/app/views/spina/admin/photos/_photo_select.html.haml b/app/views/spina/admin/photos/_photo_select.html.haml index 058637c25..1d3b25da1 100644 --- a/app/views/spina/admin/photos/_photo_select.html.haml +++ b/app/views/spina/admin/photos/_photo_select.html.haml @@ -12,4 +12,5 @@ .infinite-scroll = render partial: 'spina/admin/photos/photo_single_picker', collection: @photos - .infinite-pagination= link_to_next_page @photos, 'Next', params: {selected_photo_id: @selected_photo.try(:id)}, remote: true + .infinite-pagination= link_to_next_page @photos, 'Next', params: params.slice(:selected_photo_id), remote: true + diff --git a/app/views/spina/admin/photos/_photo_single_picker.html.haml b/app/views/spina/admin/photos/_photo_single_picker.html.haml index 23eae3513..1b6c74103 100644 --- a/app/views/spina/admin/photos/_photo_single_picker.html.haml +++ b/app/views/spina/admin/photos/_photo_single_picker.html.haml @@ -1,3 +1,3 @@ -.item{class: ('selected' if @selected_photo == photo_single_picker)} - = radio_button_tag :photo_id, photo_single_picker.id, photo_single_picker == @selected_photo +.item{ class: ('selected' if photo_single_picker.id == @selected_photo_id) } + = radio_button_tag :photo_id, photo_single_picker.id, photo_single_picker.id == @selected_photo_id = image_tag photo_single_picker.file.thumb.url, id: "photo_#{photo_single_picker.id}" diff --git a/app/views/spina/admin/photos/index.html.haml b/app/views/spina/admin/photos/index.html.haml index d1b60ac2a..cb6f37636 100644 --- a/app/views/spina/admin/photos/index.html.haml +++ b/app/views/spina/admin/photos/index.html.haml @@ -7,6 +7,7 @@ = f.file_field :file, data: {customfileinput: true} .gallery-prepend-image - .infinite-scroll= render partial: 'spina/admin/photos/photo', collection: @photos + .infinite-scroll + = render partial: 'spina/admin/photos/photo', collection: @photos - .infinite-pagination= link_to_next_page @photos, 'Next', remote: true \ No newline at end of file + .infinite-pagination= link_to_next_page @photos, 'Next', remote: true diff --git a/app/views/spina/admin/photos/insert_photo.js.erb b/app/views/spina/admin/photos/insert_photo.js.erb index f4055e974..2291c2d93 100644 --- a/app/views/spina/admin/photos/insert_photo.js.erb +++ b/app/views/spina/admin/photos/insert_photo.js.erb @@ -1,10 +1,10 @@ var hidden_input = $("input[name='<%= j params[:page_part_id] %>[page_partable_id]'], input[name='<%= j params[:page_part_id] %>[structure_partable_id]'], input[data-hidden-field='<%= j params[:hidden_field_id] %>']"); -hidden_input.parents('.media_picker').find('.image, .placeholder').remove(); +hidden_input.parents('.media_picker').find('.image').remove(); + <% if @photo.present? %> - hidden_input.parents('.media_picker').prepend("