diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb
index 62bef8fb1..2d5149c09 100644
--- a/app/controllers/attachments_controller.rb
+++ b/app/controllers/attachments_controller.rb
@@ -361,7 +361,7 @@ private
def login_without_softapplication
referer = request.headers['Referer']
- require_login unless referer =~ /softapplication/ || referer =~ /memos/
+ require_login unless referer =~ /softapplication/ || @attachment.container_type == "Memo"
end
def renderTag
diff --git a/app/controllers/contests_controller.rb b/app/controllers/contests_controller.rb
index b099a1db5..1b7791ac4 100644
--- a/app/controllers/contests_controller.rb
+++ b/app/controllers/contests_controller.rb
@@ -54,39 +54,29 @@ class ContestsController < ApplicationController
case params[:contest_sort_type]
when '0'
# modified by longjun
- # never use unless and else
+ # never use unless and else, 将下面重复操作模块化,放在private下
# unless @offset == 0
- if @offset != 0
- @contests = @contests.reorder('contests.commit').offset(@offset).limit(@limit).all.reverse
- else
- limit = @contest_count % @limit
- limit = @limit if limit == 0
- @contests = @contests.reorder('contests.commit').offset(@offset).limit(limit).all.reverse
- end
+ # if @offset != 0
+ # @contests = @contests.reorder('contests.commit').offset(@offset).limit(@limit).all.reverse
+ # else
+ # limit = @contest_count % @limit
+ # limit = @limit if limit == 0
+ # @contests = @contests.reorder('contests.commit').offset(@offset).limit(limit).all.reverse
+
+ @contests = index_page_sort(@offset, @limit, @contest_count, @contests, 'contests.commit')
+ # end
@s_state = 0
when '1'
- # modified by longjun
- # never use unless and else
- # unless @offset == 0
- if @offset != 0
- @contests = @contests.reorder('contests.created_on').offset(@offset).limit(@limit).all.reverse
- else
- limit = @contest_count % @limit
- limit = @limit if limit == 0
- @contests = @contests.reorder('contests.created_on').offset(@offset).limit(limit).all.reverse
- end
+
+ @contests = index_page_sort(@offset, @limit, @contest_count, @contests, 'contests.created_on')
@s_state = 1
- when '2'
- # modified by longjun
- # never use unless and else
- # unless @offset == 0
- if @offset != 0
- @contests = @contests.offset(@offset).limit(@limit).all.reverse
+ # modified by longjun
+ # 目前只有 0, 1 两个sort_type
+ # when '2'
else
- limit = @contest_count % @limit
- limit = @limit if limit == 0
- @contests = @contests.offset(@offset).limit(@limit).all.reverse
- end
+ # end longjun
+
+ @contests = index_page_sort(@offset, @limit, @contest_count, @contests, '')
@s_state = 0
end
else
@@ -723,5 +713,20 @@ class ContestsController < ApplicationController
end
end
+ # added by longjun
+ # 将index页面中分页排序的方法抽离出来
+ def index_page_sort(offset, limit, contest_count, contests, contest_sort_by)
+ # modified by longjun
+ # never use unless and else
+ # unless @offset == 0
+ if offset != 0
+ contests = contests.reorder(contest_sort_by).offset(offset).limit(limit).all.reverse
+ else
+ limit = contest_count % limit
+ limit = limit if limit == 0
+ contests = contests.reorder(contest_sort_by).offset(offset).limit(limit).all.reverse
+ end
+ contests
+ end
end
diff --git a/app/controllers/memos_controller.rb b/app/controllers/memos_controller.rb
index 1e537ff75..aad575ee5 100644
--- a/app/controllers/memos_controller.rb
+++ b/app/controllers/memos_controller.rb
@@ -62,7 +62,7 @@ class MemosController < ApplicationController
format.html { redirect_to back_memo_url, notice: "#{l :label_memo_create_succ}" }
format.json { render json: @memo, status: :created, location: @memo }
else
- flash[:error] = "#{l :label_memo_create_fail}: #{@memo.errors.full_messages[0]}"
+ flash.now[:error] = "#{l :label_memo_create_fail}: #{@memo.errors.full_messages[0]}"
# back_error_page = @memo.parent_id.nil? ? forum_path(@forum) : forum_memo_path(@forum, @memo.parent_id)
pre_count = REPLIES_PER_PAGE
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 38b97a501..f976918d8 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -122,12 +122,24 @@ module ApplicationHelper
s
end
+ # Generates a link to an attachment.
+ # Options:
+ # * :text - Link text (default to attachment filename)
+ # * :download - Force download (default: false)
+ def link_to_short_attachment(attachment, options={})
+ text = h(truncate(options.delete(:text) || attachment.filename, length: 25, omission: '...'))
+ route_method = options.delete(:download) ? :download_named_attachment_path : :named_attachment_path
+ html_options = options.slice!(:only_path)
+ url = send(route_method, attachment, attachment.filename, options)
+ link_to text, url, html_options
+ end
+
# Generates a link to an attachment.
# Options:
# * :text - Link text (default to attachment filename)
# * :download - Force download (default: false)
def link_to_attachment(attachment, options={})
- text = h(truncate(options.delete(:text) || attachment.filename, length: 60, omission: '...'))
+ text = options.delete(:text) || attachment.filename
route_method = options.delete(:download) ? :download_named_attachment_path : :named_attachment_path
html_options = options.slice!(:only_path)
url = send(route_method, attachment, attachment.filename, options)
diff --git a/app/views/attachments/_app_link.html.erb b/app/views/attachments/_app_link.html.erb
index 6934b76e1..263f51dc8 100644
--- a/app/views/attachments/_app_link.html.erb
+++ b/app/views/attachments/_app_link.html.erb
@@ -3,13 +3,15 @@
<% if attachments.count > 1 && attachment != attachments.first%>
<% end %>
- <%= link_to_attachment attachment, :class => 'icon icon-attachment', :download => true -%>
+ <%= link_to_short_attachment attachment, :class => 'icon icon-attachment', :download => true -%>
<% if attachment.is_text? %>
<%= link_to image_tag('magnifier.png'),
:controller => 'attachments', :action => 'show',
:id => attachment, :filename => attachment.filename %>
<% end %>
- <%= h(" - #{attachment.description}") unless attachment.description.blank? %>
+
+ <%= h(truncate(" - #{attachment.description}", length: 20, omission: '...')) unless attachment.description.blank? %>
+
(<%= number_to_human_size attachment.filesize %>)
<% end -%>
diff --git a/app/views/attachments/_links.html.erb b/app/views/attachments/_links.html.erb
index 4c4065d09..de43dce4c 100644
--- a/app/views/attachments/_links.html.erb
+++ b/app/views/attachments/_links.html.erb
@@ -2,7 +2,7 @@
<% for attachment in attachments %>
<%= f.text_field :deadline, :required => true, diff --git a/app/views/contests/_list_projects.html.erb b/app/views/contests/_list_projects.html.erb index fec4cf24c..2ffecff12 100644 --- a/app/views/contests/_list_projects.html.erb +++ b/app/views/contests/_list_projects.html.erb @@ -78,7 +78,9 @@ <%= l(:label_contest_user) %> <% unless c_project.user.nil? %> - <%= link_to c_project.user.lastname + c_project.user.firstname,user_path(c_project.user) %> + <%= link_to c_project.user.lastname + c_project.user.firstname, + user_path(c_project.user) + %> <% end %> @@ -101,5 +103,7 @@ <% end %> <% end %> -
diff --git a/app/views/messages/_form.html.erb b/app/views/messages/_form.html.erb index 8dafdf173..0856da976 100644 --- a/app/views/messages/_form.html.erb +++ b/app/views/messages/_form.html.erb @@ -3,44 +3,44 @@ <% replying ||= false %>
- <%= f.text_field :subject, :size => 60, :style => "width: 99%;display:none;", :id => "message_subject" %> -
- <% else %> -- <%= f.text_field :subject, :size => 60, :style => "width: 99%;display:none;", :id => "message_subject", :readonly => true %> -
- <% end %> -- <% unless replying %> - <% if @message.safe_attribute? 'sticky' %> + + <% unless replying %> +
+ <%= f.text_field :subject, :size => 60, :style => "width: 99%;", :id => "message_subject" %>
+
+ <%= f.text_field :subject, :size => 60, :style => "width: 99%;", :id => "message_subject", :readonly => true %>
+
+ <% unless replying %> + <% if @message.safe_attribute? 'sticky' %> <%= f.check_box :sticky %> <%= label_tag 'message_sticky', l(:label_board_sticky) %> - <% end %> - <% if @message.safe_attribute? 'locked' %> + <% end %> + <% if @message.safe_attribute? 'locked' %> <%= f.check_box :locked %> <%= label_tag 'message_locked', l(:label_board_locked) %> - <% end %> + <% end %> <% end %> -
--
++ -
- <%= text_area :quote,:quote,:style => 'display:none' %> - -- <%= label_tag "message_content", l(:description_message_content), :class => "hidden-for-sighted" %> - <%= f.text_area :content, :cols => 80, :rows => 13, :class => 'wiki-edit', :id => 'message_content' %> -
+ + <%= text_area :quote,:quote,:style => 'display:none' %> + ++ <%= label_tag "message_content", l(:description_message_content), :class => "hidden-for-sighted" %> + <%= f.text_area :content, :cols => 80, :rows => 13, :class => 'wiki-edit', :id => 'message_content' %> +
- + -
- <%= l(:label_attachment_plural) %>
-
- <%= render :partial => 'attachments/form_course', :locals => {:container => @message,:isReply => @isReply} %>
-
+ <%= l(:label_attachment_plural) %>
+
+ <%= render :partial => 'attachments/form_course', :locals => {:container => @message,:isReply => @isReply} %>
+