diff --git a/app/assets/stylesheets/new-templates.css.scss b/app/assets/stylesheets/new-templates.css.scss index 1f07d23fdd93cbc9b6550b16b3ea9a2bcf1f37c8..dd13360bbb8741e7d86eca1279696399dd969c4d 100644 --- a/app/assets/stylesheets/new-templates.css.scss +++ b/app/assets/stylesheets/new-templates.css.scss @@ -77,3 +77,6 @@ /* code */ @import 'new_styles/code'; + +/* statistics */ +@import 'new_styles/statistics' \ No newline at end of file diff --git a/app/assets/stylesheets/new_styles/_statistics.scss b/app/assets/stylesheets/new_styles/_statistics.scss new file mode 100644 index 0000000000000000000000000000000000000000..30a9a871bf8a3427179fff701320db3429beddd8 --- /dev/null +++ b/app/assets/stylesheets/new_styles/_statistics.scss @@ -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; + } + } +} \ No newline at end of file diff --git a/app/controllers/statistics_controller.rb b/app/controllers/statistics_controller.rb index 61c9998772ff8513991b1ff367c31f0cc3494064..aa7ce1825fbfabda7c700b063d16f6270b1679d4 100644 --- a/app/controllers/statistics_controller.rb +++ b/app/controllers/statistics_controller.rb @@ -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.html { render layout: "application" } end end - -end +end \ No newline at end of file diff --git a/app/helpers/statistics_helper.rb b/app/helpers/statistics_helper.rb new file mode 100644 index 0000000000000000000000000000000000000000..ed9fd1a87c1540a439c887eabf1453f3b9039ea4 --- /dev/null +++ b/app/helpers/statistics_helper.rb @@ -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 \ No newline at end of file diff --git a/app/presenters/statistics_presenter.rb b/app/presenters/statistics_presenter.rb index 5f8459a8b56e398887024309baa199fb1fd25ccd..815092db5412dd436e0d15781c1ce0cc37e556ab 100644 --- a/app/presenters/statistics_presenter.rb +++ b/app/presenters/statistics_presenter.rb @@ -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' => [] + 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 + + def base_data + { + 'name' => name, + 'network' => 'Diaspora', + 'version' => version, + 'registrations_open' => open_registrations?, + 'services' => available_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 + end - result + 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 + + 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 +end \ No newline at end of file diff --git a/app/views/statistics/_statistic.haml b/app/views/statistics/_statistic.haml new file mode 100644 index 0000000000000000000000000000000000000000..130dc6c1af515916bb7c498969efb0eebb969220 --- /dev/null +++ b/app/views/statistics/_statistic.haml @@ -0,0 +1,5 @@ +.span-3 + %h3{:class => activated} + = name + .data + = value \ No newline at end of file diff --git a/app/views/statistics/statistics.html.haml b/app/views/statistics/statistics.html.haml new file mode 100644 index 0000000000000000000000000000000000000000..d1b04619414694e325be5260776cac060c02ef9e --- /dev/null +++ b/app/views/statistics/statistics.html.haml @@ -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) \ No newline at end of file diff --git a/app/views/statistics/statistics.mobile.haml b/app/views/statistics/statistics.mobile.haml new file mode 100644 index 0000000000000000000000000000000000000000..d1b04619414694e325be5260776cac060c02ef9e --- /dev/null +++ b/app/views/statistics/statistics.mobile.haml @@ -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) \ No newline at end of file diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index 468f929e0ee5f8b6b05474dc716ca14f991c53ff..5b140c6a3dac776fa7a19a85ff633f5959f135fa 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -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"