diff --git a/Gemfile b/Gemfile index b482cb6fd..bb94100a5 100644 --- a/Gemfile +++ b/Gemfile @@ -3,14 +3,17 @@ source 'https://ruby.taobao.org/' unless RUBY_PLATFORM =~ /w32/ # unix-like only gem 'iconv' - gem "rmagick", "= 2.13.1" ## centos yum install ImageMagick-devel + if RUBY_PLATFORM =~ /darwin/ + gem "rmagick", "= 2.15.4" ## osx must be this version + else + 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/boards_controller.rb b/app/controllers/boards_controller.rb index 9a72bb4df..ceb63d7b0 100644 --- a/app/controllers/boards_controller.rb +++ b/app/controllers/boards_controller.rb @@ -125,7 +125,9 @@ class BoardsController < ApplicationController if @order.to_i == 2 @type = 2 @topics.each do |topic| - topic[:infocount] = get_praise_num(topic) + (topic.parent ? topic.parent.children.count : topic.children.count) + all_comments = [] + count=get_all_children(all_comments, topic).count + topic[:infocount] = get_praise_num(topic) + count if topic[:infocount] < 0 topic[:infocount] = 0 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/messages_controller.rb b/app/controllers/messages_controller.rb index 8ef399d10..f5ad89832 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -44,7 +44,8 @@ class MessagesController < ApplicationController offset = @topic.children.count(:conditions => ["#{Message.table_name}.id < ?", params[:r].to_i]) page = 1 + offset / REPLIES_PER_PAGE end - @reply_count = @topic.children.count + all_comments = [] + @reply_count = get_all_children(all_comments, @topic).count @reply = Message.new(:subject => "RE: #{@message.subject}") if @course messages_replies = @topic.children. @@ -137,26 +138,32 @@ class MessagesController < ApplicationController # Reply to a topic def reply - if params[:reply][:content] == "" - if params[:is_board] - if @project - (redirect_to project_boards_path(@project), :notice => l(:label_reply_empty);return) - elsif @course - (redirect_to course_boards_path(@course), :notice => l(:label_reply_empty);return) - end - else - (redirect_to board_message_url(@board, @topic, :r => @reply), :notice => l(:label_reply_empty);return) - end + if params[:parent_id] + parent = Message.find params[:parent_id] + @reply = Message.new + @reply.author = User.current + @reply.board = parent.board + @reply.content = params[:content] + @reply.subject = "RE: #{parent.subject}" + @reply.reply_id = params[:reply_id] + # @reply.reply_id = params[:id] + parent.children << @reply + @topic = params[:activity_id].nil? ? parent : Message.find(params[:activity_id].to_i) + @user_activity_id = params[:user_activity_id] if params[:user_activity_id] + @is_course = params[:is_course] if params[:is_course] + @is_board = params[:is_board] if params[:is_board] + else + @quote = params[:quote][:quote] + @reply = Message.new + @reply.author = User.current + @reply.board = @board + @reply.safe_attributes = params[:reply] + @reply.content = @quote + @reply.content + @reply.subject = "RE: #{@topic.subject}" unless params[:reply][:subject] + @topic.children << @reply + # @reply.reply_id = params[:id] end - @quote = params[:quote][:quote] - @reply = Message.new - @reply.author = User.current - @reply.board = @board - @reply.safe_attributes = params[:reply] - @reply.content = @quote + @reply.content - @reply.subject = "RE: #{@topic.subject}" unless params[:reply][:subject] - # @reply.reply_id = params[:id] - @topic.children << @reply + update_course_activity(@topic.class,@topic.id) update_user_activity(@topic.class,@topic.id) update_forge_activity(@topic.class,@topic.id) @@ -182,14 +189,10 @@ class MessagesController < ApplicationController respond_to do |format| format.js end - elsif params[:is_board] - if @project - redirect_to project_boards_path(@project) - elsif @course - redirect_to course_boards_path(@course) - end + return else - redirect_to board_message_url(@board, @topic, :r => @reply) + redirect_to board_message_url(@board, @topic) + return end end @@ -251,6 +254,17 @@ class MessagesController < ApplicationController # Delete a messages def destroy + if params[:user_activity_id] + @message.destroy + @topic = Message.find(params[:activity_id].to_i) + @user_activity_id = params[:user_activity_id] + @is_course = params[:is_course] + @is_board = params[:is_board] + respond_to do |format| + format.js + end + return + end if @project (render_403; return false) unless @message.destroyable_by?(User.current) elsif @course @@ -299,12 +313,12 @@ class MessagesController < ApplicationController end def quote - @subject = @message.subject - @subject = "RE: #{@subject}" unless @subject.starts_with?('RE:') - - @content = "> #{ll(Setting.default_language, :text_user_wrote, @message.author)}\n> " - @temp = Message.new - @temp.content = "
#{ll(Setting.default_language, :text_user_wrote, @message.author.show_name)}".html_safe + # @subject = @message.subject + # @subject = "RE: #{@subject}" unless @subject.starts_with?('RE:') + # + # @content = "> #{ll(Setting.default_language, :text_user_wrote, @message.author)}\n> " + # @temp = Message.new + # @temp.content = "
#{@message.content.html_safe}
#{ll(Setting.default_language, :text_user_wrote, @message.author.show_name)}".html_safe end def preview 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" - - # # # 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) + git_url = @gitlab_address.to_s+"/"+@project.owner.to_s+"/"+ identifier + "."+"git" + + # 替换配置文件 + @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 + + # 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 - qa.update_attribute(:sonar_version, version) + 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 b7972ff6f..fe42e6919 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -90,6 +90,8 @@ class UsersController < ApplicationController case params[:type] when 'JournalsForMessage' @comment = JournalsForMessage.find params[:comment].to_i + when 'Message' + @comment = Message.find params[:comment].to_i end end @@ -111,6 +113,13 @@ class UsersController < ApplicationController @user_activity_id = params[:user_activity_id] @activity_id = params[:activity_id] @type = 'JournalsForMessage' + when 'Message' + @reply = Message.find params[:reply_id] + @user_activity_id = params[:user_activity_id] + @activity_id = params[:activity_id] + @is_course = params[:is_course] + @is_board = params[:is_board] + @type = 'Message' end respond_to do |format| format.js @@ -1248,6 +1257,12 @@ class UsersController < ApplicationController render :layout=>'new_base_user' end + #给某人留言 + def feedBackTo + + + end + def user_comments end @@ -1367,7 +1382,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 #显示更多用户项目 @@ -3176,23 +3199,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 @@ -3200,10 +3226,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 @@ -3264,10 +3290,18 @@ class UsersController < ApplicationController @journals = obj.children.reorder("created_at desc") when 'Message' obj = Message.where('id = ?', params[:id].to_i).first - @journals = obj.children.reorder("created_on desc") + @type = 'Message' + @is_course = params[:is_course] + @is_board = params[:is_board] + @user_activity_id = params[:div_id].to_i if params[:div_id] + comments = [] + @journals = get_all_children(comments, obj) 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+"】
#{@message.content.html_safe}
您的账号尚未激活,请先进入您的注册邮箱,激活您的账号。
+ + <%#= 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 %>
+ +