Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Feature/mobility #6

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
ded7082
Change Gemfile and gemspec to use Mobility instead of Globalize
gloubier May 8, 2018
d2b8b0d
Fix migrations
gloubier May 8, 2018
8fcf4e5
Fix routes
gloubier May 8, 2018
3636a47
Change before_filter => before_action
gloubier May 8, 2018
4e6e0a2
Update models to use mobility + modern syntax
gloubier May 8, 2018
97dd843
Use Mobility.locale instead of Globalize.locale
gloubier May 8, 2018
e7c8a40
Fix action icons
gloubier May 8, 2018
05f7475
Fix Hound syntax comments
gloubier May 9, 2018
01bd144
Clean up Gemfile
bricesanchez May 9, 2018
2f819f8
Update refinerycms-testing dependency version to 4.0.0
bricesanchez May 9, 2018
bae7bce
Update bin/rails to fix rails console start
bricesanchez May 9, 2018
8dd9b65
Merge pull request #1 from refinerycms-contrib/feature/mobility
gloubier May 9, 2018
4caf0e9
Add active state to slideshows and slides
gloubier May 9, 2018
b1b4599
Change active state to draft to follow conventions
gloubier May 9, 2018
c48e2b1
Add live? method to easily check if is published
gloubier May 9, 2018
107cddf
Remove finder methods
gloubier May 9, 2018
42edd2c
Delete script/rails
bricesanchez May 10, 2018
4eb2a83
Now require refinerycms-images
bricesanchez May 10, 2018
7feb3fa
Remove height, width and js_config fields
bricesanchez May 10, 2018
1829e4d
QA
bricesanchez May 10, 2018
9e7879a
Update README
bricesanchez May 10, 2018
9d188d3
Merge pull request #2 from refinerycms-contrib/feature/mobility
gloubier May 10, 2018
20bc9a0
Remove unecessary stuff
gloubier May 17, 2018
242ec70
Add order field to slides relation
gloubier Dec 11, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,48 @@ source "https://rubygems.org"

gemspec

git "https://github.com/refinery/refinerycms", branch: "master" do
gem "refinerycms"
# TODO: use master branch before merging this PR
# git "https://github.com/refinery/refinerycms", branch: "master" do
git 'https://github.com/refinery/refinerycms', branch: 'feature/mobility' do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout/EmptyLinesAroundBlockBody: Extra empty line detected at block body beginning.

gem 'refinerycms'

group :test do
gem "refinerycms-testing"
gem 'refinerycms-testing'
end
end

# TODO: remove refinerycms-i18n and mobility from this Gemfile before merging
gem 'refinerycms-i18n', git: 'https://github.com/refinery/refinerycms-i18n', branch: 'feature/mobility'

group :development do
gem 'listen'
end

# Database Configuration
unless ENV["TRAVIS"]
gem "activerecord-jdbcsqlite3-adapter", :platform => :jruby
gem "sqlite3", :platform => :ruby
gem "activerecord-jdbcsqlite3-adapter", platform: :jruby
gem "sqlite3", platform: :ruby
end

if !ENV["TRAVIS"] || ENV["DB"] == "mysql"
gem "activerecord-jdbcmysql-adapter", :platform => :jruby
gem "jdbc-mysql", "= 5.1.13", :platform => :jruby
gem "mysql2", :platform => :ruby
gem "activerecord-jdbcmysql-adapter", platform: :jruby
gem "jdbc-mysql", "= 5.1.13", platform: :jruby
gem "mysql2", platform: :ruby
end

if !ENV["TRAVIS"] || ENV["DB"] == "postgresql"
gem "activerecord-jdbcpostgresql-adapter", :platform => :jruby
gem "pg", :platform => :ruby
gem "activerecord-jdbcpostgresql-adapter", platform: :jruby
gem "pg", platform: :ruby
end

gem "jruby-openssl", :platform => :jruby

# Refinery/rails should pull in the proper versions of these
group :assets do
gem "sass-rails"
gem "coffee-rails"
gem "uglifier"
end

group :development do
gem 'quiet_assets'
end

group :test do
gem "launchy"
end

# Load local gems according to Refinery developer preference.
if File.exist? local_gemfile = File.expand_path("../.gemfile", __FILE__)
eval File.read(local_gemfile)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ module Admin
class ImageSlidesController < ::Refinery::AdminController

crudify :'refinery/image_slideshows/image_slide',
:sortable => true,
:include => [:translations]
sortable: true,
include: [:translations]

before_filter :find_image_slideshow
before_filter :find_image_slides, only: :index
before_filter :find_image_slide, :except => [:index, :new]
before_action :find_image_slideshow
before_action :find_image_slides, only: :index
before_action :find_image_slide, except: %i( index new )

def create
if Refinery::ImageSlideshows::ImageSlide.any?
Expand All @@ -19,49 +19,30 @@ def create
end

