diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-07-05 14:41:02 +0300 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-07-05 14:41:02 +0300 |
commit | 4b74c55b1572da19d78fa6982edf54916d09eec3 (patch) | |
tree | 8acbf6788fca6b8f7f31f51c43ad9556dc74e09b | |
parent | 22005da2377275e3a80d37bfa689e474869b645a (diff) | |
download | gitlab-ci-4b74c55b1572da19d78fa6982edf54916d09eec3.tar.gz |
More charts. Correct routes to actual page names
-rw-r--r-- | ROADMAP.md | 7 | ||||
-rw-r--r-- | app/controllers/projects_controller.rb | 30 | ||||
-rw-r--r-- | app/helpers/application_helper.rb | 4 | ||||
-rw-r--r-- | app/views/layouts/project.html.haml | 12 | ||||
-rw-r--r-- | app/views/projects/charts.html.haml | 63 | ||||
-rw-r--r-- | app/views/projects/integration.html.haml (renamed from app/views/projects/details.html.haml) | 0 | ||||
-rw-r--r-- | app/views/projects/stats.html.haml | 48 | ||||
-rw-r--r-- | app/views/shared/_guide.html.haml | 2 | ||||
-rw-r--r-- | config/routes.rb | 4 | ||||
-rw-r--r-- | lib/charts.rb | 54 | ||||
-rw-r--r-- | spec/features/projects_spec.rb | 4 |
11 files changed, 143 insertions, 85 deletions
@@ -1,5 +1,6 @@ ## ROADMAP: -1. Email notification -2. Authorization. 2 types of users (admin and user) -3. API +1. Auth to GitLab with username, email, ldap +2. Email notification +3. API documentation +4. Test coverage > 85% diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 17b2759..e35cd34 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -1,6 +1,6 @@ class ProjectsController < ApplicationController before_filter :authenticate_user!, except: [:build, :status, :index, :show] - before_filter :project, only: [:build, :details, :show, :status, :edit, :update, :destroy, :stats] + before_filter :project, only: [:build, :integration, :show, :status, :edit, :update, :destroy, :charts] before_filter :authenticate_token!, only: [:build] before_filter :no_cache, only: [:status] @@ -25,7 +25,7 @@ class ProjectsController < ApplicationController @builds = @builds.order('id DESC').page(params[:page]).per(20) end - def details + def integration end def create @@ -102,27 +102,11 @@ class ProjectsController < ApplicationController send_file Rails.root.join('public', image_name), filename: image_name, disposition: 'inline' end - def stats - first_build, last_build = @project.builds.first, @project.builds.last - - labels = [] - total = [] - success = [] - - 13.times do |i| - start_month = (Date.today.years_ago(1) + i.month).beginning_of_month - end_month = start_month.end_of_month - - labels << start_month.strftime("%d %B %Y") - total << @project.builds.where("? > created_at AND created_at > ?", end_month, start_month).count - success << @project.builds.where("? > created_at AND created_at > ?", end_month, start_month).success.count - end - - @stats = { - labels: labels, - total: total, - success: success - } + def charts + @charts = {} + @charts[:week] = Charts::WeekChart.new(@project) + @charts[:month] = Charts::MonthChart.new(@project) + @charts[:year] = Charts::YearChart.new(@project) end def gitlab diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index a199d1d..1888710 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -109,4 +109,8 @@ module ApplicationHelper def current_action?(*args) args.any? { |v| v.to_s.downcase == action_name } end + + def date_from_to(from, to) + "#{from.to_s(:short)} - #{to.to_s(:short)}" + end end diff --git a/app/views/layouts/project.html.haml b/app/views/layouts/project.html.haml index 67eef3e..6827cf8 100644 --- a/app/views/layouts/project.html.haml +++ b/app/views/layouts/project.html.haml @@ -26,17 +26,17 @@ %i.icon-list-alt Builds %small.pull-right= @project.builds.count + = nav_link path: 'projects#charts' do + = link_to charts_project_path(@project) do + %i.icon-bar-chart + Charts = nav_link controller: :runner_projects do = link_to project_runner_projects_path(@project) do %i.icon-cog Runners %small.pull-right= @project.runner_projects.count - = nav_link path: 'projects#stats' do - = link_to stats_project_path(@project) do - %i.icon-bar-chart - Charts - = nav_link path: 'projects#details' do - = link_to details_project_path(@project) do + = nav_link path: 'projects#integration' do + = link_to integration_project_path(@project) do %i.icon-wrench Integration = nav_link path: 'projects#edit' do diff --git a/app/views/projects/charts.html.haml b/app/views/projects/charts.html.haml new file mode 100644 index 0000000..84ab315 --- /dev/null +++ b/app/views/projects/charts.html.haml @@ -0,0 +1,63 @@ +%fieldset + %legend + Builds chart for last week + (#{date_from_to(Date.today - 7.days, Date.today)}) + + %canvas#weekChart.padded{width: 800, height: 200} + +%fieldset + %legend + Builds chart for last month + (#{date_from_to(Date.today - 30.days, Date.today)}) + + %canvas#monthChart.padded{width: 800, height: 300} + +%fieldset + %legend Builds chart for last year + %canvas#yearChart.padded{width: 800, height: 400} + +%fieldset + %legend Overall + %p + Total: + %strong= pluralize @project.builds.count, 'build' + %p + Successful: + %strong= pluralize @project.builds.success.count, 'build' + %p + Failed: + %strong= pluralize @project.builds.failed.count, 'build' + + %p + Success ratio: + %strong + #{success_ratio(@project.builds.success, @project.builds.failed)}% + + %p + Commits covered: + %strong + = @project.builds.uniq_sha.count + +- [:week, :month, :year].each do |scope| + :javascript + var data = { + labels : #{@charts[scope].labels.to_json}, + datasets : [ + { + fillColor : "rgba(220,220,220,0.5)", + strokeColor : "rgba(220,220,220,1)", + pointColor : "rgba(220,220,220,1)", + pointStrokeColor : "#EEE", + data : #{@charts[scope].total.to_json} + }, + { + fillColor : "#4A3", + strokeColor : "rgba(151,187,205,1)", + pointColor : "rgba(151,187,205,1)", + pointStrokeColor : "#fff", + data : #{@charts[scope].success.to_json} + } + ] + } + var ctx = $("##{scope}Chart").get(0).getContext("2d"); + new Chart(ctx).Line(data,{"scaleOverlay": true}); diff --git a/app/views/projects/details.html.haml b/app/views/projects/integration.html.haml index f9b5eb2..f9b5eb2 100644 --- a/app/views/projects/details.html.haml +++ b/app/views/projects/integration.html.haml diff --git a/app/views/projects/stats.html.haml b/app/views/projects/stats.html.haml deleted file mode 100644 index 5810ad8..0000000 --- a/app/views/projects/stats.html.haml +++ /dev/null @@ -1,48 +0,0 @@ -%fieldset - %legend Builds chart for last year - %canvas#statChart.padded{width: 800, height: 400} - -%fieldset - %legend Overall - %p - Total: - %strong= pluralize @project.builds.count, 'build' - %p - Successful: - %strong= pluralize @project.builds.success.count, 'build' - %p - Failed: - %strong= pluralize @project.builds.failed.count, 'build' - - %p - Success ratio: - %strong - #{success_ratio(@project.builds.success, @project.builds.failed)}% - - %p - Commits covered: - %strong - = @project.builds.uniq_sha.count - -:javascript - var data = { - labels : #{@stats[:labels].to_json}, - datasets : [ - { - fillColor : "rgba(220,220,220,0.5)", - strokeColor : "rgba(220,220,220,1)", - pointColor : "rgba(220,220,220,1)", - pointStrokeColor : "#EEE", - data : #{@stats[:total].to_json} - }, - { - fillColor : "#4A3", - strokeColor : "rgba(151,187,205,1)", - pointColor : "rgba(151,187,205,1)", - pointStrokeColor : "#fff", - data : #{@stats[:success].to_json} - } - ] - } - var ctx = $("#statChart").get(0).getContext("2d"); - new Chart(ctx).Line(data,{"scaleOverlay": true}); diff --git a/app/views/shared/_guide.html.haml b/app/views/shared/_guide.html.haml index 28e7689..33d7d0a 100644 --- a/app/views/shared/_guide.html.haml +++ b/app/views/shared/_guide.html.haml @@ -4,7 +4,7 @@ %li Activate at least one runner for project #{link_to 'here', project_runner_projects_path(@project), target: :blank} %li - Activate GitLab CI service for project inside GitLab. Visit #{link_to 'integration tab', details_project_path(@project), target: :blank} for more details + Activate GitLab CI service for project inside GitLab. Visit #{link_to 'integration tab', integration_project_path(@project), target: :blank} for more details %li Try test settings to confirm everything is working %li diff --git a/config/routes.rb b/config/routes.rb index 095b7fb..ba175c9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -13,8 +13,8 @@ GitlabCi::Application.routes.draw do member do get :status - get :stats - get :details + get :charts + get :integration post :build end diff --git a/lib/charts.rb b/lib/charts.rb new file mode 100644 index 0000000..45ad22e --- /dev/null +++ b/lib/charts.rb @@ -0,0 +1,54 @@ +module Charts + class Chart + attr_reader :labels, :total, :success, :project + + def initialize(project) + @labels = [] + @total = [] + @success = [] + @project = project + + collect + end + + + def push(from, to, format) + @labels << from.strftime(format) + @total << project.builds.where("? > created_at AND created_at > ?", to, from).count + @success << project.builds.where("? > created_at AND created_at > ?", to, from).success.count + end + end + + class YearChart < Chart + def collect + 13.times do |i| + start_month = (Date.today.years_ago(1) + i.month).beginning_of_month + end_month = start_month.end_of_month + + push(start_month, end_month, "%d %B %Y") + end + end + end + + class MonthChart < Chart + def collect + 30.times do |i| + start_day = Date.today - 30.days + i.days + end_day = Date.today - 30.days + i.day + 1.day + + push(start_day, end_day, "%d %B") + end + end + end + + class WeekChart < Chart + def collect + 7.times do |i| + start_day = Date.today - 7.days + i.days + end_day = Date.today - 7.days + i.day + 1.day + + push(start_day, end_day, "%d %B") + end + end + end +end diff --git a/spec/features/projects_spec.rb b/spec/features/projects_spec.rb index f876060..485745e 100644 --- a/spec/features/projects_spec.rb +++ b/spec/features/projects_spec.rb @@ -34,7 +34,7 @@ describe "Projects" do describe "GET /projects/:id/stats" do before do - visit stats_project_path(@project) + visit charts_project_path(@project) end it { page.should have_content @project.name } @@ -43,7 +43,7 @@ describe "Projects" do describe "GET /projects/:id/details" do before do - visit details_project_path(@project) + visit integration_project_path(@project) end it { page.should have_content @project.name } |