Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wip] Add page with contributor specific statistic #33

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ language: ruby
sudo: false
cache: bundler
rvm:
- 2.4.1
- 2.4.2
services:
- postgresql
before_script:
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ gem 'wet-health_endpoint'
gem 'pg'

gem 'slim'
gem 'jquery-hanami'
gem 'hanami-bootstrap', '0.4'
gem 'sass'

Expand Down
5 changes: 4 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ GEM
url_mount (~> 0.2.1)
ice_nine (0.11.2)
inflecto (0.0.2)
jquery-hanami (0.1.0)
hanami-assets
json (2.1.0)
mail (2.6.6)
mime-types (>= 1.16, < 4)
Expand Down Expand Up @@ -261,6 +263,7 @@ DEPENDENCIES
hanami-pagination!
hanami-serializer!
hiredis
jquery-hanami
mock_redis
pg
puma
Expand All @@ -282,4 +285,4 @@ RUBY VERSION
ruby 2.4.2p198

BUNDLED WITH
1.15.4
1.16.0
2 changes: 1 addition & 1 deletion apps/web/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ class Application < Hanami::Application
frame-ancestors 'self';
base-uri 'self';
default-src 'none';
script-src 'self';
script-src 'self' 'unsafe-inline' https:;
connect-src 'self';
img-src 'self' https: data:;
style-src 'self' 'unsafe-inline' https:;
Expand Down
26 changes: 26 additions & 0 deletions apps/web/assets/javascripts/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
$(function() {
var projects_ctx = $("#projects");

data = {
datasets: [{
data: [10, 20, 30],
backgroundColor: [
'rgba(255, 99, 132, 0.2)',
'rgba(54, 162, 235, 0.2)',
'rgba(255, 206, 86, 0.2)'
]
}],

// These labels appear in the legend and in the tooltips when hovering different arcs
labels: [
'Red',
'Blue',
'Yellow'
]
};

var projectsPieChart = new Chart(projects_ctx,{
type: 'doughnut',
data: data
});
});
12 changes: 12 additions & 0 deletions apps/web/assets/stylesheets/main.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,15 @@ a {
}
}
}

.statistics {
.projects {
.projects__title {
margin: 10px 0;
}
.projects__chart {
margin: 20px 0;
width: 400px;
}
}
}
1 change: 1 addition & 0 deletions apps/web/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
#
# Example:
# get '/hello', to: ->(env) { [200, {}, ['Hello from Hanami!']] }
get '/statistics/:github', to: 'statistics#show'
get '/contributors/:id', to: 'contributors#show'
root to: 'contributors#index'
11 changes: 11 additions & 0 deletions apps/web/controllers/statistics/show.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Web::Controllers::Statistics
class Show
include Web::Action

expose :contributor, :commits

def call(params)
@contributor = ContributorRepository.new.find_by_github(params[:github])
end
end
end
2 changes: 1 addition & 1 deletion apps/web/templates/application.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ html
.container
= render partial: 'shared/header'
= yield
= javascript 'bootstrap'
= javascript 'jquery', 'bootstrap', 'main'
12 changes: 12 additions & 0 deletions apps/web/templates/statistics/show.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
h2 #{contributor.github} Statistic

.statistics
.projects
.projects__title
h3 Commits by projects

.projects__chart
canvas#projects width="200" height="200"

script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.1/Chart.bundle.min.js"

5 changes: 5 additions & 0 deletions apps/web/views/statistics/show.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Web::Views::Statistics
class Show
include Web::View
end
end
17 changes: 17 additions & 0 deletions spec/web/controllers/statistics/show_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
RSpec.describe Web::Controllers::Statistics::Show do
let(:action) { described_class.new }
let(:params) { { github: contributor.github } }

let(:repo) { ContributorRepository.new }
let(:contributor) { repo.create(github: 'davydovanton') }

after { repo.clear }

it { expect(action.call(params)).to be_success }

context '#contributor' do
before { action.call(params) }

it { expect(action.contributor).to be_a Contributor }
end
end
6 changes: 6 additions & 0 deletions spec/web/views/statistics/show_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
RSpec.describe Web::Views::Statistics::Show do
let(:exposures) { Hash[foo: 'bar'] }
let(:template) { Hanami::View::Template.new('apps/web/templates/statistics/show.html.slim') }
let(:view) { described_class.new(template, exposures) }
let(:rendered) { view.render }
end