diff --git a/app/assets/stylesheets/style.css b/app/assets/stylesheets/style.css index e6d988236f..620b5aa136 100644 --- a/app/assets/stylesheets/style.css +++ b/app/assets/stylesheets/style.css @@ -475,6 +475,12 @@ div.note.moderated h4 { .is-active{ cursor: default; - opacity: 0.6; background-color: #e3f2fd; } +textarea, input { + padding:10px; + font-family: FontAwesome, "Open Sans", Verdana, sans-serif; + font-style: normal; + font-weight: normal; + text-decoration: inherit; +} diff --git a/app/controllers/stats_controller.rb b/app/controllers/stats_controller.rb index 6449ff20fb..cc11273719 100644 --- a/app/controllers/stats_controller.rb +++ b/app/controllers/stats_controller.rb @@ -71,8 +71,69 @@ def index end end + def notes + time + export_as_json(@start, @end, 'note') + end + + def wikis + time + export_as_json(@start, @end, 'page') + end + + def users + time + data = User.where(created_at: @start..@end).where(status: 1) + respond_to do |format| + format.csv { send_data data.to_csv } + format.json { send_data data.to_json, :type => 'application/json; header=present', :disposition => "attachment; filename=user.json" } + end + end + + def questions + time + data = Node.published.questions.where(created: @start.to_i..@end.to_i).all + respond_to do |format| + format.csv { send_data data.to_csv } + format.json { send_data data.to_json, :type => 'application/json; header=present', :disposition => "attachment; filename=questions.json" } + end + end + + def answers + time + data = Answer.where(created_at: @start..@end).all + respond_to do |format| + format.csv { send_data data.to_csv } + format.json { send_data data.to_json, :type => 'application/json; header=present', :disposition => "attachment; filename=answers.json" } + end + end + + def comments + time + data = Comment.select(%i(status timestamp)).where(status: 1, timestamp: @start.to_i...@end.to_i).all + respond_to do |format| + format.csv { send_data data.to_csv } + format.json { send_data data.to_json, :type => 'application/json; header=present', :disposition => "attachment; filename=comment.json" } + end + end + + def export_as_json(starting, ending, type) + data = Node.published.select(%i(created type)) + .where(type: type, created: starting.to_i..ending.to_i) + .all + respond_to do |format| + format.csv { send_data data.to_csv } + format.json { send_data data.to_json, :type => 'application/json; header=present', :disposition => "attachment; filename=#{type}.json" } + end + end + private + def time + @start = params[:start] ? Time.parse(params[:start].to_s) : Time.now - 1.month + @end = params[:end] ? Time.parse(params[:end].to_s) : Time.now + end + def to_keyword(param) 1.send(param.downcase) end diff --git a/app/models/application_record.rb b/app/models/application_record.rb index 10a4cba84d..cf513eb57a 100644 --- a/app/models/application_record.rb +++ b/app/models/application_record.rb @@ -1,3 +1,13 @@ class ApplicationRecord < ActiveRecord::Base + require 'csv' self.abstract_class = true + + def self.to_csv(options = {}) + CSV.generate(options) do |csv| + csv << column_names + all.each do |object| + csv << object.attributes.values_at(*column_names) + end + end + end end diff --git a/app/models/node.rb b/app/models/node.rb index 17fe818b7a..d0180ec2c2 100644 --- a/app/models/node.rb +++ b/app/models/node.rb @@ -148,6 +148,15 @@ def generate_path end end + def self.to_csv(options = {}) + CSV.generate(options) do |csv| + csv << column_names + all.each do |object| + csv << object.attributes.values_at(*column_names) + end + end + end + private def set_path_and_slug diff --git a/app/models/user.rb b/app/models/user.rb index 8337a9c375..c5f2a4b10b 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -434,4 +434,13 @@ def self.count_all_time_contributor revisions = Revision.where(status: 1).pluck(:uid) contributors = (notes + answers + questions + comments + revisions).compact.uniq.length end + + def self.to_csv(options = {}) + CSV.generate(options) do |csv| + csv << column_names + all.each do |object| + csv << object.attributes.values_at(*column_names) + end + end + end end diff --git a/app/views/stats/index.html.erb b/app/views/stats/index.html.erb index 6a0997bfb6..b3044f05cd 100644 --- a/app/views/stats/index.html.erb +++ b/app/views/stats/index.html.erb @@ -78,20 +78,6 @@


- -
- - Download as Json -
-
- - Download as CSV -
-

-

-

-

-

diff --git a/app/views/stats/range.html.erb b/app/views/stats/range.html.erb index e1c703b878..84308a7ccb 100644 --- a/app/views/stats/range.html.erb +++ b/app/views/stats/range.html.erb @@ -74,6 +74,74 @@

Member registration may include spam accounts

+ +<% if current_user && (current_user.role == "admin") %> +
+ +
+ + + +
+   +
+ + + +
+

+ <% end %> +

Move back or forward using the buttons below

diff --git a/config/routes.rb b/config/routes.rb index 74ff36696f..1282943083 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -243,6 +243,20 @@ get 'stats' => 'stats#index' get 'stats/range/:start/:end' => 'stats#range' get 'stats/subscriptions' => 'stats#subscriptions' + get 'stats/notes' => 'stats#notes' + get 'stats/notes/:start/:end' => 'stats#notes' + get 'stats/wikis' => 'stats#wikis' + get 'stats/wikis/:start/:end' => 'stats#wikis' + get 'stats/comments' => 'stats#comments' + get 'stats/comments/:start/:end' => 'stats#comments' + get 'stats/maps' => 'stats#maps' + get 'stats/maps/:start/:end' => 'stats#maps' + get 'stats/users' => 'stats#users' + get 'stats/users/:start/:end' => 'stats#users' + get 'stats/questions' => 'stats#questions' + get 'stats/questions/:start/:end' => 'stats#questions' + get 'stats/answers' => 'stats#answers' + get 'stats/answers/:start/:end' => 'stats#answers' get 'feed' => 'notes#rss' get 'rss.xml' => 'legacy#rss'