diff --git a/app/assets/javascripts/admin/translations.coffee b/app/assets/javascripts/admin/translations.js.coffee similarity index 73% rename from app/assets/javascripts/admin/translations.coffee rename to app/assets/javascripts/admin/translations.js.coffee index 24f83d1..42cfbbe 100644 --- a/app/assets/javascripts/admin/translations.coffee +++ b/app/assets/javascripts/admin/translations.js.coffee @@ -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() \ No newline at end of file diff --git a/app/controllers/admin/translations_controller.rb b/app/controllers/admin/translations_controller.rb index db013f0..aef7ebc 100644 --- a/app/controllers/admin/translations_controller.rb +++ b/app/controllers/admin/translations_controller.rb @@ -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 diff --git a/app/controllers/translations_controller.rb b/app/controllers/translations_controller.rb index f3b0e70..25a0eab 100644 --- a/app/controllers/translations_controller.rb +++ b/app/controllers/translations_controller.rb @@ -11,18 +11,12 @@ class TranslationsController < ApplicationController 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 + if @translation.save + redirect_to @problem, notice: t('translations.notice.successfully_created') + else + render :new end end diff --git a/app/models/problem.rb b/app/models/problem.rb index a6ba173..6a712f6 100644 --- a/app/models/problem.rb +++ b/app/models/problem.rb @@ -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 diff --git a/app/models/translation.rb b/app/models/translation.rb index e4695b6..35be7a1 100644 --- a/app/models/translation.rb +++ b/app/models/translation.rb @@ -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 diff --git a/app/views/about/index.de.html.erb b/app/views/about/index.de.html.erb index 6dd18b4..b18873f 100644 --- a/app/views/about/index.de.html.erb +++ b/app/views/about/index.de.html.erb @@ -14,7 +14,7 @@
Bisher wurden leider erst <%= Problem.translated_count %> der <%= Problem.count %> Probleme übersetzt, es gibt also noch einiges zu tun!
+Sehen Sie sich die mathematischen Probleme in deutscher Sprache an.
<%= link_to problems_path, class: 'btn btn-default' do %> Zu den Problemen » @@ -22,14 +22,13 @@
Sie haben in Zukunft auch die Möglichkeit, eigene Übersetzungen vorzuschlagen. An diesem Feature wird aber zurzeit noch gearbeitet.
- +Bisher wurden erst <%= Problem.translated_count %> der <%= Problem.count %> Probleme übersetzt. Helfen Sie mit, Übersetzungen zu erstellen und anzupassen!
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!
- +Vermissen Sie eine Funktion auf der Webseite, oder ist Ihnen ein Fehler aufgefallen? Dann helfen Sie beim Entwickeln der Webseite in Ruby on Rails!
+| <%= Translation.human_attribute_name(:id) %> | +<%= Translation.human_attribute_name(:created_at) %> | +<%= Translation.human_attribute_name(:problem_id) %> | <%= Translation.human_attribute_name(:title) %> |
|---|---|---|---|
| <%= translation.id %> | +<%= time_ago_in_words(translation.created_at) %> |
+ <%= translation.problem_id %> | <%= link_to translation.title, [:admin, translation] %> |