From b7064677ff1b86d373dafe9ede12f303c28200c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonne=20Ha=C3=9F?= Date: Thu, 23 Jul 2015 16:29:31 +0200 Subject: [PATCH] Collapse StatisticsController into NodeInfoController --- app/assets/stylesheets/application.scss | 2 +- .../_statistics.scss => statistics.scss} | 2 +- app/controllers/node_info_controller.rb | 8 +++++ app/controllers/statistics_controller.rb | 15 ---------- .../{statistics => node_info}/_statistic.haml | 0 app/views/node_info/_statistics.haml | 21 +++++++++++++ app/views/node_info/statistics.html.haml | 2 ++ app/views/node_info/statistics.mobile.haml | 1 + app/views/statistics/_statistics.haml | 23 -------------- app/views/statistics/statistics.html.haml | 1 - app/views/statistics/statistics.mobile.haml | 1 - config/routes.rb | 4 +-- spec/controllers/node_info_controller_spec.rb | 23 ++++++++++++++ .../controllers/statistics_controller_spec.rb | 30 ------------------- spec/presenters/node_info_presenter_spec.rb | 2 +- 15 files changed, 59 insertions(+), 76 deletions(-) rename app/assets/stylesheets/{new_styles/_statistics.scss => statistics.scss} (92%) delete mode 100644 app/controllers/statistics_controller.rb rename app/views/{statistics => node_info}/_statistic.haml (100%) create mode 100644 app/views/node_info/_statistics.haml create mode 100644 app/views/node_info/statistics.html.haml create mode 100644 app/views/node_info/statistics.mobile.haml delete mode 100644 app/views/statistics/_statistics.haml delete mode 100644 app/views/statistics/statistics.html.haml delete mode 100644 app/views/statistics/statistics.mobile.haml delete mode 100644 spec/controllers/statistics_controller_spec.rb diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 3638522c2..427c0d549 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -95,4 +95,4 @@ @import 'highlightjs/github'; /* statistics */ -@import 'new_styles/statistics'; +@import 'statistics'; diff --git a/app/assets/stylesheets/new_styles/_statistics.scss b/app/assets/stylesheets/statistics.scss similarity index 92% rename from app/assets/stylesheets/new_styles/_statistics.scss rename to app/assets/stylesheets/statistics.scss index 30a9a871b..983fbd1b7 100644 --- a/app/assets/stylesheets/new_styles/_statistics.scss +++ b/app/assets/stylesheets/statistics.scss @@ -1,4 +1,4 @@ -.page-statistics { +.page-node_info.action-statistics { h1{ text-align: center; } h3{ diff --git a/app/controllers/node_info_controller.rb b/app/controllers/node_info_controller.rb index 689c8603b..bb0aaa14f 100644 --- a/app/controllers/node_info_controller.rb +++ b/app/controllers/node_info_controller.rb @@ -1,5 +1,6 @@ class NodeInfoController < ApplicationController respond_to :json + respond_to :html, only: :statistics def jrd render json: NodeInfo.jrd(CGI.unescape(node_info_url("123.123").sub("123.123", "%{version}"))) @@ -13,4 +14,11 @@ class NodeInfoController < ApplicationController head :not_found end end + + def statistics + respond_to do |format| + format.json { render json: StatisticsPresenter.new } + format.all { @statistics = NodeInfoPresenter.new("1.0") } + end + end end diff --git a/app/controllers/statistics_controller.rb b/app/controllers/statistics_controller.rb deleted file mode 100644 index 567a81745..000000000 --- a/app/controllers/statistics_controller.rb +++ /dev/null @@ -1,15 +0,0 @@ -# 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 StatisticsController < ApplicationController - respond_to :html, :json - - def statistics - @statistics = StatisticsPresenter.new - respond_to do |format| - format.json { render json: @statistics } - format.all - end - end -end diff --git a/app/views/statistics/_statistic.haml b/app/views/node_info/_statistic.haml similarity index 100% rename from app/views/statistics/_statistic.haml rename to app/views/node_info/_statistic.haml diff --git a/app/views/node_info/_statistics.haml b/app/views/node_info/_statistics.haml new file mode 100644 index 000000000..212c19c11 --- /dev/null +++ b/app/views/node_info/_statistics.haml @@ -0,0 +1,21 @@ +-# Copyright (c) 2010-2011, Diaspora Inc. This file is +-# licensed under the Affero General Public License version 3 or later. See +-# the COPYRIGHT file. + +.row + %h1= t("_statistics") + = render "statistic", name: t("statistics.name"), value: @statistics.name, activated: "serv-enabled" + = render "statistic", name: t("statistics.version"), value: @statistics.version, activated: "serv-enabled" + = render "statistic", name: t("statistics.registrations"), value: registrations_status(@statistics), activated: registrations_status_class(@statistics) + - if @statistics.expose_user_counts? + = render "statistic", name: t("statistics.total_users"), value: @statistics.total_users, activated: "serv-enabled" + = render "statistic", name: t("statistics.active_users_halfyear"), value: @statistics.halfyear_users, activated: "serv-enabled" + = render "statistic", name: t("statistics.active_users_monthly"), value: @statistics.monthly_users, activated: "serv-enabled" + - if @statistics.expose_posts_counts? + = render "statistic", name: t("statistics.local_posts"), value: @statistics.local_posts, activated: "serv-enabled" + - if @statistics.expose_comment_counts? + = render "statistic", name: t("statistics.local_comments"), value: @statistics.local_comments, activated: "serv-enabled" +.row + %h1= t("statistics.services") + - Configuration::KNOWN_SERVICES.each do |service| + = render "statistic", name: "#{service.capitalize}", value: service_status(service, @statistics.available_services), activated: service_class(service, @statistics.available_services) diff --git a/app/views/node_info/statistics.html.haml b/app/views/node_info/statistics.html.haml new file mode 100644 index 000000000..ba22e63d8 --- /dev/null +++ b/app/views/node_info/statistics.html.haml @@ -0,0 +1,2 @@ +.container-fluid + = render "statistics" diff --git a/app/views/node_info/statistics.mobile.haml b/app/views/node_info/statistics.mobile.haml new file mode 100644 index 000000000..246fec5d9 --- /dev/null +++ b/app/views/node_info/statistics.mobile.haml @@ -0,0 +1 @@ += render "statistics" diff --git a/app/views/statistics/_statistics.haml b/app/views/statistics/_statistics.haml deleted file mode 100644 index 28626eed3..000000000 --- a/app/views/statistics/_statistics.haml +++ /dev/null @@ -1,23 +0,0 @@ --# Copyright (c) 2010-2011, Diaspora Inc. This file is --# licensed under the Affero General Public License version 3 or later. See --# the COPYRIGHT file. - -.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: registrations_status_class(@statistics) - - 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.html.haml b/app/views/statistics/statistics.html.haml deleted file mode 100644 index a55da7893..000000000 --- a/app/views/statistics/statistics.html.haml +++ /dev/null @@ -1 +0,0 @@ -= render('statistics/statistics') \ No newline at end of file diff --git a/app/views/statistics/statistics.mobile.haml b/app/views/statistics/statistics.mobile.haml deleted file mode 100644 index a55da7893..000000000 --- a/app/views/statistics/statistics.mobile.haml +++ /dev/null @@ -1 +0,0 @@ -= render('statistics/statistics') \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index b1d988d0f..73ae1b78f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -238,9 +238,7 @@ Diaspora::Application.routes.draw do # NodeInfo get ".well-known/nodeinfo", to: "node_info#jrd" get "nodeinfo/:version", to: "node_info#document", as: "node_info", constraints: {version: /\d+\.\d+/} - - #Statistics - get :statistics, controller: :statistics + get "statistics", to: "node_info#statistics" # Terms if AppConfig.settings.terms.enable? diff --git a/spec/controllers/node_info_controller_spec.rb b/spec/controllers/node_info_controller_spec.rb index 089bdfe19..106a5a1c8 100644 --- a/spec/controllers/node_info_controller_spec.rb +++ b/spec/controllers/node_info_controller_spec.rb @@ -51,4 +51,27 @@ describe NodeInfoController do end end end + + describe "#statistics" do + it "responds to format json" do + get :statistics, format: "json" + expect(response.code).to eq("200") + end + + it "contains json" do + get :statistics, format: "json" + json = JSON.parse(response.body) + expect(json["name"]).to be_present + end + + it "responds to html" do + get :statistics, format: "html" + expect(response.code).to eq("200") + end + + it "responds to mobile" do + get :statistics, format: "mobile" + expect(response.code).to eq("200") + end + end end diff --git a/spec/controllers/statistics_controller_spec.rb b/spec/controllers/statistics_controller_spec.rb deleted file mode 100644 index 07abf7370..000000000 --- a/spec/controllers/statistics_controller_spec.rb +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright (c) 2010-2011, Diaspora Inc. This file is -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. - -require "spec_helper" - -describe StatisticsController, type: :controller do - describe "#statistics" do - it "responds to format json" do - get :statistics, format: "json" - expect(response.code).to eq("200") - end - - it "contains json" do - get :statistics, format: "json" - json = JSON.parse(response.body) - expect(json["name"]).to be_present - end - - it "responds to html" do - get :statistics, format: "html" - expect(response.code).to eq("200") - end - - it "responds to mobile" do - get :statistics, format: "mobile" - expect(response.code).to eq("200") - end - end -end diff --git a/spec/presenters/node_info_presenter_spec.rb b/spec/presenters/node_info_presenter_spec.rb index d00e75d28..8c9bc436e 100644 --- a/spec/presenters/node_info_presenter_spec.rb +++ b/spec/presenters/node_info_presenter_spec.rb @@ -112,7 +112,7 @@ describe NodeInfoPresenter do AppConfig.settings.enable_registrations = false end - it "should mark openRegistrations to be false" do + it "should mark open_registrations to be false" do expect(presenter.open_registrations?).to be false end end