diff --git a/app/api/mobile/apis/courses.rb b/app/api/mobile/apis/courses.rb index 076e0b1c7..591a4e288 100644 --- a/app/api/mobile/apis/courses.rb +++ b/app/api/mobile/apis/courses.rb @@ -272,7 +272,7 @@ module Mobile params do requires :token,type:String requires :course_id,type:Integer,desc: '课程id' - optional :name,type:String,desc:'学生的姓名或者昵称或者学号可能包含的字符' + optional :name,type:String,desc:'学生的姓名或者登录名或者学号可能包含的字符' end get ":course_id/members" do cs = CoursesService.new diff --git a/app/api/mobile/apis/users.rb b/app/api/mobile/apis/users.rb index 583a130d1..6ce3cacbb 100644 --- a/app/api/mobile/apis/users.rb +++ b/app/api/mobile/apis/users.rb @@ -82,7 +82,7 @@ module Mobile desc "用户搜索" params do requires :name, type: String, desc: '用户名关键字' - requires :search_by, type: String,desc: '搜索依据:0 昵称,1 用户名,2 邮箱,3 昵称和姓名' + requires :search_by, type: String,desc: '搜索依据:0 登录名,1 用户名,2 邮箱,3 登录名和姓名' optional :is_search_assitant,type:Integer,desc:'是否搜索注册用户来作为助教' optional :course_id,type:Integer,desc: '课程id,搜索注册用户不为该课程教师的其他用户' optional :user_id,type:Integer,desc:'用户id' diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 279975c77..43a49c7d9 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -509,7 +509,7 @@ class CoursesController < ApplicationController if @course respond_to do |format| flash[:notice] = l(:notice_successful_create) - format.html {redirect_to settings_course_url(@course, :course_type => 1)} + format.html {redirect_to course_url(@course)} format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'courses', :action => 'show', :id => @course.id) } end else diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index af8990f37..72dd0a741 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -81,6 +81,7 @@ class IssuesController < ApplicationController @priority_id = params[:priority_id] @status_id = params[:status_id] @subject = params[:subject] + @done_ratio = parmas[:done_ratio] @issue_count = @query.issue_count @issue_pages = Paginator.new @issue_count, @limit, params['page'] params[:page] = (params[:page] || 1).to_i + 1 #页码需要加1 @@ -220,19 +221,27 @@ class IssuesController < ApplicationController end def update - return unless update_issue_from_params - @issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads])) - saved = false - begin - @saved = @issue.save_issue_with_child_records(params, @time_entry) - rescue ActiveRecord::StaleObjectError - @conflict = true - if params[:last_journal_id] - @conflict_journals = @issue.journals_after(params[:last_journal_id]).all - @conflict_journals.reject!(&:private_notes?) unless User.current.allowed_to?(:view_private_notes, @issue.project) + if params[:issue_detail] + issue = Issue.find(params[:issue_id]) + issue = update_user_issue_detail(issue, params) + @saved = update_user_issue_detail(issue, params) + return + else + return unless update_issue_from_params + @issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads])) + saved = false + begin + @saved = @issue.save_issue_with_child_records(params, @time_entry) + rescue ActiveRecord::StaleObjectError + @conflict = true + if params[:last_journal_id] + @conflict_journals = @issue.journals_after(params[:last_journal_id]).all + @conflict_journals.reject!(&:private_notes?) unless User.current.allowed_to?(:view_private_notes, @issue.project) + end end end + if @saved #修改界面增加跟踪者 watcherlist = @issue.watcher_users @@ -278,6 +287,19 @@ class IssuesController < ApplicationController end end + def update_user_issue_detail(issue, params) + case params[:type] + when "status" + issue.update_attribute(:status_id, params[:status_id]) + when "assigned" + issue.update_attribute(:assigned_to_id, params[:assigned_to_id]) + when "ratio" + issue.update_attribute(:done_ratio, params[:done_ratio]) + when "prior" + issue.update_attribute(:priority_id, params[:priority_id]) + end + end + # Updates the issue form when changing the project, status or tracker # on issue creation/update def update_form diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 38d148907..b155e9f90 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -93,6 +93,11 @@ class UsersController < ApplicationController end end + # 更新issue状态 + def user_act_issue_assign_to + + end + # 用户消息 # 说明: homework 发布作业;message:讨论区; news:新闻; poll:问卷;works_reviewers:作品评阅;works_reply:作品回复,exercise:课程测验 # issue:问题;journal:缺陷状态更新; forum:公共贴吧: user_feedback: 用户留言; new_reply:新闻回复(comment) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 8aa11c3ac..51138f2ef 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -49,6 +49,16 @@ module ApplicationHelper end end + # 判断课程是否为精品课程 + def is_excellent_course course + (course.is_excellent? or course.excellent_option?) ? true : false + end + + # 判断课程对成员是否可见 + def visible_course?(course) + (course.is_delete? or (!course.is_public? && !User.current.member_of_course?(course))) ? false : true + end + # 获取项目/课程总分 # 发布缺陷 4分 回复缺陷 1分 提交一次 4分 讨论帖子 2分 回复帖子 1分 发布新闻 1分 def static_project_score obj @@ -959,7 +969,17 @@ module ApplicationHelper first_page = FirstPage.find_by_page_type('project') if args.empty? title = @html_title || [] - title << @project.name if @project + if @project + title << @project.name + elsif @course + title << @course.name + elsif @organization + title << @organization.name + elsif @user + title << @user.login + else + title << User.current.login + end if first_page.nil? || first_page.web_title.nil? title << Setting.app_title unless Setting.app_title == title.last else diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index b062351c1..fb7214fce 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -11,6 +11,44 @@ module CoursesHelper #StudentRoles = [5, 10] #AllPeople = StudentRoles+TeacherRoles ## return people count + + + # 推荐的精品课程 + def excellent_course_recommend new_course + q = "%#{new_course.name.strip}%" + result = find_excelletn_course(q, new_course) + end + + # 查询符合条件的精品课程 + # 用新课程名去匹配精品课程中按课程名和Tag名 + def find_excelletn_course keywords, current_course + # 获取tag匹配结果ID + a_tags = [] + # kc = keywords.to_a + Course.visible.where("is_excellent =?", 1).each do |ec| + if ec.tags.any?{|value| current_course.name.include?(value.to_s)} + a_tags << ec.id + end + end + # sql = "SELECT distinct c.* FROM `courses` c, tags t, taggings ts where t.id = ts.tag_id and ts.taggable_id = c.id and c.is_excellent = 1 and is_delete = 0 and + # ts.taggable_type = 'Course' and t.name like '%#{keywords}%'" + # a_tags = Course.find_by_sql(sql).select{|course| course.is_public ==1 unless User.current.member_of_course?(course)} + # 通过elastic结果获取精品课程 + a_courses = [] + courses = Course.search(keywords) + courses.each do |c| + a_courses << c.id + end + a_courses << a_tags unless a_tags.length == 0 + # 过滤条件:精品课程、本身不在搜索范围 + e_courses = Course.where("is_excellent =? and id in (?)",1,a_courses.flatten.uniq).where("id !=?",current_course.id) + e_courses + end + + # 判断精品课程是否可见,非课程成员无法查看私有课程 + def visible_excellent_course obj + # if course.is_pu + end # 返回x项目成员数量,即roles表中定义的所有成员 def projectCount project diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index bfc01a102..43ef7cefc 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -85,6 +85,11 @@ module UsersHelper end end + def link_to_user_version(version, options = {}) + return '' unless version && version.is_a?(Version) + link_to_if version.visible?, format_version_name(version), { :controller => 'versions', :action => 'show', :id => version }, :class => " f16 fb c_dblue " + end + # 统计未读消息数 def unviewed_message(user) course_count = CourseMessage.where("user_id =? and viewed =?", user, 0).count diff --git a/app/models/course.rb b/app/models/course.rb index 0194a2a9d..69dbec5d0 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -144,6 +144,26 @@ class Course < ActiveRecord::Base ) end + def self.e_search(query) + __elasticsearch__.search( + { + query: { + multi_match: { + query: query, + type:"most_fields", + operator: "or", + fields: ['name', 'description^0.5'] + } + }, + sort: { + _score:{order: "desc" }, + updated_at:{order:"desc"} + + } + } + ) + end + def visible?(user=User.current) user.allowed_to?(:view_course, self) end @@ -383,6 +403,7 @@ class Course < ActiveRecord::Base def act_as_course_message self.course_messages << CourseMessage.new(:user_id => self.tea_id, :course_id => self.id, :viewed => false) end + #项目与课程分离后,很多课程的名称等信息为空,这些数据信息存储在项目表中!!就是数据兼容的问题 #def name # read_attribute('name') || Project.find_by_identifier(self.extra).try(:name) @@ -404,6 +425,7 @@ class Course < ActiveRecord::Base self.__elasticsearch__.index_document end end + def update_course_ealasticsearch_index if self.is_public == 1 and self.is_delete == 0 #如果是初次更新成为公开或者恢复被删除的情况,会报错,那么这条记录尚未被索引过。没有报错就是更新的其他属性 begin @@ -427,8 +449,12 @@ class Course < ActiveRecord::Base end end + + end + + # Delete the previous articles index in Elasticsearch # Course.__elasticsearch__.client.indices.delete index: Course.index_name rescue nil # diff --git a/app/models/course_activity.rb b/app/models/course_activity.rb index e1f9ab9f5..194e1183a 100644 --- a/app/models/course_activity.rb +++ b/app/models/course_activity.rb @@ -6,6 +6,7 @@ class CourseActivity < ActiveRecord::Base belongs_to :user has_many :user_acts, :class_name => 'UserAcivity',:as =>:act after_save :add_user_activity, :add_course_activity + after_create :add_course_lead before_destroy :destroy_user_activity, :destroy_org_activity #在个人动态里面增加当前动态 @@ -60,4 +61,18 @@ class CourseActivity < ActiveRecord::Base org_activity = OrgActivity.where("org_act_type = '#{self.course_act_type.to_s}' and org_act_id = '#{self.course_act_id}'") org_activity.destroy_all end + + # 发布新课导语 + # 导语要放置在课程创建信息之后 + # 导语 + def add_course_lead + if self.course_act_type == "Course" + name = Redmine::Configuration['course_message_lead_subject'] + content = Redmine::Configuration['course_message_lead_content'] + # message的status状态为0为正常,为1表示创建课程时发送的message + message = Message.create(:subject => name, :content => content, :board_id => self.course.boards.first.id, :author_id => self.course.tea_id , :sticky => true, :status => true ) + # 更新的目的是为了排序,因为该条动态的时间可能与课程创建的动态创建时间一直 + message.course_acts.first.update_attribute(:updated_at, message.course_acts.first.updated_at + 1) + end + end end diff --git a/app/views/account/login.html.erb b/app/views/account/login.html.erb index 3d07f69b2..f2b43c9a3 100644 --- a/app/views/account/login.html.erb +++ b/app/views/account/login.html.erb @@ -224,7 +224,7 @@ <%= back_url_hidden_field_tag %>