数据子类(增删查改);数据主类(增删查该)

This commit is contained in:
huang 2018-02-07 14:13:09 +08:00
parent a38c68a791
commit a25dc9d6ce
29 changed files with 389 additions and 2 deletions

View File

@ -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/

View File

@ -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/

View File

@ -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/

View File

@ -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/

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,2 @@
module MainCategoriesHelper
end

View File

@ -0,0 +1,6 @@
module SubCategoriesHelper
def main_category_option
end
end

View File

@ -0,0 +1,4 @@
class MainCategory < ActiveRecord::Base
attr_accessible :name
has_many :sub_categories
end

View File

@ -0,0 +1,4 @@
class SubCategory < ActiveRecord::Base
attr_accessible :main_category_id, :name
belongs_to :main_category
end

View File

@ -0,0 +1,21 @@
<%= form_for(@main_category) do |f| %>
<% if @main_category.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@main_category.errors.count, "error") %> prohibited this main_category from being saved:</h2>
<ul>
<% @main_category.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>

View File

View File

@ -0,0 +1,6 @@
<h1>Editing main_category</h1>
<%= render 'form' %>
<%= link_to 'Show', @main_category %> |
<%= link_to 'Back', main_categories_path %>

View File

@ -0,0 +1,23 @@
<h1>Listing main_categories</h1>
<table>
<tr>
<th>Name</th>
<th></th>
<th></th>
<th></th>
</tr>
<% @main_categories.each do |main_category| %>
<tr>
<td><%= main_category.name %></td>
<td><%= link_to 'Show', main_category %></td>
<td><%= link_to 'Edit', edit_main_category_path(main_category) %></td>
<td><%= link_to 'Destroy', main_category, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</table>
<br />
<%= link_to 'New Main category', new_main_category_path, :remote => true %>

View File

@ -0,0 +1,5 @@
<h1>New main_category</h1>
<%= render 'form' %>
<%= link_to 'Back', main_categories_path %>

View File

@ -0,0 +1,2 @@
var html_value = "<%= escape_javascript(render :partial => 'main_categories/form') %>";
pop_up_box(html_value, 530);

View File

@ -0,0 +1,10 @@
<p id="notice"><%= notice %></p>
<p>
<b>Name:</b>
<%= @main_category.name %>
</p>
<%= link_to 'Edit', edit_main_category_path(@main_category) %> |
<%= link_to 'Back', main_categories_path %>

View File

@ -14,7 +14,7 @@
<div class="field line_field">
<label><span>*</span>数据名称:</label>
<%= f.text_field :name,:class=>"wb85" %>
<%= f.text_field :name, :class => "wb85" %>
</div>
<div class="field line_field">
<label><span>*</span>数据分类:</label>

View File

@ -0,0 +1,26 @@
<%= form_for(@sub_category) do |f| %>
<% if @sub_category.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@sub_category.errors.count, "error") %> prohibited this sub_category from being saved:</h2>
<ul>
<% @sub_category.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :main_category_id %><br />
<%= f.select :main_category_id, (@main_categories.collect { |mc| [mc.name, mc.id] }),
{:no_label => true}, :class => "w150" %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>

View File

@ -0,0 +1,6 @@
<h1>Editing sub_category</h1>
<%= render 'form' %>
<%= link_to 'Show', @sub_category %> |
<%= link_to 'Back', sub_categories_path %>

View File

@ -0,0 +1,25 @@
<h1>Listing sub_categories</h1>
<table>
<tr>
<th>Name</th>
<th>Main category</th>
<th></th>
<th></th>
<th></th>
</tr>
<% @sub_categories.each do |sub_category| %>
<tr>
<td><%= sub_category.name %></td>
<td><%= sub_category.main_category_id %></td>
<td><%= link_to 'Show', sub_category %></td>
<td><%= link_to 'Edit', edit_sub_category_path(sub_category) %></td>
<td><%= link_to 'Destroy', sub_category, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</table>
<br />
<%= link_to 'New Sub category', new_sub_category_path %>

View File

@ -0,0 +1,5 @@
<h1>New sub_category</h1>
<%= render 'form' %>
<%= link_to 'Back', sub_categories_path %>

View File

@ -0,0 +1,15 @@
<p id="notice"><%= notice %></p>
<p>
<b>Name:</b>
<%= @sub_category.name %>
</p>
<p>
<b>Main category:</b>
<%= @sub_category.main_category_id %>
</p>
<%= link_to 'Edit', edit_sub_category_path(@sub_category) %> |
<%= link_to 'Back', sub_categories_path %>

View File

@ -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: 项目托管平台首页

View File

@ -26,6 +26,12 @@
# Example: :via => :get ====> :via => :get
RedmineApp::Application.routes.draw do
resources :sub_categories
resources :main_categories
resources :statistics

View File

@ -0,0 +1,9 @@
class CreateMainCategories < ActiveRecord::Migration
def change
create_table :main_categories do |t|
t.string :name
t.timestamps
end
end
end

View File

@ -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

View File

@ -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"

View File

@ -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