Skip to content

Commit

Permalink
Merge pull request #473 from scientist-softserv/i472-remove-feature-b…
Browse files Browse the repository at this point in the history
…utton

🧹 disable the feature button and the featured works feat flipper
  • Loading branch information
ShanaLMoore authored Jul 19, 2023
2 parents a35ee09 + 9e5c88a commit 71f0f3c
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/controllers/hyrax/homepage_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def search_builder_class
# OVERRIDE: Hyrax v3.4.2 - For dc_repository add @collections_list

def index
@presenter = presenter_class.new(current_ability, collections)
@presenter = presenter_class.new(current_ability, collections, current_account)
@featured_researcher = ContentBlock.for(:researcher)
@marketing_text = ContentBlock.for(:marketing)
@home_text = ContentBlock.for(:home_text)
Expand Down
1 change: 1 addition & 0 deletions app/helpers/accounts_helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

module AccountsHelper
TENANTS_WITH_NO_WORK_FEATURES = ['dc'].freeze
end
5 changes: 4 additions & 1 deletion app/presenters/hyrax/homepage_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ class HomepagePresenter
self.create_work_presenter_class = Hyrax::SelectTypeListPresenter
attr_reader :current_ability, :collections

def initialize(current_ability, collections)
def initialize(current_ability, collections, current_account = nil)
@current_ability = current_ability
@collections = collections
@current_account = current_account
end

# OVERRIDE: Hyrax v3.4.0 to removed: @return [Boolean] If the
Expand Down Expand Up @@ -56,6 +57,8 @@ def display_featured_researcher?

# changed to add feature flag for featured work
def display_featured_works?
return false if AccountsHelper::TENANTS_WITH_NO_WORK_FEATURES.include?(@current_account.name)

Flipflop.show_featured_works?
end

Expand Down
70 changes: 70 additions & 0 deletions app/views/hyrax/admin/features/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<% #OVERRIDE HYRAX 3.5.0 to skip show_featured_works for the dc tenant %>
<% provide :page_header do %>
<h1><span class="fa fa-wrench" aria-hidden="true"></span> <%= t('.header') %></h1>
<% end %>
<div class="flip row">
<div class="col-md-12">
<div class="card">
<div class="card-body">
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th></th>
<th class="name"><%= t('.feature') %></th>
<th class="description"><%= t('.description') %></th>
<th class="action"><%= t('.action') %></th>
</tr>
</thead>
<tbody>
<% @feature_set.grouped_features.each do |group, features| -%>
<% if @feature_set.grouped? -%>
<tr class="group">
<td></td>
<td class="name" colspan="<%= 2 + @feature_set.strategies.size -%>">
<h2>
<%= t(group ? group.name : :default, scope: [:flipflop, :groups], default: group ? group.title : nil) -%>
</h2>
</td>
</tr>
<% end -%>
<% #OVERRIDE HYRAX 3.5.0 to skip show_featured_works per denylist: TENANTS_WITH_NO_WORK_FEATURES %>
<% modified_features = features.reject { |item| item.instance_variable_get(:@key) == :show_featured_works && AccountsHelper::TENANTS_WITH_NO_WORK_FEATURES.include?(current_account.name) } %>
<% modified_features.each do |feature| %>
<tr data-feature="<%= feature.name.dasherize.parameterize %>">
<td class="status">
<span class="badge badge-<%= @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(hyrax.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 -%>
<% end -%>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
65 changes: 65 additions & 0 deletions app/views/hyrax/base/_show_actions.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<%# OVERRIDE Hyrax 3.5.0 to remove feature work button %>

<div class="row show-actions button-row-top-two-column">
<div class="col-sm-6">
<% if !workflow_restriction?(presenter) %>
<% if presenter.show_deposit_for?(collections: @user_collections) %>
<input type="checkbox" style="display:none" name="batch_document_ids[]" id="batch_document_<%= presenter.id %>" value="<%= presenter.id %>" class="batch_document_selector" checked="checked" />
<%= button_tag t('hyrax.dashboard.my.action.add_to_collection'),
class: 'btn btn-default submits-batches submits-batches-add',
data: { toggle: "modal", target: "#collection-list-container" } %>
<% end %>
<%# OVERRIDE begin %>
<% if presenter.work_featurable? && AccountsHelper::TENANTS_WITH_NO_WORK_FEATURES.include?(@current_account.name) %>
<%= link_to t('.feature'), hyrax.featured_work_path(presenter, format: :json),
data: { behavior: 'feature' },
class: presenter.display_feature_link? ? 'btn btn-default' : 'btn btn-default collapse' %>
<%= link_to t('.unfeature'), hyrax.featured_work_path(presenter, format: :json),
data: { behavior: 'unfeature' },
class: presenter.display_unfeature_link? ? 'btn btn-default' : 'btn btn-default collapse' %>
<% end %>
<%# OVERRIDE end %>
<% end %>
<% if Hyrax.config.analytics? %>
<% # turbolinks needs to be turned off or the page will use the cache and the %>
<% # analytics graph will not show unless the page is refreshed. %>
<%= link_to t('.analytics'), presenter.stats_path, id: 'stats', class: 'btn btn-default', data: { turbolinks: false } %>
<% end %>
</div>
<div class="col-sm-6 text-right">
<% if presenter.editor? && !workflow_restriction?(presenter) %>
<%= link_to t('.edit'), edit_polymorphic_path([main_app, presenter]), class: 'btn btn-default' %>
<% if presenter.member_count > 1 %>
<%= link_to t("hyrax.file_manager.link_text"), polymorphic_path([main_app, :file_manager, presenter]), class: 'btn btn-default' %>
<% end %>
<% if presenter.valid_child_concerns.length > 0 %>
<div class="btn-group">
<button type="button" class="btn btn-default dropdown-toggle" type="button" id="dropdown-menu" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<%= t('.attach_child') %> <span class="caret"></span></button>
<ul class="dropdown-menu">
<% presenter.valid_child_concerns.each do |concern| %>
<li>
<%= link_to "Attach #{concern.human_readable_type}", polymorphic_path([main_app, :new, :hyrax, :parent, concern.model_name.singular.to_sym], parent_id: presenter.id) %>
</li>
<% end %>
</ul>
</div>
<% end %>
<%= link_to t('.delete'), [main_app, presenter], class: 'btn btn-danger', data: { confirm: t('.confirm_delete', work_type: presenter.human_readable_type) }, method: :delete %>
<% end %>
</div>
</div>
<!-- COinS hook for Zotero -->
<span class="Z3988" title="<%= export_as_openurl_ctx_kev(presenter) %>"></span>
<!-- Render Modals -->
<%= render 'hyrax/dashboard/collections/form_for_select_collection', user_collections: @user_collections %>






3 changes: 2 additions & 1 deletion spec/controllers/hyrax/homepage_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@

it "initializes the presenter with ability and a list of collections" do
expect(Hyrax::HomepagePresenter).to receive(:new).with(Ability,
[collection])
[collection],
Account)
.and_return(presenter)
get :index
expect(response).to be_success
Expand Down

0 comments on commit 71f0f3c

Please sign in to comment.