diff --git a/.travis.yml b/.travis.yml index ca31fe5..7f490c2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,10 @@ language: ruby cache: bundler rvm: + - 2.6 + - 2.5 - 2.4 - 2.3 - - 2.2 script: - export RAILS_ENV=test - bundle exec rake db:create db:migrate diff --git a/Gemfile b/Gemfile index 0099634..f177aa3 100644 --- a/Gemfile +++ b/Gemfile @@ -2,41 +2,43 @@ source 'https://rubygems.org' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' -gem 'rails', '5.1.4' +gem 'rails', '5.2.2' # Use sqlite3 as the database for Active Record gem 'sqlite3', '~> 1.3.13' -gem 'mysql2', '~> 0.4.10', group: :production +gem 'mysql2', '~> 0.5.2', group: :production + +gem 'bootsnap', require: false # Use SCSS for stylesheets -gem 'sass-rails', '~> 5.0.7' +gem 'sassc-rails', '~> 2.1.0' # Use Uglifier as compressor for JavaScript assets -gem 'uglifier', '~> 3.2.0' +gem 'uglifier', '~> 4.1.20' # Use CoffeeScript for .js.coffee assets and views gem 'coffee-rails', '~> 4.2.2' # See https://github.com/sstephenson/execjs#readme for more supported runtimes # gem 'therubyracer', platforms: :ruby -gem 'rails-i18n', '~> 5.0.0' +gem 'rails-i18n', '~> 5.1.3' gem 'rails-controller-testing' # Use jquery as the JavaScript library -gem 'jquery-rails', '~> 4.3.1' +gem 'jquery-rails', '~> 4.3.3' # Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks -gem 'turbolinks', '~> 5.0.1' +gem 'turbolinks', '~> 5.2.0' # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder -gem 'jbuilder', '~> 2.7.0' +gem 'jbuilder', '~> 2.8.0' # bundle exec rake doc:rails generates the API under doc/api. -gem 'sdoc', '~> 0.4.2', group: :doc +gem 'sdoc', '~> 1.0.0', group: :doc -gem 'web-console', '~> 3.5.1', group: :development +gem 'web-console', '~> 3.7.0', group: :development # Use Coveralls for coverage documentation -gem 'coveralls', '~> 0.8.21', require: false +gem 'coveralls', '~> 0.8.22', require: false -gem 'bootstrap-sass', '~> 3.3.7' -gem 'autoprefixer-rails', '~> 7.1.6' +gem 'bootstrap-sass', '~> 3.4.0' +gem 'autoprefixer-rails', '~> 9.4.6' gem 'bh', '~> 1.3.6' @@ -44,9 +46,7 @@ gem 'will_paginate', '~> 3.1.6' gem 'will-paginate-i18n', '~> 0.1.15' gem 'will_paginate-bootstrap', '~> 1.0.1' -gem 'mathjax-rails', '~> 2.6.1' - -gem 'devise', '~> 4.3.0' +gem 'devise', '~> 4.5.0' gem 'devise-bootstrap-views', '~> 0.0.11' gem 'codemirror-rails', '~> 5.16.0' @@ -63,4 +63,4 @@ gem 'codemirror-rails', '~> 5.16.0' # gem 'debugger', group: [:development, :test] # Windows does not include zoneinfo files, so bundle the tzinfo-data gem -gem 'tzinfo-data', platforms: [:mingw, :mswin] +gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw] diff --git a/Gemfile.lock b/Gemfile.lock index 07b88fc..53dd765 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,55 +1,62 @@ GEM remote: https://rubygems.org/ specs: - actioncable (5.1.4) - actionpack (= 5.1.4) + actioncable (5.2.2) + actionpack (= 5.2.2) nio4r (~> 2.0) - websocket-driver (~> 0.6.1) - actionmailer (5.1.4) - actionpack (= 5.1.4) - actionview (= 5.1.4) - activejob (= 5.1.4) + websocket-driver (>= 0.6.1) + actionmailer (5.2.2) + actionpack (= 5.2.2) + actionview (= 5.2.2) + activejob (= 5.2.2) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (5.1.4) - actionview (= 5.1.4) - activesupport (= 5.1.4) + actionpack (5.2.2) + actionview (= 5.2.2) + activesupport (= 5.2.2) rack (~> 2.0) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.1.4) - activesupport (= 5.1.4) + actionview (5.2.2) + activesupport (= 5.2.2) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.3) - activejob (5.1.4) - activesupport (= 5.1.4) + activejob (5.2.2) + activesupport (= 5.2.2) globalid (>= 0.3.6) - activemodel (5.1.4) - activesupport (= 5.1.4) - activerecord (5.1.4) - activemodel (= 5.1.4) - activesupport (= 5.1.4) - arel (~> 8.0) - activesupport (5.1.4) + activemodel (5.2.2) + activesupport (= 5.2.2) + activerecord (5.2.2) + activemodel (= 5.2.2) + activesupport (= 5.2.2) + arel (>= 9.0) + activestorage (5.2.2) + actionpack (= 5.2.2) + activerecord (= 5.2.2) + marcel (~> 0.3.1) + activesupport (5.2.2) concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (~> 0.7) + i18n (>= 0.7, < 2) minitest (~> 5.1) tzinfo (~> 1.1) - arel (8.0.0) - autoprefixer-rails (7.1.6) + arel (9.0.0) + autoprefixer-rails (9.4.6) execjs - bcrypt (3.1.11) - bcrypt (3.1.11-x86-mingw32) + bcrypt (3.1.12) + bcrypt (3.1.12-x64-mingw32) + bcrypt (3.1.12-x86-mingw32) bh (1.3.6) actionpack activesupport bindex (0.5.0) - bootstrap-sass (3.3.7) + bootsnap (1.3.2) + msgpack (~> 1.0) + bootstrap-sass (3.4.0) autoprefixer-rails (>= 5.2.1) - sass (>= 3.3.4) + sassc (>= 2.0.0) builder (3.2.3) codemirror-rails (5.16.0) railties (>= 3.0, < 6.0) @@ -60,140 +67,154 @@ GEM coffee-script-source execjs coffee-script-source (1.12.2) - concurrent-ruby (1.0.5) - coveralls (0.8.21) + concurrent-ruby (1.1.4) + coveralls (0.8.22) json (>= 1.8, < 3) - simplecov (~> 0.14.1) + simplecov (~> 0.16.1) term-ansicolor (~> 1.3) thor (~> 0.19.4) tins (~> 1.6) - crass (1.0.3) - devise (4.3.0) + crass (1.0.4) + devise (4.5.0) bcrypt (~> 3.0) orm_adapter (~> 0.1) - railties (>= 4.1.0, < 5.2) + railties (>= 4.1.0, < 6.0) responders warden (~> 1.2.3) devise-bootstrap-views (0.0.11) - docile (1.1.5) - erubi (1.7.0) + docile (1.3.1) + erubi (1.8.0) execjs (2.7.0) - globalid (0.4.1) + ffi (1.9.25) + ffi (1.9.25-x64-mingw32) + ffi (1.9.25-x86-mingw32) + globalid (0.4.2) activesupport (>= 4.2.0) - i18n (0.9.1) + i18n (0.9.5) concurrent-ruby (~> 1.0) - jbuilder (2.7.0) + jbuilder (2.8.0) activesupport (>= 4.2.0) multi_json (>= 1.2) - jquery-rails (4.3.1) + jquery-rails (4.3.3) rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) json (1.8.6) - loofah (2.1.1) + loofah (2.2.3) crass (~> 1.0.2) nokogiri (>= 1.5.9) - mail (2.7.0) + mail (2.7.1) mini_mime (>= 0.1.1) - mathjax-rails (2.6.1) - railties (>= 3.0) - method_source (0.9.0) - mini_mime (1.0.0) - mini_portile2 (2.3.0) - minitest (5.10.3) - multi_json (1.12.2) - mysql2 (0.4.10) - mysql2 (0.4.10-x86-mingw32) - nio4r (2.1.0) - nokogiri (1.8.1) - mini_portile2 (~> 2.3.0) - nokogiri (1.8.1-x86-mingw32) - mini_portile2 (~> 2.3.0) + marcel (0.3.3) + mimemagic (~> 0.3.2) + method_source (0.9.2) + mimemagic (0.3.3) + mini_mime (1.0.1) + mini_portile2 (2.4.0) + minitest (5.11.3) + msgpack (1.2.6) + msgpack (1.2.6-x64-mingw32) + msgpack (1.2.6-x86-mingw32) + multi_json (1.13.1) + mysql2 (0.5.2) + mysql2 (0.5.2-x64-mingw32) + mysql2 (0.5.2-x86-mingw32) + nio4r (2.3.1) + nokogiri (1.10.1) + mini_portile2 (~> 2.4.0) + nokogiri (1.10.1-x64-mingw32) + mini_portile2 (~> 2.4.0) + nokogiri (1.10.1-x86-mingw32) + mini_portile2 (~> 2.4.0) orm_adapter (0.5.0) - rack (2.0.3) - rack-test (0.8.2) + rack (2.0.6) + rack-test (1.1.0) rack (>= 1.0, < 3) - rails (5.1.4) - actioncable (= 5.1.4) - actionmailer (= 5.1.4) - actionpack (= 5.1.4) - actionview (= 5.1.4) - activejob (= 5.1.4) - activemodel (= 5.1.4) - activerecord (= 5.1.4) - activesupport (= 5.1.4) + rails (5.2.2) + actioncable (= 5.2.2) + actionmailer (= 5.2.2) + actionpack (= 5.2.2) + actionview (= 5.2.2) + activejob (= 5.2.2) + activemodel (= 5.2.2) + activerecord (= 5.2.2) + activestorage (= 5.2.2) + activesupport (= 5.2.2) bundler (>= 1.3.0) - railties (= 5.1.4) + railties (= 5.2.2) sprockets-rails (>= 2.0.0) - rails-controller-testing (1.0.2) - actionpack (~> 5.x, >= 5.0.1) - actionview (~> 5.x, >= 5.0.1) - activesupport (~> 5.x) + rails-controller-testing (1.0.4) + actionpack (>= 5.0.1.x) + actionview (>= 5.0.1.x) + activesupport (>= 5.0.1.x) rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) - rails-html-sanitizer (1.0.3) - loofah (~> 2.0) - rails-i18n (5.0.4) - i18n (~> 0.7) - railties (~> 5.0) - railties (5.1.4) - actionpack (= 5.1.4) - activesupport (= 5.1.4) + rails-html-sanitizer (1.0.4) + loofah (~> 2.2, >= 2.2.2) + rails-i18n (5.1.3) + i18n (>= 0.7, < 2) + railties (>= 5.0, < 6) + railties (5.2.2) + actionpack (= 5.2.2) + activesupport (= 5.2.2) method_source rake (>= 0.8.7) - thor (>= 0.18.1, < 2.0) - rake (12.3.0) - rdoc (4.3.0) - responders (2.4.0) - actionpack (>= 4.2.0, < 5.3) - railties (>= 4.2.0, < 5.3) - sass (3.4.19) - sass-rails (5.0.7) - railties (>= 4.0.0, < 6) - sass (~> 3.1) - sprockets (>= 2.8, < 4.0) - sprockets-rails (>= 2.0, < 4.0) - tilt (>= 1.1, < 3) - sdoc (0.4.2) - json (~> 1.7, >= 1.7.7) - rdoc (~> 4.0) - simplecov (0.14.1) - docile (~> 1.1.0) + thor (>= 0.19.0, < 2.0) + rake (12.3.2) + rdoc (6.1.1) + responders (2.4.1) + actionpack (>= 4.2.0, < 6.0) + railties (>= 4.2.0, < 6.0) + sassc (2.0.0) + ffi (~> 1.9.6) + rake + sassc-rails (2.1.0) + railties (>= 4.0.0) + sassc (>= 2.0) + sprockets (> 3.0) + sprockets-rails + tilt + sdoc (1.0.0) + rdoc (>= 5.0) + simplecov (0.16.1) + docile (~> 1.1) json (>= 1.8, < 3) simplecov-html (~> 0.10.0) simplecov-html (0.10.2) - sprockets (3.4.1) + sprockets (3.7.2) + concurrent-ruby (~> 1.0) rack (> 1, < 3) - sprockets-rails (2.3.3) - actionpack (>= 3.0) - activesupport (>= 3.0) - sprockets (>= 2.8, < 4.0) + sprockets-rails (3.2.1) + actionpack (>= 4.0) + activesupport (>= 4.0) + sprockets (>= 3.0.0) sqlite3 (1.3.13) + sqlite3 (1.3.13-x64-mingw32) sqlite3 (1.3.13-x86-mingw32) - term-ansicolor (1.6.0) + term-ansicolor (1.7.1) tins (~> 1.0) thor (0.19.4) thread_safe (0.3.6) - tilt (2.0.8) - tins (1.15.1) - turbolinks (5.0.1) - turbolinks-source (~> 5) - turbolinks-source (5.0.3) - tzinfo (1.2.4) + tilt (2.0.9) + tins (1.20.2) + turbolinks (5.2.0) + turbolinks-source (~> 5.2) + turbolinks-source (5.2.0) + tzinfo (1.2.5) thread_safe (~> 0.1) - tzinfo-data (1.2015.7) + tzinfo-data (1.2018.9) tzinfo (>= 1.0.0) - uglifier (3.2.0) + uglifier (4.1.20) execjs (>= 0.3.0, < 3) - warden (1.2.7) - rack (>= 1.0) - web-console (3.5.1) + warden (1.2.8) + rack (>= 2.0.6) + web-console (3.7.0) actionview (>= 5.0) activemodel (>= 5.0) bindex (>= 0.4.0) railties (>= 5.0) - websocket-driver (0.6.5) + websocket-driver (0.7.0) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.3) will-paginate-i18n (0.1.15) @@ -203,34 +224,35 @@ GEM PLATFORMS ruby + x64-mingw32 x86-mingw32 DEPENDENCIES - autoprefixer-rails (~> 7.1.6) + autoprefixer-rails (~> 9.4.6) bh (~> 1.3.6) - bootstrap-sass (~> 3.3.7) + bootsnap + bootstrap-sass (~> 3.4.0) codemirror-rails (~> 5.16.0) coffee-rails (~> 4.2.2) - coveralls (~> 0.8.21) - devise (~> 4.3.0) + coveralls (~> 0.8.22) + devise (~> 4.5.0) devise-bootstrap-views (~> 0.0.11) - jbuilder (~> 2.7.0) - jquery-rails (~> 4.3.1) - mathjax-rails (~> 2.6.1) - mysql2 (~> 0.4.10) - rails (= 5.1.4) + jbuilder (~> 2.8.0) + jquery-rails (~> 4.3.3) + mysql2 (~> 0.5.2) + rails (= 5.2.2) rails-controller-testing - rails-i18n (~> 5.0.0) - sass-rails (~> 5.0.7) - sdoc (~> 0.4.2) + rails-i18n (~> 5.1.3) + sassc-rails (~> 2.1.0) + sdoc (~> 1.0.0) sqlite3 (~> 1.3.13) - turbolinks (~> 5.0.1) + turbolinks (~> 5.2.0) tzinfo-data - uglifier (~> 3.2.0) - web-console (~> 3.5.1) + uglifier (~> 4.1.20) + web-console (~> 3.7.0) will-paginate-i18n (~> 0.1.15) will_paginate (~> 3.1.6) will_paginate-bootstrap (~> 1.0.1) BUNDLED WITH - 1.16.0 + 1.17.2 diff --git a/README.md b/README.md index cb79518..a4ecbad 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,8 @@ Projekt Euler [](https://travis-ci.org/PFischbeck/projekteuler) [](https://coveralls.io/r/PFischbeck/projekteuler?branch=master) [](https://codeclimate.com/github/PFischbeck/projekteuler) -[](https://gemnasium.com/PFischbeck/projekteuler) [](https://hakiri.io/github/PFischbeck/projekteuler/master) + This is a rails app for the german translation of [projecteuler.net](https://projecteuler.net). Currently, it doesn't have a website, but when most of the current issues are fixed, it will be uploaded. 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 96b7977..25a0eab 100644 --- a/app/controllers/translations_controller.rb +++ b/app/controllers/translations_controller.rb @@ -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 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] %> |