From a25dc9d6ce02f13181e9090c3d302fa34a033c9f Mon Sep 17 00:00:00 2001 From: huang Date: Wed, 7 Feb 2018 14:13:09 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=AD=90=E7=B1=BB=EF=BC=88?= =?UTF-8?q?=E5=A2=9E=E5=88=A0=E6=9F=A5=E6=94=B9=EF=BC=89=EF=BC=9B=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E4=B8=BB=E7=B1=BB=EF=BC=88=E5=A2=9E=E5=88=A0=E6=9F=A5?= =?UTF-8?q?=E8=AF=A5=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../javascripts/main_categories.js.coffee | 3 + .../javascripts/sub_categories.js.coffee | 3 + .../stylesheets/main_categories.css.scss | 3 + .../stylesheets/sub_categories.css.scss | 3 + app/controllers/main_categories_controller.rb | 88 +++++++++++++++++++ app/controllers/sub_categories_controller.rb | 85 ++++++++++++++++++ app/helpers/main_categories_helper.rb | 2 + app/helpers/sub_categories_helper.rb | 6 ++ app/models/main_category.rb | 4 + app/models/sub_category.rb | 4 + app/views/main_categories/_form.html.erb | 21 +++++ app/views/main_categories/create.js.erb | 0 app/views/main_categories/edit.html.erb | 6 ++ app/views/main_categories/index.html.erb | 23 +++++ app/views/main_categories/new.html.erb | 5 ++ app/views/main_categories/new.js.erb | 2 + app/views/main_categories/show.html.erb | 10 +++ app/views/statistics/_form.html.erb | 2 +- app/views/sub_categories/_form.html.erb | 26 ++++++ app/views/sub_categories/edit.html.erb | 6 ++ app/views/sub_categories/index.html.erb | 25 ++++++ app/views/sub_categories/new.html.erb | 5 ++ app/views/sub_categories/show.html.erb | 15 ++++ config/locales/zh.yml | 2 + config/routes.rb | 6 ++ .../20180207030032_create_main_categories.rb | 9 ++ .../20180207030237_create_sub_categories.rb | 10 +++ db/schema.rb | 15 +++- lib/redmine.rb | 2 + 29 files changed, 389 insertions(+), 2 deletions(-) create mode 100644 app/assets/javascripts/main_categories.js.coffee create mode 100644 app/assets/javascripts/sub_categories.js.coffee create mode 100644 app/assets/stylesheets/main_categories.css.scss create mode 100644 app/assets/stylesheets/sub_categories.css.scss create mode 100644 app/controllers/main_categories_controller.rb create mode 100644 app/controllers/sub_categories_controller.rb create mode 100644 app/helpers/main_categories_helper.rb create mode 100644 app/helpers/sub_categories_helper.rb create mode 100644 app/models/main_category.rb create mode 100644 app/models/sub_category.rb create mode 100644 app/views/main_categories/_form.html.erb create mode 100644 app/views/main_categories/create.js.erb create mode 100644 app/views/main_categories/edit.html.erb create mode 100644 app/views/main_categories/index.html.erb create mode 100644 app/views/main_categories/new.html.erb create mode 100644 app/views/main_categories/new.js.erb create mode 100644 app/views/main_categories/show.html.erb create mode 100644 app/views/sub_categories/_form.html.erb create mode 100644 app/views/sub_categories/edit.html.erb create mode 100644 app/views/sub_categories/index.html.erb create mode 100644 app/views/sub_categories/new.html.erb create mode 100644 app/views/sub_categories/show.html.erb create mode 100644 db/migrate/20180207030032_create_main_categories.rb create mode 100644 db/migrate/20180207030237_create_sub_categories.rb diff --git a/app/assets/javascripts/main_categories.js.coffee b/app/assets/javascripts/main_categories.js.coffee new file mode 100644 index 000000000..761567942 --- /dev/null +++ b/app/assets/javascripts/main_categories.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/assets/javascripts/sub_categories.js.coffee b/app/assets/javascripts/sub_categories.js.coffee new file mode 100644 index 000000000..761567942 --- /dev/null +++ b/app/assets/javascripts/sub_categories.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/assets/stylesheets/main_categories.css.scss b/app/assets/stylesheets/main_categories.css.scss new file mode 100644 index 000000000..ff7b8ae31 --- /dev/null +++ b/app/assets/stylesheets/main_categories.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the main_categories controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/sub_categories.css.scss b/app/assets/stylesheets/sub_categories.css.scss new file mode 100644 index 000000000..5f48cf6fa --- /dev/null +++ b/app/assets/stylesheets/sub_categories.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the sub_categories 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/main_categories_controller.rb b/app/controllers/main_categories_controller.rb new file mode 100644 index 000000000..9a6d02cbb --- /dev/null +++ b/app/controllers/main_categories_controller.rb @@ -0,0 +1,88 @@ +# encoding=utf-8 +class MainCategoriesController < ApplicationController + # GET /main_categories + # GET /main_categories.json + layout 'admin' + before_filter :require_admin + def index + @main_categories = MainCategory.all + + respond_to do |format| + format.html # index.html.erb + format.json { render json: @main_categories } + end + end + + # GET /main_categories/1 + # GET /main_categories/1.json + def show + @main_category = MainCategory.find(params[:id]) + + respond_to do |format| + format.html # show.html.erb + format.json { render json: @main_category } + end + end + + # GET /main_categories/new + # GET /main_categories/new.json + def new + @main_category = MainCategory.new + + respond_to do |format| + format.html # new.html.erb + format.js + format.json { render json: @main_category } + end + end + + # GET /main_categories/1/edit + def edit + @main_category = MainCategory.find(params[:id]) + end + + # POST /main_categories + # POST /main_categories.json + def create + @main_category = MainCategory.new(params[:main_category]) + + respond_to do |format| + if @main_category.save + format.html { redirect_to main_categories_path, notice: '朱类别创建成功' } + format.js + format.json { render json: @main_category, status: :created, location: @main_category } + else + format.html { render action: "new" } + format.json { render json: @main_category.errors, status: :unprocessable_entity } + end + end + end + + # PUT /main_categories/1 + # PUT /main_categories/1.json + def update + @main_category = MainCategory.find(params[:id]) + + respond_to do |format| + if @main_category.update_attributes(params[:main_category]) + format.html { redirect_to @main_category, notice: 'Main category was successfully updated.' } + format.json { head :no_content } + else + format.html { render action: "edit" } + format.json { render json: @main_category.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /main_categories/1 + # DELETE /main_categories/1.json + def destroy + @main_category = MainCategory.find(params[:id]) + @main_category.destroy + + respond_to do |format| + format.html { redirect_to main_categories_url } + format.json { head :no_content } + end + end +end diff --git a/app/controllers/sub_categories_controller.rb b/app/controllers/sub_categories_controller.rb new file mode 100644 index 000000000..1c0721279 --- /dev/null +++ b/app/controllers/sub_categories_controller.rb @@ -0,0 +1,85 @@ +class SubCategoriesController < ApplicationController + layout 'admin' + before_filter :require_admin + # GET /sub_categories + # GET /sub_categories.json + def index + @sub_categories = SubCategory.all + + respond_to do |format| + format.html # index.html.erb + format.json { render json: @sub_categories } + end + end + + # GET /sub_categories/1 + # GET /sub_categories/1.json + def show + @sub_category = SubCategory.find(params[:id]) + + respond_to do |format| + format.html # show.html.erb + format.json { render json: @sub_category } + end + end + + # GET /sub_categories/new + # GET /sub_categories/new.json + def new + @sub_category = SubCategory.new + @main_categories = MainCategory.all + respond_to do |format| + format.html # new.html.erb + format.json { render json: @sub_category } + end + end + + # GET /sub_categories/1/edit + def edit + @sub_category = SubCategory.find(params[:id]) + end + + # POST /sub_categories + # POST /sub_categories.json + def create + @sub_category = SubCategory.new(params[:sub_category]) + + respond_to do |format| + if @sub_category.save + format.html { redirect_to @sub_category, notice: 'Sub category was successfully created.' } + format.json { render json: @sub_category, status: :created, location: @sub_category } + else + format.html { render action: "new" } + format.json { render json: @sub_category.errors, status: :unprocessable_entity } + end + end + end + + # PUT /sub_categories/1 + # PUT /sub_categories/1.json + def update + @sub_category = SubCategory.find(params[:id]) + + respond_to do |format| + if @sub_category.update_attributes(params[:sub_category]) + format.html { redirect_to @sub_category, notice: 'Sub category was successfully updated.' } + format.json { head :no_content } + else + format.html { render action: "edit" } + format.json { render json: @sub_category.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /sub_categories/1 + # DELETE /sub_categories/1.json + def destroy + @sub_category = SubCategory.find(params[:id]) + @sub_category.destroy + + respond_to do |format| + format.html { redirect_to sub_categories_url } + format.json { head :no_content } + end + end +end diff --git a/app/helpers/main_categories_helper.rb b/app/helpers/main_categories_helper.rb new file mode 100644 index 000000000..12184171b --- /dev/null +++ b/app/helpers/main_categories_helper.rb @@ -0,0 +1,2 @@ +module MainCategoriesHelper +end diff --git a/app/helpers/sub_categories_helper.rb b/app/helpers/sub_categories_helper.rb new file mode 100644 index 000000000..2813794fc --- /dev/null +++ b/app/helpers/sub_categories_helper.rb @@ -0,0 +1,6 @@ +module SubCategoriesHelper + + def main_category_option + + end +end diff --git a/app/models/main_category.rb b/app/models/main_category.rb new file mode 100644 index 000000000..d9ebfa110 --- /dev/null +++ b/app/models/main_category.rb @@ -0,0 +1,4 @@ +class MainCategory < ActiveRecord::Base + attr_accessible :name + has_many :sub_categories +end diff --git a/app/models/sub_category.rb b/app/models/sub_category.rb new file mode 100644 index 000000000..0f0de4c35 --- /dev/null +++ b/app/models/sub_category.rb @@ -0,0 +1,4 @@ +class SubCategory < ActiveRecord::Base + attr_accessible :main_category_id, :name + belongs_to :main_category +end diff --git a/app/views/main_categories/_form.html.erb b/app/views/main_categories/_form.html.erb new file mode 100644 index 000000000..fe90504fc --- /dev/null +++ b/app/views/main_categories/_form.html.erb @@ -0,0 +1,21 @@ +<%= form_for(@main_category) do |f| %> + <% if @main_category.errors.any? %> +
+

