From 0ad1b56a272418da83e7219557ed5a96481dfde9 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 6 Nov 2019 11:23:41 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E9=BB=91=E5=AE=A2=E6=9D=BE=E5=AE=9A?= =?UTF-8?q?=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/assets/javascripts/trustie_hacks.js | 2 + app/assets/stylesheets/trustie_hacks.scss | 3 ++ app/controllers/trustie_hacks_controller.rb | 48 +++++++++++++++++++ app/helpers/trustie_hacks_helper.rb | 2 + app/models/hack_user.rb | 3 ++ app/models/trustie_hack.rb | 4 ++ app/models/trustie_hackathon.rb | 5 ++ app/views/trustie_hacks/edit.json.jbuilder | 1 + .../edit_hackathon.json.jbuilder | 2 + app/views/trustie_hacks/index.json.jbuilder | 9 ++++ config/routes.rb | 8 ++++ ...0191105093740_create_trustie_hackathons.rb | 10 ++++ .../20191105093919_create_trustie_hacks.rb | 11 +++++ .../20191105094146_create_hack_users.rb | 9 ++++ .../trustie_hacks_controller_spec.rb | 5 ++ spec/helpers/trustie_hacks_helper_spec.rb | 15 ++++++ spec/models/hack_user_spec.rb | 5 ++ spec/models/trustie_hack_spec.rb | 5 ++ spec/models/trustie_hackathon_spec.rb | 5 ++ 19 files changed, 152 insertions(+) create mode 100644 app/assets/javascripts/trustie_hacks.js create mode 100644 app/assets/stylesheets/trustie_hacks.scss create mode 100644 app/controllers/trustie_hacks_controller.rb create mode 100644 app/helpers/trustie_hacks_helper.rb create mode 100644 app/models/hack_user.rb create mode 100644 app/models/trustie_hack.rb create mode 100644 app/models/trustie_hackathon.rb create mode 100644 app/views/trustie_hacks/edit.json.jbuilder create mode 100644 app/views/trustie_hacks/edit_hackathon.json.jbuilder create mode 100644 app/views/trustie_hacks/index.json.jbuilder create mode 100644 db/migrate/20191105093740_create_trustie_hackathons.rb create mode 100644 db/migrate/20191105093919_create_trustie_hacks.rb create mode 100644 db/migrate/20191105094146_create_hack_users.rb create mode 100644 spec/controllers/trustie_hacks_controller_spec.rb create mode 100644 spec/helpers/trustie_hacks_helper_spec.rb create mode 100644 spec/models/hack_user_spec.rb create mode 100644 spec/models/trustie_hack_spec.rb create mode 100644 spec/models/trustie_hackathon_spec.rb diff --git a/app/assets/javascripts/trustie_hacks.js b/app/assets/javascripts/trustie_hacks.js new file mode 100644 index 000000000..dee720fac --- /dev/null +++ b/app/assets/javascripts/trustie_hacks.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/stylesheets/trustie_hacks.scss b/app/assets/stylesheets/trustie_hacks.scss new file mode 100644 index 000000000..78786cfb3 --- /dev/null +++ b/app/assets/stylesheets/trustie_hacks.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the trustie_hacks controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/trustie_hacks_controller.rb b/app/controllers/trustie_hacks_controller.rb new file mode 100644 index 000000000..ebc7f1578 --- /dev/null +++ b/app/controllers/trustie_hacks_controller.rb @@ -0,0 +1,48 @@ +class TrustieHacksController < ApplicationController + before_action :require_admin, :except => [:index] + before_action :require_login, :except => [:index] + before_action :find_hackathon + before_action :find_hack, :except => [:create, :index] + + def index + ## 分页参数 + page = params[:page] || 1 + limit = params[:limit] || 16 + + hacks = @hackathon.trustie_hacks + @hackathon_users_count = hacks.sum(:hack_users_count) + + @hacks = hacks.page(page).per(limit) + + end + + def edit ;end + + def create + @hackathon.trustie_hacks.create!(name: params[:name], description: params[:description]) + render_ok + end + + def update + @hack.update_attributes(name: params[:name], description: params[:description]) + end + + def edit_hackathon ;end + + def update_hackathon + @hackathon.update_attributes(name: params[:name], description: params[:description]) + end + + + private + + def find_hackathon + @hackathon = TrustieHackathon.first || + TrustieHackathon.create(name: params[:name], description: params[:description]) + end + + def find_hack + @hack = TrustieHack.find params[:id] + end + +end diff --git a/app/helpers/trustie_hacks_helper.rb b/app/helpers/trustie_hacks_helper.rb new file mode 100644 index 000000000..3ebe3a9cc --- /dev/null +++ b/app/helpers/trustie_hacks_helper.rb @@ -0,0 +1,2 @@ +module TrustieHacksHelper +end diff --git a/app/models/hack_user.rb b/app/models/hack_user.rb new file mode 100644 index 000000000..7b8030841 --- /dev/null +++ b/app/models/hack_user.rb @@ -0,0 +1,3 @@ +class HackUser < ApplicationRecord + belongs_to :trustie_hack, counter_cache: true +end diff --git a/app/models/trustie_hack.rb b/app/models/trustie_hack.rb new file mode 100644 index 000000000..898bf2195 --- /dev/null +++ b/app/models/trustie_hack.rb @@ -0,0 +1,4 @@ +class TrustieHack < ApplicationRecord + has_many :hack_users, :dependent => :destroy + belongs_to :trustie_hackathon, counter_cache: true +end diff --git a/app/models/trustie_hackathon.rb b/app/models/trustie_hackathon.rb new file mode 100644 index 000000000..7269e7856 --- /dev/null +++ b/app/models/trustie_hackathon.rb @@ -0,0 +1,5 @@ +class TrustieHackathon < ApplicationRecord + + has_many :trustie_hacks, :dependent => :destroy + +end diff --git a/app/views/trustie_hacks/edit.json.jbuilder b/app/views/trustie_hacks/edit.json.jbuilder new file mode 100644 index 000000000..9ee35736f --- /dev/null +++ b/app/views/trustie_hacks/edit.json.jbuilder @@ -0,0 +1 @@ +json.(@hack, :id, :name, :description) \ No newline at end of file diff --git a/app/views/trustie_hacks/edit_hackathon.json.jbuilder b/app/views/trustie_hacks/edit_hackathon.json.jbuilder new file mode 100644 index 000000000..52eda0fb8 --- /dev/null +++ b/app/views/trustie_hacks/edit_hackathon.json.jbuilder @@ -0,0 +1,2 @@ +json.name @hackathon&.name +json.description @hackathon&.description \ No newline at end of file diff --git a/app/views/trustie_hacks/index.json.jbuilder b/app/views/trustie_hacks/index.json.jbuilder new file mode 100644 index 000000000..05e3fd7c7 --- /dev/null +++ b/app/views/trustie_hacks/index.json.jbuilder @@ -0,0 +1,9 @@ +json.hackathon do + json.(@hackathon, :id, :name, :description) + json.hackathon_users_count @hackathon_users_count +end + +json.hacks @hacks do |hack| + json.(hack, :id, :name, :description, :hack_users_count) +end + diff --git a/config/routes.rb b/config/routes.rb index 3cf18fe75..96b8f006c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1105,6 +1105,14 @@ Rails.application.routes.draw do end end + resources :trustie_hacks, path: :osshackathon do + collection do + get :edit_hackathon + post :update_hackathon + end + + end + #git 认证回调 match 'gitauth/*url', to: 'gits#auth', via: :all diff --git a/db/migrate/20191105093740_create_trustie_hackathons.rb b/db/migrate/20191105093740_create_trustie_hackathons.rb new file mode 100644 index 000000000..4e806d346 --- /dev/null +++ b/db/migrate/20191105093740_create_trustie_hackathons.rb @@ -0,0 +1,10 @@ +class CreateTrustieHackathons < ActiveRecord::Migration[5.2] + def change + create_table :trustie_hackathons do |t| + t.string :name + t.string :description + t.integer :trustie_hacks_count, default: 0 + t.timestamps + end + end +end diff --git a/db/migrate/20191105093919_create_trustie_hacks.rb b/db/migrate/20191105093919_create_trustie_hacks.rb new file mode 100644 index 000000000..d4f65516e --- /dev/null +++ b/db/migrate/20191105093919_create_trustie_hacks.rb @@ -0,0 +1,11 @@ +class CreateTrustieHacks < ActiveRecord::Migration[5.2] + def change + create_table :trustie_hacks do |t| + t.string :name + t.string :description + t.references :user + t.integer :hack_users_count, default: 0 + t.timestamps + end + end +end diff --git a/db/migrate/20191105094146_create_hack_users.rb b/db/migrate/20191105094146_create_hack_users.rb new file mode 100644 index 000000000..2ef654b5b --- /dev/null +++ b/db/migrate/20191105094146_create_hack_users.rb @@ -0,0 +1,9 @@ +class CreateHackUsers < ActiveRecord::Migration[5.2] + def change + create_table :hack_users do |t| + t.references :user + t.references :trustie_hack + t.timestamps + end + end +end diff --git a/spec/controllers/trustie_hacks_controller_spec.rb b/spec/controllers/trustie_hacks_controller_spec.rb new file mode 100644 index 000000000..bad650328 --- /dev/null +++ b/spec/controllers/trustie_hacks_controller_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe TrustieHacksController, type: :controller do + +end diff --git a/spec/helpers/trustie_hacks_helper_spec.rb b/spec/helpers/trustie_hacks_helper_spec.rb new file mode 100644 index 000000000..6d48a0072 --- /dev/null +++ b/spec/helpers/trustie_hacks_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the TrustieHacksHelper. For example: +# +# describe TrustieHacksHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +RSpec.describe TrustieHacksHelper, type: :helper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/hack_user_spec.rb b/spec/models/hack_user_spec.rb new file mode 100644 index 000000000..5bd8221dc --- /dev/null +++ b/spec/models/hack_user_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe HackUser, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/trustie_hack_spec.rb b/spec/models/trustie_hack_spec.rb new file mode 100644 index 000000000..d4423cd2c --- /dev/null +++ b/spec/models/trustie_hack_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe TrustieHack, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/trustie_hackathon_spec.rb b/spec/models/trustie_hackathon_spec.rb new file mode 100644 index 000000000..7334fd52c --- /dev/null +++ b/spec/models/trustie_hackathon_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe TrustieHackathon, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end From 8db6bc68e12a067830c04b1722d3362f2292c836 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=A0=91=E6=98=8E?= <775174143@qq.com> Date: Wed, 6 Nov 2019 11:28:30 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/modules/osshackathon/Osshackathon.js | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/public/react/src/modules/osshackathon/Osshackathon.js b/public/react/src/modules/osshackathon/Osshackathon.js index f15599aff..f2bf71e32 100644 --- a/public/react/src/modules/osshackathon/Osshackathon.js +++ b/public/react/src/modules/osshackathon/Osshackathon.js @@ -77,6 +77,7 @@ class Osshackathon extends Component { probare, quae sunt a te dicta? Refert tamen, quo modo.

+ {/*学生身份*/} @@ -94,6 +95,26 @@ class Osshackathon extends Component {

Card content

Card content

+ + {/*教师身份*/} + + + + + 大赛介绍 + + + + + + +

Card content

+

Card content

+
+ +