diff --git a/app/api/mobile/apis/upgrade.rb b/app/api/mobile/apis/upgrade.rb index 02ff97185..e6a7916d9 100644 --- a/app/api/mobile/apis/upgrade.rb +++ b/app/api/mobile/apis/upgrade.rb @@ -3,16 +3,23 @@ module Mobile module Apis class Upgrade < Grape::API + include ApplicationHelper resource :upgrade do desc "get update info" params do requires :platform, type: String, desc: '平台名,android, ios' end get do + @current_version = ::PhoneAppVersion.reorder('created_at desc').first + attachment = @current_version.attachments.first + if attachment.nil? + raise '未发现客户端!' + end + url = Setting.host_name + "/attachments/download/" + attachment.id.to_s + "/" + attachment.filename { - version: '2', - url: 'http://u06.shellinfo.cn/trustie/Trustie_Beta1.0.0_201412310917.apk', - desc: '更新了什么功能' + version: @current_version.version, + url: url, + desc: @current_version.description } end end diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index c77ebe704..8e23041c6 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -337,6 +337,40 @@ class AdminController < ApplicationController end def create_version + @versions = PhoneAppVersion.reorder('created_at desc') + @new_version = PhoneAppVersion.new + @new_version.version = params[:version] + @new_version.description = params[:description] + if params[:attachments][:dummy][:file].nil? || params[:attachments][:dummy][:file] == "" + respond_to do |format| + flash.now[:error] = "#{l :label_version_create_fail}: #{l(:label_client_need)}" + #flash.now[:error] = "#{l :label_first_page_create_fail}: #{@course_page.errors.full_messages[0]}" + format.html { + render :action => 'mobile_version' + } + format.api { render_validation_errors(@new_version) } + end + else + @new_version.save_attachments(params[:attachments] || (params[:version] && params[:version][:uploads])) + if @new_version.save + respond_to do |format| + format.html { + flash[:notice] = l(:notice_successful_create) + redirect_to mobile_version_url + } + format.api { render_api_ok } + end + else + respond_to do |format| + flash.now[:error] = "#{l :label_version_create_fail}: #{@new_version.errors.full_messages[0]}" + #flash.now[:error] = "#{l :label_first_page_create_fail}: #{@course_page.errors.full_messages[0]}" + format.html { + render :action => 'mobile_version' + } + format.api { render_validation_errors(@new_version) } + end + end + end end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 1c26ec07e..47251cf85 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -181,6 +181,9 @@ class ApplicationController < ActionController::Base #从手机端传来apptoken则将当前登陆用户变为对应的用户 if params[:apptoken] token = ApiKey.where(access_token: params[:apptoken]).first + if token.expired? + return + end if token && !token.expired? @current_user = User.find(token.user_id) end diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 252d823e9..ccab34283 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -233,6 +233,8 @@ class AttachmentsController < ApplicationController format.html { redirect_to_referer_or softapplications_path(@attachment.container) } elsif !@attachment.container.nil? && @attachment.container.is_a?(Bid) format.html { redirect_to_referer_or respond_path(@attachment.container) } + elsif !@attachment.container.nil? && @attachment.container.is_a?(PhoneAppVersion) + format.html { redirect_to_referer_or mobile_version_path } else if @project.nil? format.html { redirect_to_referer_or forum_memo_path(@attachment.container.forum, @attachment.container) } @@ -417,7 +419,7 @@ private @attachment.container.board.course) @course = @attachment.container.board.course else - unless @attachment.container_type == 'Bid' || @attachment.container_type == 'HomeworkAttach' || @attachment.container_type == 'Memo' || @attachment.container_type == 'Softapplication' + unless @attachment.container_type == 'Bid' || @attachment.container_type == 'HomeworkAttach' || @attachment.container_type == 'Memo' || @attachment.container_type == 'Softapplication' || @attachment.container_type == 'PhoneAppVersion' @project = @attachment.project end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index e6171bf81..d770a4633 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -446,12 +446,13 @@ class UsersController < ApplicationController activity = Activity.where(where_condition).where('user_id = ?', @user.id).order('id desc') end activity = activity.reject { |e| - !User.current.admin? && + e.act.nil? || + (!User.current.admin? && !e.act.nil? (((e.act_type == "Issue") && !e.act.project.visible?(User.current)) || (e.act_type == "Bid" && !e.act.courses.first.nil? && e.act.courses.first.is_public == 0 && !User.current.member_of_course?(e.act.courses.first)) || (e.act_type == "Journal" && e.act.respond_to?("Project") && !e.act.project.visible?(User.current)) || (e.act_type == "News" && ((!e.act.project.nil? && !e.act.project.visible?(User.current)) || (!e.act.course.nil? && e.act.course.is_public == 0 && !User.current.member_of_course?(e.act.course)))) || - (e.act_type == "Message" && !e.act.board.nil? && ((!e.act.board.project.nil? && !e.act.board.project.visible?(User.current)) || (!e.act.board.course.nil? && e.act.board.course.is_public == 0 && !User.current.member_of_course?(e.act.board.course))))) + (e.act_type == "Message" && !e.act.board.nil? && ((!e.act.board.project.nil? && !e.act.board.project.visible?(User.current)) || (!e.act.board.course.nil? && e.act.board.course.is_public == 0 && !User.current.member_of_course?(e.act.board.course)))))) } @activity_count = activity.count @activity_pages = Paginator.new @activity_count, pre_count, params['page'] diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index 22eb9bfae..db547061f 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -351,10 +351,28 @@ module CoursesHelper str end - # added by nwb + # added by meng + # 课程time+term简写(2014.春/2014.秋)国际化输出 def get_course_term course - str = ( course.try(:time).to_s << '.' << course.try(:term).to_s ) - str[0..-4] + strterm = course.try(:term).to_s + if !(User.current.language == 'zh') + strterm == '春季学期' ? strterm = 'spring term' : strterm = 'autumn term' + str = ( course.try(:time).to_s << '.' << strterm ) + str[0..-6] + else + str = ( course.try(:time).to_s << '.' << strterm ) + str[0..-4] + end + end + + # added by meng + # 课程term(春季学期/秋季学期)国际化输出 + def get_course_term_locales course + str = course.try(:term).to_s + if !(User.current.language == 'zh') + str == '春季学期' ? str = ' ' + 'spring term' : str = ' ' + 'autumn term' + end + return str end def members_to_user_ids members diff --git a/app/helpers/welcome_helper.rb b/app/helpers/welcome_helper.rb index eba3c0b3c..f6e205e82 100644 --- a/app/helpers/welcome_helper.rb +++ b/app/helpers/welcome_helper.rb @@ -341,7 +341,7 @@ module WelcomeHelper end str rescue Exception => e - str << content_tag("span", l(:field_user_active_unknow)) + str << content_tag("span", l('user.active.unknow')) end def show_event_reply event diff --git a/app/models/phone_app_version.rb b/app/models/phone_app_version.rb index abf4c54e3..92a32c0d3 100644 --- a/app/models/phone_app_version.rb +++ b/app/models/phone_app_version.rb @@ -1,3 +1,6 @@ class PhoneAppVersion < ActiveRecord::Base attr_accessible :description, :version + validates_presence_of :description, :version + validates_uniqueness_of :version + acts_as_attachable end diff --git a/app/models/project.rb b/app/models/project.rb index 099870bc7..313652bf4 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -131,7 +131,7 @@ class Project < ActiveRecord::Base #ActiveModel::Dirty 这里有一个changed方法。对任何对象都可以用 after_save :update_inherited_members, :if => Proc.new {|project| project.inherit_members_changed?} # 创建project之后默认创建一个board,之后的board去掉了board的概念 - after_create :create_board_sync + after_create :create_board_sync,:acts_as_forge_activities before_destroy :delete_all_members def remove_references_before_destroy return if self.id.nil? @@ -1154,6 +1154,13 @@ class Project < ActiveRecord::Base end end - + # Time 2015-03-10 15:33:16 + # Author lizanle + # Description 新建项目要在ForgeActivities中加一条数据。 + def acts_as_forge_activities + fa = ForgeActivity.new(:user_id => User.current.id,:project_id => self.id, + :forge_act_id => self.id,:forge_act_type => "ProjectCreateInfo") + fa.save! + end end diff --git a/app/models/user_extensions.rb b/app/models/user_extensions.rb index b21f0ad36..92690d1db 100644 --- a/app/models/user_extensions.rb +++ b/app/models/user_extensions.rb @@ -33,16 +33,32 @@ class UserExtensions < ActiveRecord::Base return self.brief_introduction end -# added by bai +# added by meng def show_identity if self.identity == 0 - user_identity = '教师' + if User.current.language == 'zh' + user_identity = '教师' + else + user_identity = 'Teacher' + end elsif self.identity == 1 - user_identity = '学生' + if User.current.language == 'zh' + user_identity = '学生' + else + user_identity = 'Student' + end elsif self.identity == 2 - user_identity = '企业' + if User.current.language == 'zh' + user_identity = '企业' + else + user_identity = 'Enterprise' + end elsif self.identity == 3 - user_identity = '开发者' + if User.current.language == 'zh' + user_identity = '开发者' + else + user_identity = 'Developer' + end else user_identity = '' end diff --git a/app/views/admin/mobile_version.html.erb b/app/views/admin/mobile_version.html.erb index 293b0ec46..cc6490f90 100644 --- a/app/views/admin/mobile_version.html.erb +++ b/app/views/admin/mobile_version.html.erb @@ -1,9 +1,20 @@

