mirror of
https://github.com/projekteuler/projekteuler.git
synced 2025-12-10 08:46:41 +01:00
Merge pull request #67 from PFischbeck/translation_reviewing
Translation reviewing
This commit is contained in:
commit
b84b7fead7
@ -1,3 +1,6 @@
|
|||||||
# Place all the behaviors and hooks related to the matching controller here.
|
# Place all the behaviors and hooks related to the matching controller here.
|
||||||
# All this logic will automatically be available in application.js.
|
# All this logic will automatically be available in application.js.
|
||||||
# You can use CoffeeScript in this file: http://coffeescript.org/
|
# You can use CoffeeScript in this file: http://coffeescript.org/
|
||||||
|
|
||||||
|
$(document).on "turbolinks:load", ->
|
||||||
|
$('[data-toggle="tooltip"]').tooltip()
|
||||||
@ -1,18 +1,28 @@
|
|||||||
class Admin::TranslationsController < AdminController
|
class Admin::TranslationsController < AdminController
|
||||||
before_action :set_translation, only: :show
|
before_action :set_translation, only: [:show, :accept, :decline]
|
||||||
|
|
||||||
# GET /translations
|
# GET /translations
|
||||||
# GET /translations.json
|
|
||||||
def index
|
def index
|
||||||
@translations = Translation.paginate(page: params[:page])
|
@translations = Translation.pending.order(created_at: :desc).paginate(page: params[:page])
|
||||||
end
|
end
|
||||||
|
|
||||||
# GET /translations/1
|
# GET /translations/1
|
||||||
# GET /translations/1.json
|
|
||||||
def show
|
def show
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def accept
|
||||||
|
raise t('.must_be_pending') unless @translation.pending?
|
||||||
|
@translation.problem.set_translation(@translation)
|
||||||
|
redirect_to @translation.problem, notice: t('.success_message')
|
||||||
|
end
|
||||||
|
|
||||||
|
def decline
|
||||||
|
raise t('.must_be_pending') unless @translation.pending?
|
||||||
|
@translation.declined!
|
||||||
|
redirect_to admin_translations_path, notice: t('.success_message')
|
||||||
|
end
|
||||||
|
|
||||||
def set_translation
|
def set_translation
|
||||||
@translation = Translation.find(params[:id])
|
@translation = Translation.find(params[:translation_id])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -11,18 +11,12 @@ class TranslationsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
# POST /translations
|
# POST /translations
|
||||||
# POST /translations.json
|
|
||||||
def create
|
def create
|
||||||
@translation = @problem.translations.new(translation_params)
|
@translation = @problem.translations.new(translation_params)
|
||||||
|
|
||||||
respond_to do |format|
|
|
||||||
if @translation.save
|
if @translation.save
|
||||||
format.html { redirect_to @problem, notice: t('translations.notice.successfully_created') }
|
redirect_to @problem, notice: t('translations.notice.successfully_created')
|
||||||
format.json { render :show, status: :created, location: @translation }
|
|
||||||
else
|
else
|
||||||
format.html { render :new }
|
render :new
|
||||||
format.json { render json: @translation.errors, status: :unprocessable_entity }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -11,6 +11,14 @@ class Problem < ApplicationRecord
|
|||||||
!!self.translation
|
!!self.translation
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def set_translation(translation)
|
||||||
|
if self.is_translated?
|
||||||
|
self.translation.outdated!
|
||||||
|
end
|
||||||
|
self.update(translation: translation)
|
||||||
|
self.translation.in_use!
|
||||||
|
end
|
||||||
|
|
||||||
def original_url
|
def original_url
|
||||||
"https://projecteuler.net/problem=#{self.id}"
|
"https://projecteuler.net/problem=#{self.id}"
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
class Translation < ApplicationRecord
|
class Translation < ApplicationRecord
|
||||||
belongs_to :problem, inverse_of: :translations
|
belongs_to :problem, inverse_of: :translations
|
||||||
|
enum status: [:pending, :in_use, :outdated, :declined]
|
||||||
|
|
||||||
validates :title, :content, :problem_id, presence: true
|
validates :title, :content, :problem_id, presence: true
|
||||||
validate :title_is_unique_among_other_problems
|
validate :title_is_unique_among_other_problems
|
||||||
|
|||||||
@ -14,7 +14,7 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-4">
|
<div class="col-md-4">
|
||||||
<h2>Ansehen</h2>
|
<h2>Ansehen</h2>
|
||||||
<p>Bisher wurden leider erst <%= Problem.translated_count %> der <%= Problem.count %> Probleme übersetzt, es gibt also noch einiges zu tun!</p>
|
<p>Sehen Sie sich die mathematischen Probleme in deutscher Sprache an.</p>
|
||||||
<p>
|
<p>
|
||||||
<%= link_to problems_path, class: 'btn btn-default' do %>
|
<%= link_to problems_path, class: 'btn btn-default' do %>
|
||||||
Zu den Problemen »
|
Zu den Problemen »
|
||||||
@ -22,14 +22,13 @@
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-4">
|
<div class="col-md-4">
|
||||||
<h2>Erweitern</h2>
|
<h2>Übersetzen</h2>
|
||||||
<p>Sie haben in Zukunft auch die Möglichkeit, eigene Übersetzungen vorzuschlagen. An diesem Feature wird aber zurzeit noch gearbeitet.</p>
|
<p>Bisher wurden erst <%= Problem.translated_count %> der <%= Problem.count %> Probleme übersetzt. Helfen Sie mit, Übersetzungen zu erstellen und anzupassen!</p>
|
||||||
<p><a class="btn btn-default disabled" href="#" role="button">Übersetzung vorschlagen »</a></p>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-4">
|
<div class="col-md-4">
|
||||||
<h2>Verbessern</h2>
|
<h2>Verbessern</h2>
|
||||||
<p>Haben Sie Verbesserungsvorschläge für eine der Übersetzungen? Fehlt Ihnen eine Funktion auf der Webseite, oder ist Ihnen ein Fehler aufgefallen? Dann schreiben Sie uns!</p>
|
<p>Vermissen Sie eine Funktion auf der Webseite, oder ist Ihnen ein Fehler aufgefallen? Dann helfen Sie beim Entwickeln der Webseite in Ruby on Rails!</p>
|
||||||
<p><a class="btn btn-default disabled" href="#" role="button">Zum Kontaktformular »</a></p>
|
<p><a class="btn btn-default" href="https://github.com/pfischbeck/projekteuler" target="_blank" role="button">Projekt Euler auf GitHub »</a></p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -6,7 +6,8 @@
|
|||||||
<table class="table table-striped table-bordered">
|
<table class="table table-striped table-bordered">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th><%= Translation.human_attribute_name(:id) %></th>
|
<th><%= Translation.human_attribute_name(:created_at) %></th>
|
||||||
|
<th><%= Translation.human_attribute_name(:problem_id) %></th>
|
||||||
<th><%= Translation.human_attribute_name(:title) %></th>
|
<th><%= Translation.human_attribute_name(:title) %></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@ -14,7 +15,8 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
<% @translations.each do |translation| %>
|
<% @translations.each do |translation| %>
|
||||||
<tr>
|
<tr>
|
||||||
<td><%= translation.id %></td>
|
<td><div data-toggle="tooltip" data-placement="left" title="<%= l translation.created_at %>"><%= time_ago_in_words(translation.created_at) %></div></td>
|
||||||
|
<td><%= translation.problem_id %></td>
|
||||||
<td><%= link_to translation.title, [:admin, translation] %></td>
|
<td><%= link_to translation.title, [:admin, translation] %></td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@ -4,6 +4,20 @@
|
|||||||
<h1><%= @translation.title %> <small><%= t 'problems.show.problem_subtitle', id: @translation.problem_id %></small></h1>
|
<h1><%= @translation.title %> <small><%= t 'problems.show.problem_subtitle', id: @translation.problem_id %></small></h1>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<% if @translation.problem.is_translated? %>
|
||||||
|
<div class="alert alert-warning" role="alert"><%= t('.already_translated') %> <%= link_to t('.visit_current_translation'), @translation.problem, target: '_blank', class: 'alert-link' %></div>
|
||||||
|
<% else %>
|
||||||
|
<div class="alert alert-info" role="alert"><%= t('.is_new_translation') %></div>
|
||||||
|
<% end %>
|
||||||
|
<% if @translation.pending? %>
|
||||||
|
<%= link_to admin_translation_decline_path(@translation), method: :post, class: 'btn btn-default btn-sm pull-right' do %>
|
||||||
|
<%= icon :remove %> <%= t '.decline_translation' %>
|
||||||
|
<% end %>
|
||||||
|
<%= link_to admin_translation_accept_path(@translation), method: :post, class: 'btn btn-default btn-sm pull-right' do %>
|
||||||
|
<%= icon :ok %> <%= t '.accept_translation' %>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
<%= panel do %>
|
<%= panel do %>
|
||||||
<div class="panel-body problem-content">
|
<div class="panel-body problem-content">
|
||||||
<%= sanitize @translation.content %>
|
<%= sanitize @translation.content %>
|
||||||
|
|||||||
@ -20,15 +20,15 @@
|
|||||||
<%= csrf_meta_tags %>
|
<%= csrf_meta_tags %>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<%= render 'layouts/header' %>
|
<main role="main">
|
||||||
<div class="container">
|
<%= render 'layouts/header' %>
|
||||||
|
<div class="container">
|
||||||
<%= flash_messages %>
|
<%= flash_messages %>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-12" role="main">
|
|
||||||
<%= yield %>
|
<%= yield %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</main>
|
||||||
|
|
||||||
<%= render 'layouts/footer' %>
|
<%= render 'layouts/footer' %>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@ -10,3 +10,15 @@ de:
|
|||||||
success_message: "Problem-Anzahl wurde erfolgreich aktualisiert!"
|
success_message: "Problem-Anzahl wurde erfolgreich aktualisiert!"
|
||||||
failure_message: "Problem-Anzahl konnte nicht aktualisiert werden! Grund: %{error}"
|
failure_message: "Problem-Anzahl konnte nicht aktualisiert werden! Grund: %{error}"
|
||||||
no_problem_count: "Keine Problem-Anzahl gegeben!"
|
no_problem_count: "Keine Problem-Anzahl gegeben!"
|
||||||
|
translations:
|
||||||
|
must_be_pending: "Übersetzung muss ausstehend sein, um akzeptiert oder abgelehnt zu werden!"
|
||||||
|
show:
|
||||||
|
accept_translation: "Akzeptieren"
|
||||||
|
decline_translation: "Ablehnen"
|
||||||
|
visit_current_translation: "Aktuelle Übersetzung anschauen"
|
||||||
|
already_translated: "Dieses Problem wurde bereits übersetzt."
|
||||||
|
is_new_translation: "Dieses Problem hat bisher keine Übersetzung."
|
||||||
|
accept:
|
||||||
|
success_message: "Übersetzung wurde erfolgreich akzeptiert!"
|
||||||
|
decline:
|
||||||
|
success_message: "Übersetzung wurde erfolgreich abgelehnt!"
|
||||||
@ -1,6 +1,9 @@
|
|||||||
# ruby encoding: utf-8
|
# ruby encoding: utf-8
|
||||||
|
|
||||||
de:
|
de:
|
||||||
|
attributes:
|
||||||
|
created_at: Erstellt
|
||||||
|
updated_at: Aktualisiert
|
||||||
application:
|
application:
|
||||||
site_title: "Projekt Euler"
|
site_title: "Projekt Euler"
|
||||||
sign_in: 'Einloggen'
|
sign_in: 'Einloggen'
|
||||||
@ -9,3 +12,7 @@ de:
|
|||||||
legal: "Impressum"
|
legal: "Impressum"
|
||||||
copyright: "Copyright-Informationen"
|
copyright: "Copyright-Informationen"
|
||||||
bootstrap_html: 'Entworfen mit <a href="http://getbootstrap.com/">Bootstrap</a>'
|
bootstrap_html: 'Entworfen mit <a href="http://getbootstrap.com/">Bootstrap</a>'
|
||||||
|
helpers:
|
||||||
|
submit:
|
||||||
|
translation:
|
||||||
|
create: "%{model} vorschlagen"
|
||||||
|
|||||||
@ -9,4 +9,4 @@ de:
|
|||||||
new:
|
new:
|
||||||
new_translation: Neue Übersetzung für Problem %{id}
|
new_translation: Neue Übersetzung für Problem %{id}
|
||||||
notice:
|
notice:
|
||||||
successfully_created: Übersetzung wurde erfolgreich erstellt.
|
successfully_created: Der Übersetzungsvorschlag wurde eingereicht. Ein Organisator wird sich Ihren Vorschlag so bald wie möglich anschauen.
|
||||||
@ -26,6 +26,10 @@ Rails.application.routes.draw do
|
|||||||
namespace :admin do
|
namespace :admin do
|
||||||
get '', to: 'dashboard#index', as: 'dashboard_index'
|
get '', to: 'dashboard#index', as: 'dashboard_index'
|
||||||
post '/update_problem_count', to: 'dashboard#update_problem_count', as: 'dashboard_update_problem_count'
|
post '/update_problem_count', to: 'dashboard#update_problem_count', as: 'dashboard_update_problem_count'
|
||||||
resources :translations, only: [:index, :show]
|
resources :translations, only: [:index] do
|
||||||
|
get '', to: 'translations#show', as: ''
|
||||||
|
post 'accept', to: 'translations#accept'
|
||||||
|
post 'decline', to: 'translations#decline'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
15
db/migrate/20190202113250_add_status_to_translations.rb
Normal file
15
db/migrate/20190202113250_add_status_to_translations.rb
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
class AddStatusToTranslations < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
add_column :translations, :status, :integer, default: 0
|
||||||
|
|
||||||
|
reversible do |dir|
|
||||||
|
dir.up do
|
||||||
|
Problem.all.each do |problem|
|
||||||
|
if problem.is_translated?
|
||||||
|
problem.translation.in_use!
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@ -10,7 +10,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20150131103802) do
|
ActiveRecord::Schema.define(version: 2019_02_02_113250) do
|
||||||
|
|
||||||
create_table "admins", force: :cascade do |t|
|
create_table "admins", force: :cascade do |t|
|
||||||
t.string "email", default: "", null: false
|
t.string "email", default: "", null: false
|
||||||
@ -42,6 +42,7 @@ ActiveRecord::Schema.define(version: 20150131103802) do
|
|||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
t.integer "problem_id"
|
t.integer "problem_id"
|
||||||
|
t.integer "status", default: 0
|
||||||
t.index ["problem_id"], name: "index_translations_on_problem_id"
|
t.index ["problem_id"], name: "index_translations_on_problem_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -27,7 +27,7 @@ for i in 1..10 do
|
|||||||
)
|
)
|
||||||
|
|
||||||
problem = Problem.find(i)
|
problem = Problem.find(i)
|
||||||
problem.translation = translation
|
problem.set_translation(translation)
|
||||||
problem.save!
|
problem.save!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -6,6 +6,7 @@ class Admin::TranslationsControllerTest < ActionDispatch::IntegrationTest
|
|||||||
setup do
|
setup do
|
||||||
login
|
login
|
||||||
@translation = translations(:translation_one)
|
@translation = translations(:translation_one)
|
||||||
|
@translation_alternative = translations(:translation_two_alternative)
|
||||||
end
|
end
|
||||||
test "should get index" do
|
test "should get index" do
|
||||||
get admin_translations_url
|
get admin_translations_url
|
||||||
@ -14,8 +15,19 @@ class Admin::TranslationsControllerTest < ActionDispatch::IntegrationTest
|
|||||||
end
|
end
|
||||||
|
|
||||||
test "should show translation" do
|
test "should show translation" do
|
||||||
get admin_translation_url(id: @translation)
|
get admin_translation_url(translation_id: @translation)
|
||||||
assert_response :success
|
assert_response :success
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "should accept translation" do
|
||||||
|
post admin_translation_accept_path(@translation_alternative)
|
||||||
|
assert_redirected_to problem_path(2)
|
||||||
|
assert_equal @translation_alternative, Problem.find(2).translation
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should decline translation" do
|
||||||
|
post admin_translation_decline_path(@translation_alternative)
|
||||||
|
assert_redirected_to admin_translations_path
|
||||||
|
assert Translation.find(@translation_alternative.id).declined?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
8
test/fixtures/translations.yml
vendored
8
test/fixtures/translations.yml
vendored
@ -4,8 +4,16 @@ translation_one:
|
|||||||
problem_id: 1
|
problem_id: 1
|
||||||
title: First title
|
title: First title
|
||||||
content: The content of the translation
|
content: The content of the translation
|
||||||
|
status: 1
|
||||||
|
|
||||||
translation_two:
|
translation_two:
|
||||||
problem_id: 2
|
problem_id: 2
|
||||||
title: Second title
|
title: Second title
|
||||||
content: The content of the second translation
|
content: The content of the second translation
|
||||||
|
status: 1
|
||||||
|
|
||||||
|
translation_two_alternative:
|
||||||
|
problem_id: 2
|
||||||
|
title: Second title
|
||||||
|
content: The changed content for the second problem
|
||||||
|
status: 0
|
||||||
|
|||||||
@ -14,6 +14,13 @@ class ProblemTest < ActiveSupport::TestCase
|
|||||||
assert problems(:one).is_translated?
|
assert problems(:one).is_translated?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "set_translation should modify status correctly" do
|
||||||
|
problems(:two).set_translation(translations(:translation_two_alternative))
|
||||||
|
assert translations(:translation_two).outdated?
|
||||||
|
assert translations(:translation_two_alternative).in_use?
|
||||||
|
assert_equal translations(:translation_two_alternative), problems(:two).translation
|
||||||
|
end
|
||||||
|
|
||||||
test "should have correct original url" do
|
test "should have correct original url" do
|
||||||
assert_equal "https://projecteuler.net/problem=1", problems(:one).original_url
|
assert_equal "https://projecteuler.net/problem=1", problems(:one).original_url
|
||||||
end
|
end
|
||||||
|
|||||||
@ -36,5 +36,6 @@ class TranslationTest < ActiveSupport::TestCase
|
|||||||
problem_id: 1
|
problem_id: 1
|
||||||
)
|
)
|
||||||
assert translation.save
|
assert translation.save
|
||||||
|
assert translation.pending?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user