diff --git a/.travis.yml b/.travis.yml index e1c9f08..2a9d33a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,7 @@ language: ruby sudo: false cache: bundler rvm: - - 2.4.1 + - 2.4.2 services: - postgresql before_script: diff --git a/Gemfile b/Gemfile index 7116992..fcde259 100644 --- a/Gemfile +++ b/Gemfile @@ -15,6 +15,7 @@ gem 'wet-health_endpoint' gem 'pg' gem 'slim' +gem 'jquery-hanami' gem 'hanami-bootstrap', '0.4' gem 'sass' diff --git a/Gemfile.lock b/Gemfile.lock index 8ff0859..a115258 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) @@ -261,6 +263,7 @@ DEPENDENCIES hanami-pagination! hanami-serializer! hiredis + jquery-hanami mock_redis pg puma @@ -282,4 +285,4 @@ RUBY VERSION ruby 2.4.2p198 BUNDLED WITH - 1.15.4 + 1.16.0 diff --git a/apps/web/application.rb b/apps/web/application.rb index 2c53256..93bba0b 100644 --- a/apps/web/application.rb +++ b/apps/web/application.rb @@ -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:; diff --git a/apps/web/assets/javascripts/main.js b/apps/web/assets/javascripts/main.js new file mode 100644 index 0000000..22852e8 --- /dev/null +++ b/apps/web/assets/javascripts/main.js @@ -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 + }); +}); diff --git a/apps/web/assets/stylesheets/main.css.scss b/apps/web/assets/stylesheets/main.css.scss index 5adbe50..bacd12a 100644 --- a/apps/web/assets/stylesheets/main.css.scss +++ b/apps/web/assets/stylesheets/main.css.scss @@ -40,3 +40,15 @@ a { } } } + +.statistics { + .projects { + .projects__title { + margin: 10px 0; + } + .projects__chart { + margin: 20px 0; + width: 400px; + } + } +} diff --git a/apps/web/config/routes.rb b/apps/web/config/routes.rb index 8907344..62a5b87 100644 --- a/apps/web/config/routes.rb +++ b/apps/web/config/routes.rb @@ -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' diff --git a/apps/web/controllers/statistics/show.rb b/apps/web/controllers/statistics/show.rb new file mode 100644 index 0000000..d5c3d24 --- /dev/null +++ b/apps/web/controllers/statistics/show.rb @@ -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 diff --git a/apps/web/templates/application.html.slim b/apps/web/templates/application.html.slim index 24e1850..eebc52f 100644 --- a/apps/web/templates/application.html.slim +++ b/apps/web/templates/application.html.slim @@ -10,4 +10,4 @@ html .container = render partial: 'shared/header' = yield - = javascript 'bootstrap' + = javascript 'jquery', 'bootstrap', 'main' diff --git a/apps/web/templates/statistics/show.html.slim b/apps/web/templates/statistics/show.html.slim new file mode 100644 index 0000000..d207865 --- /dev/null +++ b/apps/web/templates/statistics/show.html.slim @@ -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" + diff --git a/apps/web/views/statistics/show.rb b/apps/web/views/statistics/show.rb new file mode 100644 index 0000000..a54c53b --- /dev/null +++ b/apps/web/views/statistics/show.rb @@ -0,0 +1,5 @@ +module Web::Views::Statistics + class Show + include Web::View + end +end diff --git a/spec/web/controllers/statistics/show_spec.rb b/spec/web/controllers/statistics/show_spec.rb new file mode 100644 index 0000000..a23b10a --- /dev/null +++ b/spec/web/controllers/statistics/show_spec.rb @@ -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 diff --git a/spec/web/views/statistics/show_spec.rb b/spec/web/views/statistics/show_spec.rb new file mode 100644 index 0000000..c818c05 --- /dev/null +++ b/spec/web/views/statistics/show_spec.rb @@ -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