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 @@
Member registration may include spam accounts
+ +<% if current_user && (current_user.role == "admin") %> +Move back or forward using the buttons below