Merge pull request #5464 from SansPseudoFix/statistics_design

[Feature] Statistics page
This commit is contained in:
Jonne Haß 2015-01-24 23:57:06 +01:00
commit 9eaa92068f
9 changed files with 227 additions and 32 deletions

View file

@ -152,6 +152,7 @@ diaspora.yml file**. The existing settings from 0.4.x and before will not work a
* Allows users to export their data in gzipped JSON format from their user settings page [#5499](https://github.com/diaspora/diaspora/pull/5499)
* Strip EXIF data from newly uploaded images [#5510](https://github.com/diaspora/diaspora/pull/5510)
* Hide user setting if the community spotlight is not enabled on the pod [#5562](https://github.com/diaspora/diaspora/pull/5562)
* Add HTML view for pod statistics [#5464](https://github.com/diaspora/diaspora/pull/5464)
# 0.4.1.2

View file

@ -77,3 +77,6 @@
/* code */
@import 'new_styles/code';
/* statistics */
@import 'new_styles/statistics'

View file

@ -0,0 +1,28 @@
.page-statistics {
h1{ text-align: center; }
h3{
margin: 0px;
padding: 10px;
background-color: $green;
}
.span-3 {
width: 30%;
height: 150px;
text-align: center;
border: 1px solid $border-grey;
margin-bottom: 10px;
border-radius: 5px;
.data{
word-wrap: break-word;
overflow: hidden;
margin-top: 25px;
font-size: 25px;
line-height: 30px;
}
.serv-disabled{
background-color: $background-grey;
}
}
}

View file

@ -3,13 +3,14 @@
# the COPYRIGHT file.
class StatisticsController < ApplicationController
respond_to :html, :json
use_bootstrap_for :statistics
respond_to :json
def statistics
@statistics = StatisticsPresenter.new
respond_to do |format|
format.json { render :json => StatisticsPresenter.new }
format.json { render json: @statistics }
format.any(:html, :mobile) { render 'statistics/statistics.html.haml' }
end
end
end
end

View file

@ -0,0 +1,29 @@
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
module StatisticsHelper
def registrations_status statistics
if statistics.open_registrations?
I18n.t('statistics.open')
else
I18n.t('statistics.closed')
end
end
def service_status service, available_services
if available_services.include? service
I18n.t('statistics.enabled')
else
I18n.t('statistics.disabled')
end
end
def service_class service, available_services
if available_services.include? service
"serv-enabled"
else
"serv-disabled"
end
end
end

View file

@ -1,38 +1,125 @@
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
class StatisticsPresenter
def as_json(options={})
result = {
'name' => AppConfig.settings.pod_name,
'network' => "Diaspora",
'version' => AppConfig.version_string,
'registrations_open' => AppConfig.settings.enable_registrations,
'services' => []
}
if AppConfig.privacy.statistics.user_counts?
result['total_users'] = User.count
result['active_users_halfyear'] = User.halfyear_actives.count
result['active_users_monthly'] = User.monthly_actives.count
end
if AppConfig.privacy.statistics.post_counts?
result['local_posts'] = self.local_posts
end
if AppConfig.privacy.statistics.comment_counts?
result['local_comments'] = self.local_comments
end
result["services"] = Configuration::KNOWN_SERVICES.select {|service| AppConfig["services.#{service}.enable"]}.map(&:to_s)
Configuration::KNOWN_SERVICES.each do |service, options|
result[service.to_s] = AppConfig["services.#{service}.enable"]
end
def as_json options={}
base_data.merge(user_counts)
.merge(post_counts)
.merge(comment_counts)
.merge(all_services)
.merge(legacy_services) # Remove in 0.6
end
result
def base_data
{
'name' => name,
'network' => 'Diaspora',
'version' => version,
'registrations_open' => open_registrations?,
'services' => available_services
}
end
def name
AppConfig.settings.pod_name
end
def version
AppConfig.version_string
end
def open_registrations?
AppConfig.settings.enable_registrations
end
def user_counts
return {} unless expose_user_counts?
{
'total_users' => total_users,
'active_users_monthly' => monthly_users,
'active_users_halfyear' => halfyear_users
}
end
def expose_user_counts?
AppConfig.privacy.statistics.user_counts?
end
def total_users
@total_users ||= User.joins(:person)
.where(people: {closed_account: false})
.where.not(username: nil)
.count
end
def monthly_users
@monthly_users ||= User.halfyear_actives.count
end
def halfyear_users
@halfyear_users ||= User.monthly_actives.count
end
def post_counts
return {} unless expose_posts_counts?
{
'local_posts' => local_posts
}
end
def local_posts
Post.where(:type => "StatusMessage").joins(:author).where("owner_id IS NOT null").count
@local_posts ||= Post.where(type: "StatusMessage")
.joins(:author)
.where("owner_id IS NOT null")
.count
end
def expose_posts_counts?
AppConfig.privacy.statistics.post_counts?
end
def comment_counts
return {} unless expose_comment_counts?
{
'local_comments' => local_comments
}
end
def expose_comment_counts?
AppConfig.privacy.statistics.comment_counts?
end
def local_comments
Comment.joins(:author).where("owner_id IS NOT null").count
@local_comments ||= Comment.joins(:author)
.where("owner_id IS NOT null")
.count
end
end
def all_services_helper
result = {}
Configuration::KNOWN_SERVICES.each {|service, options|
result[service.to_s] = AppConfig["services.#{service}.enable"]
}
result
end
def all_services
@all_services ||= all_services_helper
end
def available_services
Configuration::KNOWN_SERVICES.select {|service|
AppConfig["services.#{service}.enable"]
}.map(&:to_s)
end
def legacy_services
Configuration::KNOWN_SERVICES.each_with_object({}) {|service, result|
result[service.to_s] = AppConfig["services.#{service}.enable"]
}
end
end

View file

@ -0,0 +1,5 @@
.span-3
%h3{:class => activated}
= name
.data
= value

View file

@ -0,0 +1,24 @@
-# Copyright (c) 2010-2011, Diaspora Inc. This file is
-# licensed under the Affero General Public License version 3 or later. See
-# the COPYRIGHT file.
%header
.row-fluid
%h1
= t('_statistics')
= render 'statistics/statistic', name: t('statistics.name'), value: @statistics.name, activated: "serv-enabled"
= render 'statistics/statistic', name: t('statistics.version'), value: @statistics.version, activated: "serv-enabled"
= render 'statistics/statistic', name: t('statistics.registrations'), value: registrations_status(@statistics), activated: "serv-enabled"
- if @statistics.expose_user_counts?
= render 'statistics/statistic', name: t('statistics.total_users'), value: @statistics.total_users, activated: "serv-enabled"
= render 'statistics/statistic', name: t('statistics.active_users_halfyear'), value: @statistics.halfyear_users, activated: "serv-enabled"
= render 'statistics/statistic', name: t('statistics.active_users_monthly'), value: @statistics.monthly_users, activated: "serv-enabled"
- if @statistics.expose_posts_counts?
= render 'statistics/statistic', name: t('statistics.local_posts'), value: @statistics.local_posts, activated: "serv-enabled"
- if @statistics.expose_comment_counts?
= render 'statistics/statistic', name: t('statistics.local_comments'), value: @statistics.local_comments, activated: "serv-enabled"
.row-fluid
%h1
= t('statistics.services')
- Configuration::KNOWN_SERVICES.each do |service|
= render 'statistics/statistic', name: "#{service.capitalize}", value: service_status(service, @statistics.available_services), activated: service_class(service, @statistics.available_services)

View file

@ -47,6 +47,7 @@ en:
_contacts: "Contacts"
welcome: "Welcome!"
_terms: "terms"
_statistics: "Statistics"
#for reference translation, the real activerecord english transations are actually
#in en-US, en-GB, and en-AU yml files
@ -1380,3 +1381,19 @@ en:
default: "The secret code did not match with the image"
user: "The secret image and code were different"
failed: "Human verification failed"
statistics:
name: "Name"
network: "Network"
services: "Services"
total_users: "Total users"
active_users_halfyear: "Active users half year"
active_users_monthly: "Active users monthly"
local_posts: "Local posts"
local_comments: "Local comments"
version: "Version"
registrations: "Registrations"
enabled: "Available"
disabled: "Not available"
open: "Open"
closed: "Closed"