实训项目基础框架搭建及相关关联

This commit is contained in:
huang 2017-03-02 15:44:56 +08:00
parent 3582f70a6b
commit c14840ef83
22 changed files with 458 additions and 4 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 styles related to the shixuns 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,76 @@
class ShixunsController < ApplicationController
layout 'base_shixun'
before_filter :require_login
before_filter :find_shixun, :except => [ :index, :new, :create, :training_execute, :training_task_status]
before_filter :shixun_authorize, :only => [:show]
before_filter :require_manager, :only => [ :settings]
include ApplicationHelper
def new
@shixun = Shixun.new
respond_to do |format|
format.html{render :layout => 'new_base'}
format.json
end
end
def create
@shixun = Shixun.new(params[:shixun])
@shixun.user_id = User.current.id
respond_to do |format|
if @shixun.save
m = ShixunMember.new(:user_id => User.current.id, :role => 1)
@shixun.shixun_members << m
format.html { redirect_to @shixun, notice: l(:notice_successful_create) }
format.js
else
format.html { render action: "new" }
format.js
end
end
end
def show
@shixun
end
def index
end
def edit
end
def update
end
def destroy
end
# Find shixun of id params[:id]
def find_shixun
@shixun = Shixun.find(params[:id])
rescue ActiveRecord::RecordNotFound
render_404
end
# 权限控制
def shixun_authorize
if @shixun.is_public?
true
else
User.current.member_of?(@shixun) ? true : false
end
end
def require_manager
User.current.manager_of_shixun?(@shixun)
end
end

View File

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

View File

@ -59,6 +59,8 @@ class Role < ActiveRecord::Base
has_many :org_members,:through => :org_member_roles
has_many :contest_member_roles, :dependent => :destroy
has_many :contest_members, :through => :contest_member_roles
has_many :shixun_members, :through => :shixun_member_roles
has_many :shixun_member_roles, :dependent => :destroy
acts_as_list
serialize :permissions, ::Role::PermissionsAttributeCoder

15
app/models/shixun.rb Normal file
View File

@ -0,0 +1,15 @@
class Shixun < ActiveRecord::Base
attr_accessible :description, :is_public, :name, :parent_id
has_many :users, :through => :shixun_members
has_many :shixun_members
def parent
shixun = Shixun.find_by_parent_id(self.parent_id)
# raise ActiveRecord::RecordNotFound, "Couldn't find Shixun with parent_id=#{self.parent_id}" if shixun.nil?
end
def owner
User.find_by_id(self.user_id)
end
end

View File

@ -0,0 +1,7 @@
class ShixunMember < ActiveRecord::Base
attr_accessible :shixun_member_id, :user_id, :role
belongs_to :shixun
belongs_to :user
has_many :roles ,:through => :shixun_member_roles, :foreign_key => 'role_id'
has_many :shixun_member_roles,:dependent => :destroy
end

View File

@ -124,6 +124,8 @@ class User < Principal
has_many :contestant_work_scores
has_many :contestant_work_projects
has_many :shixuns, :through => :shixun_members, :dependent => :destroy
has_and_belongs_to_many :groups, :after_add => Proc.new {|user, group| group.user_added(user)},
:after_remove => Proc.new {|user, group| group.user_removed(user)}
has_many :changesets, :dependent => :nullify
@ -890,6 +892,20 @@ class User < Principal
projects.to_a.include?(project)
end
# Return true if the user is a member of project
def member_of?(shixun)
projects.to_a.include?(shixun)
end
def manager_of_shixun?(shixun)
@result = false
mem = Member.where("user_id = ? and project_id = ?", self.id, shixun.id)
unless mem.blank?
@result = mem.first.roles.to_s.include?("Manager") ? true : false
end
return @result
end
def member_of_course?(course)
courses.to_a.include?(course)
end

View File

