From 43e9a9a49521be1605db23bd8f095d5bf02da917 Mon Sep 17 00:00:00 2001
From: z9hang
Date: Tue, 10 Mar 2015 17:20:30 +0800
Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E5=AE=8C=E6=88=90=E6=89=8B=E6=9C=BAa?=
=?UTF-8?q?pp=E7=89=88=E6=9C=AC=E7=AE=A1=E7=90=86=EF=BC=8C=E4=B8=8A?=
=?UTF-8?q?=E4=BC=A0=E5=AE=A2=E6=88=B7=E7=AB=AF=E5=8A=9F=E8=83=BD=E3=80=82?=
=?UTF-8?q?2=E3=80=81=E6=89=8B=E6=9C=BAapp=E6=A3=80=E6=9F=A5=E6=9B=B4?=
=?UTF-8?q?=E6=96=B0=E6=8E=A5=E5=8F=A3=E5=AE=8C=E6=88=90?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/api/mobile/apis/upgrade.rb | 13 ++++++---
app/controllers/admin_controller.rb | 33 ++++++++++++++++-------
app/controllers/attachments_controller.rb | 4 ++-
app/models/phone_app_version.rb | 1 +
app/views/admin/mobile_version.html.erb | 8 +++++-
config/locales/zh.yml | 2 ++
6 files changed, 46 insertions(+), 15 deletions(-)
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 413ed9692..8e23041c6 100644
--- a/app/controllers/admin_controller.rb
+++ b/app/controllers/admin_controller.rb
@@ -341,24 +341,37 @@ class AdminController < ApplicationController
@new_version = PhoneAppVersion.new
@new_version.version = params[:version]
@new_version.description = params[:description]
- if @new_version.save
+ if params[:attachments][:dummy][:file].nil? || params[:attachments][:dummy][:file] == ""
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_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
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/models/phone_app_version.rb b/app/models/phone_app_version.rb
index 4dc1503c9..92a32c0d3 100644
--- a/app/models/phone_app_version.rb
+++ b/app/models/phone_app_version.rb
@@ -2,4 +2,5 @@ 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/views/admin/mobile_version.html.erb b/app/views/admin/mobile_version.html.erb
index 0d38b449a..cc6490f90 100644
--- a/app/views/admin/mobile_version.html.erb
+++ b/app/views/admin/mobile_version.html.erb
@@ -10,6 +10,9 @@
<%= 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 %>
@@ -33,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/config/locales/zh.yml b/config/locales/zh.yml
index 26dc11508..b8add2739 100644
--- a/config/locales/zh.yml
+++ b/config/locales/zh.yml
@@ -1980,6 +1980,7 @@ zh:
label_forum_update_fail: 贴吧更新失败
label_first_page_create_fail: 首页定制失败
label_version_create_fail: 版本发布失败
+ label_client_need: 需上传客户端
label_forum_edit: 编辑讨论区
label_memo_create: 发布
label_memo_new: 新建帖子
@@ -2382,3 +2383,4 @@ zh:
label_recently_updated_message: 最近更新了留言
label_recently_updated_courseware: 最近更新了课件
label_no_courses: 您没有参与任何课程,请搜索课程、加入课程,或者创建课程吧!
+