#435: added mock of logic

This commit is contained in:
Vokhmin Alexey V 2014-10-08 00:16:48 +04:00
parent fce6bb4142
commit 71e7b3b37e
9 changed files with 3651 additions and 3 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

View File

@ -0,0 +1,150 @@
RosaABF.controller 'StatisticsController', ['$scope', '$http', '$filter', ($scope, $http, $filter) ->
$scope.range = 'last_30_days'
$scope.range_start = $('#range_start').attr('value')
$scope.range_end = $('#range_end').attr('value')
$scope.loading = true
$scope.statistics = {}
$scope.statistics_path = '/statistics'
$scope.colors = [
'56, 132, 158',
'77, 169, 68',
'241, 128, 73',
'174, 199, 232',
'255, 187, 120',
'152, 223, 138',
'214, 39, 40',
'31, 119, 180'
]
$scope.charts = {}
$scope.init = ->
$('#range-form .date_picker').datepicker
'dateFormat': 'yy-mm-dd'
maxDate: 0
minDate: -366
showButtonPanel: true
$scope.rangeChange()
true
$scope.prepareRange = ->
range_start = new Date($scope.range_start)
range_end = new Date($scope.range_end)
if range_start > range_end
tpm = $scope.range_start
$scope.range_start = $scope.range_end
$scope.range_end = tpm
$scope.rangeChange = ->
$scope.loading = true
$scope.statistics = {}
$scope.prepareRange()
$('.doughnut-legend').remove()
params =
range: $scope.range
range_start: $scope.range_start
range_end: $scope.range_end
format: 'json'
$http.get($scope.statistics_path, params: params).success (results) ->
$scope.statistics = results
$scope.loading = false
# BuildLists
if $scope.statistics.build_lists
$scope.initBuildListsChart()
# PullRequests
if $scope.statistics.pull_requests
$scope.initPullRequestsChart()
# Issues
if $scope.statistics.issues
$scope.initIssuesChart()
.error (data, status, headers, config) ->
console.log 'error:'
$scope.loading = false
$scope.dateChart = (id, collections) ->
new_collections = $.grep collections, ( c ) ->
return c
if collections.length == new_collections.length
$scope.charts[id].destroy() if $scope.charts[id]
points = collections[0]
factor = points.length // 45 + 1
tooltipTitles = []
labels = _.map points, (d, index) ->
x = d.x
format =
if $scope.statistics.unit == 'hour'
# input date should have format: 'yyyy-MM-ddTHH:mm:ssZ'
x = x.replace(/\s/, 'T') + 'Z'
'HH:mm'
else
'MMM dd'
x = $filter('date')(x, format)
tooltipTitles.push x
if index %% factor == 0
x
else
''
datasets = _.map collections, (collection, index) ->
data = _.map collection, (d) ->
d.y
dataset =
fillColor: "rgba(#{ $scope.colors[index] }, 0.5)"
strokeColor: "rgba(#{ $scope.colors[index] }, 1)"
pointColor: "rgba(#{ $scope.colors[index] }, 1)"
pointStrokeColor: "#fff"
data: data
data =
datasets: datasets
# We display only limited count of labels on X axis, but tooltips should have titles
# See: Chart.js "Added by avokhmin"
labels: labels
tooltipTitles: tooltipTitles
options =
responsive: true
context = $(id)[0].getContext('2d')
$scope.charts[id] = new Chart(context).Line(data, options)
$scope.initBuildListsChart = ->
$scope.dateChart '#build_lists_chart', [
$scope.statistics.build_lists.build_started,
$scope.statistics.build_lists.success,
$scope.statistics.build_lists.build_error,
$scope.statistics.build_lists.build_published
]
$scope.initPullRequestsChart = ->
$scope.dateChart '#pull_requests_chart', [
$scope.statistics.pull_requests.open,
$scope.statistics.pull_requests.closed,
$scope.statistics.pull_requests.approved
]
$scope.initIssuesChart = ->
$scope.dateChart '#issues_chart', [
$scope.statistics.issues.open,
$scope.statistics.issues.closed,
$scope.statistics.issues.approved
]
]