@ -0,0 +1,53 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title><%= h html_title %></title>
<meta name="description" content="<%= Redmine::Info.app_name %>" />
<meta name="keywords" content="issue,bug,tracker" />
<%= csrf_meta_tag %>
<%= favicon %>
<%= javascript_heads %>
<%= heads_for_theme %>
<%= stylesheet_link_tag 'jquery/jquery-ui-1.9.2','css/common','css/structure','scm','css/public', 'css/project','css/popup','repository','css/gantt', 'css/calendar', 'css/moduel', 'css/font-awesome' %>
<%= call_hook :view_layouts_base_html_head %>
<!-- page specific tags -->
<%= yield :header_tags -%>
</head>
<%= @shixun %>
<!--add by huang-->
<body onload="prettyPrint();">
<div class="navContainer mb10"> <%= render :partial => User.current.logged? ? 'layouts/logined_header' : 'layouts/unlogin_header' %></div>
<div class="cl"></div>
<div id="Container">
<div id="content" class="sy_contanier" style=" width:1000px; margin:0 auto;">
<%= render :partial => 'shixuns/shixun_top' %>
</div>
<%= render_flash_messages %>
<%= yield %>
<%= call_hook :view_layouts_base_content %>
<div style="clear:both;"></div>
</div>
<div class="cl"></div>
<%= render :partial => 'layouts/footer' %>
<div class="cl"></div>
<% if hidden_unproject_infos %>
<%= render :partial => 'layouts/new_feedback' %>
<% end %>
<div id="ajax-indicator" style="display:none;">
<span><%= l(:label_loading) %></span>
</div>
<div id="ajax-modal" style="display:none;"></div>
<div id="nh_tx_dialog_html" class="white_content" style="display:none;">
<%#=render :partial => 'layouts/upload_avatar', :locals => {:source => @project} %>
</div>
<%= call_hook :view_layouts_base_body_bottom %>
</body>
<!-- MathJax的配置 -->
<script type="text/javascript" src="/javascripts/MathJax/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<%= javascript_include_tag 'cookie','project',"avatars", 'header','prettify','select_list_move','attachments' %>
</html>

View File

@ -0,0 +1,78 @@
<div class="hwork_new">
<ul>
<%= form_for(@shixun) do |f| %>
<% if @shixun.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@shixun.errors.count, "error") %> prohibited this product from being saved:</h2>
<ul>
<% @shixun.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<li class="ml45 mb10">
<label><span class="c_red">*</span>&nbsp;<%= l(:label_projects_new_name)%>&nbsp;&nbsp;:</label>
<%= f.text_field :name, :class => "project_new_input project_new_input_project_new", :placeholder => "例如:团队协作方法与机制研究", :onkeyup => "regex_project_name();" %>
<p class="c_orange ml70" id="project_name_notice" style="display: none;">项目名称不能为空</p>
</li>
<li class="ml45 mb10">
<label class="fl mr5">&nbsp;&nbsp;<%= l(:label_tags_project_description) %>&nbsp;&nbsp;:</label>
<%= f.kindeditor :description, :editor_id => 'project_create_editor',
:owner_id => @project.nil? ? 0: @project.id,
:owner_type => OwnerTypeHelper::PROJECT,
:width => '86%',
:height => 300,
:minHeight=> 300,
:class => 'courses_text ml5 fl',
:input_html => { :id => 'description',
:class => 'courses_text fl',
:maxlength => 5000 }
%>
<div class="cl"></div>
</li>
<li class="mb5 ml70">
<label >&nbsp;公开&nbsp;</label>
<%= f.text_field :is_public, :id => "project_is_public", :name => "project[is_public]", :type => "checkbox", :value => "1", :checked => "checked" %>
<span class="c_grey">(打钩为公开项目,不打钩为私有项目;私有项目仅项目成员可见。)</span>
<div class="cl"></div>
</li>
<li class=" ml90" >
<a href="javascript:void(0)" class="blue_btn fl c_white" onclick="submit_new_project();" >提交</a>
<%= link_to "取消",user_activities_path(User.current.id),:class => "grey_btn fl c_white ml10"%>
<div class="cl"></div>
</li>
<% end %>
</ul>
</div>
<div class="cl"></div>
<script>
//////////////////////////////////////////////////////////////
//新建项目
//验证项目名称
function regex_project_name()
{
var name = $.trim($("#shixun_name").val());
if(name.length == 0)
{
$("#project_name_notice").show();
return false;
}
else
{
$("#project_name_notice").hide();
return true;
}
}
//提交新建项目
function submit_new_project()
{
project_create_editor.sync();
if(regex_project_name())
{
$("#new_shixun").submit();
}
}
</script>

View File

