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 e886d1a42..9f33405a9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1113,6 +1113,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/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.
+ {/*学生身份*/}Card content
Card content
Card content
+Card content
+