if @image_slide.valid? && @image_slide.save
redirect_to image_slides_path, :notice => t('created', :scope => 'refinery.image_slideshows.admin.image_slides')
redirect_to image_slides_path, :notice => t('created', scope: 'refinery.image_slideshows.admin.image_slides')
else
render :action => :new
render action: :new
end
end

def update
if @image_slide.update_attributes(image_slide_params)
redirect_to image_slides_path, :notice => t('updated', :scope => 'refinery.image_slideshows.admin.image_slides')
redirect_to image_slides_path, :notice => t('updated', scope: 'refinery.image_slideshows.admin.image_slides')
else
render :action => :edit
render action: :edit
end
end

def destroy
if @image_slide.destroy
redirect_to image_slides_path, :notice => t('deleted', :scope => 'refinery.image_slideshows.admin.image_slides')
redirect_to image_slides_path, notice: t('deleted', scope: 'refinery.image_slideshows.admin.image_slides')
end
end

protected

def image_slide_params
params.require(:image_slide).permit(permitted_image_slide_params)
end

private

def permitted_image_slide_params
[
:id,
:title,
:image_id,
:caption,
:link_url,
:body,
:position,
:image_slideshow_id
]
end

def image_slides_path
refinery.image_slideshows_admin_image_slideshow_image_slides_path(@image_slideshow)
def image_slide_params
params.require(:image_slide).permit(permitted_image_slide_params)
end

def find_image_slide
Expand All @@ -76,6 +57,16 @@ def find_image_slideshow
def find_image_slides
@image_slides = @image_slideshow.image_slides.order(:position) if @image_slideshow.present?
end

private

def permitted_image_slide_params
[ :id, :draft, :title, :image_id, :caption, :link_url, :body, :position, :image_slideshow_id ]
end

def image_slides_path
refinery.image_slideshows_admin_image_slideshow_image_slides_path(@image_slideshow)
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ class ImageSlideshowsController < ::Refinery::AdminController

crudify :'refinery/image_slideshows/image_slideshow'

protected

def image_slideshow_params
params.require(:image_slideshow).permit(permitted_image_slideshow_params)
end

private

def image_slideshow_params
params.require(:image_slideshow).permit(
:title,
:position,
:js_config,
:height,
:width
)
end
def permitted_image_slideshow_params
[ :draft, :title, :position ]
end
end
end
end
Expand Down
21 changes: 16 additions & 5 deletions app/models/refinery/image_slideshows/image_slide.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,28 @@ module ImageSlideshows
class ImageSlide < Refinery::Core::BaseModel
self.table_name = 'refinery_image_slides'

extend Mobility
translates :title, :caption, :link_url, :body

acts_as_indexed :fields => [:title]
acts_as_indexed fields: [:title]

validates :title, :presence => true
validates :image_id, :presence => true
validates :title, presence: true

belongs_to :image_slideshow
belongs_to :image, :class_name => '::Refinery::Image'
belongs_to :image, class_name: '::Refinery::Image'

class << self

def live
where draft: false
end

end

def live?
!draft?
end

delegate :height, :width, :to => :image_slideshow
end
end
end
19 changes: 16 additions & 3 deletions app/models/refinery/image_slideshows/image_slideshow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,24 @@ module ImageSlideshows
class ImageSlideshow < Refinery::Core::BaseModel
self.table_name = 'refinery_image_slideshows'

acts_as_indexed :fields => [:title]
acts_as_indexed fields: [:title]

validates :title, :presence => true, :uniqueness => true
validates :title, presence: true, uniqueness: true

has_many :image_slides, -> { order(:position) }, dependent: :destroy

class << self

def live
where draft: false
end

end

def live?
!draft?
end

has_many :image_slides, :dependent => :destroy
end
end
end
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<% delete_url = @image_slide.id ? refinery.image_slideshows_admin_image_slideshow_image_slide_path(@image_slideshow, @image_slide) : nil %>

<%= form_for [refinery, :image_slideshows_admin, @image_slideshow, @image_slide] do |f| %>
<%= render '/refinery/admin/error_messages',
:object => @image_slide,
:include_object_name => true %>

<%= render '/refinery/admin/locale_picker',
:current_locale => Globalize.locale %>
:current_locale => Mobility.locale %>

<%= f.hidden_field :image_slideshow_id, :value => @image_slideshow.id %>

Expand Down Expand Up @@ -36,7 +38,11 @@
<%= f.label :body %>
<%= f.text_area :body, :rows => 5, :class => 'widest wymeditor' -%>
</div>
<% delete_url = @image_slide.id ? refinery.image_slideshows_admin_image_slideshow_image_slide_path(@image_slideshow, @image_slide) : nil %>

<div class='field'>
<%= f.check_box :draft %>
<%= f.label :draft, :class => 'stripped' %>
</div>

