mirror of
https://github.com/projekteuler/projekteuler.git
synced 2025-12-10 00:36:42 +01:00
Add problem count changing to the admin dashboard
This commit is contained in:
parent
ae9315a623
commit
95b84f003c
@ -1,4 +1,16 @@
|
||||
class Admin::DashboardController < AdminController
|
||||
def index
|
||||
@current_problem_count = Problem.count
|
||||
end
|
||||
|
||||
def update_problem_count
|
||||
begin
|
||||
new_problem_count = params[:problem_count].to_i
|
||||
raise t('no_problem_count') unless new_problem_count
|
||||
Problem.update_count(new_problem_count)
|
||||
redirect_to({:controller => 'admin/dashboard', :action => :index}, notice: t('.success_message'))
|
||||
rescue => e
|
||||
redirect_to({:controller => 'admin/dashboard', :action => :index}, alert: t('.failure_message', error: e.message))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -1,2 +1,8 @@
|
||||
<h1><%= t('.administration') %></h1>
|
||||
<%= link_to t('.view_translations'), admin_translations_path %>
|
||||
<%= link_to t('.view_translations'), admin_translations_path, class: 'btn btn-default' %>
|
||||
|
||||
<h1><%= t('.update_problem_count') %></h1>
|
||||
<%= form_tag '/admin/update_problem_count', method: :post, class: 'form-inline' do %>
|
||||
<%= number_field_tag 'problem_count', @current_problem_count, min: @current_problem_count, class: 'form-control' %>
|
||||
<%= submit_tag t('.update'), class: 'btn btn-warning' %>
|
||||
<% end %>
|
||||
@ -3,4 +3,10 @@ de:
|
||||
dashboard:
|
||||
index:
|
||||
administration: "Administration"
|
||||
view_translations: "Übersetzungen anschauen"
|
||||
view_translations: "Übersetzungen anschauen"
|
||||
update_problem_count: "Problem-Anzahl aktualisieren"
|
||||
update: "Aktualisieren"
|
||||
update_problem_count:
|
||||
success_message: "Problem-Anzahl wurde erfolgreich aktualisiert!"
|
||||
failure_message: "Problem-Anzahl konnte nicht aktualisiert werden! Grund: %{error}"
|
||||
no_problem_count: "Keine Problem-Anzahl gegeben!"
|
||||
@ -6,6 +6,7 @@ Rails.application.routes.draw do
|
||||
|
||||
namespace :admin do
|
||||
get '', to: 'dashboard#index', as: '/'
|
||||
post '/update_problem_count', to: 'dashboard#update_problem_count'
|
||||
resources :translations, only: [:index, :show]
|
||||
end
|
||||
|
||||
|
||||
@ -12,4 +12,10 @@ class Admin::DashboardControllerTest < ActionController::TestCase
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should post new problem count" do
|
||||
post :update_problem_count, problem_count: 15
|
||||
assert_redirected_to controller: 'admin/dashboard', action: 'index'
|
||||
assert_equal 15, Problem.count
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Loading…
Reference in New Issue
Block a user