diff --git a/Gemfile b/Gemfile
index eef93c371..bb94100a5 100644
--- a/Gemfile
+++ b/Gemfile
@@ -9,12 +9,11 @@ unless RUBY_PLATFORM =~ /w32/
gem "rmagick", "= 2.13.1" ## centos yum install ImageMagick-devel
end
gem 'certified'
+ gem 'net-ssh', '2.9.1'
+ gem 'jenkins_api_client'
+ gem 'nokogiri'
end
-gem 'net-ssh', '2.9.1'
-gem 'jenkins_api_client'
-gem 'nokogiri'
-
gem 'wechat',path: 'lib/wechat'
gem 'grack', path:'lib/grack'
gem 'gitlab', path: 'lib/gitlab-cli'
diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb
index 33d988e35..8187055be 100644
--- a/app/controllers/account_controller.rb
+++ b/app/controllers/account_controller.rb
@@ -239,14 +239,23 @@ class AccountController < ApplicationController
end
def resendmail
+ result = {:status=>1, :email=>""}
user = User.find(params[:user]) if params[:user]
+ result[:email] = user.mail
token = Token.new(:user => user, :action => "register")
if token.save
- Mailer.run.register(token)
-
+ # Mailer.run.register(token)
+ Mailer.register(token).deliver
else
yield if block_given?
+ result[:status] = 0
end
+ render :json => result
+ end
+
+ def email_activation
+
+
end
private
@@ -264,6 +273,7 @@ class AccountController < ApplicationController
if user.nil?
invalid_credentials
elsif user.status == 2
+ @user = user
invalid_credentials_new
elsif user.new_record?
onthefly_creation_failed(user, {:login => user.login, :auth_source_id => user.auth_source_id })
@@ -375,8 +385,9 @@ class AccountController < ApplicationController
def invalid_credentials_new
logger.warn "Failed login for '#{params[:username]}' from #{request.remote_ip} at #{Time.now.utc}"
- flash[:error] = l(:notice_account_invalid_creditentials_new)
- render signin_path(:login=>true)
+ # flash[:error] = l(:notice_account_invalid_creditentials_new)
+ # render signin_path(:login=>true)
+ render :action => 'email_activation'
end
# Register a user for email activation.
diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb
index 960bc61e6..a6b5f09cf 100644
--- a/app/controllers/attachments_controller.rb
+++ b/app/controllers/attachments_controller.rb
@@ -612,7 +612,7 @@ class AttachmentsController < ApplicationController
@attachment.container.board.course)
@course = @attachment.container.board.course
else
- unless @attachment.container_type == 'Bid' || @attachment.container_type == 'Organization' || @attachment.container_type == 'HomeworkAttach' || @attachment.container_type == 'Memo' || @attachment.container_type == 'Softapplication' || @attachment.container_type == 'PhoneAppVersion' || @attachment.container_type == 'StudentWorksScore'|| @attachment.container_type == 'StudentWork'
+ unless @attachment.container_type == 'Syllabus' || @attachment.container_type == 'Bid' || @attachment.container_type == 'Organization' || @attachment.container_type == 'HomeworkAttach' || @attachment.container_type == 'Memo' || @attachment.container_type == 'Softapplication' || @attachment.container_type == 'PhoneAppVersion' || @attachment.container_type == 'StudentWorksScore'|| @attachment.container_type == 'StudentWork'
@project = @attachment.project
end
end
diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb
index 7dea90e4b..e81251f63 100644
--- a/app/controllers/courses_controller.rb
+++ b/app/controllers/courses_controller.rb
@@ -715,6 +715,7 @@ class CoursesController < ApplicationController
@trackers = Tracker.sorted.all
@course = Course.new
@course.safe_attributes = params[:course]
+ @syllabus = Syllabus.where("id = #{params[:syllabus_id].to_i}").first if params[:syllabus_id]
# month = Time.now.month
render :layout => 'new_base'
else
diff --git a/app/controllers/my_controller.rb b/app/controllers/my_controller.rb
index 0883b3799..32c605516 100644
--- a/app/controllers/my_controller.rb
+++ b/app/controllers/my_controller.rb
@@ -127,12 +127,14 @@ class MyController < ApplicationController
end
@user.safe_attributes = params[:user]
+ @user.lastname = params[:lastname]
+ @user.firstname = ""
@user.pref.attributes = params[:pref]
@user.pref[:no_self_notified] = (params[:no_self_notified] == '1')
#@user.login = params[:login]
unless @user.user_extensions.nil?
if @user.user_extensions.identity == 2
- @user.firstname = params[:enterprise_name]
+ # @user.firstname = params[:enterprise_name]
end
end
@@ -144,7 +146,7 @@ class MyController < ApplicationController
# end
@se.school_id = params[:occupation]
- @se.gender = params[:gender]
+ @se.gender = params[:sex]
@se.location = params[:province] if params[:province]
@se.location_city = params[:city] if params[:city]
@se.identity = params[:identity].to_i if params[:identity]
diff --git a/app/controllers/praise_tread_controller.rb b/app/controllers/praise_tread_controller.rb
index b6eb54d2f..9f0fe41c8 100644
--- a/app/controllers/praise_tread_controller.rb
+++ b/app/controllers/praise_tread_controller.rb
@@ -131,6 +131,8 @@ class PraiseTreadController < ApplicationController
@obj = Bid.find_by_id(id)
when 'Contest'
@obj = Contest.find_by_id(id)
+ when 'Syllabus'
+ @obj = Syllabus.find_by_id(id)
else
@obj = nil
end
diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb
index 8664a1372..cb86f1165 100644
--- a/app/controllers/projects_controller.rb
+++ b/app/controllers/projects_controller.rb
@@ -653,12 +653,12 @@ class ProjectsController < ApplicationController
def update
@project.safe_attributes = params[:project]
@project.organization_id = params[:organization_id]
- params[:project][:is_public] ? @project.is_public = 1 : @project.is_public = 0
- params[:project][:hidden_repo] ? @project.hidden_repo = 1 : @project.hidden_repo = 0
+ params[:project][:is_public] == "on" ? @project.is_public = 1 : @project.is_public = 0
+ params[:project][:hidden_repo] == "on" ? @project.hidden_repo = 1 : @project.hidden_repo = 0
# 更新公开私有时同步gitlab公开私有
- if !@project.gpid.nil? && @project.is_public != (params[:project][:is_public] == "on" ? true : false)
+ if !@project.gpid.nil? && @project.is_public != (params[:project][:is_public] == "on" ? 1 : 0)
g = Gitlab.client
- params[:project][:is_public] ? g.edit_project(@project.gpid, 20, params[:branch]) : g.edit_project(@project.gpid, 0, params[:branch])
+ params[:project][:is_public] == "on" ? g.edit_project(@project.gpid, 20, params[:branch]) : g.edit_project(@project.gpid, 0, params[:branch])
end
# end
if validate_parent_id && @project.save
diff --git a/app/controllers/quality_analysis_controller.rb b/app/controllers/quality_analysis_controller.rb
index 83e5960b9..bec66aeff 100644
--- a/app/controllers/quality_analysis_controller.rb
+++ b/app/controllers/quality_analysis_controller.rb
@@ -1,8 +1,11 @@
class QualityAnalysisController < ApplicationController
before_filter :find_project_by_project_id#, :except => [:getattachtype]
+ before_filter :find_quality_analysis, :only => [:edit, :update_jenkins_job]
before_filter :authorize
+ before_filter :connect_jenkins, :only => [:create, :edit, :update_jenkins_job, :index]
layout "base_projects"
include ApplicationHelper
+ include QualityAnalysisHelper
require 'jenkins_api_client'
require 'nokogiri'
require 'json'
@@ -12,72 +15,180 @@ class QualityAnalysisController < ApplicationController
end
+ # params 说明:{identifier:版本库名}
def create
- gitlab_address = Redmine::Configuration['gitlab_address']
- jenkins_address = Redmine::Configuration['jenkins_address']
- @client = JenkinsApi::Client.new(:server_url => jenkins_address,
- :username => "temp",
- :password => '123123')
- #@client.exists?(job_name)
- @g = Gitlab.client
- user_name = User.find(params[:user_id]).try(:login)
- branch = params[:branch].nil? ? "master" : params[:branch]
- language = params[:language]
- path = params[:path]
- identifier = params[:identifier]
- qa = QualityAnalysis.where(:project_id => @project.id, :author_login => user_name).first
- version = qa.nil? ? 1 : qa.sonar_version + 1
- properties = "sonar.projectKey=#{user_name}:#{identifier}
- sonar.projectName=#{user_name}:#{identifier}
+ begin
+ user_name = User.find(params[:user_id]).try(:login)
+ identifier = params[:identifier]
+ rep_id = params[:rep_id]
+
+ # job_name and sonar_name 前者为job名字,后者为jenkins配置名
+ job_name = "#{user_name}-#{rep_id}"
+ sonar_name = "#{user_name}:#{rep_id}"
+
+ # Checks if the given job exists in Jenkins.
+ unless @client.job.exists?(job_name)
+ @g = Gitlab.client
+ branch = params[:branch]
+ language = swith_language_type(params[:language])
+ path = params[:path].blank? ? "./" : params[:path]
+ qa = QualityAnalysis.where(:project_id => @project.id, :author_login => user_name).first
+ version = qa.nil? ? 1 : qa.sonar_version + 1
+ properties = "sonar.projectKey=#{sonar_name}
+ sonar.projectName=#{sonar_name}
sonar.projectVersion=#{version}
sonar.sources=#{path}
sonar.language=#{language.downcase}
sonar.sourceEncoding=utf-8"
- git_url = gitlab_address.to_s+"/"+@project.owner.to_s+"/"+ identifier + "."+"git"
+ git_url = @gitlab_address.to_s+"/"+@project.owner.to_s+"/"+ identifier + "."+"git"
- # # # modify config
- @doc = Nokogiri::XML(File.open(File.join(Rails.root, 'tmp', 'config.xml')))
- @doc.at_xpath("//hudson.plugins.git.UserRemoteConfig/url").content = git_url
- @doc.at_xpath("//hudson.plugins.git.BranchSpec/name").content = "*/#{branch}"
- @doc.at_xpath("//hudson.plugins.sonar.SonarRunnerBuilder/properties").content = properties #sonar-properties
- #
- # replace config.xml of jenkins
- @client = @client.job.create("#{user_name}_#{identifier}", @doc.to_xml)
- # relace gitlab hook
- # genkins address
- @g.add_project_hook(@project.gpid, jenkins_address + "/project/#{user_name}_#{identifier}")
- if qa.nil?
- QualityAnalysis.create(:project_id => @project.id, :author_login => user_name, :rep_identifier => identifier, :sonar_version => version, :path => path, :branch => branch, :language => language)
+ # 替换配置文件
+ @doc = Nokogiri::XML(File.open(File.join(Rails.root, 'tmp', 'config.xml')))
+ @doc.at_xpath("//hudson.plugins.git.UserRemoteConfig/url").content = git_url
+ @doc.at_xpath("//hudson.plugins.git.BranchSpec/name").content = "*/#{branch}"
+ @doc.at_xpath("//hudson.plugins.sonar.SonarRunnerBuilder/properties").content = properties # sonar-properties
- else
- qa.update_attribute(:sonar_version, version)
+ # jenkins job创建
+ jenkins_job = @client.job.create("#{job_name}", @doc.to_xml)
+ logger.info("Jenkins status of create ==> #{jenkins_job}")
+
+ # 将地址作为hook值添加到gitlab
+ @g.add_project_hook(@project.gpid, @jenkins_address + "/project/#{job_name}")
+ # job创建完成后自动运行job,如果运行成功则返回‘200’
+ code = @client.job.build("#{job_name}")
+ logger.error("build result ==> #{code}")
+
+ # 判断调用sonar分析是否成功
+ # 等待启动时间处理, 最长时间为30分钟
+ for i in 0..60 do
+ sleep(60)
+ @current_build_status = @client.job.get_current_build_status("#{job_name}")
+ if (@current_build_status != "not_run" || @current_build_status != "running")
+ break
+ if i == 60
+ @build_console_result = false
+ break
+ end
+ end
+ end
+
+ @console_build = @client.job.get_console_output("#{job_name}", build_num = 0, start = 0, mode = 'text')
+ logger.info("@current_build_status is ==> #{@current_build_status}")
+ logger.info("@console_build is ==> #{@console_build}")
+
+ d = @client.job.delete("#{job_name}") if jenkins_job == '200' && code != '201'
+ logger.error("delete result ==> #{code}")
+ if qa.blank? && @current_build_status == "success"
+ QualityAnalysis.create(:project_id => @project.id, :author_login => user_name, :rep_identifier => identifier,
+ :sonar_version => version, :path => path, :branch => branch, :language => language, :sonar_name => "#{user_name}:#{rep_id}")
+ else
+ qa.update_attribute(:sonar_version, version)
+ end
+ end
+ rescue => e
+ puts e
+ end
+ respond_to do |format|
+ format.html{redirect_to project_quality_analysis_path(:project_id => @project.id, :resource_id => sonar_name, :branch => branch, :current_build_status => @current_build_status, :job_name => job_name)}
+ # format.js{redirect_to project_quality_analysis_path(:project_id => @project.id, :resource_id => sonar_name, :branch => branch)}
end
end
+ # get language type
+ def swith_language_type language
+ if language == "c#"
+ "cs"
+ elsif language == "python"
+ "py"
+ elsif language == "c"
+ "c++"
+ else
+ language
+ end
+ end
+
+ def edit
+ @g = Gitlab.client
+ gitlab_branches = @g.branches(@project.gpid)
+ @branch_names = gitlab_branches.map{|b| b.name}
+ @gitlab_default_branch = @g.project(@project.gpid).default_branch
+ end
+
+ # 更新Jenkins job,主要包括相关配置文件参数的更新,Trustie平台数据的更新
+ def update_jenkins_job
+ begin
+ rep_id = Repository.where(:project_id => @project.id).first.try(:id)
+ logger.error("#############################===>666")
+ sonar_name = @quality_analysis.sonar_name
+ job_name = "#{@quality_analysis.author_login}-#{rep_id}"
+ version = @quality_analysis.sonar_version
+ path = params[:path].blank? ? "./" : params[:path]
+ language = swith_language_type(params[:language])
+ branch = params[:branch]
+ identifier = @quality_analysis.rep_identifier
+ properties = "sonar.projectKey=#{sonar_name}
+ sonar.projectName=#{sonar_name}
+ sonar.projectVersion=#{version}
+ sonar.sources=#{path}
+ sonar.language=#{language.downcase}
+ sonar.sourceEncoding=utf-8"
+ git_url = @gitlab_address.to_s+"/"+@project.owner.to_s+"/"+ identifier + "."+"git"
+
+ # modify config.yml
+ @doc = Nokogiri::XML(File.open(File.join(Rails.root, 'tmp', 'config.xml')))
+ @doc.at_xpath("//hudson.plugins.git.UserRemoteConfig/url").content = git_url
+ @doc.at_xpath("//hudson.plugins.git.BranchSpec/name").content = "*/#{branch}"
+ @doc.at_xpath("//hudson.plugins.sonar.SonarRunnerBuilder/properties").content = properties # sonar-properties
+
+ # update成功则返回 ‘200’
+ jenkins_job = @client.job.update("#{job_name}", @doc.to_xml)
+ get_current_build_status = @client.job.get_current_build_status("Hjqreturn-1280")
+ logger.error("Failed to update job: ==> #{jenkins_job}") unless jenkins_job == '200'
+
+ # 数据更新到Trustie数据库
+ if jenkins_job == '200'
+ logger.info("quality_ananlysis will be updated: ==> #{jenkins_job}")
+ @quality_analysis.path = path
+ @quality_analysis.language = language
+ @quality_analysis.branch = branch
+ @quality_analysis.save
+ end
+ rescue Exception => e
+ logger.error("Update jenkins job: #{e}")
+ end
+ respond_to do |format|
+ format.html{redirect_to project_quality_analysis_path(:project_id => @project.id)}
+ format.js
+ end
+ end
+
+ # resource_id: login + @repository.id
def index
- @sonar_address = Redmine::Configuration['sonar_address']
- # if params[:resource_id].nil?
- # @name_flag = true
- # @quality_analyses = QualityAnalysis.where(:project_id => @project.id)
- # # @quality_analyses.map {|qa| qa.}
- # # if @quality_analyses.count > 0
- # # @quality_analyses.each do |qa|
- # # ["Hjqreturn:cc_rep", "Hjqreturn:putong", "Hjqreturn:sonar_rep2", "shitou:sonar_rep"]
- # #
- # # end
- # # end
- # # projects_date = open(@sonar_address + "/api/projects/index").read
- # # arr = JSON.parse(projects_date).map {|m| m["nm"]}
- # # arr.map
- # else
- qa = QualityAnalysis.where(:project_id => @project.id).first
- @resource_id = qa.author_login+":"+qa.rep_identifier
- @name_flag = false
- complexity_date = open(@sonar_address + "/api/resources/index?resource=#{@resource_id}&depth=0&metrics=sqale_rating,function_complexity,duplicated_lines_density,comment_lines_density,sqale_index,lines,file_line,files,functions,classes,directories").read
- @complexity =JSON.parse(complexity_date).first
- issue_date = open(@sonar_address + "/api/resources/index?resource=#{@resource_id}&depth=0&metrics=blocker_violations,critical_violations,major_violations,minor_violations,info_violations,violations").read
- @sonar_issues = JSON.parse(issue_date).first
- # end
+ begin
+ @branch = params[:branch]
+ @resource_id = params[:resource_id]
+ @sonar_address = Redmine::Configuration['sonar_address']
+ @jenkins_address = Redmine::Configuration['jenkins_address']
+ if params[:resource_id].nil?
+ @name_flag = true
+ projects_date = open(@sonar_address + "/api/projects/index").read
+ arr = JSON.parse(projects_date).map {|m| m["nm"]} # eg: ["Hjqreturn:cc_rep", "Hjqreturn:putong", "Hjqreturn:sonar_rep2", "shitou:sonar_rep"]
+ @quality_analyses = QualityAnalysis.where(:project_id => @project.id).select{|qa| arr.include?(qa.sonar_name)}
+
+ else
+ if params[:current_build_status] == "failure"
+ job_name = params[:job_name]
+ @console_build = @client.job.get_console_output("#{job_name}", build_num = 0, start = 0, mode = 'text')["output"]
+ end
+ complexity_date = open(@sonar_address + "/api/resources/index?resource=#{@resource_id}&depth=0&metrics=sqale_rating,function_complexity,duplicated_lines_density,comment_lines_density,sqale_index,lines,file_line,files,functions,classes,directories").read
+ @complexity =JSON.parse(complexity_date).first
+ issue_date = open(@sonar_address + "/api/resources/index?resource=#{@resource_id}&depth=0&metrics=blocker_violations,critical_violations,major_violations,minor_violations,info_violations,violations").read
+ @sonar_issues = JSON.parse(issue_date).first
+ end
+ rescue => e
+ puts e
+ end
+
end
# Find project of id params[:project_id]
@@ -87,6 +198,14 @@ class QualityAnalysisController < ApplicationController
render_404
end
+ def find_quality_analysis
+ begin
+ @quality_analysis = QualityAnalysis.find(params[:id])
+ rescue
+ render_404
+ end
+ end
+
# Authorize the user for the requested action
def authorize(ctrl = params[:controller], action = params[:action], global = false)
unless @project.archived? && @project.gpid.nil?
@@ -96,4 +215,14 @@ class QualityAnalysisController < ApplicationController
end
end
+ def connect_jenkins
+ @gitlab_address = Redmine::Configuration['gitlab_address']
+ @jenkins_address = Redmine::Configuration['jenkins_address']
+
+ # connect jenkins
+ @client = JenkinsApi::Client.new(:server_url => @jenkins_address, :username => "temp", :password => '123123')
+ rescue => e
+ logger.error("failed to connect Jenkins ==> #{e}")
+ end
+
end
diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb
index cbb5b2f69..d0904ddf5 100644
--- a/app/controllers/repositories_controller.rb
+++ b/app/controllers/repositories_controller.rb
@@ -20,6 +20,8 @@ require 'SVG/Graph/BarHorizontal'
require 'digest/sha1'
require 'redmine/scm/adapters/abstract_adapter'
require 'tempfile'
+require 'json'
+require 'open-uri'
class ChangesetNotFound < Exception; end
class InvalidRevisionParam < Exception; end
@@ -372,7 +374,7 @@ update
@changesets = g.commits(@project.gpid, :ref_name => @rev)
g_project = g.project(@project.gpid)
# 总的提交数
- @changesets_all_count = @project.gpid.nil? ? 0 : g_project.commit_count
+ @changesets_all_count = @project.gpid.nil? ? 0 : commit_count(@project, @rev)
@g_default_branch = g_project.default_branch.nil? ? "master" : g_project.default_branch
# 访问该页面的是会后则刷新
if @project.project_score.nil?
diff --git a/app/controllers/school_controller.rb b/app/controllers/school_controller.rb
index e0aff6254..44f4378fe 100644
--- a/app/controllers/school_controller.rb
+++ b/app/controllers/school_controller.rb
@@ -150,4 +150,55 @@ class SchoolController < ApplicationController
format.js
end
end
+
+ #申请高校(单位) name:名称 province:省 city:市 address:地址 remarks:备注
+ def apply_add_school
+
+ data = {result:0,name:params[:name],school_id:0}
+ #0 成功 1参数错误 2名称已存在
+ data[:result] = 0
+
+ #检验参数
+ if params[:name] == "" || params[:province] == "" || params[:city] == "" || params[:address] == ""
+ data[:result] = 1
+ else
+ school_id = School.find_by_sql("select id from schools where name='#{params[:name]}'").first
+ if school_id
+ data[:result] = 2
+ else
+ school = School.new
+ school.name = params[:name].strip
+ school.pinyin = Pinyin.t(params[:name].strip, splitter: '')
+ school.save
+
+ #status 0未处理 1通过 2拒绝
+ applyschool = ApplyAddSchools.new
+ applyschool.school_id = school.id
+ applyschool.name = school.name
+ applyschool.province = params[:province]
+ applyschool.city = params[:city]
+ applyschool.address = params[:address]
+ applyschool.remarks = params[:remarks]
+ applyschool.save
+
+ data[:school_id] = school.id
+ end
+ end
+ render :json =>data
+ end
+
+ def search_repeat_schoolname
+ status = 0
+ name = params[:name]
+
+ if name
+ school_id = School.find_by_sql("select id from schools where name='#{name}'").first
+
+ if school_id
+ status = 1
+ end
+ end
+
+ render :json =>status
+ end
end
diff --git a/app/controllers/syllabuses_controller.rb b/app/controllers/syllabuses_controller.rb
index 69982b99a..8ff88823d 100644
--- a/app/controllers/syllabuses_controller.rb
+++ b/app/controllers/syllabuses_controller.rb
@@ -1,15 +1,164 @@
+# encoding: utf-8
class SyllabusesController < ApplicationController
+ include ApplicationHelper
+ helper :attachments
+ include AttachmentsHelper
+ include CoursesHelper
- before_filter :is_logged, :only => [:index, :show]
- before_filter :find_syllabus, :only => [:show]
+ before_filter :is_logged, :only => [:index, :show, :edit, :new, :update, :destroy, :delete_syllabus]
+ before_filter :find_syllabus, :only => [:show, :edit, :update, :destroy, :syllabus_courselist, :edit_syllabus_eng_name, :update_base_info, :delete_syllabus, :delete_des]
def index
user = User.current
@syllabuses = user.syllabuses
end
def show
- @courses = @syllabus.courses
+ #@courses = @syllabus.courses
+ respond_to do |format|
+ format.js
+ format.html{render :layout => 'base_syllabus'}
+ format.api
+ end
+ end
+ def new
+ @syllabus = Syllabus.new
+ render :layout => 'new_base'
+ end
+
+ def create
+ if User.current.user_extensions.identity
+ @syllabus = Syllabus.new
+ @syllabus.title = params[:title]
+ @syllabus.eng_name = params[:eng_name]
+ @syllabus.user_id = User.current.id
+ @syllabus.description = Message.where("id = 19412").first.nil? ? '' : Message.where("id = 19412").first.content
+ if @syllabus && @syllabus.save
+ respond_to do |format|
+ flash[:notice] = l(:notice_successful_create)
+ format.html {redirect_to syllabus_path(@syllabus)}
+ format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'syllabuses', :action => 'show', :id => @syllabus.id) }
+ end
+ else
+ respond_to do |format|
+ flash[:notice] = l(:notice_create_failed)
+ format.html { redirect_to new_syllabus_path } #Added by young
+ format.api { render_validation_errors(@syllabus) }
+ end
+ end
+ end
+ end
+
+ def edit
+ respond_to do |format|
+ format.html{render :layout => 'base_syllabus'}
+ end
+ end
+
+ def delete_syllabus
+ respond_to do |format|
+ format.js
+ end
+ end
+
+ def update
+ @syllabus.description = params[:syllabus][:description]
+ @syllabus.des_status = 1
+ @syllabus.save_attachments(params[:attachments])
+ if @syllabus.save
+ if params[:asset_id]
+ ids = params[:asset_id].split(',')
+ update_kindeditor_assets_owner ids,@syllabus.id,OwnerTypeHelper::SYLLABUS
+ end
+ redirect_to syllabus_path(@syllabus)
+ else
+ redirect_to syllabus_path(@syllabus)
+ end
+ end
+
+ #删除课程大纲的描述
+ def delete_des
+ if @syllabus
+ @syllabus.description = Message.where("id = 19412").first.nil? ? '' : Message.where("id = 19412").first.content
+ @syllabus.des_status = 0
+ @syllabus.attachments.destroy_all
+ if @syllabus.save
+ redirect_to syllabus_path(@syllabus)
+ end
+ end
+ end
+
+ def destroy
+ if @syllabus && @syllabus.courses.empty?
+ @syllabus.destroy
+ redirect_to user_courselist_user_path(User.current.id)
+ end
+ end
+
+ #班级列表
+ def syllabus_courselist
+ @order, @c_sort,@type = params[:order] || 1, params[:sort] || 1, params[:type] || 1
+
+ #确定 sort_type
+ if @order.to_i == @type.to_i
+ @c_sort = @c_sort.to_i == 1 ? 2 : 1 #1升序 2降序
+ else
+ @c_sort = 2
+ end
+
+ sort_name = "updated_on"
+ sort_type = @c_sort == 1 ? "asc" : "desc"
+
+ @courses = User.current.courses.visible.where("is_delete =? and syllabus_id =?", 0, @syllabus.id).select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS #{sort_name}").order("#{sort_name} #{sort_type}")
+
+ #根据 作业+资源数排序
+ if @order.to_i == 2
+ @type = 2
+ @courses.each do |course|
+ course[:infocount] = (User.current.admin? || User.current.allowed_to?(:as_teacher,course)) ? (course.homework_commons.count + visable_attachemnts_incourse(course).count) : (course.homework_commons.where("publish_time <= '#{Date.today}'").count + visable_attachemnts_incourse(course).count)
+ if course[:infocount] < 0
+ course[:infocount] = 0
+ end
+ end
+ @c_sort == 1 ? (@courses = @courses.sort{|x,y| x[:infocount] <=> y[:infocount] }) : (@courses = @courses.sort{|x,y| y[:infocount] <=> x[:infocount]})
+ @courses = sortby_time_countcommon_nosticky @courses,sort_name
+ else
+ @type = 1
+ end
+
+ #分页
+ @limit = 10
+ @is_remote = true
+ @atta_count = @courses.count
+ @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1
+ @offset ||= @atta_pages.offset
+ @courses = paginateHelper @courses,@limit
+
+ respond_to do |format|
+ format.js
+ format.html{render :layout => 'base_syllabus'}
+ end
+ end
+
+ #修改英文名称
+ def edit_syllabus_eng_name
+ if @syllabus
+ @syllabus.update_column("eng_name",params[:eng_name])
+ end
+ respond_to do |format|
+ format.js
+ end
+ end
+
+ #编辑属性
+ def update_base_info
+ if @syllabus
+ @syllabus.update_attributes(:credit => params[:credit], :hours => params[:hours], :theory_hours => params[:theory_hours], :practice_hours => params[:practice_hours], :applicable_major => params[:applicable_major], :pre_course => params[:pre_course])
+ @syllabus.update_attributes(:syllabus_type => params[:syllabus_type])
+ respond_to do |format|
+ format.js
+ end
+ end
end
private
diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb
index 2c390025e..e66f88848 100644
--- a/app/controllers/tags_controller.rb
+++ b/app/controllers/tags_controller.rb
@@ -13,6 +13,7 @@ class TagsController < ApplicationController
include ForumsHelper
include AttachmentsHelper
include ContestsHelper
+ include SyllabusesHelper
include ActsAsTaggableOn::TagsHelper
include TagsHelper
include FilesHelper
@@ -529,6 +530,8 @@ class TagsController < ApplicationController
@obj = Course.find_by_id(@obj_id)
when '10'
@obj = Attachment.find_by_id(@obj_id)
+ when '11'
+ @obj = Syllabus.find_by_id(@obj_id)
else
@obj = nil
end
@@ -619,6 +622,9 @@ class TagsController < ApplicationController
when '9' then
@obj = Course.find_by_id(obj_id)
@obj_pages, @courses_results, @results_count = for_pagination(get_courses_by_tag(selected_tags))
+ when '11' then
+ @obj = Syllabus.find_by_id(obj_id)
+ @obj_pages, @syllabuses_results, @results_count = for_pagination(get_syllabuses_by_tag(selected_tags))
else
@obj = nil
end
@@ -684,6 +690,8 @@ class TagsController < ApplicationController
return 'Course'
when '10'
return 'Attachment'
+ when '11'
+ return 'Syllabus'
else
render_error :message => e.message
return
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index 3bf582e23..bccc5f742 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -1248,6 +1248,12 @@ class UsersController < ApplicationController
render :layout=>'new_base_user'
end
+ #给某人留言
+ def feedBackTo
+
+
+ end
+
def user_comments
end
@@ -1367,7 +1373,15 @@ class UsersController < ApplicationController
#显示更多用户课程
def user_courses4show
@page = params[:page].to_i + 1
- @courses = @user.courses.visible.where("is_delete =?", 0).select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a").order("a desc").limit(5).offset(@page * 5)
+ @type = params[:type]
+ if @type == 'User'
+ @courses = @user.courses.visible.where("is_delete =?", 0).select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a").order("a desc").limit(5).offset(@page * 5)
+ @all_count = @user.courses.visible.where("is_delete =?", 0).count
+ elsif @type == 'Syllabus'
+ @syllabus = Syllabus.where("id = #{params[:syllabus]}").first
+ @courses = User.current.courses.visible.where("is_delete =? and syllabus_id =?", 0, @syllabus.id).select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a").order("a desc").limit(5).offset(@page * 5)
+ @all_count = User.current.courses.visible.where("is_delete =? and syllabus_id =?", 0, @syllabus.id).count
+ end
end
#显示更多用户项目
@@ -3140,23 +3154,26 @@ class UsersController < ApplicationController
@c_sort = 2
end
- sort_name = "updated_on"
+ sort_name = "updated_at"
sort_type = @c_sort == 1 ? "asc" : "desc"
- # @courses = @user.courses.visible.where("is_delete =?", 0).order("#{sort_name} #{sort_type}")
- @courses = @user.courses.visible.where("is_delete =?", 0).select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS #{sort_name}").order("#{sort_name} #{sort_type}")
+ @courses = @user.courses.visible.where("is_delete =?", 0)
+ syllabus_ids = @courses.empty? ? '(-1)' : "(" + @courses.map{|course| !course.syllabus_id.nil? && course.syllabus_id}.join(",") + ")"
+ @syllabus = Syllabus.where("id in #{syllabus_ids} or user_id = #{User.current.id}").order("#{sort_name} #{sort_type}")
#根据 作业+资源数排序
if @order.to_i == 2
@type = 2
- @courses.each do |course|
- course[:infocount] = (User.current.admin? || User.current.allowed_to?(:as_teacher,course)) ? (course.homework_commons.count + visable_attachemnts_incourse(course).count) : (course.homework_commons.where("publish_time <= '#{Date.today}'").count + visable_attachemnts_incourse(course).count)
- if course[:infocount] < 0
- course[:infocount] = 0
+ @syllabus.each do |syllabus|
+ count = 0
+ courses = @courses.where("syllabus_id = #{syllabus.id}")
+ courses.each do |c|
+ count += (User.current.admin? || User.current.allowed_to?(:as_teacher,c)) ? (c.homework_commons.count + visable_attachemnts_incourse(c).count) : (c.homework_commons.where("publish_time <= '#{Date.today}'").count + visable_attachemnts_incourse(c).count)
end
+ syllabus[:infocount] = count
end
- @c_sort == 1 ? (@courses = @courses.sort{|x,y| x[:infocount] <=> y[:infocount] }) : (@courses = @courses.sort{|x,y| y[:infocount] <=> x[:infocount]})
- @courses = sortby_time_countcommon_nosticky @courses,sort_name
+ @c_sort == 1 ? (@syllabus = @syllabus.sort{|x,y| x[:infocount] <=> y[:infocount] }) : (@syllabus = @syllabus.sort{|x,y| y[:infocount] <=> x[:infocount]})
+ @syllabus = sortby_time_countcommon_nosticky @syllabus,sort_name
else
@type = 1
end
@@ -3164,10 +3181,10 @@ class UsersController < ApplicationController
#分页
@limit = 10
@is_remote = true
- @atta_count = @courses.count
+ @atta_count = @syllabus.count
@atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1
@offset ||= @atta_pages.offset
- @courses = paginateHelper @courses,@limit
+ @syllabus = paginateHelper @syllabus,@limit
respond_to do |format|
format.js
@@ -3232,6 +3249,9 @@ class UsersController < ApplicationController
when 'News'
obj = News.where('id = ?', params[:id].to_i).first
@journals = obj.comments.reorder("created_on desc")
+ when 'Syllabus'
+ obj = Syllabus.where('id = ?', params[:id].to_i).first
+ @journals = obj.comments.reorder("created_on desc")
when 'JournalsForMessage'
obj = JournalsForMessage.where('id = ?', params[:id].to_i).first
journals = []
diff --git a/app/controllers/words_controller.rb b/app/controllers/words_controller.rb
index 668269a26..828739cc4 100644
--- a/app/controllers/words_controller.rb
+++ b/app/controllers/words_controller.rb
@@ -264,6 +264,28 @@ class WordsController < ApplicationController
end
end
+ #课程大纲的回复
+ def leave_syllabus_message
+ if User.current.logged?
+ @user = User.current
+ @syllabus = Syllabus.find(params[:id]);
+ if params[:comment].size>0 && User.current.logged? && @user
+ feedback = Syllabus.add_syllabus_jour(@user, params[:comment], params[:id])
+ if (feedback.errors.empty?)
+ if params[:asset_id]
+ ids = params[:asset_id].split(',')
+ update_kindeditor_assets_owner ids,feedback[:id],OwnerTypeHelper::JOURNALSFORMESSAGE
+ end
+ redirect_to syllabus_path(@syllabus)
+ else
+ flash[:error] = feedback.errors.full_messages[0]
+ end
+ end
+ else
+ render_403
+ end
+ end
+
#作业的回复
def leave_homework_message
if User.current.logged?
@@ -337,6 +359,27 @@ class WordsController < ApplicationController
UserExtensions.introduction(user, message)
redirect_to user_url(user.id)
end
+
+ #邮箱激活问题留言 留言成功给出提示框
+ def leave_email_activation_message
+ status = 1 #成功
+ me = User.find(params[:user])
+ if me
+ #课程使者id=1
+ @user = User.find(1)
+ if params[:text].size>0 && @user
+ # @user.add_jour(me, params[:text])
+ #私信
+ message = "【未收到激活邮件的用户反馈,用户邮箱:"+me.mail+"】
"+params[:text]
+ @user.journals_for_messages << JournalsForMessage.new(:user_id => me.id, :notes => message, :reply_id => 0, :status => true, :is_readed => false, :private => 1)
+ else
+ status = 0
+ end
+ render :json => status
+ else
+ render_403
+ end
+ end
private
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index ee2e2d74a..98eb100ed 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -803,22 +803,22 @@ module ApplicationHelper
end
# 获取Gitlab版本库提交总数
- def commit_count(project)
+ def commit_count(project, branch)
g = Gitlab.client
#add by hx
- if g.commits(project.gpid , :page=>200).count > 0
+ if g.commits(project.gpid, :ref_name => @rev , :page=>200).count > 0
count = 4020
- elsif g.commits(project.gpid , :page=>25).count==0
+ elsif g.commits(project.gpid , :page=>25, :ref_name => branch).count==0
count = count_commits(project.gpid , 0 , 25)
- elsif g.commits(project.gpid , :page=>50).count ==0
+ elsif g.commits(project.gpid , :page=>50, :ref_name => branch).count ==0
count = count_commits(project.gpid , 25 , 50)+ 25 * 20
- elsif g.commits(project.gpid , :page=>75).count ==0
+ elsif g.commits(project.gpid , :page=>75, :ref_name => branch).count ==0
count = count_commits(project.gpid , 50 , 75)+ 50 * 20
- elsif g.commits(project.gpid , :page=>100).count== 0
+ elsif g.commits(project.gpid , :page=>100, :ref_name => branch).count== 0
count = count_commits(project.gpid , 75 , 100) + 75 * 20
- elsif g.commits(project.gpid , :page=>125).count==0
+ elsif g.commits(project.gpid , :page=>125, :ref_name => branch).count==0
count = count_commits(project.gpid , 100 , 125) + 100 * 20
- elsif g.commits(project.gpid , :page=>150).count==0
+ elsif g.commits(project.gpid , :page=>150, :ref_name => branch).count==0
count = count_commits(project.gpid , 125 , 150) + 125 * 20
else
count = count_commits(project.gpid , 150 ,200) + 150 * 20
@@ -832,7 +832,7 @@ module ApplicationHelper
if $g.commits(project_id,:page => page).count == 0
break
else
- count = count + $g.commits(project_id,:page => page).count
+ count = count + $g.commits(project_id, :ref_name => @rev, :page => page).count
end
end
return count
@@ -1079,6 +1079,8 @@ module ApplicationHelper
title << @organization.name
elsif @user
title << @user.try(:realname)
+ elsif @syllabus
+ title << @syllabus.title
else
title << (User.current.id == 2 ? "未登录" : User.current.try(:realname))
end
diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb
index bb144472b..55a4da73a 100644
--- a/app/helpers/courses_helper.rb
+++ b/app/helpers/courses_helper.rb
@@ -671,6 +671,22 @@ module CoursesHelper
is_current_term || is_next_term
end
+ #课程大纲下拉框
+ def syllabus_option
+ type = []
+ option1 = []
+ option1 << "请选择课程"
+ option1 << 0
+ type << option1
+ Syllabus.all.each do |syllabus|
+ option = []
+ option << syllabus.title
+ option << syllabus.id
+ type << option
+ end
+ type
+ end
+
#获取课程动态
def get_course_activity courses, activities
@course_ids=activities.keys()
@@ -777,6 +793,15 @@ module CoursesHelper
result
end
+ def visable_course_homework course
+ if User.current.admin? || User.current.allowed_to?(:as_teacher,course)
+ homework_num = course.homework_commons.count
+ else
+ homework_num = course.homework_commons.where("publish_time <= '#{Date.today}'").count
+ end
+ homework_num
+ end
+
def zh_course_role role
if role == "TeachingAsistant"
result = l(:label_TA)
diff --git a/app/helpers/organizations_helper.rb b/app/helpers/organizations_helper.rb
index cb06bd688..48b5f068b 100644
--- a/app/helpers/organizations_helper.rb
+++ b/app/helpers/organizations_helper.rb
@@ -23,7 +23,7 @@ module OrganizationsHelper
when 'activity' then
return '动态'
when 'course' then
- return '课程'
+ return '班级'
when 'project' then
return '项目'
end
diff --git a/app/helpers/owner_type_helper.rb b/app/helpers/owner_type_helper.rb
index 7119d4f60..01320660c 100644
--- a/app/helpers/owner_type_helper.rb
+++ b/app/helpers/owner_type_helper.rb
@@ -7,5 +7,6 @@ module OwnerTypeHelper
BID = 6
JOURNALSFORMESSAGE = 7
HOMEWORKCOMMON = 8
- BLOGCOMMENT=9
+ BLOGCOMMENT = 9
+ SYLLABUS = 10
end
\ No newline at end of file
diff --git a/app/helpers/quality_analysis_helper.rb b/app/helpers/quality_analysis_helper.rb
index 9c6c07109..2a7d350e7 100644
--- a/app/helpers/quality_analysis_helper.rb
+++ b/app/helpers/quality_analysis_helper.rb
@@ -3,19 +3,19 @@ module QualityAnalysisHelper
def sqale_rating_status val
arr = []
- if val.to_i > 0 && val.to_i < 5
+ if val < 5
arr << "很好"
arr << "b_green2"
- elsif val.to_i > 5 && val.to_i < 10
+ elsif val. > 5 && val < 10
arr << "较好"
arr << "b_slow_yellow"
- elsif val.to_i > 10 && val.to_i < 20
+ elsif val > 10 && val < 20
arr << "中等"
arr << "b_yellow"
- elsif val.to_i > 20 && val.to_i < 50
+ elsif val > 20 && val < 50
arr << "较差"
arr << "b_slow_red"
- elsif val.to_i > 20
+ elsif val > 20
arr << "很差"
arr << "b_red"
end
@@ -23,13 +23,13 @@ module QualityAnalysisHelper
def complexity_status val
arr = []
- if val.to_i < 10
+ if val < 10
arr << "良好"
arr << "b_green2"
- elsif val.to_i > 10 && val.to_i < 15
+ elsif val > 10 && val < 15
arr << "较高"
arr << "b_yellow"
- elsif val.to_i > 15
+ elsif val > 15
arr << "很高"
arr << "b_red"
end
@@ -37,13 +37,13 @@ module QualityAnalysisHelper
def duplicated_lines_density_status val
arr = []
- if val.to_i < 30
+ if val < 30
arr << "良好"
arr << "b_green2"
- elsif val.to_i > 30 && val.to_i < 50
+ elsif val > 30 && val < 50
arr << "较高"
arr << "b_yellow"
- elsif val.to_i > 50
+ elsif val > 50
arr << "很高"
arr << "b_red"
end
@@ -51,28 +51,28 @@ module QualityAnalysisHelper
def comment_lines_density_status val
arr = []
- if val.to_i < 20
+ if val < 20
arr << "较低"
arr << "b_yellow"
- elsif val.to_i > 20 && val.to_i < 50
+ elsif val > 20 && val < 50
arr << "正常"
arr << "b_green2"
- elsif val.to_i > 50
+ elsif val > 50
arr << "较高"
arr << "b_red"
end
end
def score_sqale_rating val
- if val.to_i > 0 && val.to_i < 5
+ if val > 0 && val < 5
"5"
- elsif val.to_i > 5 && val.to_i < 10
+ elsif val > 5 && val < 10
"4"
- elsif val.to_i > 10 && val.to_i < 20
+ elsif val > 10 && val < 20
"3"
- elsif val.to_i > 20 && val.to_i < 50
+ elsif val > 20 && val < 50
"2"
- elsif val.to_i > 20
+ elsif val > 20
"1"
end
end
diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb
index 3cf781f76..b525c4aed 100644
--- a/app/helpers/repositories_helper.rb
+++ b/app/helpers/repositories_helper.rb
@@ -41,6 +41,11 @@ module RepositoriesHelper
identifiers.include?(iden) ? false :true
end
+ def quality_analysis login, rep_id
+ long_rep_id = "#{login}:#{rep_id}"
+ QualityAnalysis.where(:sonar_name => long_rep_id).first
+ end
+
# 获取文件目录的最新动态
def get_trees_last_changes(project_id, rev, ent_name)
g = Gitlab.client
diff --git a/app/helpers/syllabuses_helper.rb b/app/helpers/syllabuses_helper.rb
index dac84937b..7e815950b 100644
--- a/app/helpers/syllabuses_helper.rb
+++ b/app/helpers/syllabuses_helper.rb
@@ -1,2 +1,72 @@
+# encoding: utf-8
module SyllabusesHelper
+ def get_syllabuses_by_tag(tag_name)
+ Syllabus.tagged_with(tag_name).order('updated_at desc')
+ end
+
+ def teacher_count syllabus
+ count = 0
+ courses = syllabus.courses
+ unless courses.empty?
+ courses.each do |c|
+ count += TeacherAndAssistantCount c
+ end
+ end
+ count
+ end
+
+ def student_count syllabus
+ count = 0
+ courses = syllabus.courses
+ unless courses.empty?
+ courses.each do |c|
+ count += studentCount c
+ end
+ end
+ count
+ end
+
+ def file_count syllabus
+ count = 0
+ courses = syllabus.courses
+ unless courses.empty?
+ courses.each do |c|
+ count += visable_attachemnts_incourse(c).count
+ end
+ end
+ count
+ end
+
+ #课程性质下拉框
+ def syllabus_type
+ type = []
+ option1 = []
+ option2 = []
+ option3 = []
+ option4 = []
+ option5 = []
+ option6 = []
+
+ option1 << "请选择"
+ option1 << 0
+ option2 << "公共必修课"
+ option2 << 1
+ option3 << "学科必修课"
+ option3 << 2
+ option4 << "专业选修课"
+ option4 << 3
+ option5 << "实践必修课"
+ option5 << 4
+ option6 << "实践选修课"
+ option6 << 5
+
+ type << option1
+ type << option2
+ type << option3
+ type << option4
+ type << option5
+ type << option6
+
+ type
+ end
end
diff --git a/app/helpers/tags_helper.rb b/app/helpers/tags_helper.rb
index 8847f4163..54753807d 100644
--- a/app/helpers/tags_helper.rb
+++ b/app/helpers/tags_helper.rb
@@ -23,6 +23,8 @@ module TagsHelper
@obj= Course.find_by_id(obj_id)
when '10'
@obj = Attachment.find_by_id(obj_id)
+ when '11'
+ @obj = Syllabus.find_by_id(obj_id)
else
raise Exception, '[TagsHelper] ===> tag type unknow.'
end
diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb
index 4a6dbc6b6..f312d2275 100644
--- a/app/helpers/users_helper.rb
+++ b/app/helpers/users_helper.rb
@@ -32,7 +32,7 @@ module UsersHelper
def get_resource_type type
case type
when 'Course'
- '课程资源'
+ '班级资源'
when 'Project'
'项目资源'
when 'Issue'
@@ -122,11 +122,11 @@ module UsersHelper
when 'homework'
'作业消息'
when 'course_message'
- '课程讨论'
+ '班级讨论'
when 'course_news'
- '课程通知'
+ '班级通知'
when 'poll'
- '课程问卷'
+ '班级问卷'
when 'issue'
'项目任务'
when 'forge_message'
diff --git a/app/models/apply_add_schools.rb b/app/models/apply_add_schools.rb
new file mode 100644
index 000000000..2082c0012
--- /dev/null
+++ b/app/models/apply_add_schools.rb
@@ -0,0 +1,3 @@
+class ApplyAddSchools < ActiveRecord::Base
+ attr_accessible :address, :city, :name, :province, :remarks, :school_id, :status
+end
diff --git a/app/models/attachment.rb b/app/models/attachment.rb
index aa4ef8670..88fadd644 100644
--- a/app/models/attachment.rb
+++ b/app/models/attachment.rb
@@ -24,6 +24,7 @@ class Attachment < ActiveRecord::Base
belongs_to :course, foreign_key: 'container_id', conditions: "attachments.container_type = 'Course'"
belongs_to :org_subfield, foreign_key: 'container_id', conditions: "attachements.container_type = 'OrgSubfield'"
belongs_to :organization, foreign_key: 'container_id', conditions: "attachements.container_type = 'Organization'"
+ belongs_to :syllabus, foreign_key: 'container_id', conditions: "attachements.container_type = 'Syllabus'"
belongs_to :softapplication, foreign_key: 'container_id', conditions: "attachments.container_type = 'Softapplication'"
belongs_to :author, :class_name => "User", :foreign_key => "author_id"
belongs_to :attachmentstype, :foreign_key => "attachtype",:primary_key => "id"
diff --git a/app/models/course.rb b/app/models/course.rb
index 0c4acce97..e4b08697b 100644
--- a/app/models/course.rb
+++ b/app/models/course.rb
@@ -90,7 +90,8 @@ class Course < ActiveRecord::Base
'description',
'class_period',
'open_student',
- 'is_delete'
+ 'is_delete',
+ 'syllabus_id'
acts_as_customizable
diff --git a/app/models/quality_analysis.rb b/app/models/quality_analysis.rb
index 229be9826..8b8034c65 100644
--- a/app/models/quality_analysis.rb
+++ b/app/models/quality_analysis.rb
@@ -1,5 +1,5 @@
class QualityAnalysis < ActiveRecord::Base
- attr_accessible :author_login, :project_id, :rep_identifier, :sonar_version, :branch, :path, :rep_identifier, :language
+ attr_accessible :author_login, :project_id, :rep_identifier, :sonar_version, :branch, :path, :rep_identifier, :language, :sonar_name
def user_rep_name
self.author_login+":"+self.rep_identifier
diff --git a/app/models/syllabus.rb b/app/models/syllabus.rb
index 7d6319955..5e368f341 100644
--- a/app/models/syllabus.rb
+++ b/app/models/syllabus.rb
@@ -1,5 +1,46 @@
+# encoding: utf-8
class Syllabus < ActiveRecord::Base
+ include Redmine::SafeAttributes
+ include ApplicationHelper
+ acts_as_taggable
+ acts_as_attachable
+ has_many_kindeditor_assets :assets, :dependent => :destroy
+
belongs_to :user
has_many :courses
- attr_accessible :description, :title
+ has_many :journals_for_messages, :as => :jour, :dependent => :destroy
+ attr_accessible :description, :title, :eng_name, :syllabus_type, :credit, :hours, :theory_hours, :practice_hours, :applicable_major, :pre_course
+ safe_attributes 'title', 'description', 'eng_name', 'syllabus_type', 'credit', 'hours', 'theory_hours', 'practice_hours', 'credit', 'applicable_major', 'pre_course'
+
+ def delete_kindeditor_assets
+ delete_kindeditor_assets_from_disk self.id,OwnerTypeHelper::SYLLABUS
+ end
+
+ def syllabus_type_str
+ case self.syllabus_type
+ when 1
+ type = "公共必修课"
+ when 2
+ type = "学科必修课"
+ when 3
+ type = "专业选修课"
+ when 4
+ type = "实践必修课"
+ when 5
+ type = "实践选修课"
+ end
+ type
+ end
+
+ ###添加回复
+ def self.add_syllabus_jour(user, notes, id , options = {})
+ syllabus = Syllabus.find(id)
+ if options.count == 0
+ jfm = syllabus.journals_for_messages.build(:user_id => user.id, :notes => notes, :reply_id => 0)
+ else
+ jfm = syllabus.journals_for_messages.build(options)
+ end
+ jfm.save
+ jfm
+ end
end
diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb
index e6143caec..7a8d0fd32 100644
--- a/app/services/courses_service.rb
+++ b/app/services/courses_service.rb
@@ -213,6 +213,7 @@ class CoursesService
#@course.safe_attributes(current_user,params[:course])
#@course.password = params[:course][:password]
@course.tea_id = current_user.id
+ @course.syllabus_id = params[:syllabus_id].to_i
@course.term = params[:term]
@course.time = params[:time]
@course.end_term = params[:end_term]
@@ -271,6 +272,7 @@ class CoursesService
course.send(:safe_attributes=, params[:course], current_user)
#course.safe_attributes = params[:course]
#course.password = params[:course][:password]
+ course.syllabus_id = params[:syllabus_id].to_i
course.time = params[:time]
course.term = params[:term]
course.end_time = params[:end_time]
@@ -328,9 +330,9 @@ class CoursesService
5, '您还未登录',
6, '申请成功,请等待审核完毕',
7, '您已经发送过申请了,请耐心等待',
- 8, '您已经是该课程的教师了',
- 9, '您已经是该课程的教辅了',
- 10, '您已经是该课程的管理员了',
+ 8, '您已经是该班级的教师了',
+ 9, '您已经是该班级的教辅了',
+ 10, '您已经是该班级的管理员了',
'未知错误,请稍后再试'
]
end
diff --git a/app/views/account/email_activation.html.erb b/app/views/account/email_activation.html.erb
new file mode 100644
index 000000000..9655efcf4
--- /dev/null
+++ b/app/views/account/email_activation.html.erb
@@ -0,0 +1,58 @@
+
您的账号尚未激活,请先进入您的注册邮箱,激活您的账号。
+ + <%#= link_to l(:label_mail_resend), { :controller => 'account', :action => 'resendmail',:user => @user}, :class=>"email_verify_btn mt30 ml30", :remote => true, :method => 'get' %> +如果您尚未收到激活邮件,请按照以下步骤操作:
+<%= f.text_field :login, :size => 25, :required => true %> - <%= l(:label_max_number) %> -
-<%= f.password_field :password, :size => 25, :required => true %> - <%= l(:text_caracters_minimum, :count => Setting.password_min_length) %> -
-<%= f.password_field :password_confirmation, :size => 25, :required => true %>
- <% end %> - -- <%= f.text_field :mail,:size => 25, :required => true %> - -
-
-
- <%= "#{l(:label_mail_attention)} " %> <%= "#{l(:label_mail_attention1)} " %>
-
<%= submit_tag l(:button_submit) %> | -
<%= f.text_field :identity_url %>
-<% end %> -<% @user.custom_field_values.select { |v| v.editable? || v.required? }.each do |value| %> -<%= custom_field_tag_with_label :user, value %>
-<% end %> - -<% password_min_length = Setting.password_min_length %> - \ No newline at end of file diff --git a/app/views/admin/course_resource_list.html.erb b/app/views/admin/course_resource_list.html.erb index 2e83a96aa..4786bbe89 100644 --- a/app/views/admin/course_resource_list.html.erb +++ b/app/views/admin/course_resource_list.html.erb @@ -39,7 +39,7 @@ <%= number_to_human_size(resource.filesize)%><%= text_field_tag("attachments[p#{i}][filename]", attachment.filename, :class => 'upload_filename readonly', :readonly=>'readonly')%> <%#= text_field_tag("attachments[p#{i}][description]", attachment.description, :maxlength => 255, :placeholder => l(:label_optional_description), :class => 'description', :style=>"display: inline-block;") %> <%#= check_box_tag("attachments[p#{i}][is_public_checkbox]", attachment.is_public,attachment.is_public == 1 ? true : false, :class => 'is_public_checkbox')%> - <%= link_to(' '.html_safe, attachment_path(attachment, :attachment_id => "p#{i}", :format => 'js'), :method => 'delete', :remote => true, :class => 'remove-upload') %> + <%= link_to(' '.html_safe, attachment_path(attachment, :attachment_id => "#{i+1}", :format => 'js'), :method => 'delete', :remote => true, :class => 'remove-upload', :containerid => "2") %> <%= hidden_field_tag "attachments[p#{i}][token]", "#{attachment.token}" %> -
+ <% end %> <% else %> <% container.attachments.each_with_index do |attachment, i| %> - + <% end %> <% end %> <% end %> diff --git a/app/views/blog_comments/show.html.erb b/app/views/blog_comments/show.html.erb index 7d8aaed86..b1cd86484 100644 --- a/app/views/blog_comments/show.html.erb +++ b/app/views/blog_comments/show.html.erb @@ -91,9 +91,10 @@<%=@syllabus.title %>
+ +