1
0
mirror of https://github.com/projekteuler/projekteuler.git synced 2026-01-26 18:18:51 +01:00

Merge remote-tracking branch 'origin/master' into translation-tips

# Conflicts:
#	app/controllers/translations_controller.rb
This commit is contained in:
2019-02-02 19:23:55 +01:00
36 changed files with 455 additions and 315 deletions

View File

@@ -1,3 +1,6 @@
# 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/
$(document).on "turbolinks:load", ->
$('[data-toggle="tooltip"]').tooltip()

View File

@@ -1,18 +1,28 @@
class Admin::TranslationsController < AdminController
before_action :set_translation, only: :show
before_action :set_translation, only: [:show, :accept, :decline]
# GET /translations
# GET /translations.json
def index
@translations = Translation.paginate(page: params[:page])
@translations = Translation.pending.order(created_at: :desc).paginate(page: params[:page])
end
# GET /translations/1
# GET /translations/1.json
def show
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
@translation = Translation.find(params[:id])
@translation = Translation.find(params[:translation_id])
end
end

View File

@@ -1,38 +1,32 @@
class TranslationsController < ApplicationController
before_action :set_problem, only: [:new, :create]
# GET /translations/new
def new
@translation = @problem.translations.build
if @problem.is_translated?
@translation.title = @problem.translation.title
@translation.content = @problem.translation.content
end
end
# POST /translations
# POST /translations.json
def create
@translation = @problem.translations.new(translation_params)
respond_to do |format|
if @translation.save
format.html { redirect_to @problem, notice: t('translations.notice.successfully_created') }
format.json { render :show, status: :created, location: @translation }
else
format.html { render :new }
format.json { render json: @translation.errors, status: :unprocessable_entity }
end
end
end
private
# Never trust parameters from the scary internet, only allow the white list through.
def translation_params
params.require(:translation).permit(:title, :content)
end
def set_problem
@problem = Problem.find(params[:problem_id])
end
end
class TranslationsController < ApplicationController
before_action :set_problem, only: [:new, :create]
# GET /translations/new
def new
@translation = @problem.translations.build
if @problem.is_translated?
@translation.title = @problem.translation.title
@translation.content = @problem.translation.content
end
end
# POST /translations
def create
@translation = @problem.translations.new(translation_params)
if @translation.save
redirect_to @problem, notice: t('translations.notice.successfully_created')
else
render :new
end
end
private
# Never trust parameters from the scary internet, only allow the white list through.
def translation_params
params.require(:translation).permit(:title, :content)
end
def set_problem
@problem = Problem.find(params[:problem_id])
end
end

View File

@@ -11,6 +11,14 @@ class Problem < ApplicationRecord
!!self.translation
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
"https://projecteuler.net/problem=#{self.id}"
end

View File

@@ -1,5 +1,6 @@
class Translation < ApplicationRecord
belongs_to :problem, inverse_of: :translations
enum status: [:pending, :in_use, :outdated, :declined]
validates :title, :content, :problem_id, presence: true
validate :title_is_unique_among_other_problems

View File

@@ -14,7 +14,7 @@
<div class="row">
<div class="col-md-4">
<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>
<%= link_to problems_path, class: 'btn btn-default' do %>
Zu den Problemen &raquo;
@@ -22,14 +22,13 @@
</p>
</div>
<div class="col-md-4">
<h2>Erweitern</h2>
<p>Sie haben in Zukunft auch die Möglichkeit, eigene Übersetzungen vorzuschlagen. An diesem Feature wird aber zurzeit noch gearbeitet.</p>
<p><a class="btn btn-default disabled" href="#" role="button">Übersetzung vorschlagen &raquo;</a></p>
<h2>Übersetzen</h2>
<p>Bisher wurden erst <%= Problem.translated_count %> der <%= Problem.count %> Probleme übersetzt. Helfen Sie mit, Übersetzungen zu erstellen und anzupassen!</p>
</div>
<div class="col-md-4">
<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><a class="btn btn-default disabled" href="#" role="button">Zum Kontaktformular &raquo;</a></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" href="https://github.com/pfischbeck/projekteuler" target="_blank" role="button">Projekt Euler auf GitHub &raquo;</a></p>
</div>
</div>
</div>

View File

@@ -6,7 +6,8 @@
<table class="table table-striped table-bordered">
<thead>
<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>
</tr>
</thead>
@@ -14,7 +15,8 @@
<tbody>
<% @translations.each do |translation| %>
<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>
</tr>
<% end %>

View File

@@ -4,6 +4,20 @@
<h1><%= @translation.title %> <small><%= t 'problems.show.problem_subtitle', id: @translation.problem_id %></small></h1>
</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 %>
<div class="panel-body problem-content">
<%= sanitize @translation.content %>

View File

@@ -16,19 +16,19 @@
"HTML-CSS": { availableFonts: ["TeX"] }
});
</script>
<%= mathjax_tag config: 'TeX-AMS_HTML' %>
<script src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS_HTML' async></script>
<%= csrf_meta_tags %>
</head>
<body>
<%= render 'layouts/header' %>
<div class="container">
<%= flash_messages %>
<div class="row">
<div class="col-md-12" role="main">
<main role="main">
<%= render 'layouts/header' %>
<div class="container">
<%= flash_messages %>
<div class="row">
<%= yield %>
</div>
</div>
</div>
</main>
<%= render 'layouts/footer' %>
</body>