<%= l(:label_mobile_version) %>

发布新版本
- + <%= form_tag({:controller => 'admin', :action => 'create_version'},{:id => 'new_version',:style=>'display:none'}) do %> +

+ + <%= text_field_tag 'version', params[:version],:value => @new_version.version, :size => 30,:style => "font-size:small;width:490px;margin-left:10px;" %> +

+

+ + <%= text_field_tag 'description', params[:description],:value => @new_version.description,:size => 30,:style => "font-size:small;width:490px;margin-left:10px;" %> +

+

+ <%= render :partial => 'attachments/form', :locals => {:container => @new_version} %> +

+ <%= submit_tag l(:button_save), :class => "small", :name => nil %> + <% end %>

当前版本:
@@ -25,7 +36,10 @@ <% end %> - +<% if @versions.first.attachments.any?%> + <% options = {:author => true, :deletable => true } %> + <%= render :partial => 'attachments/links', :locals => {:attachments => @versions.first.attachments, :options => options, :is_float => true} %> +<% end %>
历史版本:
diff --git a/app/views/courses/index.html.erb b/app/views/courses/index.html.erb index e7a4a29db..e8a917a2b 100644 --- a/app/views/courses/index.html.erb +++ b/app/views/courses/index.html.erb @@ -12,7 +12,7 @@ - 高校课程实践社区 + <%= l(:label_courses_community)%> diff --git a/app/views/courses/search.html.erb b/app/views/courses/search.html.erb index 661feb3c9..98b056487 100644 --- a/app/views/courses/search.html.erb +++ b/app/views/courses/search.html.erb @@ -7,7 +7,7 @@ - 高校课程实践社区 + <%= l(:label_courses_community)%> diff --git a/app/views/files/_attachement_list.html.erb b/app/views/files/_attachement_list.html.erb index 85739f7c3..001519a28 100644 --- a/app/views/files/_attachement_list.html.erb +++ b/app/views/files/_attachement_list.html.erb @@ -37,7 +37,7 @@ :description_placeholder => l(:label_optional_description) } %> -