Skip to content

Commit

Permalink
add deposit enable/disable button to admin
Browse files Browse the repository at this point in the history
  • Loading branch information
JackBlackLight committed Aug 30, 2024
1 parent c446177 commit 3853b4f
Show file tree
Hide file tree
Showing 8 changed files with 1,030 additions and 994 deletions.
12 changes: 12 additions & 0 deletions app/controllers/admin/site_options_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module Admin
class SiteOptionsController < AdminController
load_and_authorize_resource class: SiteOption

def update
option = SiteOption.find_by(name: "deposits_enabled")
option.update(value: params["enable_deposits"])
redirect_back fallback_location: { controller: 'admin/deposits', action: 'index' }
end

end
end
3 changes: 2 additions & 1 deletion app/javascript/packs/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
// To reference this file, add <%= javascript_pack_tag 'application' %> to the appropriate
// layout file, like app/views/layouts/application.html.erb


var Turbolinks = require("turbolinks")
Turbolinks.start()
// Uncomment to copy all static images under ../images to the output folder and reference
// them with the image_pack_tag helper in views (e.g <%= image_pack_tag 'rails.png' %>)
// or the `imagePath` JavaScript helper below.
Expand Down
5 changes: 4 additions & 1 deletion app/models/site_option.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
class SiteOption < ApplicationRecord

validates_presence_of :name
validates :value, inclusion: { in: [ true, false ] }

def self.deposits_enabled
find_by(name: 'deposits_enabled')&.value || false
find_by(name: 'deposits_enabled')&.value
end

end
Expand Down
18 changes: 15 additions & 3 deletions app/views/admin/deposits/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
<h2>Self-Deposits</h2>
<div class="pagination"> <%= will_paginate @posts %></div>
<h2>Self-Deposits <%= @posts %>
</h2>
<%= form_with url: admin_site_options_path, method: :patch do |form| %>
<% if deposits_enabled? %>
<% deposit_action = "Disable" %>
<% enable = false %>
<% else %>
<% deposit_action = "Enable" %>
<% enable = true %>
<% end %>
<%= form.hidden_field :enable_deposits, value: enable %>
<%= form.submit "#{deposit_action} Deposits" %>
<% end %>
<div class="pagination"> <%= will_paginate @deposits %></div>
<table class="table">
<thead>
<tr>
Expand Down Expand Up @@ -28,4 +40,4 @@
<% end %>
</tbody>
</table>
<div class="pagination"> <%= will_paginate @posts %></div>
<div class="pagination"> <%= will_paginate @deposits %></div>
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
get 'author_affiliation_report/create'
resources :request_agreements, only: [:new, :create]
resource :alert_message, only: [:edit, :update]
resource :site_options, only: [:edit, :update]
resources :deposits, only: [:index, :show]
resources :agreements, only: :index
resources :email_preferences
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"popper.js": "1.16.1",
"readmore-js": "^3.0.0-beta-1",
"resolve-url-loader": "^4.0.0",
"turbolinks": "^5.2.0",
"typeahead.js": "^0.11.1",
"url-loader": "^4.1.1",
"video.js": "^7.17.0",
Expand Down
3 changes: 2 additions & 1 deletion spec/features/homepage_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,17 @@
context 'when deposits are enabled' do
before do
SiteOption.create!(name: 'deposits_enabled', value: true)
visit root_path
end
it 'links to the upload page' do
# this needs to look for a link by href
expect(page).to have_css('a[href="/upload"]')
end
end

context 'when deposits are disabled' do
before do
SiteOption.create!(name: 'deposits_enabled', value: false)
visit root_path
end
it 'does not link to the upload page' do
expect(page).not_to have_css('a[href="/upload"]')
Expand Down
1,981 changes: 993 additions & 988 deletions yarn.lock

Large diffs are not rendered by default.

0 comments on commit 3853b4f

Please sign in to comment.