From 40b45ce1b46695bec25887092353733731bc8f1e Mon Sep 17 00:00:00 2001 From: huang Date: Fri, 15 Apr 2016 12:24:54 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E7=89=88=E6=9C=AC=E5=BA=93=E5=8A=A8?= =?UTF-8?q?=E6=80=81=E4=B8=AD=E7=BB=9F=E8=AE=A1=E6=94=B9=E6=88=90=E4=BB=8E?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E8=8E=B7=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/projects_controller.rb | 10 +- app/controllers/repositories_controller.rb | 10 +- app/models/project.rb | 1 + app/models/rep_statics.rb | 4 + app/views/projects/_rep_static.html.erb | 43 +- .../20160414060838_create_rep_statics.rb | 14 + ...0415025623_add_changeset_to_rep_statics.rb | 5 + db/migrate/20160415030447_sync_rep_statics.rb | 26 ++ db/schema.rb | 437 +++++++++++++++++- spec/factories/rep_statics.rb | 11 + spec/models/rep_statics_spec.rb | 5 + 11 files changed, 549 insertions(+), 17 deletions(-) create mode 100644 app/models/rep_statics.rb create mode 100644 db/migrate/20160414060838_create_rep_statics.rb create mode 100644 db/migrate/20160415025623_add_changeset_to_rep_statics.rb create mode 100644 db/migrate/20160415030447_sync_rep_statics.rb create mode 100644 spec/factories/rep_statics.rb create mode 100644 spec/models/rep_statics_spec.rb diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 517fa327c..aeed8e081 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -319,9 +319,15 @@ class ProjectsController < ApplicationController else @events_pages = ForgeActivity.includes(:project).where("forge_activities.project_id = ? and projects.is_public = ? and forge_act_type != ? ",@project,1, "Document").order("created_at desc").page(params['page'|| 1]).per(10); end - g = Gitlab.client + # g = Gitlab.client unless @project.gpid.nil? || @project.project_score.changeset_num == 0 - @static_total_per_user = g.rep_stats(@project.gpid) + rep_statics = @project.rep_statics + @a_uname = rep_statics.map {|s| s.uname } + @a_commits_num = rep_statics.map {|s| s.commits_num.to_i } + @a_commits_add = rep_statics.map {|s| s.add.to_i } + @a_commits_del = rep_statics.map {|s| s.del.to_i } + @a_commits_changeset = rep_statics.map {|s| s.changeset.to_i } + # @static_total_per_user = g.rep_stats(@project.gpid) end # 根据对应的请求,返回对应的数据 respond_to do |format| diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 82a6196cb..ec7020bce 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -573,7 +573,15 @@ update g = Gitlab.client begin @static_total_per_user = g.rep_stats(project_id, :rev => rev) - @static_total_per_user + # 更新rep_statics统计数 + @static_total_per_user.each do |static| + rep_static = RepStatics.where("project_id =? and email =?", @project.id, static.email.to_s).first + if rep_static.nil? + RepStatics.create(:project_id => @project.id, :uname => static.uname, :commits_num => static.commits_num, :email => static.email, :add => static.add, :del => static.del, :changeset => static.changes) + else + rep_static.update_attributes(:uname => static.uname, :commits_num => static.commits_num, :email => static.email, :add => static.add, :del => static.del, :changeset => static.changes) + end + end # @static_month__per_user = g.rep_stats(project_id, :rev => rev, :creator => creator, :period => 2) # @static_week_per_user = g.rep_stats(project_id, :rev => rev, :creator => creator, :period => 3) rescue diff --git a/app/models/project.rb b/app/models/project.rb index 184b3c7af..ceec0e182 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -115,6 +115,7 @@ class Project < ActiveRecord::Base has_many :org_projects,:dependent => :destroy has_many :organization,:through => :org_projects + has_many :rep_statics, :class_name => 'RepStatics' # has_many :journals diff --git a/app/models/rep_statics.rb b/app/models/rep_statics.rb new file mode 100644 index 000000000..584af6560 --- /dev/null +++ b/app/models/rep_statics.rb @@ -0,0 +1,4 @@ +class RepStatics < ActiveRecord::Base + belongs_to :project + attr_accessible :add, :commits_num, :del, :email, :project_id, :uname, :changeset +end diff --git a/app/views/projects/_rep_static.html.erb b/app/views/projects/_rep_static.html.erb index 0522fd34e..0ba1ffb5a 100644 --- a/app/views/projects/_rep_static.html.erb +++ b/app/views/projects/_rep_static.html.erb @@ -10,14 +10,18 @@ type: 'line' }, title: { - text: '版本库代码提交量' + text: '版本库代码提交行数', + style:{ + fontSize: '14px' + } + }, subtitle: { // text: 'Source: WorldClimate.com' }, xAxis: { // categories: ["Jan", "Jan", "Jan", 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] - categories: <%= raw(@static_total_per_user.map{|c| c.uname}) %> + categories: <%= raw(@a_uname) %> }, yAxis: { title: { @@ -34,6 +38,12 @@ } }, plotOptions: { + series: { + marker: { + radius: 3, //曲线点半径,默认是4 + symbol: 'circle' //曲线点类型:"circle", "square", "diamond", "triangle","triangle-down",默认是"circle" + } + }, line: { dataLabels: { enabled: true @@ -45,17 +55,20 @@ name: '改动或增加', color: '#fd9e04', -// data: [7.0, 6.9, 9.5, 14.5, 18.4, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6] - data: <%= @static_total_per_user.map{|c| c.add.to_i} %> +// data: [7.0, 6.9, 9.5, 14.5, 18.4, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6] + data: <%= @a_commits_add %>, + lineWidth: 1.5 }, { name: '删除', color: '#46baed ', - data: <%= @static_total_per_user.map{|c| c.del.to_i} %> + data: <%= @a_commits_del %>, + lineWidth: 1.5 },{ name: '总变更', color: '#d397d5', - data: <%= @static_total_per_user.map{|c| c.changes.to_i} %> + data: <%= @a_commits_changeset %>, + lineWidth: 1.5 }] }); @@ -68,14 +81,18 @@ enabled: false }, title: { - text: '版本库代码提交次数' + text: '版本库代码提交次数', + style:{ + fontSize: '14px' + } + }, subtitle: { // text: 'Source: WorldClimate.com' }, xAxis: { // categories: ["Jan", "Jan", "Jan", 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] - categories: <%= raw(@static_total_per_user.map{|c| c.uname}) %> + categories: <%= raw(@a_uname) %> }, yAxis: { title: { @@ -89,6 +106,12 @@ } }, plotOptions: { + series: { + marker: { + radius: 3, //曲线点半径,默认是4 + symbol: 'circle' //曲线点类型:"circle", "square", "diamond", "triangle","triangle-down",默认是"circle" + } + }, line: { dataLabels: { enabled: true @@ -99,7 +122,9 @@ series: [{ name: '提交次数', // data: [7.0, 6.9, 9.5, 14.5, 18.4, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6] - data: <%= @static_total_per_user.map{|c| c.commits_num.to_i} %> + data: <%= @a_commits_num %>, + lineWidth: 1.5 + } // { // name: 'London', diff --git a/db/migrate/20160414060838_create_rep_statics.rb b/db/migrate/20160414060838_create_rep_statics.rb new file mode 100644 index 000000000..125261df1 --- /dev/null +++ b/db/migrate/20160414060838_create_rep_statics.rb @@ -0,0 +1,14 @@ +class CreateRepStatics < ActiveRecord::Migration + def change + create_table :rep_statics do |t| + t.integer :project_id + t.integer :commits_num + t.string :uname + t.string :email + t.integer :add + t.integer :del + + t.timestamps + end + end +end diff --git a/db/migrate/20160415025623_add_changeset_to_rep_statics.rb b/db/migrate/20160415025623_add_changeset_to_rep_statics.rb new file mode 100644 index 000000000..45fdb02d9 --- /dev/null +++ b/db/migrate/20160415025623_add_changeset_to_rep_statics.rb @@ -0,0 +1,5 @@ +class AddChangesetToRepStatics < ActiveRecord::Migration + def change + add_column :rep_statics, :changeset, :integer + end +end diff --git a/db/migrate/20160415030447_sync_rep_statics.rb b/db/migrate/20160415030447_sync_rep_statics.rb new file mode 100644 index 000000000..29861aa61 --- /dev/null +++ b/db/migrate/20160415030447_sync_rep_statics.rb @@ -0,0 +1,26 @@ +class SyncRepStatics < ActiveRecord::Migration + def up + g = Gitlab.client + # projects = Project.find_by_sql("SELECT p.* FROM projects p, project_scores ps where p.id = ps.project_id and p.gpid is not null and ps.changeset_num > 0") + projects = Project.where("gpid is not null") + count = projects.count / 30 + 2 + transaction do + for i in 1 ... count do i + projects.page(i).per(30).each do |project| + begin + puts project.id + g.rep_stats(project.gpid).each do |static| + puts static.uname + RepStatics.create(:project_id => project.id, :uname => static.uname, :commits_num => static.commits_num, :email => static.email, :add => static.add, :del => static.del, :changeset => static.changes) + end + rescue + logger.error("Sync rep failed!") + end + end + end + end + end + + def down + end +end diff --git a/db/schema.rb b/db/schema.rb index 4e4201050..ccd953cc5 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,11 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -<<<<<<< HEAD -ActiveRecord::Schema.define(:version => 20160331063938) do -======= -ActiveRecord::Schema.define(:version => 20160405021915) do ->>>>>>> c3ee4dadfb92c75e8649cad7e0ed57c2ec02ec00 +ActiveRecord::Schema.define(:version => 20160415030447) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -56,6 +52,28 @@ ActiveRecord::Schema.define(:version => 20160405021915) do add_index "api_keys", ["access_token"], :name => "index_api_keys_on_access_token" add_index "api_keys", ["user_id"], :name => "index_api_keys_on_user_id" + create_table "application_settings", :force => true do |t| + t.integer "default_projects_limit" + t.boolean "signup_enabled" + t.boolean "signin_enabled" + t.boolean "gravatar_enabled" + t.text "sign_in_text" + t.datetime "created_at" + t.datetime "updated_at" + t.string "home_page_url" + t.integer "default_branch_protection", :default => 2 + t.boolean "twitter_sharing_enabled", :default => true + t.text "restricted_visibility_levels" + t.boolean "version_check_enabled", :default => true + t.integer "max_attachment_size", :default => 10, :null => false + t.integer "default_project_visibility" + t.integer "default_snippet_visibility" + t.text "restricted_signup_domains" + t.boolean "user_oauth_applications", :default => true + t.string "after_sign_out_path" + t.integer "session_expire_delay", :default => 10080, :null => false + end + create_table "applied_projects", :force => true do |t| t.integer "project_id", :null => false t.integer "user_id", :null => false @@ -137,6 +155,20 @@ ActiveRecord::Schema.define(:version => 20160405021915) do t.string "typeName", :limit => 50 end + create_table "audit_events", :force => true do |t| + t.integer "author_id", :null => false + t.string "type", :null => false + t.integer "entity_id", :null => false + t.string "entity_type", :null => false + t.text "details" + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "audit_events", ["author_id"], :name => "index_audit_events_on_author_id" + add_index "audit_events", ["entity_id", "entity_type"], :name => "index_audit_events_on_entity_id_and_entity_type" + add_index "audit_events", ["type"], :name => "index_audit_events_on_type" + create_table "auth_sources", :force => true do |t| t.string "type", :limit => 30, :default => "", :null => false t.string "name", :limit => 60, :default => "", :null => false @@ -234,6 +266,17 @@ ActiveRecord::Schema.define(:version => 20160405021915) do add_index "boards", ["last_message_id"], :name => "index_boards_on_last_message_id" add_index "boards", ["project_id"], :name => "boards_project_id" + create_table "broadcast_messages", :force => true do |t| + t.text "message", :null => false + t.datetime "starts_at" + t.datetime "ends_at" + t.integer "alert_type" + t.datetime "created_at" + t.datetime "updated_at" + t.string "color" + t.string "font" + end + create_table "bug_to_osps", :force => true do |t| t.integer "osp_id" t.integer "relative_memo_id" @@ -581,6 +624,15 @@ ActiveRecord::Schema.define(:version => 20160405021915) do add_index "delayed_jobs", ["priority", "run_at"], :name => "delayed_jobs_priority" + create_table "deploy_keys_projects", :force => true do |t| + t.integer "deploy_key_id", :null => false + t.integer "project_id", :null => false + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "deploy_keys_projects", ["project_id"], :name => "index_deploy_keys_projects_on_project_id" + create_table "discuss_demos", :force => true do |t| t.string "title" t.text "body" @@ -630,6 +682,16 @@ ActiveRecord::Schema.define(:version => 20160405021915) do t.datetime "created_at" end + create_table "emails", :force => true do |t| + t.integer "user_id", :null => false + t.string "email", :null => false + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "emails", ["email"], :name => "index_emails_on_email", :unique => true + add_index "emails", ["user_id"], :name => "index_emails_on_user_id" + create_table "enabled_modules", :force => true do |t| t.integer "project_id" t.string "name", :null => false @@ -652,6 +714,25 @@ ActiveRecord::Schema.define(:version => 20160405021915) do add_index "enumerations", ["id", "type"], :name => "index_enumerations_on_id_and_type" add_index "enumerations", ["project_id"], :name => "index_enumerations_on_project_id" + create_table "events", :force => true do |t| + t.string "target_type" + t.integer "target_id" + t.string "title" + t.text "data" + t.integer "project_id" + t.datetime "created_at" + t.datetime "updated_at" + t.integer "action" + t.integer "author_id" + end + + add_index "events", ["action"], :name => "index_events_on_action" + add_index "events", ["author_id"], :name => "index_events_on_author_id" + add_index "events", ["created_at"], :name => "index_events_on_created_at" + add_index "events", ["project_id"], :name => "index_events_on_project_id" + add_index "events", ["target_id"], :name => "index_events_on_target_id" + add_index "events", ["target_type"], :name => "index_events_on_target_type" + create_table "exercise_answers", :force => true do |t| t.integer "user_id" t.integer "exercise_question_id" @@ -754,6 +835,15 @@ ActiveRecord::Schema.define(:version => 20160405021915) do add_index "forge_messages", ["forge_message_id", "forge_message_type"], :name => "index_forge_messages_on_forge_message_id_and_forge_message_type" add_index "forge_messages", ["user_id", "project_id", "created_at"], :name => "index_forge_messages_on_user_id_and_project_id_and_created_at" + create_table "forked_project_links", :force => true do |t| + t.integer "forked_to_project_id", :null => false + t.integer "forked_from_project_id", :null => false + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "forked_project_links", ["forked_to_project_id"], :name => "index_forked_project_links_on_forked_to_project_id", :unique => true + create_table "forums", :force => true do |t| t.string "name", :null => false t.text "description" @@ -882,6 +972,17 @@ ActiveRecord::Schema.define(:version => 20160405021915) do t.datetime "updated_at", :null => false end + create_table "identities", :force => true do |t| + t.string "extern_uid" + t.string "provider" + t.integer "user_id" + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "identities", ["created_at", "id"], :name => "index_identities_on_created_at_and_id" + add_index "identities", ["user_id"], :name => "index_identities_on_user_id" + create_table "invite_lists", :force => true do |t| t.integer "project_id" t.integer "user_id" @@ -1025,6 +1126,20 @@ ActiveRecord::Schema.define(:version => 20160405021915) do t.integer "private", :default => 0 end + create_table "keys", :force => true do |t| + t.integer "user_id" + t.datetime "created_at" + t.datetime "updated_at" + t.text "key" + t.string "title" + t.string "type" + t.string "fingerprint" + t.boolean "public", :default => false, :null => false + end + + add_index "keys", ["created_at", "id"], :name => "index_keys_on_created_at_and_id" + add_index "keys", ["user_id"], :name => "index_keys_on_user_id" + create_table "kindeditor_assets", :force => true do |t| t.string "asset" t.integer "file_size" @@ -1036,6 +1151,27 @@ ActiveRecord::Schema.define(:version => 20160405021915) do t.integer "owner_type", :default => 0 end + create_table "label_links", :force => true do |t| + t.integer "label_id" + t.integer "target_id" + t.string "target_type" + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "label_links", ["label_id"], :name => "index_label_links_on_label_id" + add_index "label_links", ["target_id", "target_type"], :name => "index_label_links_on_target_id_and_target_type" + + create_table "labels", :force => true do |t| + t.string "title" + t.string "color" + t.integer "project_id" + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "labels", ["project_id"], :name => "index_labels_on_project_id" + create_table "member_roles", :force => true do |t| t.integer "member_id", :null => false t.integer "role_id", :null => false @@ -1086,6 +1222,47 @@ ActiveRecord::Schema.define(:version => 20160405021915) do t.integer "viewed_count", :default => 0 end + create_table "merge_request_diffs", :force => true do |t| + t.string "state" + t.text "st_commits", :limit => 2147483647 + t.text "st_diffs", :limit => 2147483647 + t.integer "merge_request_id", :null => false + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "merge_request_diffs", ["merge_request_id"], :name => "index_merge_request_diffs_on_merge_request_id", :unique => true + + create_table "merge_requests", :force => true do |t| + t.string "target_branch", :null => false + t.string "source_branch", :null => false + t.integer "source_project_id", :null => false + t.integer "author_id" + t.integer "assignee_id" + t.string "title" + t.datetime "created_at" + t.datetime "updated_at" + t.integer "milestone_id" + t.string "state" + t.string "merge_status" + t.integer "target_project_id", :null => false + t.integer "iid" + t.text "description" + t.integer "position", :default => 0 + t.datetime "locked_at" + end + + add_index "merge_requests", ["assignee_id"], :name => "index_merge_requests_on_assignee_id" + add_index "merge_requests", ["author_id"], :name => "index_merge_requests_on_author_id" + add_index "merge_requests", ["created_at", "id"], :name => "index_merge_requests_on_created_at_and_id" + add_index "merge_requests", ["created_at"], :name => "index_merge_requests_on_created_at" + add_index "merge_requests", ["milestone_id"], :name => "index_merge_requests_on_milestone_id" + add_index "merge_requests", ["source_branch"], :name => "index_merge_requests_on_source_branch" + add_index "merge_requests", ["source_project_id"], :name => "index_merge_requests_on_source_project_id" + add_index "merge_requests", ["target_branch"], :name => "index_merge_requests_on_target_branch" + add_index "merge_requests", ["target_project_id", "iid"], :name => "index_merge_requests_on_target_project_id_and_iid", :unique => true + add_index "merge_requests", ["title"], :name => "index_merge_requests_on_title" + create_table "message_alls", :force => true do |t| t.integer "user_id" t.integer "message_id" @@ -1120,6 +1297,39 @@ ActiveRecord::Schema.define(:version => 20160405021915) do add_index "messages", ["last_reply_id"], :name => "index_messages_on_last_reply_id" add_index "messages", ["parent_id"], :name => "messages_parent_id" + create_table "milestones", :force => true do |t| + t.string "title", :null => false + t.integer "project_id", :null => false + t.text "description" + t.date "due_date" + t.datetime "created_at" + t.datetime "updated_at" + t.string "state" + t.integer "iid" + end + + add_index "milestones", ["created_at", "id"], :name => "index_milestones_on_created_at_and_id" + add_index "milestones", ["due_date"], :name => "index_milestones_on_due_date" + add_index "milestones", ["project_id", "iid"], :name => "index_milestones_on_project_id_and_iid", :unique => true + add_index "milestones", ["project_id"], :name => "index_milestones_on_project_id" + + create_table "namespaces", :force => true do |t| + t.string "name", :null => false + t.string "path", :null => false + t.integer "owner_id" + t.datetime "created_at" + t.datetime "updated_at" + t.string "type" + t.string "description", :default => "", :null => false + t.string "avatar" + end + + add_index "namespaces", ["created_at", "id"], :name => "index_namespaces_on_created_at_and_id" + add_index "namespaces", ["name"], :name => "index_namespaces_on_name", :unique => true + add_index "namespaces", ["owner_id"], :name => "index_namespaces_on_owner_id" + add_index "namespaces", ["path"], :name => "index_namespaces_on_path", :unique => true + add_index "namespaces", ["type"], :name => "index_namespaces_on_type" + create_table "news", :force => true do |t| t.integer "project_id" t.string "title", :limit => 60, :default => "", :null => false @@ -1145,6 +1355,31 @@ ActiveRecord::Schema.define(:version => 20160405021915) do t.datetime "updated_at", :null => false end + create_table "notes", :force => true do |t| + t.text "note" + t.string "noteable_type" + t.integer "author_id" + t.datetime "created_at" + t.datetime "updated_at" + t.integer "project_id" + t.string "attachment" + t.string "line_code" + t.string "commit_id" + t.integer "noteable_id" + t.boolean "system", :default => false, :null => false + t.text "st_diff", :limit => 2147483647 + end + + add_index "notes", ["author_id"], :name => "index_notes_on_author_id" + add_index "notes", ["commit_id"], :name => "index_notes_on_commit_id" + add_index "notes", ["created_at", "id"], :name => "index_notes_on_created_at_and_id" + add_index "notes", ["created_at"], :name => "index_notes_on_created_at" + add_index "notes", ["noteable_id", "noteable_type"], :name => "index_notes_on_noteable_id_and_noteable_type" + add_index "notes", ["noteable_type"], :name => "index_notes_on_noteable_type" + add_index "notes", ["project_id", "noteable_type"], :name => "index_notes_on_project_id_and_noteable_type" + add_index "notes", ["project_id"], :name => "index_notes_on_project_id" + add_index "notes", ["updated_at"], :name => "index_notes_on_updated_at" + create_table "notificationcomments", :force => true do |t| t.string "notificationcommented_type" t.integer "notificationcommented_id" @@ -1154,6 +1389,49 @@ ActiveRecord::Schema.define(:version => 20160405021915) do t.datetime "updated_at", :null => false end + create_table "oauth_access_grants", :force => true do |t| + t.integer "resource_owner_id", :null => false + t.integer "application_id", :null => false + t.string "token", :null => false + t.integer "expires_in", :null => false + t.text "redirect_uri", :null => false + t.datetime "created_at", :null => false + t.datetime "revoked_at" + t.string "scopes" + end + + add_index "oauth_access_grants", ["token"], :name => "index_oauth_access_grants_on_token", :unique => true + + create_table "oauth_access_tokens", :force => true do |t| + t.integer "resource_owner_id" + t.integer "application_id" + t.string "token", :null => false + t.string "refresh_token" + t.integer "expires_in" + t.datetime "revoked_at" + t.datetime "created_at", :null => false + t.string "scopes" + end + + add_index "oauth_access_tokens", ["refresh_token"], :name => "index_oauth_access_tokens_on_refresh_token", :unique => true + add_index "oauth_access_tokens", ["resource_owner_id"], :name => "index_oauth_access_tokens_on_resource_owner_id" + add_index "oauth_access_tokens", ["token"], :name => "index_oauth_access_tokens_on_token", :unique => true + + create_table "oauth_applications", :force => true do |t| + t.string "name", :null => false + t.string "uid", :null => false + t.string "secret", :null => false + t.text "redirect_uri", :null => false + t.string "scopes", :default => "", :null => false + t.datetime "created_at" + t.datetime "updated_at" + t.integer "owner_id" + t.string "owner_type" + end + + add_index "oauth_applications", ["owner_id", "owner_type"], :name => "index_oauth_applications_on_owner_id_and_owner_type" + add_index "oauth_applications", ["uid"], :name => "index_oauth_applications_on_uid", :unique => true + create_table "onclick_times", :force => true do |t| t.integer "user_id" t.datetime "onclick_time" @@ -1309,6 +1587,23 @@ ActiveRecord::Schema.define(:version => 20160405021915) do t.integer "show_mode", :default => 0 end + create_table "permissions", :force => true do |t| + t.string "controller", :limit => 30, :default => "", :null => false + t.string "action", :limit => 30, :default => "", :null => false + t.string "description", :limit => 60, :default => "", :null => false + t.boolean "is_public", :default => false, :null => false + t.integer "sort", :default => 0, :null => false + t.boolean "mail_option", :default => false, :null => false + t.boolean "mail_enabled", :default => false, :null => false + end + + create_table "permissions_roles", :id => false, :force => true do |t| + t.integer "permission_id", :default => 0, :null => false + t.integer "role_id", :default => 0, :null => false + end + + add_index "permissions_roles", ["role_id"], :name => "permissions_roles_role_id" + create_table "phone_app_versions", :force => true do |t| t.string "version" t.text "description" @@ -1391,6 +1686,11 @@ ActiveRecord::Schema.define(:version => 20160405021915) do t.datetime "updated_at", :null => false end + create_table "project_import_data", :force => true do |t| + t.integer "project_id" + t.text "data" + end + create_table "project_infos", :force => true do |t| t.integer "project_id" t.integer "user_id" @@ -1480,6 +1780,16 @@ ActiveRecord::Schema.define(:version => 20160405021915) do add_index "projects_trackers", ["project_id", "tracker_id"], :name => "projects_trackers_unique", :unique => true add_index "projects_trackers", ["project_id"], :name => "projects_trackers_project_id" + create_table "protected_branches", :force => true do |t| + t.integer "project_id", :null => false + t.string "name", :null => false + t.datetime "created_at" + t.datetime "updated_at" + t.boolean "developers_can_push", :default => false, :null => false + end + + add_index "protected_branches", ["project_id"], :name => "index_protected_branches_on_project_id" + create_table "queries", :force => true do |t| t.integer "project_id" t.string "name", :default => "", :null => false @@ -1524,6 +1834,18 @@ ActiveRecord::Schema.define(:version => 20160405021915) do t.string "topic_resource" end + create_table "rep_statics", :force => true do |t| + t.integer "project_id" + t.integer "commits_num" + t.string "uname" + t.string "email" + t.integer "add" + t.integer "del" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + t.integer "changeset" + end + create_table "repositories", :force => true do |t| t.integer "project_id", :default => 0, :null => false t.string "url", :default => "", :null => false @@ -1602,6 +1924,25 @@ ActiveRecord::Schema.define(:version => 20160405021915) do t.integer "is_teacher_score", :default => 0 end + create_table "services", :force => true do |t| + t.string "type" + t.string "title" + t.integer "project_id" + t.datetime "created_at" + t.datetime "updated_at" + t.boolean "active", :default => false, :null => false + t.text "properties" + t.boolean "template", :default => false + t.boolean "push_events", :default => true + t.boolean "issues_events", :default => true + t.boolean "merge_requests_events", :default => true + t.boolean "tag_push_events", :default => true + t.boolean "note_events", :default => true, :null => false + end + + add_index "services", ["created_at", "id"], :name => "index_services_on_created_at_and_id" + add_index "services", ["project_id"], :name => "index_services_on_project_id" + create_table "settings", :force => true do |t| t.string "name", :default => "", :null => false t.text "value" @@ -1631,6 +1972,26 @@ ActiveRecord::Schema.define(:version => 20160405021915) do t.datetime "updated_at", :null => false end + create_table "snippets", :force => true do |t| + t.string "title" + t.text "content", :limit => 2147483647 + t.integer "author_id", :null => false + t.integer "project_id" + t.datetime "created_at" + t.datetime "updated_at" + t.string "file_name" + t.datetime "expires_at" + t.string "type" + t.integer "visibility_level", :default => 0, :null => false + end + + add_index "snippets", ["author_id"], :name => "index_snippets_on_author_id" + add_index "snippets", ["created_at", "id"], :name => "index_snippets_on_created_at_and_id" + add_index "snippets", ["created_at"], :name => "index_snippets_on_created_at" + add_index "snippets", ["expires_at"], :name => "index_snippets_on_expires_at" + add_index "snippets", ["project_id"], :name => "index_snippets_on_project_id" + add_index "snippets", ["visibility_level"], :name => "index_snippets_on_visibility_level" + create_table "softapplications", :force => true do |t| t.string "name" t.text "description" @@ -1727,6 +2088,17 @@ ActiveRecord::Schema.define(:version => 20160405021915) do t.datetime "updated_at", :null => false end + create_table "subscriptions", :force => true do |t| + t.integer "user_id" + t.integer "subscribable_id" + t.string "subscribable_type" + t.boolean "subscribed" + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "subscriptions", ["subscribable_id", "subscribable_type", "user_id"], :name => "subscriptions_user_id_and_ref_fields", :unique => true + create_table "system_messages", :force => true do |t| t.integer "user_id" t.string "content" @@ -1921,6 +2293,25 @@ ActiveRecord::Schema.define(:version => 20160405021915) do add_index "user_statuses", ["grade"], :name => "index_user_statuses_on_grade" add_index "user_statuses", ["watchers_count"], :name => "index_user_statuses_on_watchers_count" + create_table "user_wechats", :force => true do |t| + t.integer "subscribe" + t.string "openid" + t.string "nickname" + t.integer "sex" + t.string "language" + t.string "city" + t.string "province" + t.string "country" + t.string "headimgurl" + t.string "subscribe_time" + t.string "unionid" + t.string "remark" + t.integer "groupid" + t.integer "user_id" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + create_table "users", :force => true do |t| t.string "login", :default => "", :null => false t.string "hashed_password", :limit => 40, :default => "", :null => false @@ -1946,6 +2337,17 @@ ActiveRecord::Schema.define(:version => 20160405021915) do add_index "users", ["id", "type"], :name => "index_users_on_id_and_type" add_index "users", ["type"], :name => "index_users_on_type" + create_table "users_star_projects", :force => true do |t| + t.integer "project_id", :null => false + t.integer "user_id", :null => false + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "users_star_projects", ["project_id"], :name => "index_users_star_projects_on_project_id" + add_index "users_star_projects", ["user_id", "project_id"], :name => "index_users_star_projects_on_user_id_and_project_id", :unique => true + add_index "users_star_projects", ["user_id"], :name => "index_users_star_projects_on_user_id" + create_table "versions", :force => true do |t| t.integer "project_id", :default => 0, :null => false t.string "name", :default => "", :null => false @@ -1997,6 +2399,31 @@ ActiveRecord::Schema.define(:version => 20160405021915) do t.datetime "updated_at", :null => false end + create_table "web_hooks", :force => true do |t| + t.string "url" + t.integer "project_id" + t.datetime "created_at" + t.datetime "updated_at" + t.string "type", :default => "ProjectHook" + t.integer "service_id" + t.boolean "push_events", :default => true, :null => false + t.boolean "issues_events", :default => false, :null => false + t.boolean "merge_requests_events", :default => false, :null => false + t.boolean "tag_push_events", :default => false + t.boolean "note_events", :default => false, :null => false + end + + add_index "web_hooks", ["created_at", "id"], :name => "index_web_hooks_on_created_at_and_id" + add_index "web_hooks", ["project_id"], :name => "index_web_hooks_on_project_id" + + create_table "wechat_logs", :force => true do |t| + t.string "openid", :null => false + t.text "request_raw" + t.text "response_raw" + t.text "session_raw" + t.datetime "created_at", :null => false + end + create_table "wiki_content_versions", :force => true do |t| t.integer "wiki_content_id", :null => false t.integer "page_id", :null => false diff --git a/spec/factories/rep_statics.rb b/spec/factories/rep_statics.rb new file mode 100644 index 000000000..5222e8ec7 --- /dev/null +++ b/spec/factories/rep_statics.rb @@ -0,0 +1,11 @@ +FactoryGirl.define do + factory :rep_static, :class => 'RepStatics' do + project_id 1 +commits_num 1 +uname "MyString" +email "MyString" +add 1 +del 1 + end + +end diff --git a/spec/models/rep_statics_spec.rb b/spec/models/rep_statics_spec.rb new file mode 100644 index 000000000..da4870b17 --- /dev/null +++ b/spec/models/rep_statics_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe RepStatics, :type => :model do + pending "add some examples to (or delete) #{__FILE__}" +end From 4a8d572cb1225e03848042a404b7f6227b3b8567 Mon Sep 17 00:00:00 2001 From: huang Date: Fri, 15 Apr 2016 15:38:08 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E5=8A=A8=E6=80=81?= =?UTF-8?q?=E4=B8=AD=E7=89=88=E6=9C=AC=E5=BA=93=E7=BB=9F=E8=AE=A1=E6=A0=B7?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/projects_controller.rb | 14 +++-- app/views/projects/_rep_static.html.erb | 77 ++++++++++++++++++++----- public/stylesheets/project.css | 1 + 3 files changed, 70 insertions(+), 22 deletions(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index aeed8e081..7553acdbc 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -321,12 +321,14 @@ class ProjectsController < ApplicationController end # g = Gitlab.client unless @project.gpid.nil? || @project.project_score.changeset_num == 0 - rep_statics = @project.rep_statics - @a_uname = rep_statics.map {|s| s.uname } - @a_commits_num = rep_statics.map {|s| s.commits_num.to_i } - @a_commits_add = rep_statics.map {|s| s.add.to_i } - @a_commits_del = rep_statics.map {|s| s.del.to_i } - @a_commits_changeset = rep_statics.map {|s| s.changeset.to_i } + rep_statics_commit = @project.rep_statics + rep_statics_code = @project.rep_statics.sort_by {|u| u.changeset}.reverse + @a_uname = rep_statics_commit.map {|s| s.uname } + @a_uname_code = rep_statics_code.map {|s| s.uname } + @a_commits_num = rep_statics_commit.map {|s| s.commits_num.to_i } + @a_commits_add = rep_statics_code.map {|s| s.add.to_i } + @a_commits_del = rep_statics_code.map {|s| s.del.to_i } + @a_commits_changeset = rep_statics_code.map {|s| s.changeset.to_i } # @static_total_per_user = g.rep_stats(@project.gpid) end # 根据对应的请求,返回对应的数据 diff --git a/app/views/projects/_rep_static.html.erb b/app/views/projects/_rep_static.html.erb index 0ba1ffb5a..86d557f3a 100644 --- a/app/views/projects/_rep_static.html.erb +++ b/app/views/projects/_rep_static.html.erb @@ -21,7 +21,7 @@ }, xAxis: { // categories: ["Jan", "Jan", "Jan", 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] - categories: <%= raw(@a_uname) %> + categories: <%= raw(@a_uname_code) %> }, yAxis: { title: { @@ -40,7 +40,7 @@ plotOptions: { series: { marker: { - radius: 3, //曲线点半径,默认是4 + radius: 3, //曲线点半径,默认是4 symbol: 'circle' //曲线点类型:"circle", "square", "diamond", "triangle","triangle-down",默认是"circle" } }, @@ -51,23 +51,54 @@ enableMouseTracking: false } }, - series: [{ - name: '改动或增加', - color: '#fd9e04', - -// data: [7.0, 6.9, 9.5, 14.5, 18.4, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6] + series: [ + { + name: '总变更', + color: '#d05d5a', + fontWeight: 'normal', + data: <%= @a_commits_changeset %>, + dataLabels: { + enabled: false, + style: { + fontSize: '13px', + color: '#aaa', + fontFamily: 'Arial', + textShadow: '0px 0px 6px rgb(0, 0, 0), 0px 0px 3px rgb(f, f, f)', + fontWeight: 'normal' + } + }, + lineWidth: 1.5 + }, + { + name: '改动或增加', + color: '#5b6b76', data: <%= @a_commits_add %>, + dataLabels: { + enabled: false, + style: { + fontSize: '13px', + color: '#aaa', + fontFamily: 'Arial', + textShadow: '0px 0px 6px rgb(0, 0, 0), 0px 0px 3px rgb(f, f, f)', + fontWeight: 'normal' + } + }, lineWidth: 1.5 }, { - name: '删除', - color: '#46baed ', + name: '删除', + color: '#84b5bb', data: <%= @a_commits_del %>, - lineWidth: 1.5 - },{ - name: '总变更', - color: '#d397d5', - data: <%= @a_commits_changeset %>, + dataLabels: { + enabled: false, + style: { + fontSize: '13px', + color: '#aaa', + fontFamily: 'Arial', + textShadow: '0px 0px 6px rgb(0, 0, 0), 0px 0px 3px rgb(f, f, f)', + fontWeight: 'normal' + } + }, lineWidth: 1.5 }] }); @@ -120,9 +151,22 @@ } }, series: [{ - name: '提交次数', + name: '提交次数', + fontWeight: 'normal', + color: '#d05d5a', // data: [7.0, 6.9, 9.5, 14.5, 18.4, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6] data: <%= @a_commits_num %>, + dataLabels: { + enabled: false, + + style: { + fontSize: '13px', + color: '#aaa', + fontFamily: 'Arial', + textShadow: '0px 0px 6px rgb(0, 0, 0), 0px 0px 3px rgb(f, f, f)', + fontWeight: 'normal' + } + }, lineWidth: 1.5 } @@ -133,4 +177,5 @@ ] }); }); - \ No newline at end of file + +
当前分支:develop
\ No newline at end of file diff --git a/public/stylesheets/project.css b/public/stylesheets/project.css index f711c25e2..085fc64be 100644 --- a/public/stylesheets/project.css +++ b/public/stylesheets/project.css @@ -1200,3 +1200,4 @@ a.chooseActive {background-color:#269ac9; color:#ffffff;} .popupClose {background:url(../images/resource_icon_list.png) 0px -40px no-repeat; width:20px; height:20px; display:inline-block; position: absolute; z-index: 1000; right:10px; top:5px;} .subjectType {width:70px; text-align:center;} .subjectCount {width:65px; text-align:center;} +.button-rep { color: #888;display: inline-block;background: #eee;padding: 2px 5px;} From a21200ab14a89989e3695184765b268edd76552b Mon Sep 17 00:00:00 2001 From: huang Date: Fri, 15 Apr 2016 15:53:29 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E5=8A=A8=E6=80=81=E4=B8=AD=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=88=86=E6=94=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/projects_controller.rb | 8 +++++++- app/views/projects/_rep_static.html.erb | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 7553acdbc..e9151c473 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -329,7 +329,13 @@ class ProjectsController < ApplicationController @a_commits_add = rep_statics_code.map {|s| s.add.to_i } @a_commits_del = rep_statics_code.map {|s| s.del.to_i } @a_commits_changeset = rep_statics_code.map {|s| s.changeset.to_i } - # @static_total_per_user = g.rep_stats(@project.gpid) + g = Gitlab.client + begin + g_branch = g.project(@project.gpid).default_branch.to_s + rescue + logger.error("get gitlab project failed!") + end + @rev = g_branch.nil? ? "master" : g_branch end # 根据对应的请求,返回对应的数据 respond_to do |format| diff --git a/app/views/projects/_rep_static.html.erb b/app/views/projects/_rep_static.html.erb index 86d557f3a..9ebf68d0c 100644 --- a/app/views/projects/_rep_static.html.erb +++ b/app/views/projects/_rep_static.html.erb @@ -178,4 +178,4 @@ }); }); -
当前分支:develop
\ No newline at end of file +
当前分支:<%= @rev %>
\ No newline at end of file From a18daeecd1812d1bcdee0549e015120581c8b318 Mon Sep 17 00:00:00 2001 From: huang Date: Fri, 15 Apr 2016 16:01:25 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E7=89=88=E6=9C=AC=E5=BA=93=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=E4=B8=8E=E5=8A=A8=E6=80=81=E7=BB=9F=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/repositories/stats.html.erb | 106 +++++++++++++++++++++----- 1 file changed, 89 insertions(+), 17 deletions(-) diff --git a/app/views/repositories/stats.html.erb b/app/views/repositories/stats.html.erb index 4a8bd9217..4b35e64f6 100644 --- a/app/views/repositories/stats.html.erb +++ b/app/views/repositories/stats.html.erb @@ -14,6 +14,7 @@
+