diff --git a/app/controllers/libraries_controller.rb b/app/controllers/libraries_controller.rb index ce34e603..4b73a246 100644 --- a/app/controllers/libraries_controller.rb +++ b/app/controllers/libraries_controller.rb @@ -1,11 +1,13 @@ class LibrariesController < ApplicationController + layout 'base_library' + before_filter :require_login def index libraries = Library.where(nil) libraries = - if params[:filter] == 'mine' + if params[:type] == 'mine' libraries.where(user_id: current_user.id).order('created_at desc') else libraries.where(status: :published).order('visited_count desc') @@ -14,11 +16,15 @@ class LibrariesController < ApplicationController search = params[:search].to_s.strip libraries = libraries.where('title LIKE ?', "%#{search}%") if search.present? - @libraries = paginateHelper libraries.includes(user: :user_extensions) + per_page = params[:per_page].to_i <= 0 ? 20 : params[:per_page].to_i + @libraries = paginateHelper libraries.includes(user: :user_extensions), per_page end def show @library = Library.find(params[:id]) + return redirect_to libraries_path unless admin_or_self? + + @library_applies = @library.library_applies.where(status: :refused).order('created_at desc') @library.increment_visited_count! end @@ -28,22 +34,41 @@ class LibrariesController < ApplicationController def create @library = current_user.libraries.new - Libraries::SaveService.new(@library, current_user, params).call - redirect_to library_path(id: @library.id) + Libraries::SaveService.new(@library, current_user, form_params).call + if with_publish? + Libraries::SubmitService.new(current_library).call + redirect_to publish_success_libraries_path + else + flash[:message] = '保存成功' + render 'new' + end rescue ActiveRecord::RecordInvalid => _ render 'new' + rescue Libraries::SubmitService::Error => ex + flash[:message] = ex.message + render 'new' end def edit @library = current_library + redirect_to library_path(id: @library.id) unless @library.editable? end def update @library = current_library - Libraries::SaveService.new(@library, current_user, params).call - redirect_to library_path(id: @library.id) + Libraries::SaveService.new(@library, current_user, form_params).call + if with_publish? + Libraries::SubmitService.new(current_library).call + redirect_to publish_success_libraries_path + else + flash[:message] = '保存成功' + render 'edit' + end rescue ActiveRecord::RecordInvalid => _ render 'edit' + rescue Libraries::SubmitService::Error => ex + flash[:message] = ex.message + render 'edit' end def publish @@ -53,9 +78,28 @@ class LibrariesController < ApplicationController render json: { status: 0, message: ex.message } end + def publish_success + end + private def current_library @_current_library ||= current_user.libraries.find(params[:id]) end + + def form_params + @_form_params ||= begin + hash = params[:library].presence || {} + hash[:attachment_ids] = (params[:attachments].presence || []).values.map{|h| h[:attachment_id]} + hash + end + end + + def with_publish? + params[:apply_publish].to_s == 'true' + end + + def admin_or_self? + @library.user_id == current_user.id || current_user.admin? + end end \ No newline at end of file diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 83d80b3e..a50da8aa 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -7432,7 +7432,7 @@ def tiding_url tiding when 'Department' my_account_path when 'Library' - tiding.tiding_type == 'System' ? library_applies_path : library_path(tiding.container_id) + tiding.tiding_type == 'Apply' ? library_applies_path : library_path(tiding.container_id) end end diff --git a/app/models/library.rb b/app/models/library.rb index 735445c9..78bc7fc5 100644 --- a/app/models/library.rb +++ b/app/models/library.rb @@ -12,6 +12,8 @@ class Library < ActiveRecord::Base validates :content, presence: true validates :uuid, presence: true, uniqueness: true + acts_as_attachable + aasm(:status) do state :pending, initiali: true state :processing @@ -43,4 +45,8 @@ class Library < ActiveRecord::Base def increment_visited_count! Library.connection.execute("update libraries set visited_count = COALESCE(visited_count, 0) + 1 where id = #{id}") end + + def editable? + pending? || refused? + end end \ No newline at end of file diff --git a/app/models/tiding.rb b/app/models/tiding.rb index 6b40615c..91bcf0b9 100644 --- a/app/models/tiding.rb +++ b/app/models/tiding.rb @@ -359,12 +359,12 @@ class Tiding < ActiveRecord::Base when 'Department' "你选填的二级单位:#{self.container.try(:name)}(#{self.container.try(:school).name})因不符合规范,已被系统删除.请重新选择" when 'Library' - library = Library.find_by(id: container_id) + library = Library.find_by_id(container_id) if tiding_type == 'Apply' - "申请发布文库:#{library.try(:name)}" + "申请发布文库:#{library.try(:title)}" elsif tiding_type == 'System' text = status == 1 ? "审核已通过" : "审核未通过,
原因:#{extra}" - "你提交的发布文库申请:#{library.try(:name)},#{text}" + "你提交的发布文库申请:#{library.try(:title)},#{text}" end else logger.error "error type: 1" diff --git a/app/services/libraries/refuse_apply_service.rb b/app/services/libraries/refuse_apply_service.rb index 5661773c..78fdbcb0 100644 --- a/app/services/libraries/refuse_apply_service.rb +++ b/app/services/libraries/refuse_apply_service.rb @@ -21,6 +21,8 @@ class Libraries::RefuseApplyService library_apply.refuse library_apply.save! + library.refuse! + # 将消息改为已处理 Tiding.where(container_id: library.id, container_type: 'Library', tiding_type: 'Apply', status: 0).update_all(status: 1) notify_library_author! diff --git a/app/views/attachments/_from_libraries.html.erb b/app/views/attachments/_from_libraries.html.erb index 4486ec13..4abb3c80 100644 --- a/app/views/attachments/_from_libraries.html.erb +++ b/app/views/attachments/_from_libraries.html.erb @@ -10,7 +10,7 @@ <% if defined?(container) && container && container.saved_attachments %> <% container.attachments.each_with_index do |attachment, i| %> - + <% size = judge_Chinese_num attachment.filename %> <%= text_field_tag("attachments[p#{i}][filename]", attachment.filename, :class => 'upload_filename readonly hidden color-grey fl', :size => size, :style => 'border:none; max-width:980px;white-space: nowrap; text-overflow:ellipsis;font-family: Consolas;', :readonly => 'readonly') %> <%= number_to_human_size attachment.filesize %> @@ -21,7 +21,7 @@ <% container.saved_attachments.each_with_index do |attachment, i| %> - + <%= text_field_tag("attachments[p#{i}][filename]", attachment.filename, :class => 'hidden atta_input readonly color-grey fl', :style => 'border:none; max-width:980px;', :readonly => 'readonly') %> <%= link_to(''.html_safe, attachment_path(attachment, :attachment_id => "p#{i}", :format => 'js'), :method => 'delete', :remote => true, :class => 'remove-upload fl mt2') unless attachment.id.nil? %> <%= hidden_field_tag "attachments[p#{i}][token]", "#{attachment.token}" %> diff --git a/app/views/layouts/_logined_header.html.erb b/app/views/layouts/_logined_header.html.erb index 30ef0658..077ef249 100644 --- a/app/views/layouts/_logined_header.html.erb +++ b/app/views/layouts/_logined_header.html.erb @@ -25,6 +25,7 @@ <%= link_to "认证", department_ecs_path(:school_id => User.current.ec_school) %> <% end %> +
  • "><%= link_to '文库', libraries_path %>
  • \ No newline at end of file diff --git a/app/views/libraries/publish.html.erb b/app/views/libraries/publish_success.html.erb similarity index 63% rename from app/views/libraries/publish.html.erb rename to app/views/libraries/publish_success.html.erb index 1c5a718c..372053e6 100644 --- a/app/views/libraries/publish.html.erb +++ b/app/views/libraries/publish_success.html.erb @@ -1,4 +1,3 @@ -
    @@ -8,8 +7,8 @@

    通过平台管理员审核后,即可公开显示

  • - 查看已上传文档 - 继续上传 + <%= link_to '查看已上传文档', libraries_path(type: 'mine'), class: 'white-btn edu-blueline-btn changebtn mr20 fl' %> + <%= link_to '继续上传', new_library_path, class: 'white-btn edu-blueback-btn changebtn fl' %>
  • \ No newline at end of file diff --git a/app/views/libraries/show.html.erb b/app/views/libraries/show.html.erb index f8906b04..1c23d979 100644 --- a/app/views/libraries/show.html.erb +++ b/app/views/libraries/show.html.erb @@ -1,57 +1,69 @@ +<% + admin_or_self = User.current.admin? || @library.user_id == User.current.id +%>

    - 胡莎莎 > - 文库 > - 新建 + <%= link_to '文库', libraries_path, class: 'color-grey-9' %> > + 详情

    - C语言程序教学案例 - 草稿 - 返回 + <%= @library.title %> + <% if admin_or_self %> + <% if @library.pending? %> + 草稿 + <% elsif @library.processing? %> + 审核中 + <% elsif @library.refused? %> + 未通过 + <% end %> + <% end %> + <%= link_to('返回', libraries_path, class: 'fr color-grey-9 mt5') %>

    -
    -

    - 私有化原因 - (请按照提示修改,并在完成编辑后重新提交) - 点击展开 -

    -
    -
  • -

    2018-12-25 03:58

    -

    文档&视频的任何位置(包括文档标题、简介、文档等),都不允许出现任何有推广或宣传目的内容,如电话号码、电子邮箱地址、即时通讯工具号码等具体联系信息以及广告宣传语等,其中被警告多次而仍然添加广告内容的用户会被判定为广告用户,将接受封号处罚。

    -
  • -
  • -

    2018-12-25 03:58

    -

    文档&视频的任何位置(包括文档标题、简介、文档等),都不允许出现任何有推广或宣传目的内容,如电话号码、电子邮箱地址、即时通讯工具号码等具体联系信息宣传语等,其中被警告多次而仍然添加广告内容的用户会被判定为广告用户,将接受封号处罚。

    -
  • + <% if admin_or_self && !@library.published? && @library_applies.size > 0 %> +
    +

    + 私有化原因 + (请按照提示修改,并在完成编辑后重新提交) + 点击展开 +

    +
    + <% @library_applies.each do |apply| %> +
  • +

    <%= apply.updated_at.strftime('%Y-%m-%d %H:%M') %>

    +

    <%= apply.reason %>

    +
  • + <% end %> +
    -
    + <% end %>

    详情 - 编辑 + <% if admin_or_self && @library.editable? %> + <%= link_to '编辑', edit_library_path(id: @library.id), class: 'white-btn edu-blueline-btn fr' %> + <% end %>

    - +
    -
  • 胡莎莎
  • +
  • <%= @library.user.show_real_name %>
  • - 国防科技大学 - 教授 + <%= @library.user.school_name %> + <%= @library.user.identity %> - 编码:2018120409235950611737 - 上传时间:2018-12-04 09:23 + 编码:<%= @library.uuid %> + 上传时间:<%= @library.created_at.strftime('%Y-%m-%d %H:%M') %>
  • - +
    - + <%= render partial: 'attachments/links', locals: { attachments: @library.attachments, options: {} } %>
    @@ -63,11 +75,11 @@ if(at=="0"){ $(item).html('点击收起'); $(item).attr("at","1"); - $(".private_reason").css({height:"auto"}); + $(".private_reason").css({maxHeight:"unset"}); }else{ $(item).html('点击展开'); $(item).attr("at","0"); - $(".private_reason").css({height:"166px"}); + $(".private_reason").css({maxHeight:"150px"}); } } var homeworkDescr = editormd.markdownToHTML("labraries_editorMd_content", { @@ -77,20 +89,4 @@ flowChart: true, // 默认不解析 sequenceDiagram: true // 默认不解析 }); - - - -
    -
    - -
    -

    恭喜!

    -

    文档上传成功

    -
    -

    通过平台管理员审核后,即可公开显示

    -
  • - 查看已上传文档 - 继续上传 -
  • -
    -
    \ No newline at end of file + \ No newline at end of file diff --git a/app/views/managements/_libraries_index.html.erb b/app/views/managements/_libraries_index.html.erb deleted file mode 100644 index e69de29b..00000000 diff --git a/app/views/managements/library_applies/_library_apply_list.html.erb b/app/views/managements/library_applies/_library_apply_list.html.erb index 46fe1b54..81e6c1d4 100644 --- a/app/views/managements/library_applies/_library_apply_list.html.erb +++ b/app/views/managements/library_applies/_library_apply_list.html.erb @@ -66,7 +66,7 @@ if (data && data.status != -1) { $('#authentication_list .admin-con-box.apply-' + id).remove(); - if($('#authentication_list .admin-con-box').length < 5){ + if($('#authentication_list .admin-con-box').length == 0){ location.reload(); } } else { diff --git a/app/views/managements/library_applies/index.html.erb b/app/views/managements/library_applies/index.html.erb index 6cef2418..23d898c4 100644 --- a/app/views/managements/library_applies/index.html.erb +++ b/app/views/managements/library_applies/index.html.erb @@ -77,7 +77,7 @@ if (data && data.status != -1) { $('#authentication_list .admin-con-box.apply-' + id).remove(); - if($('#authentication_list .admin-con-box').length < 5){ + if($('#authentication_list .admin-con-box').length == 0){ location.reload(); } } else { diff --git a/config/routes.rb b/config/routes.rb index 6a053d70..5d523390 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2659,7 +2659,7 @@ RedmineApp::Application.routes.draw do ## oauth相关 resource :sso, only: [:show, :create] resources :libraries do - post :publish, on: :member + get :publish_success, on: :collection end get '/:sub_dir_name', :to => 'org_subfields#show', :as => 'show_subfield_without_id' diff --git a/db/migrate/20190626004605_create_libraries.rb b/db/migrate/20190626004605_create_libraries.rb index b782eacd..07e9c1d8 100644 --- a/db/migrate/20190626004605_create_libraries.rb +++ b/db/migrate/20190626004605_create_libraries.rb @@ -7,7 +7,7 @@ class CreateLibraries < ActiveRecord::Migration t.text :content t.string :uuid, unique: true t.string :status - t.integer :visited_count + t.integer :visited_count, default: 0 t.datetime :published_at t.timestamps diff --git a/public/stylesheets/educoder/edu-all.css b/public/stylesheets/educoder/edu-all.css index 49aeda33..b48526c6 100644 --- a/public/stylesheets/educoder/edu-all.css +++ b/public/stylesheets/educoder/edu-all.css @@ -3355,7 +3355,7 @@ line-height: 16px;display: inline-block;color: rgba(65, 140, 205, 1) !important; width: 100%;background: #F2F9FF;justify-content: center;align-items: center;display: -webkit-flex;text-align: center; height: 120px;border-radius: 4px;border:1px dashed #4cacff; } -.private_reason{overflow: hidden} +.private_reason{overflow: hidden;max-height:150px;} .private_reason li{margin-bottom: 10px;} .successPage{ justify-content: center;align-items: center;display: -webkit-flex;height: 570px;text-align: center;margin-bottom: 50px; diff --git a/public/stylesheets/educoder/edu-main.css b/public/stylesheets/educoder/edu-main.css index bab8eb70..fca9b02b 100644 --- a/public/stylesheets/educoder/edu-main.css +++ b/public/stylesheets/educoder/edu-main.css @@ -529,6 +529,10 @@ a.edu-blueback-btn{padding: 0px 10px;background: #4CACFF;color: #fff!important;b a.edu-blueline-btn{padding: 0px 10px;color: #4CACFF!important;border: 1px solid #4CACFF;} a.edu-blueback-btn:hover{background-color: #459BE6;} a.edu-blueline-btn:hover{border:1px solid #459BE6;color: #459BE6!important;} +input.edu-blueback-btn{padding: 0px 10px;background: #4CACFF;color: #fff!important;border: 1px solid #4CACFF;} +input.edu-blueline-btn{padding: 0px 10px;color: #4CACFF!important;border: 1px solid #4CACFF;} +input.edu-blueback-btn:hover{background-color: #459BE6;} +input.edu-blueline-btn:hover{border:1px solid #459BE6;color: #459BE6!important;} a.edu-orangeback-btn{background-color: #ff7500;color: #fff!important;border:1px solid #FF7500} a.edu-orangeback-btn:hover{background-color: #F06200;}