From a5d2949f28ce74d603d64b60dbfcb06ad7a2dbba Mon Sep 17 00:00:00 2001 From: "sylor_huang@126.com" Date: Fri, 17 Jan 2020 17:19:22 +0800 Subject: [PATCH] change --- Gemfile | 1 + app/assets/javascripts/application.js | 2 + .../admins/project_statistics_controller.rb | 47 ++++++++++++++++--- app/controllers/issues_controller.rb | 4 +- app/models/project.rb | 2 +- .../admins/project_statistics/index.html.erb | 3 +- config/application.rb | 2 +- config/routes.rb | 6 ++- 8 files changed, 56 insertions(+), 11 deletions(-) diff --git a/Gemfile b/Gemfile index 984972fc2..e398c4fd4 100644 --- a/Gemfile +++ b/Gemfile @@ -13,6 +13,7 @@ gem 'uglifier', '>= 1.3.0' gem 'turbolinks', '~> 5' gem 'jbuilder', '~> 2.5' gem 'groupdate', '~> 4.1.0' +gem 'chartkick' gem 'grape-entity', '~> 0.7.1' gem 'kaminari', '~> 1.1', '>= 1.1.1' diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 839fadb57..4e57f532b 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -16,3 +16,5 @@ //= require jquery3 //= require popper //= require bootstrap-sprockets +//= require chartkick +//= require Chart.bundle diff --git a/app/controllers/admins/project_statistics_controller.rb b/app/controllers/admins/project_statistics_controller.rb index ce3491ec5..43db94b55 100644 --- a/app/controllers/admins/project_statistics_controller.rb +++ b/app/controllers/admins/project_statistics_controller.rb @@ -1,7 +1,40 @@ class Admins::ProjectStatisticsController < Admins::BaseController + def index - projects = Project.all.project_statics_select + projects = Project.project_statics_select.all + by_time = params[:time] + project_type = params[:project_type] + is_private = params[:is_private] + project_category_id = params[:project_category_id] + project_language_id = params[:project_language_id] + license_id = params[:license_id] + + projects = projects.where(project_type: project_type) if project_type.present? + projects = projects.where(is_private: is_private) if is_private.present? + projects = projects.where(project_category_id: project_category_id) if project_category_id.present? + projects = projects.where(project_language_id: project_language_id) if project_language_id.present? + projects = projects.where(license_id: license_id) if license_id.present? + + if by_time.present? + case by_time.to_s + when "week" + projects = projects.group_by_week(:created_on).size + when "month" + projects = projects.group_by_month(:created_on).size + when "quarter" + projects = projects.group_by_month(:created_on).size + when "year" + projects = projects.group_by_year(:created_on).size + else + projects = projects.group_by_day(:created_on).size + end + end + @projects = projects + end + + def visits_static + projects = Project.project_statics_select.all by_time = params[:time] project_type = params[:project_type] is_private = params[:is_private] @@ -18,18 +51,20 @@ class Admins::ProjectStatisticsController < Admins::BaseController if by_time.present? case by_time.to_s when "week" - projects = projects.group_by_week(:created_on, time_zone: "Beijing").count + projects = projects.group_by_week(:created_on).size when "month" - projects = projects.group_by_month(:created_on, time_zone: "Beijing").count + projects = projects.group_by_month(:created_on).size when "quarter" - projects = projects.group_by_month(:created_on, time_zone: "Beijing").count + projects = projects.group_by_month(:created_on).size when "year" - projects = projects.group_by_year(:created_on, time_zone: "Beijing").count + projects = projects.group_by_year(:created_on).size else - projects = projects.group_by_day(:created_on, time_zone: "Beijing").count + projects = projects.group_by_day(:created_on).size end end @projects = projects end + + end \ No newline at end of file diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index f72fd4109..f51e03146 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -163,7 +163,7 @@ class IssuesController < ApplicationController closed_on: (params[:status_id].to_i == 5) ? Time.now : nil, issue_classify: "issue", branch_name: params[:branch_name].to_s, - author_id: params[:author_id] || current_user.id, + author_id: current_user.id, project_id: @project.id } @issue = Issue.new(issue_params) @@ -173,6 +173,7 @@ class IssuesController < ApplicationController attachment = Attachment.select(:id, :container_id, :container_type)&.find_by_id(id) unless attachment.blank? attachment.container = @issue + attachment.author_id = current_user.id attachment.save end end @@ -241,6 +242,7 @@ class IssuesController < ApplicationController attachment = Attachment.select(:id, :container_id, :container_type)&.find_by_id(id) unless attachment.blank? attachment.container = @issue + attachment.author_id = current_user.id attachment.save end end diff --git a/app/models/project.rb b/app/models/project.rb index 78538ba7e..97d4aca94 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -30,7 +30,7 @@ class Project < ApplicationRecord has_and_belongs_to_many :trackers, :order => "#{Tracker.table_name}.position" after_save :check_project_members - scope :project_statics_select, -> {select(:id,:name, :is_public, :identifier, :status, :project_type, :hidden_repo, :user_id, :forked_count, :visits, :project_category_id, :project_language_id, :license_id, :ignore_id, :watchers_count, :created_on)} + scope :project_statics_select, -> {select(:id,:name, :is_public, :identifier, :status, :project_type, :user_id, :forked_count, :visits, :project_category_id, :project_language_id, :license_id, :ignore_id, :watchers_count, :created_on)} # 创建者 diff --git a/app/views/admins/project_statistics/index.html.erb b/app/views/admins/project_statistics/index.html.erb index 030693d17..a5054aee4 100644 --- a/app/views/admins/project_statistics/index.html.erb +++ b/app/views/admins/project_statistics/index.html.erb @@ -1 +1,2 @@ -<%= @projects %> \ No newline at end of file + +<%= line_chart @projects %> \ No newline at end of file diff --git a/config/application.rb b/config/application.rb index baa0011f2..1fb0b4627 100644 --- a/config/application.rb +++ b/config/application.rb @@ -19,7 +19,7 @@ module Educoderplus # # config.educoder = config_for(:configuration) - config.active_record.default_timezone = :local + config.active_record.default_timezone = :utc config.time_zone = 'Beijing' # I18n diff --git a/config/routes.rb b/config/routes.rb index 07f9794f2..b119eb11e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -743,7 +743,11 @@ Rails.application.routes.draw do namespace :admins do get '/', to: 'dashboards#index' - resources :project_statistics + resources :project_statistics, only: [:index] do + collection do + get :visits_static + end + end resources :major_informations, only: [:index] resources :ec_templates, only: [:index, :destroy] do collection do