<%= render '/refinery/admin/form_actions', :f => f,
:continue_editing => false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,35 @@
<%
# setup params for various action links
edit_url = refinery.edit_image_slideshows_admin_image_slideshow_image_slide_path(@image_slideshow, image_slide)
delete_url = refinery.image_slideshows_admin_image_slideshow_image_slide_path(@image_slideshow, image_slide)
delete_options = {
class: "cancel confirm-delete",
data: {confirm: t('message', scope: 'refinery.admin.delete', title: image_slide.title)}
}
%>
<li class='clearfix record <%= cycle("on", "on-hover") %>' id="<%= dom_id(image_slide) -%>" style="background-color: #EAEAEA; margin-bottom: 10px;">
<%= image_fu image_slide.image, '128x128', :style => 'padding: 1em 1em 0 1em;' %>

<span class="preview">
<% image_slide.translations.each do |translation| %>
<% if translation.title.present? %>
<%= link_to refinery_icon_tag("flags/#{translation.locale}.png", :size => '16x11'),
refinery.edit_image_slideshows_admin_image_slideshow_image_slide_path(@image_slideshow, image_slide, :switch_locale => translation.locale),
:class => 'locale' %>
<%= link_to refinery.edit_image_slideshows_admin_image_slideshow_image_slide_path(@image_slideshow, image_slide, :switch_locale => translation.locale),
class: 'locale', title: translation.locale.upcase do %>

<div class="<%=translation.locale %> locale_marker">
<%= locale_text_icon(translation.locale.upcase) %>
</div>
<% end %>
<% end %>
<% end %>
</span>

<%= content_tag :span, class: 'label notice' do
::I18n.t('draft', :scope => 'refinery.image_slideshows.admin.image_slides.records')
end if image_slide.draft? %>

<span class='actions'>
<%= link_to refinery_icon_tag("application_edit.png"), refinery.edit_image_slideshows_admin_image_slideshow_image_slide_path(@image_slideshow, image_slide),
:title => t('.edit') %>
<%= link_to refinery_icon_tag("delete.png"), refinery.image_slideshows_admin_image_slideshow_image_slide_path(@image_slideshow, image_slide),
:class => "cancel confirm-delete",
:title => t('.delete'),
:confirm => t('message', :scope => 'refinery.admin.delete', :title => image_slide.title),
:method => :delete %>
<%= action_icon(:edit, edit_url , t('edit', scope: 'refinery.image_slideshows.admin.image_slides.image_slide' ) ) %>
<%= action_icon(:delete, delete_url, t('delete', scope: 'refinery.image_slideshows.admin.image_slides.image_slide' ), delete_options ) %>
</span>
</li>
</li>
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,8 @@
</div>

<div class='field'>
<%= f.label :height %>
<%= f.text_field :height %>
</div>

<div class='field'>
<%= f.label :width %>
<%= f.text_field :width %>
</div>

<div class='field'>
<%= f.label :js_config %>
<%= f.text_area :js_config, :cols => 80, :rows => 20 %>
<%= f.check_box :draft %>
<%= f.label :draft, :class => 'stripped' %>
</div>

<%= render '/refinery/admin/form_actions', :f => f,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
<%
# setup params for various action links
manage_url = refinery.image_slideshows_admin_image_slideshow_image_slides_path(image_slideshow)
edit_url = refinery.edit_image_slideshows_admin_image_slideshow_path(image_slideshow)
delete_url = refinery.image_slideshows_admin_image_slideshow_path(image_slideshow)
delete_options = {
class: "cancel confirm-delete",
data: {confirm: t('message', scope: 'refinery.admin.delete', title: image_slideshow.title)}
}
%>
<li class='clearfix record <%= cycle("on", "on-hover") %>' id="<%= dom_id(image_slideshow) -%>">
<span class='title'>
<%= link_to refinery.image_slideshows_admin_image_slideshow_image_slides_path(image_slideshow) do %>
<%= image_slideshow.title %>
<% end %>
</span>

<%= content_tag :span, class: 'label notice' do
::I18n.t('draft', :scope => 'refinery.image_slideshows.admin.image_slideshows.records')
end if image_slideshow.draft? %>

<span class='actions'>
<%= link_to refinery_icon_tag("img.png"), refinery.image_slideshows_admin_image_slideshow_image_slides_path(image_slideshow),
:title => t('.manage_image_slides') %>
<%= link_to refinery_icon_tag("application_edit.png"), refinery.edit_image_slideshows_admin_image_slideshow_path(image_slideshow),
:title => t('.edit') %>
<%= link_to refinery_icon_tag("delete.png"), refinery.image_slideshows_admin_image_slideshow_path(image_slideshow),
:class => "cancel confirm-delete",
:title => t('.delete'),
:confirm => t('message', :scope => 'refinery.admin.delete', :title => image_slideshow.title),
:method => :delete %>
<%= action_icon(:switch_view_list, manage_url, t('.manage_image_slides') ) %>
<%= action_icon(:edit, edit_url , t('.edit') ) %>
<%= action_icon(:delete, delete_url, t('.delete'), delete_options ) %>
</span>
</li>
</li>
Loading