1
0
mirror of https://github.com/projekteuler/projekteuler.git synced 2025-12-10 08:46:41 +01:00

Move translation viewing to admin namespace

This commit is contained in:
Philipp Fischbeck 2015-02-16 09:37:13 +01:00
parent 49c7d97a41
commit 6b463417ba
26 changed files with 96 additions and 39 deletions

View 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/

View 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/

View 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/

View 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/

View File

@ -0,0 +1,4 @@
class Admin::DashboardController < AdminController
def index
end
end

View 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

View File

@ -0,0 +1,3 @@
class AdminController < ApplicationController
before_action :authenticate_admin!
end

View File

@ -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

View File

@ -1,5 +1,4 @@
class ProblemsController < ApplicationController
skip_before_action :authenticate_admin!, only: [:index, :show]
before_action :set_problem, only: [:show]
def index

View File

@ -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)

View File

@ -0,0 +1,2 @@
module Admin::DashboardHelper
end

View File

@ -0,0 +1,2 @@
module Admin::TranslationsHelper
end

View File

@ -0,0 +1,2 @@
<h1><%= t('.administration') %></h1>
<%= link_to t('.view_translations'), admin_translations_path %>

View File

@ -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>

View File

@ -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 %>

View File

@ -0,0 +1,6 @@
de:
admin:
dashboard:
index:
administration: "Administration"
view_translations: "Übersetzungen anschauen"

View File

@ -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.

View File

@ -3,7 +3,11 @@ Rails.application.routes.draw do
resources :problems, only: [:index, :show] do
resources :translations, only: [:new, :create]
end
namespace :admin do
get '', to: 'dashboard#index', as: '/'
resources :translations, only: [:index, :show]
end
mathjax 'mathjax'

View 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

View 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

View File

@ -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

View File

@ -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