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 13 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 @@ -7,9 +7,9 @@ class ImageSlidesController < ::Refinery::AdminController
: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 Down Expand Up @@ -48,16 +48,7 @@ def image_slide_params
private

def permitted_image_slide_params
[
:id,
:title,
:image_id,
:caption,
:link_url,
:body,
:position,
:image_slideshow_id
]
%i( id active title image_id caption link_url body position image_slideshow_id )
end

def image_slides_path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class ImageSlideshowsController < ::Refinery::AdminController

def image_slideshow_params
params.require(:image_slideshow).permit(
:active,
Copy link
Member

Choose a reason for hiding this comment

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

by convention we use draft logic instead of active logic

:title,
:position,
:js_config,
Expand Down
20 changes: 15 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,27 @@ 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
validates :image_id, presence: true

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

delegate :height, :width, to: :image_slideshow

class << self

def active
where active: true
end

end

delegate :height, :width, :to => :image_slideshow
end
end
end
21 changes: 19 additions & 2 deletions app/models/refinery/image_slideshows/image_slideshow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,26 @@ class ImageSlideshow < Refinery::Core::BaseModel

acts_as_indexed :fields => [:title]

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

has_many :image_slides, dependent: :destroy

class << self

def active
where active: true
end

def with_active_slides
includes(:image_slides).where( refinery_image_slides: { active: true } )
end

def slideshow_by_title(title)
active.with_active_slides.find_by_title(title)
end

end

has_many :image_slides, :dependent => :destroy
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@
: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 %>

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

<div class='field'>
<%= f.label :title %>
<%= f.text_field :title, :class => 'larger widest' %>
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: "#{image_slide.active? ? :success_icon : :failure_icon} less-important" do %>
Copy link
Member

Choose a reason for hiding this comment

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

<strong><%== t(image_slide.active? ? 'active' : 'inactive', scope: 'refinery.image_slideshows.admin.states' ).titleize %></strong>
<% end %>

<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 @@ -3,6 +3,10 @@
:object => @image_slideshow,
:include_object_name => true %>

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

<div class='field'>
<%= f.label :title %>
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: "#{image_slideshow.active? ? :success_icon : :failure_icon} less-important" do %>
<strong><%== t(image_slideshow.active? ? 'active' : 'inactive', scope: 'refinery.image_slideshows.admin.states' ).titleize %></strong>
<% end %>

<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>
12 changes: 9 additions & 3 deletions bin/rails
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#!/usr/bin/env ruby
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
# This command will automatically be run when you run "rails" with Rails gems
# installed from the root of your application.

ENGINE_PATH = File.expand_path('../..', __FILE__)
load File.expand_path('../../spec/dummy/bin/rails', __FILE__)
begin
load File.join(File.expand_path('../../', __FILE__), 'spec/dummy/bin/rails')
rescue LoadError => load_error
warn "No dummy Rails application found! \n" \
"To create one in spec/dummy, please run: \n\n" \
" rake refinery:testing:dummy_app"
end
5 changes: 5 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ en:
title: Image Slideshows
image_slideshows:
admin:
states:
active: active
inactive: inactive
image_slideshows:
actions:
create_new: Add New Image Slideshow
Expand Down Expand Up @@ -41,12 +44,14 @@ en:
activerecord:
attributes:
refinery/image_slideshows/image_slide:
active: Active
title: Title
image: Image
caption: Caption
link_url: Link
body: Text body
refinery/image_slideshows/image_slideshow:
active: Active
title: Title
height: Height
width: Width
Expand Down
5 changes: 5 additions & 0 deletions config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ fr:
title: Diaporamas
image_slideshows:
admin:
states:
active: actif
inactive: inactif
image_slideshows:
actions:
create_new: Créer un nouveau diaporama
Expand Down Expand Up @@ -42,12 +45,14 @@ fr:
activerecord:
attributes:
refinery/image_slideshows/image_slide:
active: Actif
title: Titre
image: Image
caption: Légende
link_url: Lien
body: Corps du texte
refinery/image_slideshows/image_slideshow:
active: Actif
title: Titre
height: Hauteur
width: Largeur
Expand Down
3 changes: 2 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Refinery::Core::Engine.routes.append do
# frozen_string_literal: true
Refinery::Core::Engine.routes.draw do

Choose a reason for hiding this comment

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

Style/FrozenStringLiteralComment: Missing magic comment # frozen_string_literal: true.


# Admin routes
namespace :image_slideshows, :path => '' do
Expand Down
3 changes: 2 additions & 1 deletion db/migrate/1_create_image_slideshows_image_slideshows.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class CreateImageSlideshowsImageSlideshows < ActiveRecord::Migration
# frozen_string_literal: true
class CreateImageSlideshowsImageSlideshows < ActiveRecord::Migration[5.1]

def up
create_table :refinery_image_slideshows do |t|
Expand Down
3 changes: 2 additions & 1 deletion db/migrate/2_create_image_slides_image_slides.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class CreateImageSlidesImageSlides < ActiveRecord::Migration
# frozen_string_literal: true
class CreateImageSlidesImageSlides < ActiveRecord::Migration[5.1]

def up
create_table :refinery_image_slides do |t|
Expand Down
3 changes: 2 additions & 1 deletion db/migrate/3_add_image_and_caption_to_image_slides.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class AddImageAndCaptionToImageSlides < ActiveRecord::Migration
# frozen_string_literal: true
class AddImageAndCaptionToImageSlides < ActiveRecord::Migration[5.1]
def change
add_column :refinery_image_slides, :image_id, :integer
add_column :refinery_image_slides, :caption, :string
Expand Down
3 changes: 2 additions & 1 deletion db/migrate/4_add_js_config_to_image_slideshows.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class AddJsConfigToImageSlideshows < ActiveRecord::Migration
# frozen_string_literal: true
class AddJsConfigToImageSlideshows < ActiveRecord::Migration[5.1]

Choose a reason for hiding this comment

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

Style/Documentation: Missing top-level class documentation comment.
Style/FrozenStringLiteralComment: Missing magic comment # frozen_string_literal: true.

def change
add_column :refinery_image_slideshows, :js_config, :text
end
Expand Down
3 changes: 2 additions & 1 deletion db/migrate/5_add_link_url_to_image_slides.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class AddLinkUrlToImageSlides < ActiveRecord::Migration
# frozen_string_literal: true
class AddLinkUrlToImageSlides < ActiveRecord::Migration[5.1]

Choose a reason for hiding this comment

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

Style/Documentation: Missing top-level class documentation comment.
Style/FrozenStringLiteralComment: Missing magic comment # frozen_string_literal: true.

def change
add_column :refinery_image_slides, :link_url, :string
end
Expand Down
Loading