3383
app/assets/javascripts/lib/Chart.js vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,19 @@
module StatisticsHelper
RANGES = %w(
twenty_four_hours
last_7_days
last_30_days
last_60_days
last_90_days
last_180_days
last_year
custom
)
def statistics_range_options
options_for_select(
RANGES.map { |r| [I18n.t(r, scope: 'statistics.helper.period'), r] }
)
end
end

View File

@ -0,0 +1,55 @@
.row
.span8
.graph-wrapper
%h3
%span.graph-key-color1
= t('.build_started_title')
%span.graph-key-color2
= t('.success_title')
%span.graph-key-color3
= t('.build_error_title')
%span.graph-key-color4
= t('.build_published_title')
.centered.graph-loading{ ng_show: 'loading' }
= image_tag 'loading-large.gif'
.no-data{ ng_hide: 'loading || statistics.build_lists' }
= t('.no_data')
%canvas#build_lists_chart ng-show='statistics.build_lists'
.span3
.panel-wrapper
%h3
= t('.total_build_started')
.panel-data
= image_tag 'loading-small.gif', ng_show: 'loading'
.no-data{ ng_hide: 'loading || statistics.build_lists.build_started_count >= 0' }
= t('.no_data')
{{ statistics.build_lists.build_started_count | number }}
.panel-wrapper
%h3
= t('.total_success')
.panel-data
= image_tag 'loading-small.gif', ng_show: 'loading'
.no-data{ ng_hide: 'loading || statistics.build_lists.success_count >= 0' }
= t('.no_data')
{{ statistics.build_lists.success_count | number }}
.panel-wrapper
%h3
= t('.total_build_error')
.panel-data
= image_tag 'loading-small.gif', ng_show: 'loading'
.no-data{ ng_hide: 'loading || statistics.build_lists.build_error_count >= 0' }
= t('.no_data')
{{ statistics.build_lists.build_error_count | number }}
.panel-wrapper
%h3
= t('.total_build_published')
.panel-data
= image_tag 'loading-small.gif', ng_show: 'loading'
.no-data{ ng_hide: 'loading || statistics.build_lists.build_published_count >= 0' }
= t('.no_data')
{{ statistics.build_lists.build_published_count | number }}

View File

@ -0,0 +1,14 @@
.row
.span11.flash_notify
%h3.text-info
= t('.header')
= form_tag '#', class: 'form-inline alert alert-info centered', id: 'range-form' do
%label.control-label
= t('.range_label')
= select_tag 'range', statistics_range_options, id: 'range_select', class: 'select input-medium', ng_model: 'range', ng_change: 'rangeChange()'
%span{ ng_show: "range == 'custom'" }
= text_field_tag :range_start, Date.today - 1.month, class: 'date_picker input-medium', placeholder: t('.range_start_placeholder'), ng_model: 'range_start', ng_change: 'rangeChange()', readonly: true
= t('.range_separator')
= text_field_tag :range_end, Date.today, class: 'date_picker input-medium', placeholder: t('.range_end_placeholder'), ng_model: 'range_end', ng_change: 'rangeChange()', readonly: true

View File

@ -1,3 +1,7 @@
- set_meta_tags title: t('.header')
= t('.hello')
#manage-statistics{ ng_controller: 'StatisticsController', ng_init: 'init()' }
= render 'filter'
= render 'build_lists'

View File

@ -1,5 +1,28 @@
en:
statistics:
index:
header: Statistics
hello: QQqqq
header: "Statistics"
filter:
header: "Statistics"
range_label: "Display data for"
range_start_placeholder: "Select a start date"
range_separator: " and "
range_end_placeholder: "Select an end date"
page_views_title: " Page views"
unique_visitors_title: " Unique visitors"
total_page_views: "Total page views"
total_user_sessions: "Total user sessions"
no_data: "No data available"
helper:
period:
twenty_four_hours: "the last 24 hours"
last_7_days: "the last 7 days"
last_30_days: "the last 30 days"
last_60_days: "the last 60 days"
last_90_days: "the last 90 days"
last_180_days: "the last 6 months"
last_year: "the last year"
custom: "custom"