diff options
author | Michael Sprauer <Michael@Sprauer.net> | 2013-10-28 12:36:00 +0100 |
---|---|---|
committer | Michael Sprauer <Sprauer@inline.de> | 2013-11-13 18:18:59 +0100 |
commit | 46ef51e16cde2de3ebf367e8f44d84680f6729c7 (patch) | |
tree | 4dd293b80cd147a45f107cb4c027cf064f74527a /app | |
parent | 84432ef38e01289412faddbccffeefca30a69166 (diff) | |
download | gitlab-ci-46ef51e16cde2de3ebf367e8f44d84680f6729c7.tar.gz |
New Chart: Build duration
Diffstat (limited to 'app')
-rw-r--r-- | app/assets/javascripts/charts.js.coffee | 11 | ||||
-rw-r--r-- | app/controllers/charts_controller.rb | 39 | ||||
-rw-r--r-- | app/controllers/projects_controller.rb | 9 | ||||
-rw-r--r-- | app/views/charts/_build_times.haml | 25 | ||||
-rw-r--r-- | app/views/charts/_builds.haml (renamed from app/views/projects/charts.html.haml) | 31 | ||||
-rw-r--r-- | app/views/charts/_overall.haml | 21 | ||||
-rw-r--r-- | app/views/charts/index.html.haml | 7 | ||||
-rw-r--r-- | app/views/layouts/project.html.haml | 2 |
8 files changed, 115 insertions, 30 deletions
diff --git a/app/assets/javascripts/charts.js.coffee b/app/assets/javascripts/charts.js.coffee new file mode 100644 index 0000000..02744cf --- /dev/null +++ b/app/assets/javascripts/charts.js.coffee @@ -0,0 +1,11 @@ + +reloadChart = (event, data) -> + $('#charts').html(data.responseText) + $('.chart-links li.active').removeClass('active') + $(event.target).parent('li').addClass('active') + #console.log($(event.target).parent('li')) + + +jQuery -> + $('.chart-links a').bind('ajax:complete',reloadChart) + $('.chart-links a').first().click()
\ No newline at end of file diff --git a/app/controllers/charts_controller.rb b/app/controllers/charts_controller.rb new file mode 100644 index 0000000..b68fc1e --- /dev/null +++ b/app/controllers/charts_controller.rb @@ -0,0 +1,39 @@ +class ChartsController < ApplicationController + before_filter :authenticate_user! + before_filter :project + before_filter :authorize_access_project! + + layout 'project' + + def index + end + + def show + case @chart + when 'builds' then builds + when 'build_times' then build_times + end + end + + def builds + @charts = {} + @charts[:week] = Charts::WeekChart.new(@project) + @charts[:month] = Charts::MonthChart.new(@project) + @charts[:year] = Charts::YearChart.new(@project) + + render :partial => 'charts/builds' + end + + def build_times + @charts = {} + @charts[:build_times] = Charts::BuildTime.new(@project) + render :partial => 'charts/build_times' + end + + protected + def project + @project = Project.find(params[:project_id]) + @chart = params[:id] || 'builds' + end + +end diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 2eb5de6..fc95c2a 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, :integration, :show, :status, :edit, :update, :destroy, :charts] + before_filter :project, only: [:build, :integration, :show, :status, :edit, :update, :destroy] before_filter :authorize_access_project!, except: [:build, :gitlab, :status, :index, :show, :new, :create] before_filter :authenticate_token!, only: [:build] before_filter :no_cache, only: [:status] @@ -117,13 +117,6 @@ class ProjectsController < ApplicationController send_file Rails.root.join('public', image_name), filename: image_name, disposition: 'inline' end - def charts - @charts = {} - @charts[:week] = Charts::WeekChart.new(@project) - @charts[:month] = Charts::MonthChart.new(@project) - @charts[:year] = Charts::YearChart.new(@project) - end - protected def project diff --git a/app/views/charts/_build_times.haml b/app/views/charts/_build_times.haml new file mode 100644 index 0000000..e8156d6 --- /dev/null +++ b/app/views/charts/_build_times.haml @@ -0,0 +1,25 @@ + +%fieldset + %legend + Builds duration chart for last 30 builds + + %canvas#build_timesChart.padded{width: 800, height: 200} + +=render :partial => 'overall' + +- [:build_times].each do |scope| + :javascript + var data = { + labels : #{@charts[scope].labels.to_json}, + datasets : [ + { + fillColor : "#4A3", + strokeColor : "rgba(151,187,205,1)", + pointColor : "rgba(151,187,205,1)", + pointStrokeColor : "#fff", + data : #{@charts[scope].build_times.to_json} + } + ] + } + var ctx = $("##{scope}Chart").get(0).getContext("2d"); + new Chart(ctx).Line(data,{"scaleOverlay": true}); diff --git a/app/views/projects/charts.html.haml b/app/views/charts/_builds.haml index 84ab315..b5a70cc 100644 --- a/app/views/projects/charts.html.haml +++ b/app/views/charts/_builds.haml @@ -1,3 +1,5 @@ + + %fieldset %legend Builds chart for last week @@ -13,30 +15,17 @@ %canvas#monthChart.padded{width: 800, height: 300} %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 +=render :partial => 'charts/overall' - [:week, :month, :year].each do |scope| :javascript diff --git a/app/views/charts/_overall.haml b/app/views/charts/_overall.haml new file mode 100644 index 0000000..36e1616 --- /dev/null +++ b/app/views/charts/_overall.haml @@ -0,0 +1,21 @@ +%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
\ No newline at end of file diff --git a/app/views/charts/index.html.haml b/app/views/charts/index.html.haml new file mode 100644 index 0000000..b88169f --- /dev/null +++ b/app/views/charts/index.html.haml @@ -0,0 +1,7 @@ +%ul.nav.nav-tabs.chart-links + %li + = link_to 'Build duration', project_chart_path(@project, 'build_times'), remote: true, :data => {:toggle=>"charts"} + %li + = link_to 'All builds', project_chart_path(@project, 'builds'), remote: true, :data => {:toggle=>"charts"} + +#charts
\ No newline at end of file diff --git a/app/views/layouts/project.html.haml b/app/views/layouts/project.html.haml index 3daba2c..e897742 100644 --- a/app/views/layouts/project.html.haml +++ b/app/views/layouts/project.html.haml @@ -28,7 +28,7 @@ Builds %small.pull-right= @project.builds.count = nav_link path: 'projects#charts' do - = link_to charts_project_path(@project) do + = link_to project_charts_path(@project) do %i.icon-bar-chart Charts = nav_link path: 'projects#integration' do |