mirror of
https://github.com/projekteuler/projekteuler.git
synced 2026-01-26 18:18:51 +01:00
Add ability to accept or decline translations
This commit is contained in:
@@ -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()
|
||||
@@ -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
|
||||
|
||||
@@ -15,7 +15,7 @@ class Problem < ApplicationRecord
|
||||
if self.is_translated?
|
||||
self.translation.outdated!
|
||||
end
|
||||
self.translation = translation
|
||||
self.update(translation: translation)
|
||||
self.translation.in_use!
|
||||
end
|
||||
|
||||
|
||||
@@ -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 %>
|
||||
|
||||
@@ -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 %>
|
||||
|
||||
Reference in New Issue
Block a user