@ -0,0 +1,55 @@
<%# training_tasks_count = @shixun.training_tasks.count %>
<% project_acts = 99999 %>
<%# 更新访问数,刷新的时候更新访问次数 %>
<% update_visiti_count @shixun %>
<div class="pro_new_top clear mb10">
<div class="fl pro_new_name ml15 clear">
<% unless @shixun.is_public? %><span class="icons_newpro_lock fl "></span><% end %>
<%=link_to "#{@shixun.owner.try(:show_name)+ (@shixun.parent_id.nil? ? "导师" : "")}<span class='ml5 mr5'>/</span>".html_safe, user_path(@shixun.owner), :class => "pro_new_username" %>
<%=link_to @shixun.name, shixun_path(@shixun), :class => "pro_new_username break_word" %>
</div>
<div class="cl"></div>
<% unless @shixun.parent_id %>
<div class="fl pro_new_name ml15 clear mt5">
<span class="vl_fork fl mr5 mt2">forked from</span> <%=link_to "#{@shixun.parent.try(:owner).try(:show_name)}<span class='ml5 mr5'>/</span>".html_safe, user_path(@shixun.parent.try(:owner)), :class => "pro_new_username_fork fl", :target => "_blank" %>
<%=link_to @shixun.parent.try(:name), shixun_path(@shixun.parent), :class => "pro_new_username_fork fl", :target => "_blank" %>
</div>
<div class="cl"></div>
<% end %>
<div class="pro_new_topnav mt8">
<ul>
<li id="project_menu_01">
<%= link_to "#{l(:label_activity)}<span class='issues_nav_tag ml5'>#{switch_integer_into_k(project_acts)}</span>".html_safe, shixun_path(@shixun), :class => "pro_new_proname", :title => "#{project_acts}" %>
</li>
<!--实训任务-->
<li id="project_menu_011">
<%= link_to 1 > 0 ? "#{l(:project_module_training_tasks)}<span class='issues_nav_tag ml5'>#{switch_integer_into_k 99999}</span>".html_safe : "#{l(:project_module_training_tasks)}", project_training_tasks_url(@shixun), :class => "pro_new_proname", :title => "#{99999}" %>
</li>
<!--讨论区-->
<li id="project_menu_03">
<%= link_to 1 > 0 ? "#{l(:project_module_boards)}<span class='issues_nav_tag ml5'>#{switch_integer_into_k 99999}</span>".html_safe : "#{l(:project_module_boards)}", project_boards_path(@shixun), :class => "pro_new_proname", :title => "#{99999}" %>
</li>
<!--版本库-->
<li id="project_menu_05"><%= link_to 1 > 0 ? "#{l(:project_module_repository)}<span class='issues_nav_tag ml5'>#{switch_integer_into_k 99999}</span>".html_safe : "#{l(:project_module_repository)}",({:controller => 'repositories', :action => 'show', :id => @shixun, :repository_id => gitlab_repository(@shixun).try(:identifier)}), :class => "pro_new_proname", :title => "#{99999}" %></li>
<li id="project_menu_010">
<%= link_to "#{l(:button_configure)}", settings_project_path(@shixun), :class => "pro_new_proname" %>
</li>
</ul>
</div>
</div>
<!--新版项目头部结束-->
<script>
$(function(){
$("#project_menu_0<%= @shixun_menu_type %>").addClass('pro_new_topnav_active');
})
</script>

View File

@ -0,0 +1,12 @@
<%= content_for(:header_tags) do %>
<%= import_ke(enable_at: false, prettify: false, init_activity: false) %>
<% end %>
<%= error_messages_for 'project' %>
<div class="project_r_h02">
<h2 class="project_h2"><%= l(:label_project_new)%></h2>
</div>
<%= render 'form' %>

View File

@ -0,0 +1 @@
<%= @shixun %>

View File

@ -28,6 +28,16 @@
RedmineApp::Application.routes.draw do
mount Mobile::API => '/api'
resources :shixuns do
member do
end
collection do
end
end
# Enable Grack support
# mount Trustie::Grack.new, at: '/', constraints: lambda { |request| /[-\/\w\.]+\.git\//.match(request.path_info) }, via: [:get, :post]

View File

@ -0,0 +1,17 @@
class CreateShixuns < ActiveRecord::Migration
def change
create_table :shixuns do |t|
t.string :name
t.text :description
t.text :script
t.boolean :is_public, :default => 1
t.integer :parent_id
t.integer :user_id
t.integer :gpid
t.integer :forked_count, :default => 0
t.integer :visits, :default => 0
t.timestamps
end
end
end

