Skip to content

Commit

Permalink
Switch from flip to flipflop. Fixes #2599
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Aug 31, 2016
1 parent adc7b57 commit 3b4fd55
Show file tree
Hide file tree
Showing 16 changed files with 106 additions and 74 deletions.
22 changes: 22 additions & 0 deletions app/assets/stylesheets/sufia/_form.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
.form-tab-content {
margin: 15px 10px;
}

/* For the admin page */
td.status {
width: 2rem;
font-size: 1.1rem;

span {
@extend .label;
@extend .badge;
&.on { @extend .label-success; }
&.off { @extend .label-default; }
}
}

td.toggle {
input[type=submit] {
@extend .btn;
@extend .btn-sm;
&.active { @extend .btn-primary; }
&:not(.active) { @extend .btn-default; }
}
}
1 change: 1 addition & 0 deletions app/assets/stylesheets/sufia/admin.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ $header-height: 35px !default;
$title-text-color: #4e4a42 !default;
$content-background-color: #f5f5f5 !default;


.page-title {
float: left;
padding: 5px 10px;
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/sufia/admin/features_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Sufia
module Admin
class FeaturesController < Flip::FeaturesController
class FeaturesController < Flipflop::FeaturesController
layout 'admin'
before_action do
authorize! :manage, Sufia::Feature
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/sufia/admin/strategies_controller.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module Sufia
module Admin
class StrategiesController < Flip::StrategiesController
class StrategiesController < Flipflop::StrategiesController
before_action do
authorize! :manage, Feature
authorize! :manage, Sufia::Feature
end

# TODO: we could remove this if we used an isolated engine
Expand Down
10 changes: 0 additions & 10 deletions app/models/sufia/feature.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
module Sufia
class Feature < ActiveRecord::Base
self.table_name = 'sufia_features'
extend Flip::Declarable

strategy Flip::CookieStrategy
strategy Flip::DatabaseStrategy
strategy Flip::DeclarationStrategy
default false

feature :assign_admin_set,
default: true,
description: "Ability to assign uploaded items to an admin set"
end
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<% if Flip.assign_admin_set? %>
<% if Flipflop.assign_admin_set? %>
<%= f.input :admin_set_id, as: :select,
collection: CurationConcerns::AdminSetService.new(controller).select_options,
include_blank: true,
Expand Down
51 changes: 0 additions & 51 deletions app/views/flip/features/index.html.erb

This file was deleted.

57 changes: 57 additions & 0 deletions app/views/sufia/admin/features/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<% content_for :page_header do %>
<h1><span class="fa fa-cog"></span> Settings</h1>
<% end %>
<div class="flip row">
<div class="col-md-12">
<div class="panel">
<div class="panel-body">
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th></th>
<th class="name">Feature</th>
<th class="description">Description</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<% @feature_set.features.each do |feature| -%>
<tr data-feature="<%= feature.name.dasherize.parameterize %>">
<td class="status">
<span class="<%= @feature_set.status(feature) -%>"><%= @feature_set.status(feature) -%></span>
</td>
<td class="name"><%= feature.name.humanize -%></td>
<td class="description"><%= feature.description -%></td>

<% @feature_set.strategies.each do |strategy| -%>
<% next unless strategy.is_a? Flipflop::Strategies::ActiveRecordStrategy %>
<td class="toggle" data-strategy="<%= strategy.name.dasherize.parameterize %>">
<div class="toolbar">
<%= form_tag(sufia.admin_feature_strategy_path(feature.key, strategy.key), method: :put) do -%>
<div class="btn-group">
<%= submit_tag "on",
type: "submit",
class: Flipflop.enabled?(feature.name.to_sym) ? 'active' : nil,
disabled: !strategy.switchable?
-%>

<%= submit_tag "off",
type: "submit",
class: Flipflop.enabled?(feature.name.to_sym) ? nil : 'active',
disabled: !strategy.switchable?
-%>
</div>
<% end -%>
</div>
</td>
<% end -%>
</tr>
<% end -%>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
10 changes: 10 additions & 0 deletions config/features.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Flipflop.configure do
# Strategies will be used in the order listed here.
strategy :cookie
strategy :active_record, class: Sufia::Feature
strategy :default

feature :assign_admin_set,
default: true,
description: "Ability to assign uploaded items to an admin set"
end
1 change: 0 additions & 1 deletion config/initializers/flip.rb

This file was deleted.

5 changes: 4 additions & 1 deletion lib/sufia/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ class Engine < ::Rails::Engine
require 'jquery-ui-rails'
require 'flot-rails'
require 'almond-rails'
require 'flip'
require 'jquery-datatables-rails'
require 'flipflop'

config.autoload_paths += %W(
#{config.root}/app/controllers/concerns
Expand All @@ -34,6 +34,9 @@ class Engine < ::Rails::Engine
end

initializer 'configure' do
# Set the path for the flipflop config:
Flipflop::Engine.config_file = Sufia::Engine.root + "config/features.rb"

Sufia.config.tap do |c|
Hydra::Derivatives.ffmpeg_path = c.ffmpeg_path
Hydra::Derivatives.temp_file_base = c.temp_file_base
Expand Down
5 changes: 3 additions & 2 deletions spec/controllers/sufia/admin/strategies_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
sign_in user
end
let(:user) { create(:user) }
let(:strategy) { Flipflop::Strategies::ActiveRecordStrategy.new(class: Sufia::Feature).key }

context "when not authorized" do
it "redirects away" do
patch :update, params: { feature_id: '123', id: 'database' }
patch :update, params: { feature_id: '123', id: strategy }
expect(response).to redirect_to root_path
end
end
Expand All @@ -21,7 +22,7 @@
end

it "is successful" do
patch :update, params: { feature_id: '123', id: 'database' }
patch :update, params: { feature_id: '123', id: strategy }
expect(response).to redirect_to Sufia::Engine.routes.url_helpers.admin_features_path
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/models/flip_spec.rb → spec/models/flipflop_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

RSpec.describe Flip do
RSpec.describe Flipflop do
describe "assign_admin_set?" do
subject { described_class.assign_admin_set? }
it { is_expected.to be true }
Expand Down
2 changes: 1 addition & 1 deletion spec/test_app_templates/Gemfile.extra
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Use this file to reference specific commits of gems.
gem 'acts_as_follower', git: 'https://github.com/awjecc/acts_as_follower.git', branch: 'rails5-fix-parent_class_name'
gem 'flip', git: 'https://github.com/jcoyne/flip.git', branch: 'alternate_classes'
gem 'flipflop', git: 'https://github.com/jcoyne/flipflop.git', branch: 'hydra'

group :development do
gem 'better_errors'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

context 'with assign_admin_set turned on' do
before do
allow(Flip).to receive(:assign_admin_set?).and_return(true)
allow(Flipflop).to receive(:assign_admin_set?).and_return(true)
end

it "draws the page" do
Expand All @@ -39,7 +39,7 @@

context 'with assign_admin_set disabled' do
before do
allow(Flip).to receive(:assign_admin_set?).and_return(false)
allow(Flipflop).to receive(:assign_admin_set?).and_return(false)
end
it 'draws the page, but not the admin set widget' do
expect(page).not_to have_content('administrative set')
Expand Down
2 changes: 1 addition & 1 deletion sufia.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Gem::Specification.new do |spec|
spec.add_dependency 'flot-rails', '~> 0.0.6'
spec.add_dependency 'almond-rails', '~> 0.0.1'
spec.add_dependency 'qa', '~> 0.8' # questioning_authority
spec.add_dependency 'flip', '~> 1.1'
spec.add_dependency 'flipflop', '~> 2.2'
spec.add_dependency 'jquery-datatables-rails', '~> 3.3.0'

spec.add_development_dependency 'engine_cart', '~> 1.0'
Expand Down

0 comments on commit 3b4fd55

Please sign in to comment.