<%= pluralize(@main_category.errors.count, "error") %> prohibited this main_category from being saved:

+ + +
+ <% end %> + +
+ <%= f.label :name %>
+ <%= f.text_field :name %> +
+
+ <%= f.submit %> +
+<% end %> diff --git a/app/views/main_categories/create.js.erb b/app/views/main_categories/create.js.erb new file mode 100644 index 000000000..e69de29bb diff --git a/app/views/main_categories/edit.html.erb b/app/views/main_categories/edit.html.erb new file mode 100644 index 000000000..0ec171264 --- /dev/null +++ b/app/views/main_categories/edit.html.erb @@ -0,0 +1,6 @@ +

Editing main_category

+ +<%= render 'form' %> + +<%= link_to 'Show', @main_category %> | +<%= link_to 'Back', main_categories_path %> diff --git a/app/views/main_categories/index.html.erb b/app/views/main_categories/index.html.erb new file mode 100644 index 000000000..dd4eca05e --- /dev/null +++ b/app/views/main_categories/index.html.erb @@ -0,0 +1,23 @@ +

Listing main_categories

+ + + + + + + + + +<% @main_categories.each do |main_category| %> + + + + + + +<% end %> +
Name
<%= main_category.name %><%= link_to 'Show', main_category %><%= link_to 'Edit', edit_main_category_path(main_category) %><%= link_to 'Destroy', main_category, method: :delete, data: { confirm: 'Are you sure?' } %>
+ +
+ +<%= link_to 'New Main category', new_main_category_path, :remote => true %> diff --git a/app/views/main_categories/new.html.erb b/app/views/main_categories/new.html.erb new file mode 100644 index 000000000..36bf413b2 --- /dev/null +++ b/app/views/main_categories/new.html.erb @@ -0,0 +1,5 @@ +