View File

@ -0,0 +1,11 @@
class CreateShixunMembers < ActiveRecord::Migration
def change
create_table :shixun_members do |t|
t.integer :user_id
t.integer :shixun_id
t.integer :role
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 => 20170219070127) do
ActiveRecord::Schema.define(:version => 20170302032957) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false
@ -1064,6 +1064,33 @@ ActiveRecord::Schema.define(:version => 20170219070127) do
add_index "homework_attaches", ["bid_id"], :name => "index_homework_attaches_on_bid_id"
create_table "homework_bank_tests", :force => true do |t|
t.text "input"
t.text "output"
t.boolean "test_type"
t.integer "homework_bank_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "homework_banks", :force => true do |t|
t.integer "user_id"
t.string "name"
t.text "description"
t.integer "homework_type"
t.integer "quotes", :default => 0
t.boolean "is_public"
t.string "language"
t.text "standard_code", :limit => 2147483647
t.integer "min_num"
t.integer "max_num"
t.boolean "base_on_project"
t.string "applicable_syllabus"
t.integer "homework_common_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "homework_commons", :force => true do |t|
t.string "name"
t.integer "user_id"
@ -1073,8 +1100,8 @@ ActiveRecord::Schema.define(:version => 20170219070127) do
t.integer "homework_type", :default => 1
t.string "late_penalty"
t.integer "course_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "teacher_priority", :default => 1
t.integer "anonymous_comment", :default => 0
t.integer "quotes", :default => 0
@ -1082,6 +1109,8 @@ ActiveRecord::Schema.define(:version => 20170219070127) do
t.datetime "simi_time"
t.integer "score_open", :default => 1
t.integer "anonymous_appeal", :default => 0
t.integer "homework_bank_id"
t.boolean "is_update", :default => false
end
add_index "homework_commons", ["course_id", "id"], :name => "index_homework_commons_on_course_id_and_id"
@ -1137,6 +1166,16 @@ ActiveRecord::Schema.define(:version => 20170219070127) do
add_index "homework_for_courses", ["bid_id"], :name => "index_homework_for_courses_on_bid_id"
add_index "homework_for_courses", ["course_id"], :name => "index_homework_for_courses_on_course_id"
create_table "homework_samples", :force => true do |t|
t.text "input"
t.text "output"
t.integer "homework_common_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "homework_samples", ["homework_common_id"], :name => "index_homework_samples_on_homework_common_id"
create_table "homework_tests", :force => true do |t|
t.text "input"
t.text "output"
@ -1980,6 +2019,28 @@ ActiveRecord::Schema.define(:version => 20170219070127) do
t.datetime "updated_at", :null => false
end
create_table "shixun_members", :force => true do |t|
t.integer "user_id"
t.integer "shixun_id"
t.integer "role"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "shixuns", :force => true do |t|
t.string "name"
t.text "description"
t.text "script"
t.boolean "is_public", :default => true
t.integer "parent_id"
t.integer "user_id"
t.integer "gpid"
t.integer "forked_count", :default => 0
t.integer "visits", :default => 0
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "softapplications", :force => true do |t|
t.string "name"
t.text "description"
@ -2264,7 +2325,8 @@ ActiveRecord::Schema.define(:version => 20170219070127) do
t.datetime "updated_at", :null => false
t.integer "author_id"
t.integer "status", :limit => 1, :default => 0
t.integer "position", :limit => 1, :default => 0
t.integer "position", :limit => 1
t.integer "result", :default => 0
end
create_table "user_actions", :force => true do |t|

View File

@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe ShixunsController, :type => :controller do
end

View File

@ -0,0 +1,7 @@
FactoryGirl.define do
factory :shixun_member do
user_id 1
shixun_id 1
end
end

View File

@ -0,0 +1,9 @@
FactoryGirl.define do
factory :shixun do
name "MyString"
description "MyText"
is_public 1
parent_id 1
end
end

View File

@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe ShixunMember, :type => :model do
pending "add some examples to (or delete) #{__FILE__}"
end

View File

@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe Shixun, :type => :model do
pending "add some examples to (or delete) #{__FILE__}"
end