diff --git a/Gemfile b/Gemfile index f6143f7..bc0a8c2 100644 --- a/Gemfile +++ b/Gemfile @@ -51,7 +51,7 @@ gem 'tacky', '0.3.5' gem 'telepost', '>=0.3.2' gem 'thin', '1.7.2' gem 'threads', '>=0.3' -gem 'veils', '0.1.1' +gem 'veils', '0.2.0' gem 'xcop', '0.6' gem 'zache', '>=0.12.0' gem 'zold-ruby-sdk', '0.2.3' diff --git a/Gemfile.lock b/Gemfile.lock index 62864dc..ef7810c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -232,7 +232,7 @@ GEM usagewatch (0.0.7) usagewatch_ext (0.2.1) usagewatch (~> 0.0.6) - veils (0.1.1) + veils (0.2.0) virtus (1.0.5) axiom-types (~> 0.1) coercible (~> 1.0) @@ -308,7 +308,7 @@ DEPENDENCIES telepost (>= 0.3.2) thin (= 1.7.2) threads (>= 0.3) - veils (= 0.1.1) + veils (= 0.2.0) xcop (= 0.6) zache (>= 0.12.0) zold-ruby-sdk (= 0.2.3) diff --git a/codexia.rb b/codexia.rb index 55f7713..c6dd059 100644 --- a/codexia.rb +++ b/codexia.rb @@ -160,6 +160,7 @@ def iri require_relative 'front/front_login.rb' require_relative 'front/front_helpers.rb' require_relative 'front/front_author.rb' +require_relative 'front/front_authors.rb' require_relative 'front/front_project.rb' require_relative 'front/front_projects.rb' require_relative 'front/front_karma.rb' diff --git a/front/front_authors.rb b/front/front_authors.rb new file mode 100644 index 0000000..2e102a9 --- /dev/null +++ b/front/front_authors.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +# Copyright (c) 2020 Yegor Bugayenko +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the 'Software'), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +get '/authors' do + haml :authors, layout: :layout, locals: merged( + title: '/authors', + list: the_authors.best + ) +end diff --git a/objects/authors.rb b/objects/authors.rb index dfd3323..ca5c414 100644 --- a/objects/authors.rb +++ b/objects/authors.rb @@ -22,6 +22,7 @@ require 'loog' require 'telepost' +require 'unpiercable' require_relative 'xia' require_relative 'author' @@ -41,4 +42,23 @@ def named(login) id = @pgsql.exec('SELECT id FROM author WHERE login=$1', [login])[0]['id'].to_i Xia::Author.new(@pgsql, id, log: @log, telepost: @telepost) end + + def best(limit: 25) + @pgsql.exec( + [ + 'SELECT author.id, author.login, SUM(withdrawal.points) AS points FROM author', + 'JOIN withdrawal ON author.id=withdrawal.author', + 'GROUP BY author.id', + 'ORDER BY points DESC', + 'LIMIT $1' + ].join(' '), + [limit] + ).map do |r| + Unpiercable.new( + Xia::Author.new(@pgsql, r['id'].to_i, log: @log, telepost: @telepost), + login: r['login'], + points: r['points'].to_i + ) + end + end end diff --git a/test/test_codexia.rb b/test/test_codexia.rb index 1ddfe0b..d6310e3 100644 --- a/test/test_codexia.rb +++ b/test/test_codexia.rb @@ -75,6 +75,7 @@ def test_200_user_pages '/payables?a=-test', '/a/-test', '/submit', + '/authors', '/terms', '/bots', '/sql', diff --git a/views/authors.haml b/views/authors.haml new file mode 100644 index 0000000..762851f --- /dev/null +++ b/views/authors.haml @@ -0,0 +1,13 @@ +%table + %thead + %tr + %th Login + %th.right Earned + %tbody + - list.each do |a| + %tr + %td + = partial(:author, locals, a: a) + %td + = a.points + diff --git a/views/layout.haml b/views/layout.haml index 12703d9..778ce29 100644 --- a/views/layout.haml +++ b/views/layout.haml @@ -53,6 +53,10 @@ %li %a{href: iri.cut('/submit'), title: 'Submit a new project'} = '/submit' + - if defined?(author) + %li + %a{href: iri.cut('/authors'), title: 'Most active authors'} + = '/authors' - if defined?(author) %li %a{href: iri.cut('/terms')}