New main_category

+ +<%= render 'form' %> + +<%= link_to 'Back', main_categories_path %> diff --git a/app/views/main_categories/new.js.erb b/app/views/main_categories/new.js.erb new file mode 100644 index 000000000..3a7665250 --- /dev/null +++ b/app/views/main_categories/new.js.erb @@ -0,0 +1,2 @@ +var html_value = "<%= escape_javascript(render :partial => 'main_categories/form') %>"; +pop_up_box(html_value, 530); diff --git a/app/views/main_categories/show.html.erb b/app/views/main_categories/show.html.erb new file mode 100644 index 000000000..8cae57ac8 --- /dev/null +++ b/app/views/main_categories/show.html.erb @@ -0,0 +1,10 @@ +

<%= notice %>

+ +

+ Name: + <%= @main_category.name %> +

+ + +<%= link_to 'Edit', edit_main_category_path(@main_category) %> | +<%= link_to 'Back', main_categories_path %> diff --git a/app/views/statistics/_form.html.erb b/app/views/statistics/_form.html.erb index 6a7b460c6..8b65ed2bc 100644 --- a/app/views/statistics/_form.html.erb +++ b/app/views/statistics/_form.html.erb @@ -14,7 +14,7 @@
- <%= f.text_field :name,:class=>"wb85" %> + <%= f.text_field :name, :class => "wb85" %>
diff --git a/app/views/sub_categories/_form.html.erb b/app/views/sub_categories/_form.html.erb new file mode 100644 index 000000000..5f3b93534 --- /dev/null +++ b/app/views/sub_categories/_form.html.erb @@ -0,0 +1,26 @@ +<%= form_for(@sub_category) do |f| %> + <% if @sub_category.errors.any? %> +
+

