mirror of
https://github.com/projekteuler/projekteuler.git
synced 2025-12-10 08:46:41 +01:00
Merge pull request #37 from PFischbeck/admin-panel
Move translation viewing to admin namespace
This commit is contained in:
commit
46540391d8
3
app/assets/javascripts/admin/dashboard.coffee
Normal file
3
app/assets/javascripts/admin/dashboard.coffee
Normal file
@ -0,0 +1,3 @@
|
||||
# Place all the behaviors and hooks related to the matching controller here.
|
||||
# All this logic will automatically be available in application.js.
|
||||
# You can use CoffeeScript in this file: http://coffeescript.org/
|
||||
3
app/assets/javascripts/admin/translations.coffee
Normal file
3
app/assets/javascripts/admin/translations.coffee
Normal file
@ -0,0 +1,3 @@
|
||||
# Place all the behaviors and hooks related to the matching controller here.
|
||||
# All this logic will automatically be available in application.js.
|
||||
# You can use CoffeeScript in this file: http://coffeescript.org/
|
||||
3
app/assets/stylesheets/admin/dashboard.scss
Normal file
3
app/assets/stylesheets/admin/dashboard.scss
Normal file
@ -0,0 +1,3 @@
|
||||
// Place all the styles related to the admin/dashboard controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
3
app/assets/stylesheets/admin/translations.scss
Normal file
3
app/assets/stylesheets/admin/translations.scss
Normal file
@ -0,0 +1,3 @@
|
||||
// Place all the styles related to the admin/translations controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
4
app/controllers/admin/dashboard_controller.rb
Normal file
4
app/controllers/admin/dashboard_controller.rb
Normal file
@ -0,0 +1,4 @@
|
||||
class Admin::DashboardController < AdminController
|
||||
def index
|
||||
end
|
||||
end
|
||||
18
app/controllers/admin/translations_controller.rb
Normal file
18
app/controllers/admin/translations_controller.rb
Normal file
@ -0,0 +1,18 @@
|
||||
class Admin::TranslationsController < AdminController
|
||||
before_action :set_translation, only: :show
|
||||
|
||||
# GET /translations
|
||||
# GET /translations.json
|
||||
def index
|
||||
@translations = Translation.paginate(page: params[:page])
|
||||
end
|
||||
|
||||
# GET /translations/1
|
||||
# GET /translations/1.json
|
||||
def show
|
||||
end
|
||||
|
||||
def set_translation
|
||||
@translation = Translation.find(params[:id])
|
||||
end
|
||||
end
|
||||
3
app/controllers/admin_controller.rb
Normal file
3
app/controllers/admin_controller.rb
Normal file
@ -0,0 +1,3 @@
|
||||
class AdminController < ApplicationController
|
||||
before_action :authenticate_admin!
|
||||
end
|
||||
@ -2,5 +2,4 @@ class ApplicationController < ActionController::Base
|
||||
# Prevent CSRF attacks by raising an exception.
|
||||
# For APIs, you may want to use :null_session instead.
|
||||
protect_from_forgery with: :exception
|
||||
before_action :authenticate_admin!
|
||||
end
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
class ProblemsController < ApplicationController
|
||||
skip_before_action :authenticate_admin!, only: [:index, :show]
|
||||
before_action :set_problem, only: [:show]
|
||||
|
||||
def index
|
||||
|
||||
@ -1,19 +1,6 @@
|
||||
class TranslationsController < ApplicationController
|
||||
skip_before_action :authenticate_admin!, only: [:new, :create]
|
||||
before_action :set_translation, only: :show
|
||||
before_action :set_problem, only: [:new, :create]
|
||||
|
||||
# GET /translations
|
||||
# GET /translations.json
|
||||
def index
|
||||
@translations = Translation.paginate(page: params[:page])
|
||||
end
|
||||
|
||||
# GET /translations/1
|
||||
# GET /translations/1.json
|
||||
def show
|
||||
end
|
||||
|
||||
# GET /translations/new
|
||||
def new
|
||||
@translation = @problem.translations.build
|
||||
@ -40,11 +27,6 @@ class TranslationsController < ApplicationController
|
||||
end
|
||||
|
||||
private
|
||||
# Use callbacks to share common setup or constraints between actions.
|
||||
def set_translation
|
||||
@translation = Translation.find(params[:id])
|
||||
end
|
||||
|
||||
# Never trust parameters from the scary internet, only allow the white list through.
|
||||
def translation_params
|
||||
params.require(:translation).permit(:title, :content)
|
||||
|
||||
2
app/helpers/admin/dashboard_helper.rb
Normal file
2
app/helpers/admin/dashboard_helper.rb
Normal file
@ -0,0 +1,2 @@
|
||||
module Admin::DashboardHelper
|
||||
end
|
||||
2
app/helpers/admin/translations_helper.rb
Normal file
2
app/helpers/admin/translations_helper.rb
Normal file
@ -0,0 +1,2 @@
|
||||
module Admin::TranslationsHelper
|
||||
end
|
||||
2
app/views/admin/dashboard/index.html.erb
Normal file
2
app/views/admin/dashboard/index.html.erb
Normal file
@ -0,0 +1,2 @@
|
||||
<h1><%= t('.administration') %></h1>
|
||||
<%= link_to t('.view_translations'), admin_translations_path %>
|
||||
@ -13,7 +13,7 @@
|
||||
<% @translations.each do |translation| %>
|
||||
<tr>
|
||||
<td><%= translation.id %></td>
|
||||
<td><%= link_to translation.title, translation %></td>
|
||||
<td><%= link_to translation.title, [:admin, translation] %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
@ -27,7 +27,7 @@
|
||||
<%= nav class: 'navbar-left' do %>
|
||||
<%= link_to Problem.model_name.human(count: 2), problems_path %>
|
||||
<% if admin_signed_in? %>
|
||||
<%= link_to Translation.model_name.human(count: 2), translations_path %>
|
||||
<%= link_to t('admin.dashboard.index.administration'), :admin %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<%= nav class: 'navbar-right' do %>
|
||||
|
||||
6
config/locales/views/admin/de.yml
Normal file
6
config/locales/views/admin/de.yml
Normal file
@ -0,0 +1,6 @@
|
||||
de:
|
||||
admin:
|
||||
dashboard:
|
||||
index:
|
||||
administration: "Administration"
|
||||
view_translations: "Übersetzungen anschauen"
|
||||
@ -7,7 +7,6 @@ de:
|
||||
source_code: Quelltext
|
||||
translation_source_explanation: Hier kommt der HTML-Quelltext der Übersetzung hin.
|
||||
new:
|
||||
back: Zurück
|
||||
new_translation: Neue Übersetzung für Problem %{id}
|
||||
notice:
|
||||
successfully_created: Übersetzung wurde erfolgreich erstellt.
|
||||
@ -3,7 +3,11 @@ Rails.application.routes.draw do
|
||||
resources :problems, only: [:index, :show] do
|
||||
resources :translations, only: [:new, :create]
|
||||
end
|
||||
resources :translations, only: [:index, :show]
|
||||
|
||||
namespace :admin do
|
||||
get '', to: 'dashboard#index', as: '/'
|
||||
resources :translations, only: [:index, :show]
|
||||
end
|
||||
|
||||
mathjax 'mathjax'
|
||||
|
||||
|
||||
15
test/controllers/admin/dashboard_controller_test.rb
Normal file
15
test/controllers/admin/dashboard_controller_test.rb
Normal file
@ -0,0 +1,15 @@
|
||||
require 'test_helper'
|
||||
|
||||
class Admin::DashboardControllerTest < ActionController::TestCase
|
||||
include Devise::TestHelpers
|
||||
|
||||
setup do
|
||||
login
|
||||
end
|
||||
|
||||
test "should get index" do
|
||||
get :index
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
end
|
||||
21
test/controllers/admin/translations_controller_test.rb
Normal file
21
test/controllers/admin/translations_controller_test.rb
Normal file
@ -0,0 +1,21 @@
|
||||
require 'test_helper'
|
||||
|
||||
class Admin::TranslationsControllerTest < ActionController::TestCase
|
||||
include Devise::TestHelpers
|
||||
|
||||
setup do
|
||||
login
|
||||
@translation = translations(:translation_one)
|
||||
end
|
||||
test "should get index" do
|
||||
get :index
|
||||
assert_response :success
|
||||
assert_not_nil assigns(:translations)
|
||||
end
|
||||
|
||||
test "should show translation" do
|
||||
get :show, id: @translation
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
end
|
||||
@ -4,7 +4,6 @@ class TranslationsControllerTest < ActionController::TestCase
|
||||
include Devise::TestHelpers
|
||||
|
||||
setup do
|
||||
@translation = translations(:translation_one)
|
||||
@update = {
|
||||
title: 'New title',
|
||||
content: 'This is the new content',
|
||||
@ -13,14 +12,6 @@ class TranslationsControllerTest < ActionController::TestCase
|
||||
title: '',
|
||||
content: ''
|
||||
}
|
||||
@admin = admins(:admin)
|
||||
end
|
||||
|
||||
test "should get index" do
|
||||
sign_in @admin
|
||||
get :index
|
||||
assert_response :success
|
||||
assert_not_nil assigns(:translations)
|
||||
end
|
||||
|
||||
test "should get new for translated problem" do
|
||||
@ -46,10 +37,4 @@ class TranslationsControllerTest < ActionController::TestCase
|
||||
post :create, problem_id: 1, translation: @incorrect
|
||||
end
|
||||
end
|
||||
|
||||
test "should show translation" do
|
||||
sign_in @admin
|
||||
get :show, id: @translation
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
|
||||
@ -10,4 +10,8 @@ class ActiveSupport::TestCase
|
||||
fixtures :all
|
||||
|
||||
# Add more helper methods to be used by all tests here...
|
||||
def login
|
||||
admin = admins(:admin)
|
||||
sign_in admin
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
Reference in New Issue
Block a user