From bab2e8cc34edccb5856e0b082cec417d7dc20fda Mon Sep 17 00:00:00 2001 From: "K. Volchenko" Date: Mon, 25 Sep 2017 18:07:20 +0300 Subject: [PATCH] Remove leaderboards (Issue #163) --- apps/web/assets/stylesheets/_leaderboard.scss | 137 ------------------ apps/web/assets/stylesheets/main.scss | 1 - apps/web/config/routes.rb | 2 - apps/web/controllers/leaderboards/index.rb | 19 --- .../templates/leaderboards/index.html.slim | 30 ---- apps/web/views/leaderboards/index.rb | 14 -- config/sidekiq.yml | 2 - lib/container.rb | 3 +- lib/ossboard/entities/point.rb | 2 - lib/ossboard/entities/user.rb | 1 - lib/ossboard/repositories/point_repository.rb | 2 - lib/ossboard/repositories/user_repository.rb | 5 - lib/ossboard/services/points_calculator.rb | 32 ---- .../workers/calculate_points_worker.rb | 9 -- spec/ossboard/entities/point_spec.rb | 3 - .../repositories/point_repository_spec.rb | 2 - .../repositories/user_repository_spec.rb | 19 --- .../services/points_calculator_spec.rb | 104 ------------- .../workers/calculate_points_worker_spec.rb | 103 ------------- .../controllers/leaderboards/index_spec.rb | 21 --- spec/web/views/leaderboards/index_spec.rb | 21 --- 21 files changed, 1 insertion(+), 531 deletions(-) delete mode 100644 apps/web/assets/stylesheets/_leaderboard.scss delete mode 100644 apps/web/controllers/leaderboards/index.rb delete mode 100644 apps/web/templates/leaderboards/index.html.slim delete mode 100644 apps/web/views/leaderboards/index.rb delete mode 100644 lib/ossboard/entities/point.rb delete mode 100644 lib/ossboard/repositories/point_repository.rb delete mode 100644 lib/ossboard/services/points_calculator.rb delete mode 100644 lib/ossboard/workers/calculate_points_worker.rb delete mode 100644 spec/ossboard/entities/point_spec.rb delete mode 100644 spec/ossboard/repositories/point_repository_spec.rb delete mode 100644 spec/ossboard/services/points_calculator_spec.rb delete mode 100644 spec/ossboard/workers/calculate_points_worker_spec.rb delete mode 100644 spec/web/controllers/leaderboards/index_spec.rb delete mode 100644 spec/web/views/leaderboards/index_spec.rb diff --git a/apps/web/assets/stylesheets/_leaderboard.scss b/apps/web/assets/stylesheets/_leaderboard.scss deleted file mode 100644 index 5706c287..00000000 --- a/apps/web/assets/stylesheets/_leaderboard.scss +++ /dev/null @@ -1,137 +0,0 @@ -/* - * -- TABLET (AND UP) MEDIA QUERIES -- - * On tablets and other medium-sized devices, we want to customize some - * of the mobile styles. - */ -@media (max-width: 48em) { - .leaderboard { - width: 100%; - } -} - -/* - * -- DESKTOP (AND UP) MEDIA QUERIES -- - * On desktops and other large devices, we want to over-ride some - * of the mobile and tablet styles. - */ -@media (min-width: 48em) { - .leaderboard { - width: 700px; - } -} - -.leaderboard { - margin: 2em auto; - - .leaderboard__title { - svg { - display: block; - margin: 0 auto; - } - - h2 { - text-align: center; - } - } - - .leaderboard__switch { - font-size: 0; - text-align: center; - - .leaderboard__switch-item { - font-size: 20px; - display: inline-block; - vertical-align: top; - margin: 0.6em 0; - } - - button.leaderboard__switch-item-link { - } - - .leaderboard__switch-item-link, - .leaderboard__switch-item-link:link, - .leaderboard__switch-item-link:active, - .leaderboard__switch-item-link:visited { - cursor: pointer; - background: none; - display: inline-block; - vertical-align: top; - text-align: center; - font-size: 0.7em; - line-height: 3.28; - text-decoration: none; - border: 1px solid #214CFD; - color: #214CFD; - width: 10.5em; - } - .leaderboard__switch-item-link:hover { - background: #FD2121; - border-color: #FD2121; - color: #fff; - } - .leaderboard__switch-item-link_active, - .leaderboard__switch-item-link_active:hover { - background: #214CFD; - border-color: #214CFD; - color: #fff; - cursor: default; - } - .leaderboard__switch-item:first-child .leaderboard__switch-item-link { - border-radius: 100px 0 0 100px; - } - .leaderboard__switch-item:last-child .leaderboard__switch-item-link { - border-radius: 0 100px 100px 0; - } - } - - .leaderboard__list { - background: #FFFFFF; - box-shadow: 0 0 1px 0 rgba(43, 59, 124, 0.18), 0 1px 3px 0 rgba(43, 59, 125, 0.14); - border-radius: 2px; - margin: 20px 0; - - a:link, - a:active, - a:visited { - color: #214CFD; - } - - .leaderboard__contributors { - } - - .leaderboard__maintainers { - } - } - - .user-row { - padding: 1em 1em; - display: flex; - flex-wrap: wrap; - justify-content: space-between; - - &:hover { - background: #244FFE; - color: #fff; - - a { - color: #fff; - } - } - - .user-row__rank { - margin-right: 1em; - } - - .user-row__name { - flex-grow: 1; - } - - .user-row__avatar { - width: 24px; - height: 24px; - border-radius: 100px; - margin: 0px 0.4em -5px 0; - } - } -} - diff --git a/apps/web/assets/stylesheets/main.scss b/apps/web/assets/stylesheets/main.scss index fe19bf56..64445419 100644 --- a/apps/web/assets/stylesheets/main.scss +++ b/apps/web/assets/stylesheets/main.scss @@ -1,4 +1,3 @@ -@import 'leaderboard'; @import 'settings'; @import 'buttons'; @import 'labels'; diff --git a/apps/web/config/routes.rb b/apps/web/config/routes.rb index 2682006a..a61bdd1d 100644 --- a/apps/web/config/routes.rb +++ b/apps/web/config/routes.rb @@ -1,7 +1,5 @@ root to: 'main#index' -get '/leaderboards', to: 'leaderboards#index' - get '/about', to: 'static#about', as: 'about' get '/how-to-help', to: 'static#help', as: 'help' diff --git a/apps/web/controllers/leaderboards/index.rb b/apps/web/controllers/leaderboards/index.rb deleted file mode 100644 index 54be0eee..00000000 --- a/apps/web/controllers/leaderboards/index.rb +++ /dev/null @@ -1,19 +0,0 @@ -module Web::Controllers::Leaderboards - class Index - include Web::Action - expose :users, :developers, :maintainers - - # TODO: replace to model - def call(params) - @users = UserRepository.new.all_with_points_and_tasks - - @developers = @users.sort do |first, second| - second.points.first&.developer <=> first.points.first&.developer - end - - @maintainers = @users.sort do |first, second| - second.points.first&.maintainer <=> first.points.first&.maintainer - end - end - end -end diff --git a/apps/web/templates/leaderboards/index.html.slim b/apps/web/templates/leaderboards/index.html.slim deleted file mode 100644 index 0c3b7860..00000000 --- a/apps/web/templates/leaderboards/index.html.slim +++ /dev/null @@ -1,30 +0,0 @@ -#js-switcher.leaderboard.main-content - .leaderboard__title - svg height="32px" version="1.1" viewbox=("84 0 32 32") width="32px" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" - g#ic_local_bar_black_24px-copy fill="none" fill-rule="evenodd" stroke="none" stroke-width="1" transform="translate(84.000000, 0.000000)" - g#Group - polygon#Shape points=("0 0 32 0 32 32 0 32") - path#Combined-Shape d="M24,5.66666667 C26.209139,5.66666667 28,7.45752767 28,9.66666667 C28,11.8758057 26.209139,13.6666667 24,13.6666667 L24,14.9975267 C24,15.544239 23.6159042,16.2304575 23.1420979,16.5147412 L17.3333333,20 L17.3333333,25.3333333 L24,25.3333333 L24,28 L8,28 L8,25.3333333 L14.6666667,25.3333333 L14.6666667,20 L8.85790207,16.5147412 C8.37753026,16.2265182 8,15.5511774 8,14.9975267 L8,13.6666667 C5.790861,13.6666667 4,11.8758057 4,9.66666667 C4,7.45752767 5.790861,5.66666667 8,5.66666667 L8,4 L24,4 L24,5.66666667 Z M8,7.84848485 C6.99584591,7.84848485 6.18181818,8.66251258 6.18181818,9.66666667 C6.18181818,10.6708208 6.99584591,11.4848485 8,11.4848485 L8,7.84848485 Z M24,7.84848485 C25.0041541,7.84848485 25.8181818,8.66251258 25.8181818,9.66666667 C25.8181818,10.6708208 25.0041541,11.4848485 24,11.4848485 L24,7.84848485 Z" fill="#FBC02D" - - h2 Leaderboard - - .leaderboard__switch - .leaderboard__switch-item - button.leaderboard__switch-item-link v-bind:class="{ 'leaderboard__switch-item-link_active': firstCase }" v-on:click="displayFirstCase" Top contributors - .leaderboard__switch-item - button.leaderboard__switch-item-link v-bind:class="{ 'leaderboard__switch-item-link_active': secondCase }" v-on:click="displaySecondCase" Top maintainers - - .leaderboard__list - .leaderboard__contributors v-if="firstCase" - - developers.each_with_index do |user, i| - .user-row - .user-row__rank = i + 1 - = user_information(user) - .user-row__points = user.points&.first&.developer - - .leaderboard__maintainers v-if="secondCase" - - maintainers.each_with_index do |user, i| - .user-row - .user-row__rank = i + 1 - = user_information(user) - .user-row__points = user.points&.first&.maintainer diff --git a/apps/web/views/leaderboards/index.rb b/apps/web/views/leaderboards/index.rb deleted file mode 100644 index 802e1a1a..00000000 --- a/apps/web/views/leaderboards/index.rb +++ /dev/null @@ -1,14 +0,0 @@ -module Web::Views::Leaderboards - class Index - include Web::View - - def user_information(user) - html.div(class: 'user-row__name') do - a(href: routes.user_path(user.login)) do - img class: 'user-row__avatar', src: user.avatar_url - text(user.login) - end - end - end - end -end diff --git a/config/sidekiq.yml b/config/sidekiq.yml index b204e259..555218a9 100644 --- a/config/sidekiq.yml +++ b/config/sidekiq.yml @@ -1,5 +1,3 @@ :schedule: RefreshUserReposWorker: every: 12h - CalculatePointsWorker: - every: 12h diff --git a/lib/container.rb b/lib/container.rb index d842f589..6509d874 100644 --- a/lib/container.rb +++ b/lib/container.rb @@ -4,7 +4,7 @@ %w[markdown http_request].each { |file| require_relative "ossboard/core/#{file}" } %w[ - analytic_reporter url_shortener points_calculator task_tweeter + analytic_reporter url_shortener task_tweeter ].each { |file| require_relative "ossboard/services/#{file}" } require_relative 'tasks/matchers/git_host' @@ -19,7 +19,6 @@ class Container namespace('services') do register('analytic_reporter', Services::AnalyticReporter.new) - register('points_calculator', Services::PointsCalculator.new) register('task_twitter', Services::TaskTwitter.new) register('url_shortener', Services::UrlShortener.new) end diff --git a/lib/ossboard/entities/point.rb b/lib/ossboard/entities/point.rb deleted file mode 100644 index ec91d2b5..00000000 --- a/lib/ossboard/entities/point.rb +++ /dev/null @@ -1,2 +0,0 @@ -class Point < Hanami::Entity -end diff --git a/lib/ossboard/entities/user.rb b/lib/ossboard/entities/user.rb index 8390b7d1..ce77b42d 100644 --- a/lib/ossboard/entities/user.rb +++ b/lib/ossboard/entities/user.rb @@ -13,7 +13,6 @@ class User < Hanami::Entity attribute :created_at_day, Types::Date attribute :tasks, Types::Collection(Task) - attribute :points, Types::Collection(Point) attribute :repos, Types::Collection(Repo) attribute :accounts, Types::Collection(Account) end diff --git a/lib/ossboard/repositories/point_repository.rb b/lib/ossboard/repositories/point_repository.rb deleted file mode 100644 index cf6f37d2..00000000 --- a/lib/ossboard/repositories/point_repository.rb +++ /dev/null @@ -1,2 +0,0 @@ -class PointRepository < Hanami::Repository -end diff --git a/lib/ossboard/repositories/user_repository.rb b/lib/ossboard/repositories/user_repository.rb index e0f124e9..07c32fcf 100644 --- a/lib/ossboard/repositories/user_repository.rb +++ b/lib/ossboard/repositories/user_repository.rb @@ -3,7 +3,6 @@ class UserRepository < Hanami::Repository has_many :tasks has_many :accounts has_many :repos - has_many :points end def admins @@ -35,10 +34,6 @@ def find_with_tasks(id) aggregate(:tasks).where(id: id).map_to(User).one end - def all_with_points_and_tasks - aggregate(:points, :tasks).map_to(User).to_a - end - private def all_from_date_request(from) diff --git a/lib/ossboard/services/points_calculator.rb b/lib/ossboard/services/points_calculator.rb deleted file mode 100644 index 4a9ad8b5..00000000 --- a/lib/ossboard/services/points_calculator.rb +++ /dev/null @@ -1,32 +0,0 @@ -module Services - class PointsCalculator - def call(user) - if point = user.points.first - PointRepository.new.update(point.id, points_params(user)) - else - PointRepository.new.create(points_params(user)) - end - end - - private - - POINTS_FOR_STATUS = { - 'in progress' => 1, - 'assigned' => 3, - 'closed' => 2, - 'done' => 5 - } - - def points_params(user) - { - maintainer: points(user.tasks), - developer: points(TaskRepository.new.assigned_tasks_for_user(user)), - user_id: user.id - } - end - - def points(tasks) - tasks.map{ |t| POINTS_FOR_STATUS[t.status] }.inject(:+) || 0 - end - end -end diff --git a/lib/ossboard/workers/calculate_points_worker.rb b/lib/ossboard/workers/calculate_points_worker.rb deleted file mode 100644 index 8c7a6eaf..00000000 --- a/lib/ossboard/workers/calculate_points_worker.rb +++ /dev/null @@ -1,9 +0,0 @@ -class CalculatePointsWorker - include Sidekiq::Worker - - def perform - UserRepository.new - .all_with_points_and_tasks - .each { |user| Container['services.points_calculator'].call(user) } - end -end diff --git a/spec/ossboard/entities/point_spec.rb b/spec/ossboard/entities/point_spec.rb deleted file mode 100644 index 3e8cd064..00000000 --- a/spec/ossboard/entities/point_spec.rb +++ /dev/null @@ -1,3 +0,0 @@ -RSpec.describe Point do - # place your tests here -end diff --git a/spec/ossboard/repositories/point_repository_spec.rb b/spec/ossboard/repositories/point_repository_spec.rb deleted file mode 100644 index 55fe2bb7..00000000 --- a/spec/ossboard/repositories/point_repository_spec.rb +++ /dev/null @@ -1,2 +0,0 @@ -RSpec.describe PointRepository do -end diff --git a/spec/ossboard/repositories/user_repository_spec.rb b/spec/ossboard/repositories/user_repository_spec.rb index 13d68cfc..deb12d33 100644 --- a/spec/ossboard/repositories/user_repository_spec.rb +++ b/spec/ossboard/repositories/user_repository_spec.rb @@ -89,23 +89,4 @@ it { expect(subject.tasks).to be_a Array } it { expect(subject.tasks.count).to eq 1 } end - - describe '#all_with_points_and_tasks' do - let(:task_repo) { TaskRepository.new } - - let(:user) { Fabricate.create(:user, uuid: 'test') } - - before do - Fabricate.create(:task, title: 'bad', user_id: user.id ) - Fabricate.create(:task, title: 'good', approved: true) - end - - subject { repo.all_with_points_and_tasks } - - it { expect(subject).to be_a Array } - - it { expect(subject[0]).to be_a User } - it { expect(subject[0].points).to be_a Array } - it { expect(subject[0].tasks).to be_a Array } - end end diff --git a/spec/ossboard/services/points_calculator_spec.rb b/spec/ossboard/services/points_calculator_spec.rb deleted file mode 100644 index 46ce2449..00000000 --- a/spec/ossboard/services/points_calculator_spec.rb +++ /dev/null @@ -1,104 +0,0 @@ -RSpec.describe Services::PointsCalculator do - let(:user) { Fabricate.create(:user, login: 'davydovanton') } - let(:service) { Services::PointsCalculator.new } - subject { service.call(UserRepository.new.all_with_points_and_tasks.last) } - - describe '#perform' do - context 'when user does not have tasks' do - it 'does nothing' do - user and subject - point = PointRepository.new.points.where(user_id: user.id).first - expect(point.maintainer).to eq 0 - expect(point.developer).to eq 0 - end - end - - context 'when user have tasks' do - context 'and tasks only in progress' do - before do - 5.times { Fabricate.create(:task, user_id: user.id, status: 'in progress') } - end - - it 'calculates points' do - subject - point = PointRepository.new.points.where(user_id: user.id).first - expect(point.maintainer).to eq 5 - expect(point.developer).to eq 0 - end - - context 'when user have point object' do - before do - PointRepository.new.create(user_id: user.id) - end - - it 'calculates points' do - subject - point = PointRepository.new.points.where(user_id: user.id).first - expect(point.maintainer).to eq 5 - expect(point.developer).to eq 0 - end - end - end - - context 'and tasks with different status' do - before do - Fabricate.create(:task, user_id: user.id, status: 'in progress') - Fabricate.create(:task, user_id: user.id, status: 'assigned') - Fabricate.create(:task, user_id: user.id, status: 'closed') - Fabricate.create(:task, user_id: user.id, status: 'done') - end - - it 'calculates points' do - subject - point = PointRepository.new.points.where(user_id: user.id).first - expect(point.maintainer).to eq 11 - expect(point.developer).to eq 0 - end - end - end - - context 'when user complete tasks' do - context 'and tasks only in progress' do - before do - 5.times { Fabricate.create(:task, assignee_username: user.login, status: 'in progress') } - end - - it 'calculates points' do - subject - point = PointRepository.new.points.where(user_id: user.id).first - expect(point.maintainer).to eq 0 - expect(point.developer).to eq 5 - end - - context 'when user have point object' do - before do - PointRepository.new.create(user_id: user.id) - end - - it 'calculates points' do - subject - point = PointRepository.new.points.where(user_id: user.id).first - expect(point.maintainer).to eq 0 - expect(point.developer).to eq 5 - end - end - end - - context 'and tasks with different status' do - before do - Fabricate.create(:task, assignee_username: user.login, status: 'in progress') - Fabricate.create(:task, assignee_username: user.login, status: 'assigned') - Fabricate.create(:task, assignee_username: user.login, status: 'closed') - Fabricate.create(:task, assignee_username: user.login, status: 'done') - end - - it 'calculates points' do - subject - point = PointRepository.new.points.where(user_id: user.id).first - expect(point.maintainer).to eq 0 - expect(point.developer).to eq 11 - end - end - end - end -end diff --git a/spec/ossboard/workers/calculate_points_worker_spec.rb b/spec/ossboard/workers/calculate_points_worker_spec.rb deleted file mode 100644 index 648bb8e9..00000000 --- a/spec/ossboard/workers/calculate_points_worker_spec.rb +++ /dev/null @@ -1,103 +0,0 @@ -RSpec.describe CalculatePointsWorker do - let(:user) { Fabricate.create(:user, login: 'davydovanton') } - subject { CalculatePointsWorker.new.perform } - - describe '#perform' do - context 'when user does not have tasks' do - it 'does nothing' do - user and subject - point = PointRepository.new.points.where(user_id: user.id).first - expect(point.maintainer).to eq 0 - expect(point.developer).to eq 0 - end - end - - context 'when user have tasks' do - context 'and tasks only in progress' do - before do - 5.times { Fabricate.create(:task, user_id: user.id, status: 'in progress') } - end - - it 'calculates points' do - subject - point = PointRepository.new.points.where(user_id: user.id).first - expect(point.maintainer).to eq 5 - expect(point.developer).to eq 0 - end - - context 'when user have point object' do - before do - PointRepository.new.create(user_id: user.id) - end - - it 'calculates points' do - subject - point = PointRepository.new.points.where(user_id: user.id).first - expect(point.maintainer).to eq 5 - expect(point.developer).to eq 0 - end - end - end - - context 'and tasks with different status' do - before do - Fabricate.create(:task, user_id: user.id, status: 'in progress') - Fabricate.create(:task, user_id: user.id, status: 'assigned') - Fabricate.create(:task, user_id: user.id, status: 'closed') - Fabricate.create(:task, user_id: user.id, status: 'done') - end - - it 'calculates points' do - subject - point = PointRepository.new.points.where(user_id: user.id).first - expect(point.maintainer).to eq 11 - expect(point.developer).to eq 0 - end - end - end - - context 'when user complete tasks' do - context 'and tasks only in progress' do - before do - 5.times { Fabricate.create(:task, assignee_username: user.login, status: 'in progress') } - end - - it 'calculates points' do - subject - point = PointRepository.new.points.where(user_id: user.id).first - expect(point.maintainer).to eq 0 - expect(point.developer).to eq 5 - end - - context 'when user have point object' do - before do - PointRepository.new.create(user_id: user.id) - end - - it 'calculates points' do - subject - point = PointRepository.new.points.where(user_id: user.id).first - expect(point.maintainer).to eq 0 - expect(point.developer).to eq 5 - end - end - end - - context 'and tasks with different status' do - before do - Fabricate.create(:task, assignee_username: user.login, status: 'in progress') - Fabricate.create(:task, assignee_username: user.login, status: 'assigned') - Fabricate.create(:task, assignee_username: user.login, status: 'closed') - Fabricate.create(:task, assignee_username: user.login, status: 'done') - end - - it 'calculates points' do - subject - point = PointRepository.new.points.where(user_id: user.id).first - expect(point.maintainer).to eq 0 - expect(point.developer).to eq 11 - end - end - end - end -end diff --git a/spec/web/controllers/leaderboards/index_spec.rb b/spec/web/controllers/leaderboards/index_spec.rb deleted file mode 100644 index c5eae47e..00000000 --- a/spec/web/controllers/leaderboards/index_spec.rb +++ /dev/null @@ -1,21 +0,0 @@ -require_relative '../../../../apps/web/controllers/leaderboards/index' - -RSpec.describe Web::Controllers::Leaderboards::Index do - let(:action) { described_class.new } - let(:params) { Hash[] } - - it { expect(action.call(params)).to be_success } - - describe 'exposes' do - describe '#users' do - before do - UserRepository.new.create(login: 'anton') - action.call(params) - end - - it 'returns all users' do - expect(action.users).to every(be_an(User)) - end - end - end -end diff --git a/spec/web/views/leaderboards/index_spec.rb b/spec/web/views/leaderboards/index_spec.rb deleted file mode 100644 index 20591668..00000000 --- a/spec/web/views/leaderboards/index_spec.rb +++ /dev/null @@ -1,21 +0,0 @@ -require_relative '../../../../apps/web/views/leaderboards/index' - -RSpec.describe Web::Views::Leaderboards::Index do - let(:exposures) { Hash[foo: 'bar'] } - let(:template) { Hanami::View::Template.new('apps/web/templates/leaderboards/index.html.slim') } - let(:user) { User.new(id: 1, admin: false, login: 'whatever', avatar_url: 'test_url') } - let(:view) { described_class.new(template, exposures) } - let(:rendered) { view.render } - - describe 'exposes' do - describe '#user_information' do - let(:info) { view.user_information(user) } - - # it { expect(info).to have_css('.user-row__name', count: 1) } - # it { expect(info).to have_css('.user-row__avatar', count: 1) } - # it { expect(info).to have_selector(:css, 'a[href="/users/whatever"]') } - # it { expect(info).to have_selector(:css, 'img[src="test_url"]') } - # it { expect(info).to have_content(user.login, count: 1) } - end - end -end