<%= pluralize(@sub_category.errors.count, "error") %> prohibited this sub_category from being saved:

+ +
    + <% @sub_category.errors.full_messages.each do |msg| %> +
  • <%= msg %>
  • + <% end %> +
+
+ <% end %> + +
+ <%= f.label :name %>
+ <%= f.text_field :name %> +
+
+ <%= f.label :main_category_id %>
+ <%= f.select :main_category_id, (@main_categories.collect { |mc| [mc.name, mc.id] }), + {:no_label => true}, :class => "w150" %> +
+
+ <%= f.submit %> +
+<% end %> diff --git a/app/views/sub_categories/edit.html.erb b/app/views/sub_categories/edit.html.erb new file mode 100644 index 000000000..bb69cf9e6 --- /dev/null +++ b/app/views/sub_categories/edit.html.erb @@ -0,0 +1,6 @@ +

Editing sub_category

+ +<%= render 'form' %> + +<%= link_to 'Show', @sub_category %> | +<%= link_to 'Back', sub_categories_path %> diff --git a/app/views/sub_categories/index.html.erb b/app/views/sub_categories/index.html.erb new file mode 100644 index 000000000..6ea3adc41 --- /dev/null +++ b/app/views/sub_categories/index.html.erb @@ -0,0 +1,25 @@ +

Listing sub_categories

+ + + + + + + + + + +<% @sub_categories.each do |sub_category| %> + + + + + + + +<% end %> +
NameMain category
<%= sub_category.name %><%= sub_category.main_category_id %><%= link_to 'Show', sub_category %><%= link_to 'Edit', edit_sub_category_path(sub_category) %><%= link_to 'Destroy', sub_category, method: :delete, data: { confirm: 'Are you sure?' } %>
+ +
+ +<%= link_to 'New Sub category', new_sub_category_path %> diff --git a/app/views/sub_categories/new.html.erb b/app/views/sub_categories/new.html.erb new file mode 100644 index 000000000..ca17198ec --- /dev/null +++ b/app/views/sub_categories/new.html.erb @@ -0,0 +1,5 @@ +

New sub_category

+ +<%= render 'form' %> + +<%= link_to 'Back', sub_categories_path %> diff --git a/app/views/sub_categories/show.html.erb b/app/views/sub_categories/show.html.erb new file mode 100644 index 000000000..66714d041 --- /dev/null +++ b/app/views/sub_categories/show.html.erb @@ -0,0 +1,15 @@ +

<%= notice %>

+ +

+ Name: + <%= @sub_category.name %> +

+ +

+ Main category: + <%= @sub_category.main_category_id %> +

+ + +<%= link_to 'Edit', edit_sub_category_path(@sub_category) %> | +<%= link_to 'Back', sub_categories_path %> diff --git a/config/locales/zh.yml b/config/locales/zh.yml index f95546a06..d57375084 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -396,6 +396,8 @@ zh: label_organization_edit: 修改组织 label_project_plural: 项目列表 label_contest_plural: 竞赛列表 + label_main_categories: 数据主类 + label_sub_categories: 数据子类 label_first_page_made: 首页定制 label_project_first_page: 项目托管平台首页 diff --git a/config/routes.rb b/config/routes.rb index 919b036ea..117ca0a8d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -26,6 +26,12 @@ # Example: :via => :get ====> :via => :get RedmineApp::Application.routes.draw do + resources :sub_categories + + + resources :main_categories + + resources :statistics diff --git a/db/migrate/20180207030032_create_main_categories.rb b/db/migrate/20180207030032_create_main_categories.rb new file mode 100644 index 000000000..b0562aa10 --- /dev/null +++ b/db/migrate/20180207030032_create_main_categories.rb @@ -0,0 +1,9 @@ +class CreateMainCategories < ActiveRecord::Migration + def change + create_table :main_categories do |t| + t.string :name + + t.timestamps + end + end +end diff --git a/db/migrate/20180207030237_create_sub_categories.rb b/db/migrate/20180207030237_create_sub_categories.rb new file mode 100644 index 000000000..a8e2f5534 --- /dev/null +++ b/db/migrate/20180207030237_create_sub_categories.rb @@ -0,0 +1,10 @@ +class CreateSubCategories < ActiveRecord::Migration + def change + create_table :sub_categories do |t| + t.string :name + t.integer :main_category_id + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 079c5f089..5093608f2 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20180205031602) do +ActiveRecord::Schema.define(:version => 20180207030237) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -1660,6 +1660,12 @@ ActiveRecord::Schema.define(:version => 20180205031602) do t.integer "owner_type", :default => 0 end + create_table "main_categories", :force => true do |t| + t.string "name" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + create_table "major_courses", :force => true do |t| t.integer "course_list_id" t.integer "major_id" @@ -2741,6 +2747,13 @@ ActiveRecord::Schema.define(:version => 20180205031602) do add_index "students_for_courses", ["course_id"], :name => "index_students_for_courses_on_course_id" add_index "students_for_courses", ["student_id"], :name => "index_students_for_courses_on_student_id" + create_table "sub_categories", :force => true do |t| + t.string "name" + t.integer "main_category_id" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + create_table "sub_document_comments", :force => true do |t| t.text "content" t.text "title" diff --git a/lib/redmine.rb b/lib/redmine.rb index 86b513539..f50e4bb74 100644 --- a/lib/redmine.rb +++ b/lib/redmine.rb @@ -381,6 +381,8 @@ Redmine::MenuManager.map :admin_menu do |menu| menu.push :syllabuses, {:controller => 'admin', :action => 'syllabuses'}, :caption => :label_course_all menu.push :contests, {:controller => 'admin', :action => 'contests'}, :caption => :label_contest_plural menu.push :users, {:controller => 'admin', :action => 'users'}, :caption => :label_user_plural + menu.push :main_categories, {:controller => 'main_categories', :action => 'index'}, :caption => :label_main_categories + menu.push :sub_categories, {:controller => 'sub_categories', :action => 'index'}, :caption => :label_sub_categories menu.push :messages, {:controller => 'admin', :action => 'messages'}, :caption => :label_system_message menu.push :schools, {:controller => 'admin', :action => 'schools'}, :caption => :label_school_plural menu.push :applied_schools, {:controller => 'admin', :action => 'applied_schools'}, :caption => :label_applied_shcools