Compare commits

...

65 Commits

Author SHA1 Message Date
yystopf bfabcf112e Merge pull request '后台上传文件问题修复' (#266) from yystopf/forgeplus:hotfix_settings into dev_forum 2021-11-25 17:04:08 +08:00
viletyy d4e59e8773 fix: change attachment code 2021-11-25 16:59:53 +08:00
xxq250 d868953f8d Merge pull request '通知铃铛URL统一' (#261) from xxq250/forgeplus:hotfix_index_url into dev_forum 2021-11-24 18:35:24 +08:00
xiaoxiaoqiong 342c665e68 通知铃铛URL 2021-11-24 18:33:31 +08:00
yystopf 7a3539136e Merge pull request '更改网站图标' (#259) from yystopf/forgeplus:hotfix_settings into dev_forum 2021-11-24 15:52:31 +08:00
viletyy f60ba8ec07 fix: change website ico 2021-11-24 15:45:22 +08:00
yystopf e6f361b567 Merge pull request 'settings接口更改' (#258) from yystopf/forgeplus:hotfix_settings into dev_forum 2021-11-24 14:46:53 +08:00
viletyy e28ac9c319 add: settings personal add common 2021-11-24 14:43:25 +08:00
xxq250 65151d41bd Merge pull request '导航域名跳转配置' (#256) from xxq250/forgeplus:hotfix_index_url into dev_forum 2021-11-24 11:40:55 +08:00
xiaoxiaoqiong 53c65e9ee9 fix 域名跳转配置 2021-11-24 11:38:52 +08:00
xxq250 16ef6c2f85 Merge pull request '首页域名配置文件配置' (#255) from xxq250/forgeplus:hotfix_index_url into dev_forum 2021-11-24 10:42:00 +08:00
xiaoxiaoqiong b5f161f553 fix 首页域名配置文件配置 2021-11-24 10:39:18 +08:00
yystopf c7a089481a Merge pull request 'forge调用接口时,无须增加阅读数量' (#245) from yystopf/forgeplus:dev_forum into dev_forum 2021-11-11 17:47:49 +08:00
yystopf f941976a78 fix: add memos read data not increment view count 2021-11-11 17:44:02 +08:00
jasder 21b55eba83 ADD 版块管理授予平台管理员身份 2021-05-12 14:26:34 +08:00
jasder 273a17861b FIX bug 2021-05-11 18:30:06 +08:00
jasder 9f8a55fe12 FIX code bug 2021-05-11 18:23:20 +08:00
jasder 529e8e5fe6 FIX 一级板块加载帖子列表为空的bug 2021-05-11 18:20:59 +08:00
jasder f38e01edaf FIX *一级板块可以查看帖子
* 板块管理中的审核帖子添加超级管理员权限
2021-05-11 18:17:17 +08:00
Jasder 1be0a918a6 FIX CORS problem for develop 2021-01-29 11:13:03 +08:00
Jasder 82bd15d4ec fix cherry pick merge 458fca9992 2021-01-29 11:11:37 +08:00
sylor_huang@126.com 441589b7f2 Reset settings show.json about navbar url 2020-10-16 16:43:57 +08:00
sylor_huang@126.com 3c5e6effc9 Add Setting button 2020-10-16 16:26:15 +08:00
sylor_huang@126.com 15565e513e change 2020-10-16 15:11:10 +08:00
sylor_huang@126.com 38abe195c5 Reset Memo Replies Count1 2020-10-16 15:07:05 +08:00
sylor_huang@126.com 1809e580b7 Reset Memo Replies Count 2020-10-16 15:04:53 +08:00
sylor_huang@126.com c3c9f24e22 Remove Admins Extra sidebar, migrate memos replies_count 2020-10-16 15:00:16 +08:00
sylor_huang@126.com dffb859c38 change 2020-10-16 14:38:40 +08:00
sylor_huang@126.com 31a9b14639 change 2020-10-16 14:30:02 +08:00
sylor_huang@126.com f196977cd6 change 2020-10-16 14:23:31 +08:00
sylor_huang@126.com 6b7b6b9a66 change forum_sections index 2020-10-16 14:20:32 +08:00
sylor_huang@126.com a956d3d7ed change1 2020-10-15 19:10:18 +08:00
sylor_huang@126.com f4ed8086d4 change 2020-10-15 19:04:23 +08:00
sylor_huang@126.com 075100e468 change 2020-10-15 19:01:18 +08:00
sylor_huang@126.com 458e7147c5 Add Sync Forum 2020-10-15 18:45:50 +08:00
sylor_huang@126.com e404843eb7 change children_forum_id 2020-10-15 15:48:42 +08:00
sylor_huang@126.com 9143a96894 change current_image_url 2020-10-15 15:21:21 +08:00
sylor_huang@126.com 5ee88ee7d8 change current_image_url 2020-10-15 15:19:30 +08:00
sylor_huang@126.com 921655567a change my_interested bugs 2020-10-15 14:47:48 +08:00
sylor_huang@126.com 598571e8f4 Change User find_by errors 2020-10-15 13:59:03 +08:00
sylor_huang@126.com 5ae9c9bebc change user picture 2020-10-15 11:53:22 +08:00
sylor_huang@126.com 79b61913c5 Change assets precompile 2020-10-15 11:45:30 +08:00
sylor_huang@126.com 61e7091ece Change Forum Url 2020-10-15 11:27:54 +08:00
sylor_huang@126.com e9c118fb77 Change ForumUser Page 2020-10-15 10:02:10 +08:00
sylor_huang@126.com 84ff2e4bf5 Change ForumUser 2020-10-14 19:18:44 +08:00
sylor_huang@126.com 3062528fb0 change 2020-10-14 17:12:21 +08:00
sylor_huang@126.com 3fd76d2f9e Merge branch 'dev_forum' of http://git.trustie.net/jasder/forgeplus into dev_forum 2020-10-14 16:25:00 +08:00
sylor_huang@126.com d5e57da6d4 Change Bug 2020-10-14 16:24:47 +08:00
Jasder ae8b6b82f1 FIX forums page 500 bug 2020-10-14 16:09:23 +08:00
Jasder 4cd459ce58 Merge branch 'dev_forum' of http://git.trustie.net/jasder/forgeplus into dev_forum 2020-10-14 15:54:46 +08:00
sylor_huang@126.com 1f42076d20 Change Forum Backend Routes 2020-10-14 15:50:09 +08:00
sylor_huang@126.com 20dd1aeedf Add ForumSection admin manages 2020-10-14 15:31:43 +08:00
sylor_huang@126.com 8ad3160ab7 Change Bug 2020-10-14 09:55:49 +08:00
sylor_huang@126.com 93e887e0e5 Merge branch 'dev_trustie' into dev_forum 2020-10-14 09:41:30 +08:00
sylor_huang@126.com f3b88d77b0 Change 2020-10-14 09:40:25 +08:00
sylor_huang@126.com 5639a69f78 Change Forum 2020-10-13 19:25:17 +08:00
sylor_huang@126.com 141bf1a488 Add Memo API 2020-10-13 14:35:18 +08:00
Jasder 2383a0d21e Merge branch 'dev_forum' of http://git.trustie.net/jasder/forgeplus into dev_forum 2020-10-12 18:57:30 +08:00
sylor_huang@126.com fbec7a6e35 change 2020-10-12 18:09:13 +08:00
sylor_huang@126.com ce2deaf543 change add user memos relationships 2020-10-12 17:57:48 +08:00
sylor_huang@126.com dba0303428 change current_user method 2020-10-12 17:54:59 +08:00
sylor_huang@126.com d656e3c3b7 Change Application Controller 2020-10-12 17:46:17 +08:00
sylor_huang@126.com 4fa4e7493c Add Memo related models-2 2020-10-12 17:38:32 +08:00
sylor_huang@126.com 4d3a6c4811 Add Memo related models-1 2020-10-12 14:25:02 +08:00
sylor_huang@126.com 7c290482aa Add Memo related models 2020-10-12 14:19:33 +08:00
232 changed files with 49281 additions and 1173817 deletions

View File

@ -14,6 +14,7 @@ gem 'turbolinks', '~> 5'
gem 'jbuilder', '~> 2.5'
gem 'groupdate', '~> 4.1.0'
gem 'chartkick'
# gem 'grape', '~> 0.9.0'
gem 'grape-entity', '~> 0.7.1'
gem 'kaminari', '~> 1.1', '>= 1.1.1'
@ -47,7 +48,7 @@ gem 'redcarpet', '~> 3.4'
gem 'rqrcode', '~> 0.10.1'
gem 'rqrcode_png'
gem 'acts_as_tree', '~> 2.9', '>= 2.9.1'
gem 'acts-as-taggable-on', '~> 6.0'
# a tree structure
@ -128,3 +129,4 @@ gem 'request_store'
gem 'harmonious_dictionary', '~> 0.0.1'
gem 'parallel', '~> 1.19', '>= 1.19.1'

View File

@ -57,6 +57,8 @@ GEM
activerecord (>= 5.0, < 6.1)
acts_as_list (0.9.19)
activerecord (>= 3.0)
acts_as_tree (2.9.1)
activerecord (>= 3.0.0)
addressable (2.7.0)
public_suffix (>= 2.0.2, < 5.0)
ancestry (3.0.7)
@ -436,6 +438,7 @@ DEPENDENCIES
active_decorator
acts-as-taggable-on (~> 6.0)
acts_as_list
acts_as_tree (~> 2.9, >= 2.9.1)
ancestry
awesome_print
axlsx (~> 3.0.0.pre)

View File

@ -0,0 +1,4 @@
$(document).on('turbolinks:load', function() {
var $addSectionModal = $('.admin-import-user-modal');
});

View File

@ -0,0 +1,2 @@
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.

View File

@ -0,0 +1,7 @@
// .admins-banned-users-index-page {
// .width240 {
// width: 240px;
// }
// .mr15{margin-right: 15px;}
// .mt2{margin-top: 2px;}
// }

View File

@ -136,5 +136,36 @@
background: #fff;
}
.mt-10{margin-top: 10px;}
.nav_blueline_status{
list-style-type: none;
padding: 0;
margin: 0;
li {
padding: 0px 15px;
border-radius: 15px;
border: 1px solid #CDCDCD;
height: 30px;
line-height: 30px;
float: left;
margin-right: 30px;
a {
color: #CDCDCD!important;
display: block;
}
};
li.active {
border: 1px solid #4CACFF;
a {
color: #4CACFF!important;
}
}
}
.fr{float: right;}
.width240 {
width: 240px;
}
.mr15{margin-right: 15px;}
.mt2{margin-top: 2px;}
}

View File

@ -0,0 +1,11 @@
.admins-forum-moderators-index-page {
.df{
display: flex;
}
.flex1 {
flex: 1;
}
.text-center {
text-align: center;
}
}

View File

@ -0,0 +1,128 @@
.admins-forum-sections-index-page {
.color-grey{color: #888;}
.grid-item-top {
display: grid;
grid-template-columns: max-content 1fr;
align-self: start;
}
.mt20{margin-top: 20px;}
.none{display: none;}
.color-red{color: red!important;}
.upload-image-100 {
height: 100px;
width: 100px;
border-radius: 8px;
text-align: center;
/* line-height: 100px; */
background: #f5f5f5;
color: #999;
position: relative;
}
.pointer {
cursor: pointer;
}
.avatar100{
height: 100px;
width: 100px;
border-radius: 8px;
}
.upload-image-100:hover .admin-show-again-upload{display: block;}
.admin-show-again-upload {
bottom: 0;
width: 100px;
height: 100%;
line-height: 100px;
/* top: 0; */
background: rgba(0,0,0,0.6);
color: #fff;
position: absolute;
border-radius: 8px;
}
.menu_operate {
position: relative;
cursor: pointer;
.operateList {
position: absolute;
right: -110px;
top: 9px;
background: #fff;
width: 100px;
color: #999;
box-shadow: 0px 0px 9px rgba(0,0,0,0.2);
z-index: 100;
display: none;
a {
display: block;
height: 30px;
line-height: 30px;
padding: 0px 10px;
}
}
.operateList.active {
display: block !important;
}
}
.color-grey-6 {
color: #666!important;
}
.set_l_submenu {
padding-left: 50px;
display: none;
width: 180px;
list-style-type: none;
li{
padding: 4px 0;
}
}
.set_l_submenu.active {
display: block;
}
.set_l_premenu {
position: relative;
display: flex;
height: 30px;
line-height: 30px;
cursor: pointer;
}
.df{
display: flex;
}
.flex1 {
flex: 1;
}
.text-center {
text-align: center;
}
.grid-item-left {
display: grid;
grid-template-columns:1fr max-content;
align-self: start;
}
.ml20{margin-left: 20px;}
.forum-moderators-items {
padding: 10px 30px;
max-height: 175px;
overflow-y: auto;
background: #F4FAFF;
margin-top: 20px;
}
.mr4 {margin-right: 4px;}
.blue-user-btn {
margin: 0 5px;
padding: 2px 8px;
background: #F4F8FA!important;
color: #fff!important;
border: 1px solid #4CACFF;
border-radius: 4px;
white-space: nowrap;
}
.mr5 {
margin-right: 5px;
}
.moderator-list-content{
display: inline-block;
margin: 5px 0;
}
}

View File

@ -0,0 +1,5 @@
.admins-memos-index-page {
.users-list-container {
text-align: center;
}
}

View File

@ -0,0 +1,3 @@
// Place all the styles related to the customers controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

View File

@ -0,0 +1,31 @@
class Admins::ApplyDestroyController < Admins::BaseController
def index
memos = Memo.where(destroy_status: 1).includes(:author).order("created_at desc")
@memos = paginate memos
respond_to do |format|
format.html
format.js
end
end
def confirm_apply_destroy
memo = Memo.find(params[:id])
apply_status = params[:confirm]
if apply_status == "delete"
memo.destroy
extra = "d_2"
Tiding.create!(:user_id => memo.author_id, :trigger_user_id => 0,
container_id: memo.id, container_type: 'Memo',
:viewed => 0, :tiding_type => "System", :extra => "d_2")
else
memo.common!
memo.save
extra = "d_3"
Tiding.create!(:user_id => memo.author_id, :trigger_user_id => 0,
container_id: memo.id, container_type: 'Memo',
:viewed => 0, :tiding_type => "System", :extra => "d_3")
end
@status = 1
@message = "操作成功"
end
end

View File

@ -0,0 +1,66 @@
class Admins::BannedUsersController < Admins::BaseController
# include Admins::BaseHelper
def index
@menu_type = 8
@sub_type = 6
#被禁言的用户
all_banned_users = BannedForum.includes(:memo, :author, user: :user_extensions)
banned_true = all_banned_users.where(is_banned: true)
@banned_users_size = banned_true.size
@banned_type = params[:banned_type] || "banned"
@search_params = params[:search] || nil
if @banned_type == "banned"
banned_users = banned_true
else
banned_users = all_banned_users.where(is_banned: false)
end
if @search_params.present?
banned_users = banned_users.joins(:user).where("LOWER(users.login) LIKE ? or LOWER(concat(users.lastname, users.firstname)) LIKE ?", "%#{@search_params}%", "%#{@search_params}%")
end
banned_users = banned_users.order("updated_at desc")
@banned_users_count = banned_users.size
@banned_users = paginate banned_users
# page = (params[:page] || 1).to_i
# per_page = 15
# @banned_users_pages = Paginator.new @banned_users_count, per_page, page
# @banned_users = banned_users.limit(@banned_users_pages.per_page).offset(@banned_users_pages.offset).to_a
end
def confirm_banned
if params[:user_id].blank? || params[:id].blank?
@status = -1
@message = "参数缺失"
else
before_users_banned = BannedForum.where(user_id:params[:user_id])
banned_params = {
user_id: params[:user_id],
author_id: current_user.id,
memo_id: params[:id],
is_banned: false,
banned_count: before_users_banned.present? ? (before_users_banned.last.banned_count + 1) : 1
}
new_banned = BannedForum.new(banned_params)
if new_banned.save
before_users_banned&.update_all(is_banned: false) if before_users_banned.present?
@status = 1
@message = "取消禁言成功"
else
@status = -1
@message = "取消禁言失败,请稍后重试"
end
end
end
end

View File

@ -43,4 +43,30 @@ class Admins::BaseController < ApplicationController
def setup_laboratory
Laboratory.current = Laboratory.find_by_subdomain(request.subdomain) || Laboratory.find(1)
end
def up_and_down(opr,current_target,position,model_name)
modal_target = model_name.capitalize.classify.constantize
if model_name == "forum_section" #只有root才能移动
modal_target = modal_target.roots
end
if opr.to_s == "up"
last_target = modal_target.where("position > ?",position)&.first
if last_target.present?
current_target.update_attribute(:position, last_target.position)
last_target.update_attribute(:position, position) # 重新获取当前问题的位置
return 0
else
return -1
end
elsif opr.to_s == "down"
next_target = modal_target.where("position < ?",position)&.last
if next_target.present?
current_target.update_attribute(:position, next_target.position)
next_target.update_attribute(:position, position)
return 0
else
return -1
end
end
end
end

View File

@ -0,0 +1,89 @@
class Admins::ForumAppliesController < Admins::BaseController
# include Admins::BaseHelper
def index
@menu_type = 8
@sub_type = 7
all_forum_applies = ApplyForum.includes(:forum_section,:reviews, user: :user_extensions)
@select_type = params[:select_type] || "unconfirm"
@section_name = params[:section_name] || nil
@search_name = params[:user_name] || nil
if @select_type == "unconfirm"
forum_applies = all_forum_applies.where(is_confirm: 0)
else
forum_applies = all_forum_applies.where(is_confirm: [1,2])
end
if @section_name.present?
forum_applies = forum_applies.joins(:forum_section).where("forum_sections.title like ?", "%#{@section_name}%")
end
if @search_name.present?
forum_applies = forum_applies.joins(:user).where("LOWER(users.login) LIKE ? or LOWER(concat(users.lastname, users.firstname)) LIKE ?", "%#{@search_name}%", "%#{@search_name}%")
end
forum_applies = forum_applies.order("apply_forums.updated_at desc")
@forum_applies_count = forum_applies.size
@forum_applies = paginate forum_applies
# page = (params[:page] || 1).to_i
# per_page = 15
# @forum_applies_pages = Paginator.new @forum_applies_count, per_page, page
# @forum_applies = forum_applies.limit(@forum_applies_pages.per_page).offset(@forum_applies_pages.offset).to_a
end
def confirm_apply
@forum_apply = ApplyForum.find(params[:id])
@is_confirm = params[:is_confirm].to_i
review_result = params[:review_result].to_i
review_params = {
review_status: review_result,
reason: params[:reason].present? ? params[:reason] : nil,
user_id: current_user.id,
reviewable_type: "ApplyForum",
reviewable_id: params[:id],
source: "apply_forum"
}
if Review.exists?(reviewable_type: "ApplyForum", reviewable_id: params[:id], source: "apply_forum")
this_review = Review.where(reviewable_type: "ApplyForum", reviewable_id: params[:id], source: "apply_forum").first
if this_review.update_attributes(review_params)
@status = 1
@message = "操作成功"
else
@status = -1
@message = "操作失败"
end
else
review = Review.new(review_params)
if review.save
@status = 1
@message = "操作成功"
else
@status = -1
@message = "操作失败"
end
end
if @status > 0
@forum_apply.update_attributes(is_confirm: (review_result+1),deal_time: Time.now)
exists_moder = ForumModerator.where(user_id: @forum_apply.user_id,forum_section_id: @forum_apply.forum_section_id)
if review_result == 1
exists_moder.delete_all if exists_moder.exists?
elsif review_result == 0
unless exists_moder.exists?
ForumModerator.create(user_id: @forum_apply.user_id, forum_section_id: @forum_apply.forum_section_id,is_children: @forum_apply.forum_section.try(:parent_id).present?)
end
end
Tiding.where(container_type: "ForumSection", container_id: @forum_apply.forum_section_id, status: 0).update_all(status: 1)
Tiding.create(:user_id => @forum_apply.user_id, :trigger_user_id => 1,
container_id: @forum_apply.forum_section_id, container_type: 'ForumSection',
:parent_container_id => @forum_apply.id, :parent_container_type => "ApplyForum",
:viewed => 0,status: 1, :tiding_type => "System",extra: "4")
end
end
end

View File

@ -0,0 +1,59 @@
class Admins::ForumModeratorsController < Admins::BaseController
before_action :set_forum
def new
end
def create
user_ids = params[:member_ids]
is_children = @forum_section.parent_id.present?
if user_ids.present? && user_ids.size > 0
user_ids = user_ids.reject(&:blank?)
user_ids.each do |user_id|
unless ForumModerator.exists?(user_id: user_id, forum_section_id: @forum_section.id)
@forum_section.forum_moderators.create!(user_id: user_id, is_children: is_children)
end
unless is_children
children_forum_sections = @forum_section.children_forum
children_forum_sections.each do |children|
unless ForumModerator.exists?(user_id: user_id, forum_section_id: children.id)
children.forum_moderators.create!(user_id: user_id, is_children: true)
end
end
end
end
@forum_moderators = @forum_section.forum_moderators
@forum_status = 1
else
@forum_status = -1
end
end
def destroy
@forum_moderator = ForumModerator.find_by_id(params[:id])
@forum_moderator.destroy
end
def search_user
return_html = ""
user_name = params[:user_name].strip
if user_name.present?
users = User.where("( LOWER(login) LIKE ? or LOWER(concat(lastname, firstname)) LIKE ? or LOWER(mail) LIKE ? )",
"%#{user_name}%","%#{user_name}%","%#{user_name}%")
users.each do |u|
check_html = "<div class='search-user-check'><input id='check_user_#{u.login}' class='magic-checkbox mr4' type='checkbox' name='member_ids[]' value=""#{u.id}"" checked='false'><label for='check_user_#{u.login}'>#{u.try(:show_real_name)}</label></div>"
return_html << check_html
end
end
render json: {html: return_html }
end
private
def set_forum
@forum_section = ForumSection.find_by_id(params[:forum_section_id])
end
end

View File

@ -0,0 +1,153 @@
#论坛的板块设置
class Admins::ForumSectionsController < Admins::BaseController
before_action :set_forum, except: [:index, :new,:create]
def index
@menu_type = 8
@sub_type = 5
forum_sections = ForumSection.roots.includes(:forum_moderators).order("position desc")
@max_position = forum_sections&.maximum(:position).to_i
@min_position = forum_sections&.minimum(:position).to_i
@forum_sections_count = forum_sections.size
# page = (params[:page] || 1).to_i
# per_page = 15
# @forum_sections_pages = Paginator.new @forum_sections_count, per_page, page
# @forum_sections = forum_sections.limit(@forum_sections_pages.per_page).offset(@forum_sections_pages.offset).to_a
@forum_sections = paginate forum_sections
respond_to do |format|
format.html
format.js
end
end
def new
@parent_id = params[:parent_id]
@forum_section = ForumSection.new
respond_to do |format|
format.js
end
end
def create
attachment_id = params[:attachments]&.first
positions = ForumSection.pluck(:position).select { |a| a.is_a? Integer }
positions = positions.max.to_i
if params[:forum_section][:parent_id].present?
@parent_forum = ForumSection.find_by_id(params[:forum_section][:parent_id])
end
if params[:forum_section][:title].blank?
forum_status = 0
forum_msg = "标题不能为空"
elsif params[:forum_section][:title].strip.length > 20
forum_status = 0
forum_msg = "不能超过最大限制20个字符"
elsif ForumSection.exists?(title: params[:forum_section][:title].strip)
forum_status = 0
forum_msg = "不能重名"
else
forum_section_params = {
user_id: current_user.id,
title: params[:forum_section][:title].strip,
position: positions + 1,
parent_id: params[:forum_section][:parent_id],
is_recommend: false,
description: params[:forum_section][:description].to_s.truncate(200)
}
@forum_section = ForumSection.new(forum_section_params)
if @forum_section.save
if attachment_id.present?
attachment = Attachment.find(attachment_id)
attachment.container = @forum_section
attachment.save
@forum_section.attachment_id = attachment_id
@forum_section.save
end
forum_status = 1
forum_msg = "创建成功"
else
forum_status = -1
forum_msg = "创建失败,请重试"
end
end
@forum_status = {status: forum_status, msg: forum_msg}
end
def edit
@children_forum = params[:children_forum]
@attachment = @forum_section.image_attachment
end
def update
attachment_id = params[:attachments]&.first
if params[:forum_section][:title].blank?
forum_status = 0
forum_msg = "名称不能为空"
elsif params[:forum_section][:title].strip.length > 20
forum_status = 0
forum_msg = "不能超过最大限制20个字符"
elsif params[:forum_section][:title].strip != @forum_section.title && ForumSection.exists?(title: params[:forum_section][:title].strip)
forum_status = 0
forum_msg = "不能重名"
else
if @forum_section.update_attributes(title: params[:forum_section][:title].strip, description: params[:forum_section][:description].to_s.truncate(200))
unless attachment_id.blank? || @forum_section.attachment_id.to_i == attachment_id.to_i
Attachment.where(id: @forum_section.attachment_id.to_i).destroy_all if @forum_section.attachment_id.present?
attachment = Attachment.find(attachment_id)
attachment.container = @forum_section
attachment.save
@forum_section.attachment_id = attachment_id
@forum_section.save
end
forum_status = 1
forum_msg = "更新成功"
else
forum_status = -1
forum_msg = "更新失败,请重试"
end
end
@edit_forum_status = {status: forum_status, msg: forum_msg}
end
def destroy
if @forum_section.destroy
delete_status = 1
delete_msg = "删除成功"
else
delete_status = -1
delete_msg = "删除失败,请稍后重试"
end
@delete_status = {status: delete_status, msg: delete_msg}
end
def order_forums
@children_forums = @forum_section.get_children_section("asc")
end
def recommend_forums
@forum_section.update_attribute(:is_recommend, params[:is_recommend])
end
def move
cate_opt = params[:opr]
cate_position = @forum_section.position.to_i
move_status = up_and_down(cate_opt,@forum_section,cate_position,"forum_section")
if move_status == 0
@c_msg = "移动成功"
else
@c_msg = "移动失败"
end
redirect_to admins_forum_sections_path
end
private
def set_forum
@forum_section = ForumSection.find_by_id(params[:id])
end
end

View File

@ -6,6 +6,12 @@ class Admins::LaboratoriesController < Admins::BaseController
@laboratories = paginate laboratories.preload(:laboratory_users)
end
def new
respond_to do |format|
format.js
end
end
def create
Admins::CreateLaboratoryService.call(create_params)
render_ok

View File

@ -1,4 +1,11 @@
class Admins::LaboratorySettingsController < Admins::BaseController
def new
respond_to do |format|
format.js
end
end
def show
@laboratory = current_laboratory
end

View File

@ -0,0 +1,16 @@
class Admins::MemoReplyListsController < Admins::BaseController
def index
@memo_hidden_type = params[:hidden] || ""
memos = Memo.where("parent_id is not null").includes(:author, :parent)
if @memo_hidden_type.present?
memos = memos.where(hidden: @memo_hidden_type.to_s == "hidden")
end
memos = memos.order("created_at desc")
@memos = paginate memos
respond_to do |format|
format.html
format.js
end
end
end

View File

@ -0,0 +1,79 @@
class Admins::MemosController < Admins::BaseController
# include Admins::BaseHelper
# 帖子
def index
@memo_hidden_type = params[:hidden] || ""
memos = Memo.where(parent_id: nil).includes(:author)
if @memo_hidden_type.present?
memos = memos.where(hidden: @memo_hidden_type.to_s == "hidden")
end
memos = memos.order("created_at desc")
@memos = paginate memos
respond_to do |format|
format.html
format.js
end
end
def memo_homepage_show
memo = Memo.find params[:id]
memo.update_column(:homepage_show, params[:checked]) unless memo.hidden?
render :json => {status: 1, message: "设置成功!"}
end
def memo_hidden
memo = Memo.find params[:id]
if params[:checked].to_s == 'true'
publish_time = Time.now
action_type = "passed"
extra = "1"
else
publish_time = nil
action_type = "refuse"
extra = "2"
end
memo.update_attributes(hidden: !(params[:checked].to_s == 'true'), published_at: publish_time) # 勾选代表不隐藏,所以要取反
CheckedAction.create!(user_id: current_user.id,checkable_type: "Memo",checkable_id: params[:id], action_type: action_type, action_at: Time.now)
if !memo.hidden? && memo.parent_id.present? && !memo.tidings.exists?(user_id: memo.parent.author_id,trigger_user_id: memo.author_id, extra: "3")
Tiding.create(:user_id => memo.parent.author_id, :trigger_user_id => memo.author_id,
container_id: memo.id, container_type: 'Memo',
:parent_container_id => memo.root_id, :parent_container_type => "Memo",
:viewed => 0, :tiding_type => "Comment", :extra => "3")
elsif !memo.hidden? && memo.parent_id.blank?
Tiding.create(:user_id => memo.author_id, :trigger_user_id => current_user.id,
container_id: memo.id, container_type: 'Memo',
:viewed => 0, :tiding_type => "Comment",:extra => extra)
end
render :json => {status: 1, message: "设置成功!"}
end
def delete_memo
memo = Memo.find params[:id]
memo.destroy if memo.hidden?
redirect_to memo.parent_id.present? ? admins_memo_reply_lists_path : admins_memos_path
end
# def memo_reply_list
# @menu_type = 8
# @sub_type = 4
# @memo_hidden_type = params[:hidden] || ""
# Rails.logger.info("======================sub_type==================#@sub_type")
# memos = Memo.where("parent_id is not null").includes(:author, :parent)
# if @memo_hidden_type.present?
# memos = memos.where(hidden: @memo_hidden_type.to_s == "hidden")
# end
# memos = memos.order("created_at desc")
# @memos = paginate memos
# respond_to do |format|
# format.html
# format.js
# end
# end
end

View File

@ -28,8 +28,8 @@ class AttachmentsController < ApplicationController
update_downloads(@file)
end
def get_file
def get_file
normal_status(-1, "参数缺失") if params[:download_url].blank?
url = URI.encode(params[:download_url].to_s.gsub("http:", "https:"))
response = Faraday.get(url)
@ -45,7 +45,7 @@ class AttachmentsController < ApplicationController
uid_logger("#########################file_params####{params["#{params[:file_param_name]}"]}")
raise "未上传文件" unless upload_file
folder = edu_setting('attachment_folder')
folder = file_storage_directory
raise "存储目录未定义" unless folder.present?
month_folder = current_month_folder
@ -92,6 +92,52 @@ class AttachmentsController < ApplicationController
end
end
#后台上传图片
def upload_images
upload_file = params["file"] || params["#{params[:file_param_name]}"]# 这里的file_param_name是为了方便其他插件名称
raise "未上传文件" unless upload_file
folder = file_storage_directory
raise "存储目录未定义" unless folder.present?
month_folder = current_month_folder
save_path = File.join(folder, month_folder)
ext = file_ext(upload_file.original_filename)
local_path, digest = file_save_to_local(save_path, upload_file.tempfile, ext)
content_type = upload_file.content_type.presence || 'application/octet-stream'
remote_path = nil # TODO 暂时本地上传,待域名配置后方可上传至云端
logger.info "local_path: #{local_path}"
logger.info "remote_path: #{remote_path}"
disk_filename = local_path[save_path.size + 1, local_path.size]
@attachment = Attachment.where(disk_filename: disk_filename,
author_id: current_user.id,
cloud_url: remote_path).first
if @attachment.blank?
@attachment = Attachment.new
@attachment.filename = upload_file.original_filename
@attachment.disk_filename = local_path[save_path.size + 1, local_path.size]
@attachment.filesize = upload_file.tempfile.size
@attachment.content_type = content_type
@attachment.digest = digest
@attachment.author_id = current_user.id
@attachment.disk_directory = month_folder
@attachment.cloud_url = remote_path
@attachment.save!
@status = 1
else
@status = -1
end
respond_to do |format|
format.js
end
end
def destroy
begin
@file_path = absolute_path(local_path(@file))
@ -108,7 +154,7 @@ class AttachmentsController < ApplicationController
end
# 附件为视频时,点击播放
def preview_attachment
def preview_attachment
attachment = Attachment.find_by(id: params[:id])
dir_path = "#{Rails.root}/public/preview"
Dir.mkdir(dir_path) unless Dir.exist?(dir_path)
@ -118,10 +164,10 @@ class AttachmentsController < ApplicationController
else
normal_status(-1, "出现错误,请稍后重试")
end
else
else
if system("rm -rf #{dir_path}/#{attachment.disk_filename}")
normal_status(1, "操作成功")
else
else
normal_status(-1, "出现错误,请稍后重试")
end
end

View File

@ -0,0 +1,36 @@
# encoding=utf-8
class CategoriesController < ApplicationController
before_action :require_login, :except => [:all]
include ApplicationHelper
# 所有类型,通过参数过滤
def all
render_react
end
def guide
render_react
end
def techShare
render_react
end
def show
render_react
end
def shixun_discuss
render_react
end
# 我的发布
def my_published
end
private
def render_react
render "/common/index", :layout => false
end
end

View File

@ -35,15 +35,15 @@ module LaboratoryHelper
# my_projects: "/users/#{current_user.try(:login)}/projects",
# my_projects: "https://www.trustie.net/users/#{current_user.try(:login)}/user_projectlist",
{
new_syllabuses: "https://www.trustie.net/syllabuses/new",
new_course: "https://www.trustie.net/courses/new",
edit_account: "https://www.trustie.net/my/account",
my_courses: "https://www.trustie.net/users/#{current_user.try(:login)}/user_courselist",
my_projects: "/users/#{current_user.try(:login)}/projects",
my_organ: "https://www.trustie.net/users/#{current_user.try(:login)}/user_organizations",
default_url: "https://www.trustie.net/",
tiding_url: "https://www.trustie.net/users/#{current_user.try(:login)}/user_messages",
register_url: "https://www.trustie.net/login?login=false"
new_syllabuses: "#{Rails.application.config_for(:configuration)['platform_url']}/syllabuses/new",
new_course: "#{Rails.application.config_for(:configuration)['platform_url']}/courses/new",
edit_account: "#{Rails.application.config_for(:configuration)['platform_url']}/my/account",
my_courses: "#{Rails.application.config_for(:configuration)['platform_url']}/users/#{current_user.try(:login)}/user_courselist",
my_projects: "#{Rails.application.config_for(:configuration)['platform_url']}/users/#{current_user.try(:login)}/projects",
my_organ: "#{Rails.application.config_for(:configuration)['platform_url']}/users/#{current_user.try(:login)}/user_organizations",
default_url: Rails.application.config_for(:configuration)['platform_url'],
tiding_url: "#{Rails.application.config_for(:configuration)['platform_url']}/settings/notice",
register_url: "#{Rails.application.config_for(:configuration)['platform_url']}/login?login=false"
}
end
end

View File

@ -0,0 +1,11 @@
class CustomersController < ApplicationController
def show
targets = UsersService.new.user_info params, current_user
render json: targets
end
def edit_brief
targets = UsersService.new.edit_brief params, current_user
render json: targets
end
end

View File

@ -0,0 +1,101 @@
class ForumSectionsController < ApplicationController
def index
targets = ForumSectionsService.new.index params
render json: targets
end
def select_sections
targets = ForumSectionsService.new.select_sections
render json: targets
end
def user_apply
targets = ForumSectionsService.new.user_apply params, current_user, current_user_ip
render json: targets
end
def edit_notice
targets = ForumSectionsService.new.edit_notice params
render json: targets
end
def forum_section_header
targets = ForumSectionsService.new.forum_section_header params, current_user
render json: targets
end
def create
targets = ForumSectionsService.new.create params, current_user
render json: targets
end
def rename
targets = ForumSectionsService.new.rename params, current_user
render json: targets
end
def destroy_forum
targets = ForumSectionsService.new.destroy params, current_user
render json: targets
end
def order_forums
targets = ForumSectionsService.new.order_forums params, current_user
render json: targets
end
def search_users
targets = ForumSectionsService.new.search_users params, current_user
render json: targets
end
def add_users
targets = ForumSectionsService.new.add_users params, current_user
render json: targets
end
def managements
targets = ForumSectionsService.new.managements params, current_user
render json: targets
end
def applied_forums
targets = ForumSectionsService.new.applied_forums params, current_user
render json: targets
end
def deal_applies
targets = ForumSectionsService.new.deal_applies params, current_user
render json: targets
end
def destroy_moderator
targets = ForumSectionsService.new.destroy_moderator params, current_user
render json: targets
end
def unchecked_memos
targets = ForumSectionsService.new.unchecked_memos params, current_user
render json: targets
end
def unchecked_replies
targets = ForumSectionsService.new.unchecked_replies params, current_user
render json: targets
end
def checked_memos
targets = ForumSectionsService.new.checked_memos params, current_user
render json: targets
end
private
def current_user_ip
env['REMOTE_ADDR']
end
end

View File

@ -0,0 +1,434 @@
# encoding=utf-8
# For react
class ForumsController < ApplicationController
before_action :require_login, :only => [:new, :edit]
include ApplicationHelper
def show
render_react
end
def new
render_react
end
def index
render_react
end
def edit
render_react
end
def shixun_discuss
render_react
end
def manage
render_react
end
def detail
render_react
end
def theme
render_react
end
private
def render_react
render file: 'public/react/build/index.html', :layout => false
end
end
# # encoding: utf-8
# # added by fq
# class ForumsController < ApplicationController
# layout "users_base"
# include ApplicationHelper
# # GET /forums
# # GET /forums.json
# before_action :find_forum_if_available
# before_action :authenticate_user_edit, :only => [:edit, :update]
# before_action :authenticate_user_destroy, :only => [:destroy]
# before_action :require_login, :only => [:new, :create,:destroy,:update,:edit]
# before_action :check_authentication
#
# helper :sort
# include SortHelper
#
# PageLimit = 20
# def create_feedback
# if User.current.logged?
# #@memo = Memo.new(params[:memo])
# #@memo.forum_id = "1"
# #@memo.author_id = User.current.id
# #@forum = @memo.forum
# cs = CommentService.new
# @memo,message = cs.create_feedback params,User.current
# respond_to do |format|
# if !@memo.new_record?
# if params[:direct]
# format.html { redirect_to forums_path() }
# else
# format.html { redirect_to forum_path(@memo.forum) }
# end
# # format.html { redirect_to forum_path(@memo.forum) }
# else
# sort_init 'updated_at', 'desc'
# sort_update 'created_at' => "#{Memo.table_name}.created_at",
# 'replies' => "#{Memo.table_name}.replies_count",
# 'updated_at' => "COALESCE (last_replies_memos.created_at, #{Memo.table_name}.created_at)"
#
# @topic_count = @forum.topics.count
# @topic_pages = Paginator.new @topic_count, per_page_option, params['page']
# @memos = @forum.topics.
# reorder("#{Memo.table_name}.sticky DESC").
# includes(:last_reply).
# limit(@topic_pages.per_page).
# offset(@topic_pages.offset).
# order(sort_clause).
# preload(:author, {:last_reply => :author}).
# all
#
# 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)
# format.html { render action: :show, layout: 'base_forums' }#, error: "#{l :label_memo_create_fail}: #{@memo.errors.full_messages[0]}" }
# format.json { render json: @memo.errors, status: :unprocessable_entity }
# end
# end
# else
# respond_to do |format|
# format.html { redirect_to signin_path }
# end
# end
# end
#
# def mail_feedback
# @user = User.where(:id => params[:user_id]).first
# unless @user.nil?
# cs = CommentService.new
# @memo, message = cs.create_feedback params, @user
# end
# respond_to do |format|
# format.js
# end
# end
#
# def forum_create_memo
# @memo = Memo.new
# @my_forums_count = Forum.where(:creator_id => User.current.id).count
# @my_memos_count = Memo.where(:author_id => User.current.id).count
# @forums = Forum.reorder("topic_count desc,updated_at desc")
# respond_to do |format|
# format.js
# format.html {render layout: 'base_new_forum'}
# end
# end
#
# def create_memo
# @memo = Memo.new(params[:memo])
# @memo.forum_id = @forum.id
# @memo.author_id = User.current.id
#
# @memo.save_attachments(params[:attachments] || (params[:memo] && params[:memo][:uploads]))
#
# respond_to do |format|
# if @memo.save
# if params[:asset_id]
# ids = params[:asset_id].split(',')
# update_kindeditor_assets_owner ids ,@memo.id,OwnerTypeHelper::MEMO
# end
# #end
# format.html { redirect_to (forum_memo_url(@forum, (@memo.parent_id.nil? ? @memo : @memo.parent_id))), notice: "#{l :label_memo_create_succ}" }
# format.json { render json: @memo, status: :created, location: @memo }
# else
# sort_init 'updated_at', 'desc'
# sort_update 'created_at' => "#{Memo.table_name}.created_at",
# 'replies' => "#{Memo.table_name}.replies_count",
# 'updated_at' => "COALESCE (last_replies_memos.created_at, #{Memo.table_name}.created_at)"
#
# @topic_count = @forum.topics.count
# @topic_pages = Paginator.new @topic_count, per_page_option, params['page']
# @memos = @forum.topics.
# reorder("#{Memo.table_name}.sticky DESC").
# includes(:last_reply).
# limit(@topic_pages.per_page).
# offset(@topic_pages.offset).
# order(sort_clause).
# preload(:author, {:last_reply => :author}).
# all
# @memos
# 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)
# format.html { render action: :show, layout: 'base_forums' }#, error: "#{l :label_memo_create_fail}: #{@memo.errors.full_messages[0]}" }
# format.json { render json: @memo.errors, status: :unprocessable_entity }
# end
# end
# end
#
# # id: 1 问题反馈 3 操作指南 5 技术分享
# def index
#
# render "/common/index", :layout => false
# end
#
# # GET /forums/1
# # GET /forums/1.json
# def show
# # sort_init 'updated_at', 'desc'
# # sort_update 'created_at' => "#{Memo.table_name}.created_at",
# # 'replies' => "#{Memo.table_name}.replies_count",
# # 'updated_at' => "COALESCE (last_replies_memos.created_at, #{Memo.table_name}.created_at)"
# order = ""
# @order_str = ""
# if(params[:reorder_complex])
# order = "#{Memo.table_name}.sticky desc, last_replies_memos.created_at #{params[:reorder_complex]}, #{Memo.table_name}.created_at #{params[:reorder_complex]}"
# @order_str = "reorder_complex="+params[:reorder_complex]
# elsif(params[:reorder_popu])
# order = "#{Memo.table_name}.sticky desc, replies_count #{params[:reorder_popu]}"
# @order_str = "reorder_popu="+params[:reorder_popu]
# elsif(params[:reorder_time])
# order = "#{Memo.table_name}.sticky desc, #{Memo.table_name}.updated_at #{params[:reorder_time]}"
# @order_str = "reorder_time="+params[:reorder_time]
# else
# order = "#{Memo.table_name}.sticky desc, #{Memo.table_name}.updated_at desc"
# @order_str = "reorder_time=desc"
# end
# @memo = Memo.new(:forum => @forum)
# @topic_count = @forum.topics.count
# @limit = 20
# @is_remote = true
# @topic_pages = Paginator.new @topic_count, @limit, params['page'] || 1
# @memos = paginateHelper @forum.topics.includes(:last_reply).reorder(order).preload(:author, {:last_reply => :author}), @limit
# @my_topic_count = Memo.where("forum_id = #{@memo.forum_id} and parent_id is null").count
# @my_replies_count = Memo.where("forum_id = #{@memo.forum_id} and parent_id is not null").count
# @errors = params[:errors]
# # 推荐贴吧
# @forums = Forum.where("id !=?", @forum.id).reorder("topic_count desc,updated_at desc").first(3)
# respond_to do |format|
# format.js
# format.html {
# render :layout => 'base_new_forum'
# }# show.html.erb
# format.json { render json: @forum }
# end
# end
#
# # GET /forums/new
# # GET /forums/new.json
# def new
# @forum = Forum.new
# respond_to do |format|
# format.html # new.html.erb
# format.js
# format.json { render json: @forum }
# end
# end
#
# # GET /forums/1/edit
# def edit
# @forum = Forum.find(params[:id])
# respond_to do |format|
# format.html
# format.js
# end
# end
#
# # POST /forums
# # POST /forums.json
# def create
# @forum = Forum.new(params[:forum])
# @forum.creator_id = User.current.id
# if @forum.save
# # Time 2015-03-24 17:07:05
# # Author lizanle
# # Description after save后需要进行资源记录的更新
# # owner_type = 2 对应的是 forum
# @save_flag = true
# if params[:asset_id]
# ids = params[:asset_id].split(',')
# update_kindeditor_assets_owner ids, @forum.id, OwnerTypeHelper::FORUM
# end
# #end
# respond_to do |format|
# format.js{ redirect_to forums_path, notice: l(:label_forum_create_succ)}
# format.html { redirect_to @forum, notice: l(:label_forum_create_succ) }
# format.json { render json: @forum, status: :created, location: @forum }
# end
# else
# @save_flag=false
# respond_to do |format|
# flash.now[:error] = "#{l :label_forum_create_fail}: #{@forum.errors.full_messages[0]}"
# format.js
# format.html { render action: "new" }
# format.json { render json: @forum.errors, status: :unprocessable_entity }
# end
# end
# end
#
# # PUT /forums/1
# # PUT /forums/1.json
# def update
# @forum = Forum.find(params[:id])
# respond_to do |format|
# if @forum.update_attributes(params[:forum])
# format.js
# format.html { redirect_to @forum, notice: l(:label_forum_update_succ) }
# format.json { head :no_content }
# else
# flash.now[:error] = "#{l :label_forum_update_fail}: #{@forum.errors.full_messages[0]}"
# format.js
# format.html { render action: "edit" }
# format.json { render json: @forum.errors, status: :unprocessable_entity }
# end
# end
# end
#
# # DELETE /forums/1
# # DELETE /forums/1.json
# def destroy
# @forum = Forum.find(params[:id])
# @forum.destroy
#
# respond_to do |format|
# format.html { redirect_to forums_url }
# format.json { head :no_content }
# end
# end
#
# # 更新贴吧描述
# def update_memo_description
# @forum = Forum.find(params[:id])
# if @forum.blank?
# result = { :result => false }
# else
# forum_decription = params[:forum][:description]
# @forum.update_attributes(:description => forum_decription )
# result = { :result => true }
# end
# render :json => result
# end
#
# def search_forum
# # @forums = paginateHelper Forum.where("name LIKE '%#{params[:name]}%'")
# q = "%#{params[:name].strip}%"
# (redirect_to forums_url, :notice => l(:label_sumbit_empty);return) if params[:name].blank?
# @offset, @limit = api_offset_and_limit({:limit => 10})
# @forums_all = Forum.where("name LIKE ?", q)
# @forums_count = @forums_all.count
# @forums_pages = Paginator.new @forums_count, @limit, params['page']
#
# @offset ||= @forums_pages.offset
# @forums = @forums_all.offset(@offset).limit(@limit).all
# respond_to do |format|
# format.html {
# render 'index'
# }
# format.json { render json: @forums }
# end
# end
#
# def search_memo
# q = "%#{params[:name].strip}%"
#
# limit = PageLimit
# @memo = Memo.new
# @offset, @limit = api_offset_and_limit({:limit => limit})
# @forum = Forum.find(params[:id])
# @memos_all = @forum.topics.where("subject LIKE ?", q)
# @topic_count = @memos_all.count
# @topic_pages = Paginator.new @topic_count, @limit, params['page']
#
# @offset ||= @topic_pages.offset
# @memos = @memos_all.offset(@offset).limit(@limit).all
# respond_to do |format|
# format.html {
# render 'show', :layout => 'base_forums'
# }
# format.json { render json: @forum }
# end
# end
#
# #检查forum的名字
# def check_forum_name
# begin
# forum_name = params[:forum_name]
# if params[:forum_id]
# result = Forum.where("name = '#{forum_name}' and id != #{params[:forum_id]}").first.blank? ? {:result => true} : {:result => false}
# else
# result = Forum.where(:name => forum_name).first.blank? ? {:result => true} : {:result => false}
# end
# rescue Exception => e
# puts e
# end
# render :json => result
# # if params[:forum_id]
# # forum_name_exist = Forum.where("name = '#{params[:forum_name]}' and id != #{params[:forum_id]}").count >= 1 ? true : false
# # else
# # forum_name_exist = Forum.where("name = '#{params[:forum_name]}' ").count >= 1 ? true : false
# # end
# # render :text => forum_name_exist
# end
#
#
#
#
# #添加论坛tag
# def add_forum_tag
# @forum = Forum.find(params[:id])
# unless @forum.nil?
# @forum.tag_list.add(params[:tag_str].split(','))
# @forum.save
# end
# respond_to do |format|
# format.js {render :delete_forum_tag}
# end
# end
#
# #删除forum的tag
# def delete_forum_tag
# @tag_id = (ActsAsTaggableOn::Tag.find_by_name(params[:tag_name])).id
# #forum的taggable_type = 5
# @taggings = ActsAsTaggableOn::Tagging.find_by_tag_id_and_taggable_id_and_taggable_type(@tag_id,params[:id],'Forum')
#
# unless @taggings.nil?
# @taggings.delete
# end
#
# # 是否还有其他记录 引用了 tag_id
# @tagging = ActsAsTaggableOn::Tagging.find_by_tag_id(@tag_id)
# # 如果taggings表中记录已经不存在 那么检查tags表 作删除动作
# if @tagging.nil?
# @tag = ActsAsTaggableOn::Tag.find_by_id(@tag_id)
# @tag.delete unless @tag.nil?
# end
# @forum = Forum.find(params[:id])
# respond_to do |format|
# format.js
# end
# end
#
# private
#
# def find_forum_if_available
# @forum = Forum.find(params[:id]) if params[:id]
# rescue ActiveRecord::RecordNotFound
# render_404
# nil
# end
#
# def authenticate_user_edit
# find_forum_if_available
# render_403 unless @forum.editable_by? User.current
# end
#
# def authenticate_user_destroy
# find_forum_if_available
# render_403 unless @forum.destroyable_by? User.current
# end
# end

View File

@ -0,0 +1,109 @@
class MemosController < ApplicationController
before_action :require_login, only: [:create, :edit, :update, :watch_memo]
def index
memos = MemosService.new.index params, current_user
render json: memos
end
def related_memos
targets = MemosService.new.related_memos params, current_user
render json: targets
end
def edit
targets = MemosService.new.edit params, current_user
render json: targets
end
def update
targets = MemosService.new.update params, current_user
render json: targets
end
def create
params.permit!
targets = MemosService.new.create params, current_user
render json: targets
end
def show
targets = MemosService.new.show params, current_user
render json: targets
end
def watch_memo
targets = MemosService.new.watch_memo params, current_user
render json: targets
end
def hidden
Memo.find(params[:id]).update_attribute(:hidden, true)
{status: 0, message: "隐藏成功"}
end
def memo_hidden
targets = MemosService.new.memo_hidden params, current_user
render json: targets
end
def reply
targets = MemosService.new.reply params, current_user
render json: targets
end
def destroy
targets = MemosService.new.destroy params, current_user
render json: targets
end
def set_top_or_down
targets = MemosService.new.set_top_or_down params, current_user
render json: targets
end
def is_fine
targets = MemosService.new.is_fine params, current_user
render json: targets
end
def banned_user
targets = MemosService.new.banned_user params, current_user
render json: targets
end
def more_reply
targets = MemosService.new.more_reply params, current_user
render json: targets
end
def forum_memos
targets = MemosService.new.forum_memos params, current_user
render json: targets
end
def forum_memos_head
targets = MemosService.new.forum_memos_head params, current_user
render json: targets
end
def forum_memos_right
targets = MemosService.new.forum_memos_right params, current_user
render json: targets
end
def is_watch
targets = MemosService.new.is_watch params, current_user
render json: targets
end
def confirm_delete
targets = MemosService.new.confirm_delete params, current_user
render json: targets
end
def plus
targets = MemosService.new.plus params, current_user
render json: targets
end
end

View File

@ -0,0 +1,22 @@
class MyMemosController < ApplicationController
def index
targets = MyMemosService.new.index params, current_user
render json: targets
end
def my_interested
targets = MyMemosService.new.my_interested params, current_user
render json: targets
end
def replies_memos
targets = MyMemosService.new.replies_memos params,current_user
render json: targets
end
def recommend_memos
targets = MyMemosService.new.recommend_memos current_user
render json: targets
end
end

View File

@ -0,0 +1,30 @@
class PlatesController < ApplicationController
def index
render_react
end
def show
render_react
end
def all
render_react
end
def is_fine
render_react
end
def my_memos
render_react
end
def my_topics
render_react
end
private
def render_react
render "/common/index", :layout => false
end
end

View File

@ -2,5 +2,56 @@ class SettingsController < ApplicationController
def show
@old_projects_url = nil
@old_projects_url = "https://www.trustie.net/users/#{current_user.try(:login)}/projects" if User.current.logged?
get_add_menu
get_common_menu
get_personal_menu
end
private
def get_add_menu
@add = []
Site.add.select(:id, :name, :url, :key).to_a.map(&:serializable_hash).each do |site|
hash = {}
site.each {|k, v|
hash.merge!("#{k}": get_site_url(k, v))
}
@add << hash
end
end
def get_common_menu
@common = {}
Site.common.select(:url, :key).each do |site|
next if site["url"].to_s.include?("current_user") && !User.current.logged?
@common.merge!("#{site["key"]}": append_http(reset_site_url(site["url"])))
end
end
def get_personal_menu
@personal = []
if User.current.logged?
Site.personal.select(:id, :name, :url, :key).to_a.map(&:serializable_hash).each do |site|
hash = {}
site.each {|k, v|
hash.merge!("#{k}": get_site_url(k, v))
}
@personal << hash
end
end
end
def get_site_url(key, value)
key.to_s === "url" ? append_http(reset_site_url(value)) : reset_site_url(value)
end
def reset_site_url(url)
return url unless url.to_s.include?("current_user")
split_arr = url.split('current_user')
split_arr.length > 1 ? split_arr.join(current_user&.login) : (split_arr << current_user&.login).join('')
end
def append_http(url)
url.to_s.start_with?("http") ? url : [request.protocol, request.host_with_port, url].join('')
end
end

View File

@ -1,4 +1,5 @@
class UsersController < ApplicationController
include ApplicationHelper
before_action :load_user, only: [:show, :homepage_info, :sync_token, :sync_gitea_pwd, :projects, :watch_users, :fan_users]
before_action :check_user_exist, only: [:show, :homepage_info,:projects, :watch_users, :fan_users]
@ -66,7 +67,7 @@ class UsersController < ApplicationController
def attachment_show
file_name = params[:file_name]
path = params[:path] || edu_setting('attachment_folder')
path = params[:path] || file_storage_directory
send_file "#{path}/#{file_name}", :filename => "#{file_name}",
:type => 'game',
:disposition => 'attachment' #inline can open in browser

553
app/helpers/api_helper.rb Normal file
View File

@ -0,0 +1,553 @@
# encoding: utf-8
module ApiHelper
ONE_MINUTE = 60 * 1000
ONE_HOUR = 60 * ONE_MINUTE
ONE_DAY = 24 * ONE_HOUR
ONE_MONTH = 30 * ONE_DAY
ONE_YEAR = 12 * ONE_MONTH
#获取用户的工作单位
def get_user_work_unit user
work_unit = ""
if user.user_extensions.identity == 0 || user.user_extensions.identity == 1
work_unit = user.user_extensions.school.name unless user.user_extensions.school.nil?
elsif user.user_extensions.identity == 3
work_unit = user.user_extensions.occupation
elsif user.user_extensions.identity == 2
work_unit = user.firstname
end
work_unit
end
#获取用户地区
def get_user_location user
location = ""
location << (user.user_extensions.location || '')
location << (user.user_extensions.location_city || '')
location
end
def get_user_realname user
name = user.lastname + user.firstname
name.empty? || name.nil? || name == " " ? user.login : name
end
def get_assigned_homeworks(homeworks, n, index)
homeworks += homeworks
homeworks[index + 1 .. index + n]
end
def stars_to_json_like starts,show_jour,homework,show_real_name
result = []
starts.each do |s|
comment = get_homework_review homework,show_jour,s.rater
rater_name = show_real_name ? s.rater.login : l(:label_anonymous)
rater_id = show_real_name ? s.rater.id : ''
result << {:rater_id =>rater_id ,:rater_name => rater_name,:created_at => format_time(s.created_at),:stars => s.stars,:comment => comment}
end
result
end
#########################################################
#sw
#获取课程未匿评数量
#param: user => "用户", course_id => "查询的课程ID"
#return: 作业的数量
#########################################################
def get_course_anonymous_evaluation user,course
count = 0
if course
is_teacher = is_course_teacher user,course
if is_teacher #如果是老师,显示学生提交的作业数
course.homeworks.each do |bid|
count += bid.homeworks.count
end
else #如果是学生,显示未匿评的数量
course.homeworks.each do |bid|
count += get_student_not_batch_homework_list bid,user
end
end
end
[count,is_teacher]
end
def get_user_language user
(user.language.nil? || user.language == "") ? 'zh':user.language
end
# 学生获取课程作业的状态
def get_homework_status homework
homework_status = ""
if homework
if homework.homework_type == 1 && homework.homework_detail_manual
case homework.homework_detail_manual.comment_status
when 1
homework_status = show_homework_deadline homework
when 2
homework_status = "正在匿评"
when 3
homework_status = "匿评结束"
end
elsif homework.homework_type == 0
homework_status = "未启用匿评"
elsif homework.homework_type == 2
homework_status = "编程作业"
else
end
end
homework_status
end
#获取作业的是否可以匿评的描述
def homework_status_desc homework
if homework.homework_type == 1 && homework.homework_detail_manual #匿评作业
if homework.end_time >= Time.now
link = show_homework_deadline homework
elsif homework.student_works.count >= 2 #作业份数大于2
case homework.homework_detail_manual.comment_status
when 1
link = '启动匿评'
when 2
link = '关闭匿评'
when 3
link = " 匿评结束"
end
else
link = "提交作业数过少"
end
else
link = "未开启匿评作业"
end
link
end
#获取
def get_submit_sutdent_list homework
studentlist = []
if homework.is_a?(Hash) && homework.key?(:studentlist)
studentlist = homework[:studentlist]
else
homework.student_works.order("created_at desc").page(1).per(6).each do |work|
studentlist << work.user
end
end
studentlist
end
#计算作业的截止日期,剩余日期
def show_homework_deadline homework
day = 0
if (day = (Date.parse(homework.end_time.to_s) - Date.parse(Time.now.to_s)).to_i) > 0
"距作业截止还有" << day.to_s << ""
else
"已截止,但可补交"
end
end
#获取作业中学生的匿评比率
# 匿评比率 = 学生总共评价的作业的作业份数 / 作业份数 * 分配数 * 100%
# 教辅匿评比率 = 教辅已经评价的作业份数 / 总的作业份数 * 100%
def get_evaluation_part homework,role
homework_eva_completed_task_num = 0
homework_eva_task_num = 0
#匿评作业 # 且匿评状态不是还没有开启匿评
if homework.homework_type == 1 && homework.homework_detail_manual && homework.homework_detail_manual.comment_status != 1
# 总共需要评价的任务数
homework_eva_task_num = homework.homework_detail_manual.evaluation_num * homework.student_works.count
unless homework_eva_task_num == 0 #总任务数不为0 的情况下
#获取已经评价了多少的份作业 student_work_score里记录了评价情况每条记录有提交作业的id
#先求出提交作业的id集合
work_ids = "(" + homework.student_works.map(&:id).join(",") + ")"
#只要 student_work_score 中的 student_work_id在work_ids集合中那么久说明这个任务被完成了
sql = "select count(1) from student_works_scores where reviewer_role = #{role} and student_work_id in #{work_ids} "
homework_eva_completed_task_num = ActiveRecord::Base.connection().select_value(sql)
end
end
if homework_eva_task_num == 0
0
else
( homework_eva_completed_task_num / homework_eva_task_num.to_f * 100 ) .round(1)
end
end
# 获取当前时间
def time_from_now time
lastUpdateTime = time.to_i*1000
currentTime = Time.now.to_i*1000
timePassed = currentTime - lastUpdateTime
timeIntoFormat = 0
updateAtValue = ""
if timePassed < 0
updateAtValue = "刚刚"
elsif timePassed < ONE_MINUTE
updateAtValue = "1分钟前"
elsif timePassed < ONE_HOUR
timeIntoFormat = timePassed / ONE_MINUTE
updateAtValue = timeIntoFormat.to_s + "分钟前"
elsif (timePassed < ONE_DAY)
timeIntoFormat = timePassed / ONE_HOUR
updateAtValue = timeIntoFormat.to_s + "小时前"
elsif (timePassed < ONE_MONTH)
timeIntoFormat = timePassed / ONE_DAY
updateAtValue = timeIntoFormat.to_s + "天前"
elsif (timePassed < ONE_YEAR)
timeIntoFormat = timePassed / ONE_MONTH
updateAtValue = timeIntoFormat.to_s + "个月前"
else
timeIntoFormat = timePassed / ONE_YEAR
updateAtValue = timeIntoFormat.to_s + "年前"
end
updateAtValue
end
# 获取当前时间
def time_from_future time
lastUpdateTime = time.to_i*1000
currentTime = Time.now.to_i*1000
timePassed = lastUpdateTime - currentTime;
timeIntoFormat = 0
updateAtValue = ""
if timePassed < 0
updateAtValue = "马上"
elsif timePassed < ONE_MINUTE
updateAtValue = "1分钟"
elsif timePassed < ONE_HOUR
timeIntoFormat = timePassed / ONE_MINUTE
updateAtValue = timeIntoFormat.to_s + "分钟"
elsif (timePassed < ONE_DAY)
timeIntoFormat = timePassed / ONE_HOUR
updateAtValue = timeIntoFormat.to_s + "小时"
elsif (timePassed < ONE_MONTH)
timeIntoFormat = timePassed / ONE_DAY
updateAtValue = timeIntoFormat.to_s + ""
elsif (timePassed < ONE_YEAR)
timeIntoFormat = timePassed / ONE_MONTH
updateAtValue = timeIntoFormat.to_s + "个月"
else
timeIntoFormat = timePassed / ONE_YEAR
updateAtValue = timeIntoFormat.to_s + ""
end
updateAtValue
end
# 计算到结束还有多长时间 **天**小时**分
def how_much_time time
result = ""
result = ((time - Time.now.to_i).to_i / (24*60*60)).to_s + ""
result += (((time - Time.now.to_i).to_i % (24*60*60)) / (60*60)).to_s + " 小时 "
result += ((((time - Time.now.to_i).to_i % (24*60*60)) % (60*60)) / 60).to_s + ""
end
#日期转换为时间
def convert_to_time date, num
if num == 0
date = date.to_s + " 00:00"
elsif num == 1
date = date.to_s + " 23:59"
end
return date
end
#获取用户
def get_user user_id
user = User.find user_id
user
end
#获取项目
def get_project project_id
project = Project.find project_id
project
end
#获取课程
def get_course course_id
course = Course.find course_id
course
end
#获取点赞数
def get_activity_praise_num(object)
obj_type = object.class
obj_id = object.id
record = PraiseTreadCache.find_by_object_id_and_object_type(obj_id,obj_type)
if record
return ((record.praise_num.nil? ? 0 : record.praise_num.to_i)-(record.tread_num.nil? ? 0 : record.tread_num.to_i))
else
return 0
end
end
#获取缺陷的优先级
def get_issue_priority_api value
issuetype = ""
if value == 4
issuetype = "紧急"
elsif value == 2
issuetype = "正常"
elsif value == 3
issuetype = ""
elsif value == 1
issuetype = ""
else
issuetype = "立刻"
end
end
def jdetails_to_strings(details, no_html=false, options={})
options[:only_path] = (options[:only_path] == false ? false : true)
options[:token] = options[:token] if options[:token]
strings = []
values_by_field = {}
details.each do |detail|
if detail.property == 'cf'
field_id = detail.prop_key
field = CustomField.find_by_id(field_id)
if field && field.multiple?
values_by_field[field_id] ||= {:added => [], :deleted => []}
if detail.old_value
values_by_field[field_id][:deleted] << detail.old_value
end
if detail.value
values_by_field[field_id][:added] << detail.value
end
next
end
end
strings << jshow_detail(detail, no_html, options)
end
values_by_field.each do |field_id, changes|
detail = JournalDetail.new(:property => 'cf', :prop_key => field_id)
if changes[:added].any?
detail.value = changes[:added]
strings << jshow_detail(detail, no_html, options)
elsif changes[:deleted].any?
detail.old_value = changes[:deleted]
strings << jshow_detail(detail, no_html, options)
end
end
strings
end
# Returns the textual representation of a single journal detail
def jshow_detail(detail, no_html=false, options={})
multiple = false
case detail.property
when 'attr'
field = detail.prop_key.to_s.gsub(/\_id$/, "")
label = l(("field_" + field).to_sym)
case detail.prop_key
when 'due_date', 'start_date'
value = format_date(detail.value.to_date) if detail.value
old_value = format_date(detail.old_value.to_date) if detail.old_value
when 'project_id', 'status_id', 'tracker_id', 'assigned_to_id',
'priority_id', 'category_id', 'fixed_version_id'
value = find_name_by_reflection(field, detail.value)
old_value = find_name_by_reflection(field, detail.old_value)
when 'estimated_hours'
value = "%0.02f" % detail.value.to_f unless detail.value.blank?
old_value = "%0.02f" % detail.old_value.to_f unless detail.old_value.blank?
when 'parent_id'
label = l(:field_parent_issue)
value = "##{detail.value}" unless detail.value.blank?
old_value = "##{detail.old_value}" unless detail.old_value.blank?
when 'is_private'
value = l(detail.value == "0" ? :general_text_No : :general_text_Yes) unless detail.value.blank?
old_value = l(detail.old_value == "0" ? :general_text_No : :general_text_Yes) unless detail.old_value.blank?
end
when 'cf'
custom_field = CustomField.find_by_id(detail.prop_key)
if custom_field
multiple = custom_field.multiple?
label = custom_field.name
value = format_value(detail.value, custom_field.field_format) if detail.value
old_value = format_value(detail.old_value, custom_field.field_format) if detail.old_value
end
when 'attachment'
label = l(:label_attachment)
end
call_hook(:helper_issues_show_detail_after_setting,
{:detail => detail, :label => label, :value => value, :old_value => old_value })
label ||= detail.prop_key
value ||= detail.value
old_value ||= detail.old_value
unless no_html
label = content_tag('strong', label)
old_value = content_tag("i", old_value) if detail.old_value
old_value = content_tag("del", old_value) if detail.old_value and detail.value.blank?
if detail.property == 'attachment' && !value.blank? && atta = Attachment.find_by_id(detail.prop_key)
# Link to the attachment if it has not been removed
if options[:token].nil?
value = atta.filename
else
value = atta.filename
end
# 放大镜搜索功能
# if options[:only_path] != false && atta.is_text?
# value += link_to(
# image_tag('magnifier.png'),
# :controller => 'attachments', :action => 'show',
# :id => atta, :filename => atta.filename
# )
# end
else
value = content_tag("i", value) if value
end
end
# 缺陷更新结果在消息中显示样式
if no_html == "message"
label = content_tag(:span, label, :class => "issue_update_message")
old_value = content_tag("span", old_value) if detail.old_value
old_value = content_tag("del", old_value) if detail.old_value and detail.value.blank?
if detail.property == 'attachment' && !value.blank? && atta = Attachment.find_by_id(detail.prop_key)
# Link to the attachment if it has not been removed
if options[:token].nil?
value = atta.filename
else
value = atta.filename
end
else
value = content_tag(:span, value, :class => "issue_update_message_value") if value
end
end
if detail.property == 'attr' && detail.prop_key == 'description'
s = l(:text_journal_changed_no_detail, :label => label)
unless no_html
diff_link = link_to l(:label_diff),
{:controller => 'journals', :action => 'diff', :id => detail.journal_id,
:detail_id => detail.id, :only_path => options[:only_path]},
:title => l(:label_view_diff)
s << " (#{ diff_link })"
end
s.html_safe
elsif detail.value.present?
case detail.property
when 'attr', 'cf'
if detail.old_value.present?
l(:text_journal_changed, :label => label, :old => old_value, :new => value).html_safe
elsif multiple
l(:text_journal_added, :label => label, :value => value).html_safe
else
l(:text_journal_set_to, :label => label, :value => value).html_safe
end
when 'attachment'
l(:text_journal_added, :label => label, :value => value).html_safe
end
else
l(:text_journal_deleted, :label => label, :old => old_value).html_safe
end
end
#课程动态的更新
def update_course_activity_api type, id
course_activity = CourseActivity.where("course_act_type=? and course_act_id =?", type.to_s, id.to_i).first
if course_activity
course_activity.updated_at = Time.now
course_activity.save
end
end
#首页动态更新
def update_user_activity_api type, id
user_activity = UserActivity.where("act_type=? and act_id =?", type.to_s, id.to_i).first
if user_activity
user_activity.updated_at = Time.now
user_activity.save
end
end
#项目动态更新
def update_forge_activity_api type, id
forge_activity = ForgeActivity.where("forge_act_type=? and forge_act_id=?", type.to_s, id.to_i).first
if forge_activity
forge_activity.updated_at = Time.now
forge_activity.save
end
end
#组织动态更新
def update_org_activity_api type , id
org_activity = OrgActivity.where("org_act_type=? and org_act_id =?", type.to_s, id.to_i).first
if org_activity
org_activity.updated_at = Time.now
org_activity.save
end
end
#个人动态更新
def update_principal_activity_api type, id
principal_activity = PrincipalActivity.where("principal_act_type=? and principal_act_id =?", type.to_s, id.to_i).first
if principal_activity
principal_activity.updated_at = Time.now
principal_activity.save
end
end
#赞/取消赞
def praise_or_cancel(type,id,user,flag)
unless id.nil? and type.nil?
#首先创建或更新praise_tread 表
pt = PraiseTread.new
pt.user_id = user.id
pt.praise_tread_object_id = id.to_i
pt.praise_tread_object_type = type
pt.praise_or_tread = flag
pt.save
# end
#再创建或更新praise_tread_cache表
#@ptc = PraiseTreadCache.find_by_object_id_and_object_type(id,type)
ptc = PraiseTreadCache.where("object_id = ? and object_type = ?",id.to_i,type).first
ptc = ptc.nil? ? PraiseTreadCache.new : ptc
ptc.object_id = id.to_i
ptc.object_type = type
ptc.save
ptc.praise_plus(flag,1)
end
end
def praise_plus(flag,num)
case flag
when 1
self.update_attribute(:praise_num, self.praise_num.to_i + num)
end
end
def praise_minus(num)
self.update_attribute(:praise_num, self.praise_num.to_i - num)
end
class Errors
def self.define_error(arr)
@errors = {}
arr.each_with_index { |item, index|
if index %2 == 1
@errors[arr[index-1]] = item
end
}
if arr.count % 2== 1
@default_error = arr.last
else
@default_error = "未知错误"
end
end
def self.message(msg_id)
@errors[msg_id] || @default_error
end
end
end

View File

@ -0,0 +1,278 @@
module ApiIndexHelper
#当前用户在论坛模块是否被禁言
def user_is_banned?(user)
return false if user.blank?
(user&.banned_forums&.where(is_banned: true).exists? && !user.admin?)
end
def format_for_current_user(current_user)
if current_user.present? && (current_user.id != 2)
{username: current_user.show_real_name,
login: current_user.login,
user_id: current_user.id,
image_url: "/images/#{url_to_avatar(current_user)}?#{Time.now.to_i}",
admin: current_user.admin?,
user_url: "/users/#{current_user.try(:login)}",
is_banned: user_is_banned?(current_user),
tidding_count: unviewed_tiddings(current_user)
}
else
{}
end
end
def format_common_user(user)
{username: user.show_real_name,
user_id: user.id,
login: user.login,
image_url: "/images/#{url_to_avatar(user)}?#{Time.now.to_i}",
admin: user.admin?,
user_url: "/users/#{user.try(:login)}"
}
end
def get_bread_crumb(forum_section, current_user)
if forum_section.present?
is_children = forum_section&.parent_id&.present?
children_bread_crumb = nil
if is_children
children_bread_crumb = {
title: forum_section.try(:title),
id: forum_section.try(:id)
}
forum_section_tag = {
title: forum_section.parent_forum.try(:title),
id:forum_section.try(:parent_id),
children_bread_crumb: children_bread_crumb
}
else
if forum_section&.children_forum.present?
children_bread_crumb = object_to_hash(forum_section&.children_forum&.select([:id, :title]))
end
# children_bread_crumb = object_to_hash(forum_section&.children_forum&.select([:id, :title])) if forum_section&.children_forum.present?
forum_section_tag = {
title: forum_section.try(:title),
id: forum_section.try(:id),
children_bread_crumb: children_bread_crumb
}
end
else
is_children = false
forum_section_tag = nil
end
{
is_children: is_children, #是否为二级分类
user:{login: current_user.try(:login), url: "/users/#{current_user.try(:login)}"},
forum: {title: "论坛交流", url: ""},
forum_tag: forum_section_tag
}
end
def get_user_ip(ip)
addr = "--"
unless ip.nil?
result = SM.find_by_ip(ip)
if result.present?
addr = "#{result[:province]}-#{result[:city]}"
end
end
return addr
end
def get_children_sections(children_sections)
children_forum_users = []
children_sections.each do |children|
children_users_array = []
children_users = children.forum_moderators.children_moder
children_users.each do |moder|
user = moder.user
children_user_hash = {
moderator_id: moder.id,
user_id: user.id,
login: user.login,
username: user.try(:show_real_name),
image_url: url_to_avatar(user),
user_url: "/users/#{user.try(:login)}"
}
children_users_array.push(children_user_hash)
end
children_forums = {
id: children.id,
title: children.title,
forum_moderators: children_users_array #二级分类的管理者
}
children_forum_users.push(children_forums)
end
children_forum_users
end
#论坛的全部一级分类和二级分类
def all_sections(is_detail)
forum_all_tags = []
forum_first_tags = ForumSection.roots.select([:id, :title, :ancestry, :position]).order("position desc")
forum_first_tags.each do |forum|
forum_second_tags = forum.children.includes(:user)
forum_hash =
{id: forum.id,
name: forum.title,
children_tags: set_children_sections(forum_second_tags,is_detail)
}
forum_all_tags.push(forum_hash)
end
forum_all_tags
end
# 将数据库对象转换成哈希对象
def object_to_hash objects
objects.map{|o| o.attributes.dup}
end
def set_children_sections(objects,is_detail)
children_sections_array = []
objects.find_each do |sec|
image = sec.image_attachment
s_section = {
id: sec.id,
title: sec.title
}
if is_detail
s_section.merge!({
picture: image.present? ? "/attachments/download/" + "#{image.id}" + "/" + "#{image.filename}" : "",
description: sec.description,
memos_count: sec.visible_memos_count,
user_name: sec.user.try(:show_real_name),
user_login: sec.user.try(:login)
})
end
children_sections_array.push(s_section)
end
return children_sections_array
end
def unviewed_tiddings current_user
current_user_onclick_time = current_user.onclick_time.onclick_time
new_tidings_count = current_user.tidings.where("created_at > '#{current_user_onclick_time}'").length
new_pri_message_count = current_user.private_messages.where("created_at > '#{current_user_onclick_time}'").length
count = new_tidings_count + new_pri_message_count
return count
end
#给论坛管理员发信息
def create_user_tidings memo, type
memo_parent_id = ""
memo_parent_type = ""
if memo.parent_id.present?
memo_parent_id = memo.parent_id
memo_parent_type = "Memo"
end
user_ids = User.select(:admin, :id).admin_users.pluck(:id)
# admin_role_ids= AdminRole.includes(:admin_permissions).joins(:admin_permissions).where("admin_permissions.name = '#{type}'").pluck(:id)
# user_ids = UserAdminRole.where(admin_role_id: admin_role_ids).pluck(:user_id).uniq
if user_ids.size > 0
user_ids.each do |id|
Tiding.create(:user_id => id, :trigger_user_id => memo.author_id,
container_id: memo.id, container_type: 'Memo',
:parent_container_id => memo_parent_id, :parent_container_type => memo_parent_type,
:viewed => 0, :tiding_type => "Memo")
end
else
Tiding.create(:user_id => 1, :trigger_user_id => memo.author_id,
container_id: memo.id, container_type: 'Memo',
:parent_container_id => memo_parent_id, :parent_container_type => memo_parent_type,
:viewed => 0, :tiding_type => "Memo")
end
end
def user_banned_permission current_user, forum_id
return true if current_user&.admin?
if current_user.present?
if forum_id.present?
user_forum_moder = ForumModerator.where(forum_section_id: forum_id,user_id: current_user.id).exists?
else
user_forum_moder = false
end
permission_user = (current_user.admin? || user_forum_moder)
else
permission_user = false
end
permission_user
end
def rename_time_day(time)
return "" if time.blank?
time.strftime("%Y-%m-%d")
end
def rename_time_second(time)
return "" if time.blank?
time.strftime("%Y-%m-%d %H:%M:%S")
end
def rename_time_minute(time)
return "" if time.blank?
time.strftime("%Y-%m-%d %H:%M")
end
def get_memo_lists(all_memos, last_reply, current_user, show_hidden_memo)
memo_lists = []
all_memos.field_for_list.each do |memo|
if last_reply
last_memo = memo&.last_reply_memo(show_hidden_memo)
if last_memo
new_reply = {
username: last_memo&.author.try(:show_real_name),
user_login: last_memo&.author.try(:login),
user_id: last_memo&.author.try(:id),
content: last_memo&.content,
time: time_from_now(last_memo&.created_at),
published_time: rename_time_second(last_memo&.created_at)
}
end
end
memo_section = memo&.forum_section
memo_watched = memo.watched_by?(current_user)
banned_permission = user_banned_permission current_user, memo.forum_section_id
memo = {
id: memo.id,
subject: memo.try(:subject),
tag_name: memo.meno_tag_name,
sticky: memo.sticky,
is_fine: memo.is_fine,
is_original: memo.is_original,
username: memo.author.try(:show_real_name),
image_url: "#{url_to_avatar(memo.author)}?#{Time.now.to_i}",
user_login: memo.author.try(:login),
user_id: memo.author.try(:id),
memo_watched:memo_watched,
replies_count: memo.can_see_reply_count(current_user),
praises_count: memo.praises_count,
viewed_count: memo.viewed_count,
published_time: rename_time_day(memo.published_at),
forum_section_id: memo_section.try(:id),
forum_section_title: memo_section.try(:title),
new_reply: new_reply || nil,
apply_destroy: current_user&.id == memo.author_id && memo.apply_destroy?,
banned_permission: banned_permission
}
memo_lists << memo
end
memo_lists
end
def get_all_sections(sections)
section_item = []
sections.each do |tag|
children_tags = tag.children.as_json(only: [:id, :title])
section_item.push({
id: tag.id,
title: tag.title,
childrens: children_tags
})
end
return section_item
end
end

View File

@ -141,6 +141,7 @@ module ApplicationHelper
# 用户图像url如果不存在的话source为匿名用户即默认使用匿名用户图像
def url_to_avatar(source)
return "" if source&.id.blank?
if File.exist?(disk_filename(source&.class, source&.id))
ctime = File.ctime(disk_filename(source.class, source.id)).to_i
if source.class.to_s == 'User'
@ -322,7 +323,15 @@ module ApplicationHelper
end
def absolute_path(file_path)
File.join(edu_setting('attachment_folder'), file_path)
file_root_directory + File.join(edu_setting('attachment_folder'), file_path)
end
def file_root_directory
Rails.root.to_s
end
def file_storage_directory
file_root_directory + edu_setting('attachment_folder')
end
def local_path(file)

View File

@ -0,0 +1,2 @@
module CustomersHelper
end

View File

@ -0,0 +1,27 @@
class SyncCreateMemoJob < ApplicationJob
queue_as :default
def perform(memo_params)
all_memos = Memo.all
memo_params.each do |m|
SyncLog.sync_log("==========mmeo_params============id:#{m}")
begin
if all_memos.exists?(m[:id])
memo = all_memos.where(id: m[:id]).first
memo.update_attributes!(m.merge(hidden: false))
else
memo = Memo.new(m.merge({forum_section_id: m[:forum_id], hidden: false}))
if memo.save!
SyncLog.sync_log("==========create_memo_success============id:#{memo.id}")
else
SyncLog.sync_log("==========create_memo_failed============id:#{m[:id]}")
end
end
rescue => e
SyncLog.sync_log("==========sync_memos_1111111_to_forge_failed============errors:#{e}")
end
end
end
end

View File

@ -0,0 +1,34 @@
require 'uri'
require 'net/http'
class SyncMemosJob < ApplicationJob
queue_as :default
def perform(forum_id, main_url)
SyncLog.sync_log("==========sync_memos_to_forge===forum_id==#{forum_id}=========")
begin
url = "#{main_url}/sync_forges/get_memos"
uri = URI.parse(url)
http = Net::HTTP.new(uri.hostname, uri.port)
http.use_ssl = main_url.include?("https")
# headers = { "Content-Type" => "application/json" }
sync_params = {
forum_id: forum_id
}
response = http.send_request('GET', uri.path, sync_params.to_json, {'Content-Type' => 'application/json'})
# response = http.get(uri.path,{forum_id: forum_id}.to_json, headers)
if response.code == '200'
target_jsons = eval(response.body)
SyncLog.sync_log("==========sync_memos_jobs_target========#{target_jsons[:all_memos]}====")
SyncCreateMemoJob.perform_later(target_jsons[:all_memos])
# create_target(target_jsons[:all_memos])
else
SyncLog.sync_log("==========sync_memos_to_forge_failed============")
end
rescue => e
SyncLog.sync_log("==========sync_memos_to_forge_failed=____2222===========errors:#{e}")
end
end
end

20
app/models/api_key.rb Normal file
View File

@ -0,0 +1,20 @@
class ApiKey < ApplicationRecord
attr_accessor :access_token, :active, :expires_at, :user_id
before_create :generate_access_token
before_create :set_experation
# validates_presence_of :user_id, :access_token
def expired?
DateTime.now >= self.expires_at
end
private
def generate_access_token
self.access_token = SecureRandom.hex
end
def set_experation
self.expires_at = DateTime.now + 30
end
end

View File

@ -0,0 +1,6 @@
class ApplyForum < ApplicationRecord
#is_confirm 默认为0 1为通过2为拒绝
belongs_to :user
belongs_to :forum_section
has_many :reviews, as: :reviewable,dependent: :destroy
end

View File

@ -0,0 +1,10 @@
class BannedForum < ApplicationRecord
# user_id #被禁言用户
# author_id #禁言的创建者
# memo_id #禁言的帖子id
# banned_count, default: 0 #被禁言的次数,每次禁言的时候+1
# is_banned, default: false #是否禁言
belongs_to :user
belongs_to :memo
belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
end

4
app/models/block_user.rb Normal file
View File

@ -0,0 +1,4 @@
class BlockUser < ApplicationRecord
belongs_to :user
scope :block_user_present, ->(target_id){where(block_user_id: target_id)}
end

View File

@ -0,0 +1,2 @@
class CheckedAction < ApplicationRecord
end

View File

@ -4,14 +4,19 @@ module Watchable
included do
has_many :watchers, as: :watchable, dependent: :destroy
has_many :watcher_users, through: :watchers, source: :user, validate: false
scope :watched_by, -> (user_id) { includes(:watchers).where(watchers: { user_id: user_id }) }
attr_reader :watcher_ids, :watcher_user_ids
end
def watched?(watchable)
watchable.watchers.exists?(user: self)
end
def watched_by?(user)
watcher_users.exists?(id: user.id)
# !!(user && self.watcher_user_ids && self.watcher_user_ids.detect {|uid| uid == user.id })
end
def watch!(watchable)
watchable.watchers.create!(user: self, created_at: Time.current)
end

2
app/models/forum.rb Normal file
View File

@ -0,0 +1,2 @@
class Forum < ApplicationRecord
end

View File

@ -0,0 +1,8 @@
class ForumModerator < ApplicationRecord
#版主的表
# attr_accessible :title, :body
belongs_to :forum_section
belongs_to :user
scope :children_moder, -> {where(is_children: true)}
end

View File

@ -0,0 +1,41 @@
class ForumSection < ApplicationRecord
include Watchable
has_ancestry
#论坛板块的表
# attr_accessible :title, :body
has_many :forum_moderators
belongs_to :user
has_many :apply_forums, dependent: :destroy
has_many :memo_forums, :dependent => :destroy, foreign_key: "forum_id"
has_many :memos, dependent: :destroy
has_one :section_notice, dependent: :destroy
# scope :group_today, -> {joins(:memos).where("memos.hidden = false and memos.created_at between ? and ?", Time.current.beginning_of_day, Time.current.end_of_day)}
# acts_as_watchable
# acts_as_attachable
def group_today
memos.where("memos.hidden = false and memos.created_at between ? and ?", Time.current.beginning_of_day, Time.current.end_of_day)
end
def visible_memos_count
memos.posts.visible.size
end
def image_attachment
Attachment.find_by_id(attachment_id)
end
def children_forum
ForumSection.where(parent_id: id)
end
def parent_forum
ForumSection.find_by_id(parent_id)
end
def get_children_section(type)
children.order("position #{type}")
# ForumSection.where(parent_id: id).order("position #{type}")
end
end

290
app/models/memo.rb Normal file
View File

@ -0,0 +1,290 @@
# root_idnil => 主贴; 有值 => 主帖的ID值为帖子的ID
# parent_id 回复对这个id的回复
# sticky 顶置 1
# is_fine 是否加精默认为false
# hidden 是否隐藏
class Memo < ApplicationRecord
include ApplicationHelper, Watchable
#敏感词过滤
# include DunCheckAble
has_many :forums, :through => :memo_forums
belongs_to :forum_section, counter_cache: true, optional: true
has_many :memo_forums, :dependent => :destroy
has_many :visit_actions, as: :visitable, dependent: :destroy
#用户是否禁言
has_many :banned_forums
# has_many_kindeditor_assets :assets, :dependent => :destroy
has_many :tidings, :as => :container , :dependent => :destroy
belongs_to :author, :class_name => "User", :foreign_key => 'author_id'
validates_presence_of :author_id, :subject,:content
# 若是主题帖,则内容可以是空
#validates :content, presence: true, if: Proc.new{|o| !o.parent_id.nil? }
validates_length_of :subject, maximum: 50
validate :cannot_reply_to_locked_topic, :on => :create
scope :total_replies, ->{where("hidden = false and root_id is not null")}
# scope :roots, -> {where()}
has_many :attachments, as: :container, dependent: :destroy
# 创意征集方式 0-默认1-申请, ps. 删除后,该帖子即删除, 拒绝后,该帖子状态将为初始状态
enum destroy_status: { common: 0, apply_destroy: 1 }
acts_as_tree :counter_cache => :replies_count, :order => "#{Memo.table_name}.created_at ASC", dependent: :destroy
# acts_as_attachable
has_many :user_score_details, :class_name => 'UserScoreDetails',:as => :score_changeable_obj
has_many :praise_tread, as: :praise_tread_object, dependent: :destroy
has_one :praise_tread_cache, as: :object, dependent: :destroy
# 消息
has_many :memo_messages, :class_name =>'MemoMessage', :dependent => :destroy
# end
belongs_to :last_reply, :class_name => 'Memo', :foreign_key => 'last_reply_id', optional: true
scope :indexable,lambda {
where('parent_id is null')
}
scope :visible, lambda{where(hidden: false)}
scope :hidden_memos, lambda{where(hidden: true)}
scope :field_for_list, lambda{
select([:id, :subject,:destroy_status, :author_id, :sticky, :published_at, :language, :reward, :replies_count,:is_fine, :viewed_count, :praises_count,:forum_section_id, :tag_id, :is_original])
}
scope :field_for_recommend, lambda{select([:id, :subject, :replies_count, :language])}
scope :user_posts, ->(user_id){where(root_id: nil, author_id: user_id)}
scope :user_replies, ->(user_id){where("root_id is not null and author_id = ?", user_id)}
scope :memo_replies, ->(id){where(:root_id => id)}
scope :hot, lambda{order("replies_count desc")}
scope :posts, lambda{ where(root_id: nil) }
scope :recommend_memos, lambda{ where(is_fine: true) }
scope :in_week, lambda{ where("published_at >= ?",7.days.ago ) }
scope :related_search_name, -> (name) {ransack(subject_cont: "#{name}").result(distinct: true)}
scope :order_index, -> (sort_params) {reorder("sticky desc, is_fine desc, #{sort_params} desc")}
def self.search_by_time(time_type, start_time, end_time)
where("#{time_type} between ? and ?",start_time.present? ? start_time.to_time : Time.now, end_time.present? ? end_time.to_time.end_of_day : Time.now)
end
def memo_parent
Memo.find(parent_id)
end
def last_reply_memo(show_hidden_memo)
memo_children = self.children
if !show_hidden_memo
memo_children = memo_children.visible
end
memo_children&.reorder("created_at desc")&.first
end
def reply_for_memo
Memo.where(:parent_id => self.id)
end
def all_replies
Memo.where(:root_id => self.id)
end
#未审核发布的帖子数
def uncheck_memo_count
self&.reply_for_memo&.where(hidden: true).size
end
def can_see_reply_count(user)
memo_replies_count = self.replies_count
unless user.try(:admin?)
uncheck_memos_count = self.uncheck_memo_count #全部未审核的
user_uncheck_memos_count = self&.reply_for_memo&.where("hidden = true and author_id = ?", user.id)&.size #当前用户发布的,且未审核的
memo_replies_count = memo_replies_count - uncheck_memos_count + user_uncheck_memos_count
end
memo_replies_count
end
def self.hottest_five_memos
order("replies_count desc, praises_count desc, viewed_count desc").limit(8).select(:id,:subject)
end
def self.recommend_five_memos
recommend_memos.order("updated_at desc").limit(8).select(:id,:subject)
end
def send_mail
# Mailer.run.forum_message_added(self) if Setting.notified_events.include?('forum_message_added')
end
def creator_user
self.author
end
def created_time
self.created_on
end
def content_detail
self.content
end
# 公共贴吧消息记录
# 原则:新帖子给超级管理员发消息
def send_tiding
if self.parent_id.present?
# self.tidings << Tiding.new(:user_id => self.parent.author_id, :trigger_user_id => self.author_id, :parent_container_id => self.root_id, :parent_container_type => "Memo",
# :belong_container_id => self.forum_id, :belong_container_type => "Forum", :viewed => 0, :tiding_type => "Comment")
else
self.tidings << Tiding.new(:user_id => 1, :trigger_user_id => self.author_id, :parent_container_id => self.id, :parent_container_type => "Memo", :viewed => 0, :tiding_type => "Comment")
end
end
def cannot_reply_to_locked_topic
errors.add :base, l(:label_memo_locked) if root.locked? && self != root
end
# def update_memos_forum
# if forum_id_changed?
# Message.update_all({:board_id => board_id}, ["id = ? OR parent_id = ?", root.id, root.id ])
# Forum.reset_counters!(forum_id_was)
# Forum.reset_counters!(forum_id)
# end
# end
def reset_counters!
if parent && parent.id
parent.update_attribute(:last_reply_id, parent.children.maximum(:id))
end
if root
root.update_attribute(:last_reply_id, Memo.where(:root_id => root.id).maximum(:id)) unless root.destroyed?
end
forum.reset_counters!
end
def sticky?
sticky == 1
end
def replies
Memo.where("parent_id = ?", id)
end
def locked?
self.lock
end
def editable_by? user
# user && user.logged? || (self.author == usr && usr.allowed_to?(:edit_own_messages, project))
user.admin? || self.author == user
end
def destroyable_by? user
(user && self.author == user) || user.admin? || self.forum.creator == user || Memo.find(self.root_id).author == user
#self.author == user || user.admin?
end
def deleted_attach_able_by? user
(user && user.logged? && (self.author == user) ) || user.admin?
end
def meno_tag_name
tag_id.to_i == 1 ? "交流" : "求助"
end
def update_attachments(attachment_ids)
Attachment.where(id: attachment_ids).update_all(container_id: id, container_type: "Memo")
end
private
def add_author_as_watcher
Watcher.create(:watchable => self.root, :user => author)
end
def send_notification
# if Setting.notified_events.include?('message_posted')
# Mailer.run.message_posted(self)
# end
end
# def update_reply_count
# if self.root_id
# self.root.increment!(:replies_count)
# end
# end
def plusParentAndForum
@forum = Forum.find(self.forum_id)
@forum.memo_count = @forum.memo_count.to_int + 1
@forum.last_memo_id = self.id
if self.parent_id
@parent_memo = Memo.find_by_id(self.parent_id)
@parent_memo.last_reply_id = self
@parent_memo.replies_count = @parent_memo.replies_count.to_int + 1
@parent_memo.save
else
@forum.topic_count = @forum.topic_count.to_int + 1
end
@forum.save
end
def minusParentAndForum
@forum = Forum.find(self.forum_id)
@forum.memo_count = @forum.memo_count.to_int - 1
@forum.memo_count = 0 if @forum.memo_count.to_int < 0
# @forum.last_memo_id = Memo.reorder('created_at ASC').find_all_by_forum_id(self.forum_id).last.id
if self.parent_id
@parent_memo = Memo.find_by_id(self.parent_id)
# @parent_memo.last_reply_id = Memo.reorder('created_at ASC').find_all_by_parent_id(self.parent_id).last.id
@parent_memo.replies_count = @parent_memo.replies_count.to_int - 1
@parent_memo.replies_count = 0 if @parent_memo.replies_count.to_int < 0
@parent_memo.save
else
@forum.topic_count = @forum.topic_count.to_int - 1
@forum.topic_count = 0 if @forum.topic_count.to_int < 0
end
@forum.save
end
#更新用户分数 -by zjc
def be_user_score
#新建memo且无parent的为发帖
if self.parent_id.nil?
UserScore.joint(:post_message, User.current,nil,self ,{ memo_id: self.id })
update_memo_number(User.current,1)
#新建memo且有parent的为回帖
elsif !self.parent_id.nil?
UserScore.joint(:reply_posting, User.current,self.parent.author,self, { memo_id: self.id })
update_replay_for_memo(User.current,1)
end
end
#被删除时更新用户分数
def down_user_score
update_memo_number(User.current,1)
update_replay_for_memo(User.current,1)
end
# Time 2015-03-26 15:20:24
# Author lizanle
# Description 从硬盘上删除资源
def delete_kindeditor_assets
delete_kindeditor_assets_from_disk self.id,OwnerTypeHelper::MEMO
end
def create_memo_ealasticsearch_index
if self.parent_id.nil?
self.__elasticsearch__.index_document
end
end
def update_memo_ealasticsearch_index
if self.parent_id.nil?
self.__elasticsearch__.update_document
end
end
def delete_memo_ealasticsearch_index
if self.parent_id.nil?
self.__elasticsearch__.delete_document
end
end
end

5
app/models/memo_forum.rb Normal file
View File

@ -0,0 +1,5 @@
class MemoForum < ApplicationRecord
belongs_to :memo
belongs_to :forum
belongs_to :forum_section, foreign_key: "forum_id"
end

View File

@ -0,0 +1,2 @@
class MemoMessage < ApplicationRecord
end

View File

@ -14,6 +14,10 @@ class PraiseTread < ApplicationRecord
end
end
def self.is_user_praise(target_id,target_type, target_user_id)
where(:praise_tread_object_id => target_id, :praise_tread_object_type => target_type, :user_id => target_user_id, :praise_or_tread => 1)
end
def self.find_object_by_type_and_id(id, type)
type.constantize find_by_id id
end

View File

@ -0,0 +1,3 @@
class SectionNotice < ApplicationRecord
belongs_to :forum_section
end

79
app/models/site.rb Normal file
View File

@ -0,0 +1,79 @@
# == Schema Information
#
# Table name: sites
#
# id :integer not null, primary key
# name :string(255)
# url :string(255)
# key :string(255)
# site_type :integer
# created_at :datetime not null
# updated_at :datetime not null
#
class Site < ApplicationRecord
# add: 添加类链接
# personal: 个人名下类链接,
# common: 普通链接
enum site_type: { add: 0, personal: 1, common: 2 }
scope :by_search, -> (keyword){ where("name LIKE :keyword OR url LIKE :keyword", keyword: "%#{strip_param(keyword)}%") unless strip_param(keyword).blank? }
scope :by_site_type, -> (site_type){ where(site_type: strip_param(site_type)) unless strip_param(site_type).blank? }
def self.set_default_menu
set_add_menu!
set_personal_menu!
set_common_menu!
end
def self.has_notice_menu?
self.common.where(key: 'notice').present?
end
private
def self.set_add_menu!
adds= [
{name: '新建项目', key: 'add_mirror_project', url: '/projects/mirror/new'},
{name: '导入项目', key: 'add_common', url: '/projects/deposit/new'},
{name: '新建组织', key: 'add_r', url: '/organize/new'}]
adds.each { |ele|
Site.find_or_create_by(key: ele[:key]) do |site|
site.name = ele[:name]
site.url = ele[:url]
site.site_type = Site.site_types[:add]
end
}
end
def self.set_personal_menu!
personals = [
{name: '个人中心', key: 'my_page', url: '/users/current_user'},
{name: '我的组织', key: 'my_organizes', url: '/users/current_user/organizes'}
]
personals.each { |ele|
Site.find_or_create_by(key: ele[:key]) do |site|
site.name = ele[:name]
site.url = ele[:url]
site.site_type = Site.site_types[:personal]
end
}
end
def self.set_common_menu!
commons = [
{name: '通知', key: 'notice', url: '/users/current_user/user_messages'},
{name: '找回密码', key: 'lost_password', url: '/account/lost_password'},
{name: '注册', key: 'register', url: '/login?login=false'}
]
commons.each { |ele|
Site.find_or_create_by(key: ele[:key]) do |site|
site.name = ele[:name]
site.url = ele[:url]
site.site_type = Site.site_types[:common]
end
}
end
end

View File

@ -54,6 +54,7 @@ class User < ApplicationRecord
has_one :qq_open_user, class_name: 'OpenUsers::QQ'
accepts_nested_attributes_for :user_extension, update_only: true
has_many :fork_users, dependent: :destroy
has_many :block_users, :dependent => :destroy
has_many :versions
has_many :issue_times, :dependent => :destroy
@ -72,7 +73,7 @@ class User < ApplicationRecord
has_many :be_watchers, foreign_key: :user_id, dependent: :destroy # 我的关注
has_many :be_watcher_users, through: :be_watchers, dependent: :destroy # 我关注的用户
has_many :watchers, as: :watchable, dependent: :destroy
# has_many :watchers, as: :watchable, dependent: :destroy
# 认证
has_many :apply_user_authentication
@ -81,6 +82,15 @@ class User < ApplicationRecord
has_many :apply_actions, dependent: :destroy
has_many :trail_auth_apply_actions, -> { where(container_type: 'TrialAuthorization') }, class_name: 'ApplyAction'
#用户是否禁言
has_many :banned_forums, :dependent => :destroy
has_many :apply_forums, :dependent => :destroy
has_many :memos , :foreign_key => 'author_id'
#论坛的板块内容,及版主
has_many :forum_moderators, :dependent => :destroy
has_many :forum_sections, :dependent => :destroy
# has_many :attendances
# 项目
@ -311,6 +321,10 @@ class User < ApplicationRecord
status == STATUS_LOCKED
end
def self.admin_users
where(admin: true)
end
def activate
self.status = STATUS_ACTIVE
end
@ -570,6 +584,10 @@ class User < ApplicationRecord
end
end
def blocked_for(user_id)
block_users.where(block_user_id: user_id).exists?
end
def salt_password(clear_password)
self.salt = User.generate_salt
self.hashed_password = User.hash_password("#{salt}#{User.hash_password clear_password}")

View File

@ -0,0 +1,7 @@
class VisitAction < ApplicationRecord
belongs_to :visitable, polymorphic: true
def self.search_by_time(time_type, start_time, end_time)
where("#{time_type} between ? and ?",start_time.present? ? start_time.to_time : Time.now, end_time.present? ? end_time.to_time.end_of_day : Time.now)
end
end

View File

@ -0,0 +1,49 @@
<div class="fl" style="width: 600px">
<% for attachment in attachments %>
<!--<p style="width: 100%;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;">-->
<!--<div style="max-width:55%;white-space: nowrap; overflow: hidden; text-overflow: ellipsis;float: left;">-->
<!--<span title="<%#= attachment.filename%>" id = "attachment_">-->
<% if options[:length] %>
<span class="pic_files fl "></span>
<%= link_to_attachment attachment, :class => 'fl FilesName02', :download => true,:length => options[:length] -%>
<a class="fl FilesName02"> (<%= number_to_human_size attachment.filesize , :precision => 0 %>)</a>
<% if options[:deletable] %>
<%#= link_to image_tag('delete.png'), attachment_path(attachment),
:data => {:confirm => l(:text_are_you_sure)},
:method => :delete,
:class => 'delete',
#:remote => true,
#:id => "attachments_" + attachment.id.to_s,
:title => l(:button_delete) %>
<span class="pic_del fl "> <a href="<%=attachment_path(attachment) %>" onclick="confirm(<%=l(:text_are_you_sure) %>)" data-method="delete"> </a></span>
<% end %>
<div class="cl"></div>
<% else %>
<span class="pic_files fl "></span>
<!--<i class="fa fa-folder mr5 color-orange03 mt8 fl" aria-hidden="true"></i> 文件icon-->
<%= link_to_short_attachment attachment, :class => 'fl FilesName02 color-orange03', :download => true, :length => 45 -%>
<!--<span class="fl FilesName02"> (<%#= number_to_human_size attachment.filesize , :precision => 0 %>)</span> 文件大小-->
<!--<a href="<%#= user_path(attachment.author) %>" class="fl color-orange05"><%#= attachment.author %></a> 上传者-->
<span class="fl color-grey ml15"><%= format_time attachment.created_on %></span>
<% if options[:deletable] %>
<a href="<%=attachment_path(attachment) %>" onclick="confirm(<%=l(:text_are_you_sure) %>)" data-method="delete"> <span class="pic_del fl "></span> </a>
<% end %>
<div class="cl"></div>
<% end %>
<% end %>
<% if defined?(thumbnails) && thumbnails %>
<% images = attachments.select(&:thumbnailable?) %>
<% if images.any? %>
<div class="pro_pic mb10" width="100" height="73">
<% images.each do |attachment| %>
<div><%= thumbnail_tag(attachment) %></div>
<% end %>
</div>
<% end %>
<% end %>
</div>

View File

@ -0,0 +1,128 @@
<div class="panel-mes-head clearfix">
<h4 class="fl">全部回复<span class="ml5">
<% unless count == 0 %>
(<%= count %>)
<% end %>
</span></h4>
<p class="fr mr15">
<% if User.current.admin? %>
<a href="javascript:void(0)" class="mr15 white-btn orange-btn" id="reward_btn_<%= memo.id %>" onclick="reward('<%= reward_credit_user_path(memo.author, :container_id => memo.id, :container_type => "Memo") %>')"><i class="fa fa-gift font-16 mr5"></i>奖励</a>
<% end %>
<a href="javascript:void(0);" class="mr15 white-btn orange-btn" onclick="editor_focus(<%= memo.id %>);"><i class="fa fa-comments-o mr5"></i>回复<!--<span class="ml5"><%#= count %></span>--></a>
<!--<span class="mr10 color-grey"><i class="fa fa-eye color-grey mr5"></i><%#= @topic.visits %></span>-->
<!--<span id="praise_count_<%#=activity.id %>">
<%#= render :partial => 'praise_tread/edu_praise', :locals => {:activity=>activity, :user_activity_id=>activity.id,:type=>"activity"} %>
</span>-->
<span id="praise_count_<%= memo.id %>" class="fr mr10">
<%= render :partial => 'praise_tread/activity_praise', :locals => {:activity => memo, :user_activity_id => memo.id, :type => "Memo"} %>
</span>
</p>
</div>
<div class="panel-comment_item">
<% no_children_comments.each do |comment| %>
<% unless comment.nil? %>
<script type="text/javascript">
$(function(){
showNormalImage('reply_content_<%= comment.id %>');
autoUrl('reply_content_<%= comment.id %>');
});
</script>
<div class="comment_item_cont clearfix">
<div class="J_Comment_Face fl">
<%= link_to image_tag(url_to_avatar(comment.creator_user), :width => 50, :height => 50, :alt => "用户头像"), user_url_in_org(comment.creator_user), :target => '_blank' %>
</div>
<div class="t_content fl">
<div class="J_Comment_Reply">
<div class="comment_orig_content" style="margin:0px">
<% if !comment.parent.nil? && !comment.parent.parent.nil? %>
<% parents_rely = [] %>
<% parents_rely = get_reply_parents_no_root parents_rely, comment %>
<% length = parents_rely.length %>
<div id="comment_reply_<%= comment.id %>">
<% if length <= 5 %>
<%#=render :partial => 'users/journal_comment_reply', :locals => {:comment => comment.parent, :type => memo.class.to_s, :user_activity_id => memo.id, :parent_id => comment.id} %>
<%=render :partial => 'messages/message_reply', :locals => {:comment => comment.parent, :parent_id => comment.id, :user_activity_id => memo.id, :type => memo.class.to_s} %>
<% else %>
<div class="orig_cont clearfix">
<div class="orig_cont clearfix">
<div class="orig_cont clearfix">
<div class="orig_cont clearfix">
<div class="orig_cont clearfix">
<%=render :partial => 'student_work/homework_reply_detail', :locals => {:comment => parents_rely[length - 1], :type => memo.class.to_s, :user_activity_id => memo.id, :parent_id => comment.id} %>
</div>
<div class="orig_cont_hide clearfix">
<i class="fa fa-long-arrow-down mr5"></i>
<%= link_to '点击展开隐藏楼层', show_all_replies_users_path(:comment => comment, :type => comment.class, :user_activity_id => memo.id, :parent_id => comment.id),:remote=>true, :class => '' %>
</div>
<%=render :partial => 'student_work/homework_reply_detail', :locals => {:comment => parents_rely[3], :type => memo.class.to_s, :user_activity_id => memo.id, :parent_id => comment.id} %>
</div>
<%=render :partial => 'student_work/homework_reply_detail', :locals => {:comment => parents_rely[2], :type => memo.class.to_s, :user_activity_id => memo.id, :parent_id => comment.id} %>
</div>
<%=render :partial => 'student_work/homework_reply_detail', :locals => {:comment => parents_rely[1], :type => memo.class.to_s, :user_activity_id => memo.id, :parent_id => comment.id} %>
</div>
<%=render :partial => 'student_work/homework_reply_detail', :locals => {:comment => parents_rely[0], :type => memo.class.to_s, :user_activity_id => memo.id, :parent_id => comment.id} %>
</div>
<% end %>
</div>
<% end %>
<!--onmouseover="$('#delete_reply_<%#=activity.id %>_<%#=comment.id %>').show();" onmouseout="$('#delete_reply_<%#=activity.id %>_<%#=comment.id %>').hide();"-->
<div class="comment_content clearfix" >
<div class="color-grey3"><%= comment.content_detail.html_safe %></div>
<div class="J_Comment_Info clearfix">
<div class="t_info fl">
<%= link_to comment.creator_user.show_real_name, user_url_in_org(comment.creator_user), :class => "content-username hide fl" %>
<span class="t_area fl"><%= time_from_now(comment.created_at) %></span>
<span id="reword_score_<%= comment.id %>">
<% if comment.try(:reward).present? %>
<span class="ml15 fl color-orange03" data-tip-down="获得平台奖励金币:<%= comment.try(:reward) %>"><i class="fa fa-gift font-16 ml5 mr3"></i><%= comment.try(:reward) %></span>
<% end %>
</span>
</div>
<p class="fr mr10 orig_reply">
<% if User.current.admin? %>
<a href="javascript:void(0)" class="ml15 color-grey" data-tip-down="给TA奖励金币" id="reward_btn_<%= comment.id %>" onclick="reward('<%= reward_credit_user_path(comment.author, :container_id => comment.id, :container_type => "Memo") %>')"><i class="fa fa-gift font-16 mr5"></i>奖励<span class="ml5 mr5">|</span></a>
<% end %>
<% if comment.creator_user == User.current %>
<a href="javascript:void(0);" class="color-grey" id="delete_reply_<%= memo.id %>_<%=comment.id %>" onclick="delete_confirm_box_2('<%= forum_memo_path(comment.forum, comment, :user_activity_id => memo.id) %>', '确定要删除该条回复吗?')"><i class="fa fa-trash-o mr5"></i>删除</a>
<span class="ml5 mr5 color-grey">|</span>
<% end %>
<%= link_to(
'<i class="fa fa-mail-reply mr5"></i>回复'.html_safe,
{:controller => 'users' ,:action => 'reply_to',:reply_id => comment.id, :type => memo.class.to_s, :user_activity_id => memo.id},
:remote => true,
:method => 'get',
:title => l(:button_reply),:class => "color-grey") %>
<span class="ml5 mr5 color-grey">|</span>
<span class="reply_praise_count_<%= comment.id %>">
<%=render :partial=> "praise_tread/edu_praise", :locals => {:activity=>comment, :user_activity_id=>comment.id,:type=>"reply"}%>
</span>
</p>
</div>
<div class="">
<div class="cl"></div>
<div id="reply_message_<%= comment.id%>" class="reply_to_message"></div>
</div>
</div>
<!--回复end-->
</div>
</div>
</div>
<div class="cl"></div>
</div>
<% end %>
<% end %>
</div>
<script>
function ThumbUp(item){
$(item).toggleClass("orange-btn");
$(item).toggleClass("orange-bg-btn");
if($(item).attr("attr-thumb")=="0"){
$(item).find("span").html(parseInt($(item).find("span").html())+1);
$(item).attr("attr-thumb","1");
}else{
$(item).find("span").html(parseInt($(item).find("span").html())-1);
$(item).attr("attr-thumb","0");
}
}
</script>

View File

@ -0,0 +1,313 @@
<%= content_for(:header_tags) do %>
<%= import_ke(enable_at: false, prettify: false, init_activity: false) %>
<% end %>
<ul>
<!--<li class="clearfix mb15 pl30 pr30">
<label class="panel-form-label fl color-dark-grey"><span class="color-orange mr5">*</span>类别&nbsp;&nbsp;&nbsp;</label>
<div class="with30 fl pr" select-for>
<input type="hidden" name="major_level" id="major_level" value="0">
<input class="task-height-40 task-form-100 panel-box-sizing pr20 color-grey3" readonly placeholder="选择话题类别"/>
<div class="down-select bor-grey-e user_bg_shadow" id="major_level_option">
<p data-major="3">通 告</p>
<p data-major="2">智能课堂</p>
<p data-major="1">实训项目</p>
</div>
</div>
</li>-->
<li class="clearfix mb15 pl30 pr30">
<label class="panel-form-label fl color-dark-grey"><span class="color-orange mr5">*</span>标题&nbsp;&nbsp;&nbsp;</label>
<input type="text" name="memo[subject]" id="memo_subject" value="<%= @memo.try(:subject) %>" class="panel-form-width-690 panel-form-height-30 fl panel-box-sizing" maxlength="60" id="memo_subject" placeholder="最多60个字符">
<p class="color-red undis" style="margin-left: 10%;" id="memo_notice"><i class="fa fa-exclamation-circle mr5"></i>标题不能超过60个字符</p>
</li>
<% if User.current.admin? %>
<li class="clearfix">
<label class="fl panel-form-label" style="width: 12%;">&nbsp;</label>
<span class="fl mr20">
<input type="checkbox" name="memo[sticky]" <%= @memo.sticky ? 'checked' : '' %> value="<%= @memo.sticky ? 1 : 0 %>" id="to_top" class="ml-3 mr5 magic-checkbox">
<label for="to_top">置顶</label>
</span>
</li>
<% end %>
<li class="clearfix mb5 pl30 pr30">
<label class="panel-form-label fl color-dark-grey"><span class="color-orange mr5">*</span>内容&nbsp;&nbsp;&nbsp;</label>
<%= hidden_field_tag :asset_id, params[:asset_id], :required => false, :style => 'display:none' %>
<textarea class="panel-form-width-690 panel-form-height-150 fl panel-box-sizing" style="display: none"></textarea>
<%= f.kindeditor :content, :editor_id => 'memo_content_editor',
:owner_id => @memo.nil? ? 0: @memo.id,
:owner_type => OwnerTypeHelper::MESSAGE,
:width => '89.8%',
:height => 300,
:minHeight=>300,
:class => 'talk_text fl',
:input_html => { :id => 'memo_content',
:class => 'talk_text fl',
:maxlength => 5000 }
%>
<p class="color-red undis" style="margin-left: 10%;" id="new_memo_content_notice"><i class="fa fa-exclamation-circle mr5"></i>内容不能为空</p>
</li>
<li class="clearfix mb5 pl30 pr30 ml25">
<%= render :partial => 'forums/file_form', :locals => {:container => @memo} %>
</li>
<div class="clearfix mb15 pl92 pr30">
<p class="color-dark-grey h40">
<span class="color-orange mr5">*</span>
选择话题分类(技术可选三项)
<span id="forum_type_notice" class="undis color-red ml20"><i class="fa fa-exclamation-circle mr5"></i>请选择话题分类</span>
</p>
<input type="hidden" id="forum_type" name="forum_type" value="<%= edit ? (@memo.try(:forum).try(:id) == 1 ? 1 : (@memo.try(:forum).try(:id) == 3 ? 3 : (@memo.try(:forum).try(:id) == 5 && @memo.try(:language) ? @memo.try(:language) : 'other'))) : '' %>">
<div class="ml55 clearfix topic-hover">
<li class="fl mb10">
<span data-val="1" class="un_language_type font-14 mr8 bor-gray-c ptl5-10 forum_type <%= @memo.try(:forum).try(:id) == 1 ? 'forum_type_active' : '' %>">问题反馈</span>
</li>
<li class="fl mb10">
<span data-val="3" class="un_language_type font-14 mr8 bor-gray-c ptl5-10 forum_type <%= @memo.try(:forum).try(:id) == 3 ? 'forum_type_active' : '' %>">操作指南</span>
</li>
<% @mirrors_name.each do |language| %>
<li class="fl mb10">
<span data-val="<%= language %>" class="language_type font-14 mr8 bor-gray-c ptl5-10 forum_type <%= @memo.try(:language) && @memo.try(:language).split("/").include?(language) ? 'forum_type_active' : '' %>"><%= language %></span>
</li>
<% end %>
<li class="fl mb10">
<span data-val="other" class="language_type font-14 mr8 bor-gray-c ptl5-10 forum_type <%= @memo.try(:forum).try(:id) == 5 && (@memo.language.nil? || @memo.try(:language).split("/").include?('other')) ? 'forum_type_active' : '' %>">技术分享(其它)</span>
</li>
</div>
</div>
<li class="clearfix mt10 pl30 pr30 mt50">
<a href="javascript:void(0);" class="task-btn task-btn-orange fr" onclick="submitCoursesBoard()">保存</a>
<a href="<%= forums_path %>" class="task-btn fr mr10">取消</a>
</li>
</ul>
<script>
$(function(){
$("span.forum_type").on('click', function(){
if($(this).hasClass("language_type")){
if($(this).hasClass("forum_type_active")){
$(this).removeClass("forum_type_active");
} else{
if($("span.un_language_type.forum_type_active").length > 0){
$("span.un_language_type").removeClass("forum_type_active");
}
if($("span.language_type.forum_type_active").length < 3){
$(this).addClass("forum_type_active");
}
}
$("#forum_type").val("");
for(var i=0; i < $("span.language_type.forum_type_active").length; i++){
$("#forum_type").val().trim() != "" ? $("#forum_type").val($("#forum_type").val() + "/" + $($("span.language_type.forum_type_active")[i]).attr("data-val")) : $("#forum_type").val($($("span.language_type.forum_type_active")[i]).attr("data-val"));
}
} else{
if($(this).hasClass("forum_type_active")){
$(this).removeClass("forum_type_active");
$("#forum_type").val('');
} else{
$("span.forum_type").removeClass("forum_type_active");
$(this).addClass("forum_type_active");
$("#forum_type").val($(this).attr("data-val"));
}
}
});
// var count = 0;
// $("span.forum_type").on('click', function(){
// count++;
// if(count>3){
// $("span.forum_type").removeClass("forum_type_active");
// count=1;
// }
// $(this).addClass("forum_type_active");
// $("#forum_type").val($(this).attr("data-val"));
//
// });
})
function regexSubject() {
var content = $.trim($("#memo_subject").val());
if (content.length == 0) {
$("#memo_notice").show();
return false;
}
else {
$("#memo_notice").hide();
return true;
}
return false;
}
function regexContent() {
if(memo_content_editor.isEmpty()){
$("#new_memo_content_notice").show();
return false;
}
else {
$("#new_memo_content_notice").hide();
return true;
}
return false;
}
function regexForumType(){
if($("#forum_type").val().trim() == ""){
$("#forum_type_notice").show();
return false;
} else{
$("#forum_type_notice").hide();
return true;
}
}
function submitCoursesBoard(){
if(regexSubject() && regexContent() && regexForumType()){
memo_content_editor.sync();
$("#memo-form").submit();
}
}
document.onkeydown = function(event) {
var target, code, tag;
if (!event) {
event = window.event; //针对ie浏览器
target = event.srcElement;
code = event.keyCode;
if (code == 13) {
tag = target.tagName;
if (tag == "INPUT") { return true; }
else { return false; }
}
}
else {
target = event.target; //针对遵循w3c标准的浏览器如Firefox
code = event.keyCode;
if (code == 13) {
tag = target.tagName;
if (tag == "INPUT") { return false; }
else { return true; }
}
}
};
</script>
<% if false %>
<%= content_for(:header_tags) do %>
<%= import_ke(enable_at: false, prettify: false, init_activity: false) %>
<% end %>
<div class="wenba-tiwenbox fl mr10 mb10">
<div class="wenba-tiwen-con">
<ul >
<li class="mb10">
<%= f.text_field :subject,
:no_label => true,
:id => "memo_subject",
:maxlength => "50",
:style => "width:708px",
:onblur => "check_memo_name();",
:onfocus => "$('#memo_name_error_tips').hide();",
:onmouseover => "this.style.borderColor='#d9d9d9'",
:class => "wenba-tiwen-input",
:placeholder => "请输入标题" %>
<p class="c_red" style="display: none" id="memo_name_error_tips"></p>
<script>
var textarea1 = document.getElementById('memo_subject');
autoTextarea(textarea1);
</script>
</li>
<li class="mb10">
<%= f.kindeditor :content, :editor_id => "memo_content", :height => 300, :no_label => true %>
</li>
<p class="c_red" style="display: none" id="memo_contents_error_tips"></p>
<li class="clear mb10">
<%= render :partial => 'forums/file_form', :locals => {:container => @memo} %>
</li>
</ul>
<ul class="wenba-tagbox clearfix">
<h3 class="mb5 c_red" id="memo_classify_tips">请选择分类</h3>
<% @forums.each do |forum| %>
<li class="hidden" style="max-width: 200px;"><a href="javascript:void(0)" class="wenba-tiwen-tag" name="<%= forum.name %>" id="forums_question_<%= forum.id %>" onclick="add_forum('forums_question_<%= forum.id %>')" ><%= forum.name %></a></li>
<% end %>
</ul>
<input type="text" style="display: none" id="forum_name" name="forum_name" value="">
<div class="clear ">
<%= link_to "取消", forum_path(@forum), :class => "btn fr" %>
<a href="javascript:void(0);" class="btn btn-blue fr mr5" onclick="memo_commit();">确定</a>
</div>
</div>
</div>
<script>
$(document).ready(function(){
<% if params[:forum_index] != 'true'%>
$("#forums_question_"+<%= params[:forum_id] %>).addClass("wenba-tiwen-tag-active");
<% end %>
});
function add_forum(id){
$("#memo_classify_tips").attr('style','color: #333;');
$('a').removeClass("wenba-tiwen-tag-active");
$("#"+id).addClass("wenba-tiwen-tag-active");
}
function check_memo_name(){
if($("#memo_subject").val().trim().length > 50){
$("#memo_name_error_tips").html("主题 过长(最长为 50 个字符)").show();
return false;
}
if(memo_content.html().length > 20000){
$("#memo_contents_error_tips").html("内容 过长(最长为 20000 个字符)").show();
$("html,body").animate({scrollTop:$("#memo_contents_error_tips").offset().top},1000);
return false;
}
if($("#memo_subject").val().trim() == ""){
$("#memo_name_error_tips").html("标题不能为空").show();
}
return true;
}
var first_click = true;
function check_and_submit(){
if(!check_memo_name()){
return;
}
if($("textarea[name='memo[subject]']").val().trim() != "" && !memo_content.isEmpty() && first_click){
first_click = false;
memo_content.sync();
$.ajax({
url:'/forums/'+'<%= @forum.id.to_s%>'+'/memos',
type:'post',
data:$("#new_memo").serialize(),
success:function(data){
},
error:function(){
alert('请检查当前网络连接')
}
});
//$("#new_memo").submit();
}else if($("textarea[name='memo[subject]']").val().trim() == "" && memo_content.isEmpty()){
$("#memo_error_tips").html("主题和内容不能为空").show();
}
else if($("textarea[name='memo[subject]']").val().trim() == "" && !memo_content.isEmpty() ){
$("#memo_error_tips").html("主题不能为空").show();
}else if($("textarea[name='memo[subject]']").val().trim() != "" && memo_content.isEmpty()){
$("#memo_error_tips").html("内容不能为空").show();
}
}
var first_click = true;
function memo_commit(){
$("#memo_name_error_tips").hide();
$("#memo_contents_error_tips").hide();
var f_name = $('.wenba-tiwen-tag-active').attr('name');
$("#forum_name").attr('value',f_name);
if($("#memo_subject").val().trim() != "" && !memo_content.isEmpty() && first_click && $("#forum_name").attr('value') != ""){
// alert($("#forum_name").attr('name'));
memo_content.sync();
$("#new_memo").submit();
} else if($("#memo_subject").val().trim() == ""){
$("#memo_name_error_tips").html("标题不能为空").show();
}else if(memo_content.isEmpty()){
$("#memo_contents_error_tips").html("内容不能为空").show();
}else if ($("#forum_name").attr('value')== ""){
$("#memo_classify_tips").attr('style','color: #F00;');
}
}
</script>
<% end %>

View File

@ -0,0 +1,115 @@
<%#= render :partial => "messages/common_reply_box", :locals => {:count => @reply_count, :activity => @topic, :no_children_comments => @replies, :is_teacher => is_teacher} %>
<%= render :partial => "memos/common_reply_box", :locals => {:count => @reply_count, :memo => @memo, :no_children_comments => @replies} %>
<div class="comment_item_cont clearfix">
<div class="comment_reply_box">
<div class="J_Comment_Face fl">
<%= link_to image_tag(url_to_avatar(User.current), :width => "50", :height => "50"), :target => "_blank", :alt => "用户头像" %>
</div>
<div nhname='new_message_<%= @memo.id%>' id="mao<%= @memo.id%>" class="fl ml15 mr20" style="display:none; width: 92.7%;">
<%= form_for('memo', :as => :reply, :url => reply_forum_memo_path(@memo.forum, @memo), :method => "post", :remote => true) do |f|%>
<%#= form_for @memo, :as => :reply, :url => {:action => 'reply', :id => @topic}, :remote => true, :html => {:multipart => true, :id => 'message_form'} do |f| %>
<%#= f.hidden_field :subject, :required => true, value: @memo.subject %>
<%#= f.hidden_field :forum_id, :required => true, value: @memo.forum_id %>
<%#= f.hidden_field :parent_id, :required => true, value: @memo.parent_id %>
<div nhname='toolbar_container_<%= @memo.id%>'></div>
<textarea placeholder="有问题或有建议,请直接给我留言吧!" style="display: none" nhname='new_message_textarea_<%= @memo.id %>' name="content"></textarea>
<a id="new_message_submit_btn_<%= @memo.id%>" href="javascript:void(0)" onclick="this.style.display='none'" class="mt10 task-btn edu-greenback-btn fr">发送</a>
<div class="cl"></div>
<p nhname='contentmsg_<%= @memo.id%>'></p>
<% end%>
</div>
<div class="cl"></div>
</div>
</div>
<% if false %>
<% @replies.each do |reply| %>
<script type="text/javascript">
$(function(){
$("#activity_description_<%= reply.id %> p,#activity_description_<%= reply.id %> span,#activity_description_<%= reply.id %> em").each(function(){
var postContent = $(this).html();
postContent = postContent.replace(/&nbsp;/g," ");
postContent= postContent.replace(/ {2}/g,"&nbsp; ");
postContent=postContent.replace(/&nbsp; &nbsp;/g,"&nbsp;&nbsp;&nbsp;");
postContent=postContent.replace(/&nbsp; /g,"&nbsp;&nbsp; ");
postContent = postContent.replace(/<script>*/g, "<script>");
postContent = postContent.replace(/<html>*/g, "<html>");
$(this).html(postContent);
});
autoUrl('activity_description_<%= reply.id %>');
description_show_hide(<%= reply.id %>);
});
$(".homepagePostReplyDes").mouseover(function(){
$(this).find("a[id*='delete_memo_reply']").show();
}).mouseout(function(){
$(this).find("a[id*='delete_memo_reply']").hide();
});
</script>
<div class="homepagePostReplyContainer" >
<div class="homepagePostReplyPortrait">
<%= link_to image_tag(url_to_avatar(reply.author), :width => 33,:height => 33), user_path(reply.author) %>
</div>
<div class="homepagePostReplyDes" onmouseover="$('#delete_reply_<%=reply.id %>').show();" onmouseout="$('#delete_reply_<%=reply.id %>').hide();">
<div class="homepagePostReplyPublisher">
<%= render :partial => 'users/message_contents', :locals => {:comment => reply, :type => 'Memo', :user_activity_id => @memo.id}%>
</div>
<div class="homepagePostReplyContent break_word" style="margin-bottom:15px;" id="activity_description_<%= reply.id %>">
<p><%= reply.content.gsub(/\/script/, "script").gsub(/script/, "&nbsp;script").html_safe %></p>
</div>
<div class="orig_reply mb10 mt-10">
<div class="reply">
<span class="reply-right">
<span class="reply_praise_count_<%= reply.id %>">
<%= render :partial => "praise_tread/praise", :locals => {:activity => reply, :user_activity_id => reply.id, :type => "reply"} %>
</span>
<span style="position: relative" class="fr mr20">
<%= link_to(
l(:button_reply),
{:action => 'quote', :id => reply},
:remote => true,
:method => 'get',
:title => l(:button_reply)) %>
<span id="reply_iconup_<%= reply.id %>" class="reply_iconup02" style="display: none"> ︿</span>
</span>
<%= link_to(
l(:button_delete),
forum_memo_path(@memo.forum, reply),
:method => :delete,
:id => "delete_reply_#{reply.id}",
:class => 'fr mr20 undis',
:data => {:confirm => l(:text_are_you_sure)},
:title => l(:button_delete)
) if @memo.author.id == User.current.id || User.current.admin? || User.current == @forum.creator %>
</span>
<div class="cl"></div>
</div>
</div>
<div id="reply_message_<%= comment.id%>" class="reply_to_message"></div>
</div>
<div class="cl"></div>
</div>
<% end %>
<% if @limit_count > @page * @limit + 10 %>
<div id="more_memo_replies">
<div class="detail_cont_hide clearfix">
<span class="orig_icon" >&darr; </span>
<span class="orig_icon" style="display:none;" > &uarr;</span>
<%= link_to '点击展开更多回复', forum_memo_path(@memo.forum_id, @memo, :page => @page),:remote=>true %>
</div>
</div>
<% end %>
<% end %>

View File

@ -0,0 +1,150 @@
<div class="homepageLeft-new">
<div class="postDetailContainer">
<div class="fl mr10 pr"> <%= link_to image_tag(url_to_avatar(@forum.creator),:width => 60,:height => 60,:alt => '贴吧图像' ), user_path( @forum.creator) %>
<!--<div class="homepageEditProfile"><a href="javascript:void(0);" class="homepageEditProfileIcon"></a></div>-->
</div>
<div class="fl" style="width: 135px;">
<% user_name = @forum.creator.show_real_name.empty? ? @forum.creator.name : @forum.creator.show_real_name %>
<div class="fl mb8 mt10">吧主:</div>
<a href="<%= user_path(@forum.creator)%>" target="_blank" class="linkBlue w80 fl mb8 mt10" style="overflow: hidden;white-space: nowrap;text-overflow:ellipsis; "><%= user_name %></a>
<div class="fontGrey3 fl">回答:<a href="javascript:void(0);" class="linkOrange mr5" style="cursor: default"><%= @my_replies_count %></a>
<% unless @my_topic_count == 0 %>
帖子:<a href="javascript:void(0);" class="linkOrange" style="cursor: default"><%= @my_topic_count %></a>
<% end %>
</div>
</div>
<div class="cl"></div>
<div class="fl">
<%= link_to @forum.name, forum_path(@forum), :class => "f16 fontBlue", :style => "word-break: break-all; word-wrap:break-word;white-space:pre-wrap;" %>
</div>
<div class="cl"></div>
<div class="fontGrey2 mt10">
<span id="forum_desc_span" style="word-break:normal; width:auto; display:block; white-space:pre-wrap;word-wrap : break-word ;overflow: hidden ;"><%= h @forum.description.html_safe%></span>
<% if @forum.creator.id == User.current.id %>
<a href="javascript:void(0);" onclick="edit_desc();">
<%= image_tag('signature_edit.png',{:width => 12,:height => 12}) %>
</a>
<% end %>
</div>
<% if @forum.creator.id == User.current.id %>
<span class="postEdit"></span>
<%= link_to "编辑贴吧", edit_forum_path(@forum), :class => "linkGrey3", :remote => true %>
<a href="javascript:void(0);" data-method="delete" onclick="del_forum_confirm();" class="fr linkGrey3">删除贴吧</a>
<a href="<%= forum_path(@forum) %>" data-method="delete" id="del_link" type="hidden"></a>
<span class="postDelete"></span>
<% end %>
</div>
<% unless params[:controller] == "forums" %>
<div class="f1">
<%= link_to "<span class='btn-big-blue mt10'>我要提问</span>".html_safe, new_forum_memo_path(:forum_id => @forum) %>
</div>
<% end %>
</div>
<script>
var desc;
function edit_desc(){
desc = $("#forum_desc_span").html();
$("#forum_desc_span").html("<textarea id='forum_desc_input' onblur='change_forum_desc();' style='width: 200px;height: 80px; max-width: 207px; max-height: 80px; border: 1px solid #d9d9d9;outline: none;margin: 0px 0px 12px 0px;'>" + desc + "</textarea>");
$("#forum_desc_input").focus();
}
function change_forum_desc(){
$.ajax({
url: '<%= update_memo_description_forum_path(@forum) %>',
type: 'post',
data:{"forum[description]":$("#forum_desc_input").val().trim()},
success:function(data){
if(data.result == true){
$("#forum_desc_input").hide();
$("#forum_desc_span").html($("#forum_desc_input").val().trim());
}else{
alert("保存失败");
$("#forum_desc_input").hide();
$("#forum_desc_span").html(desc);
}
}
});
}
function delete_forum_tag(doc){
tag_name = doc.parent().children().eq(0).html().trim();
$.ajax(
"<%= delete_forum_tag_forum_path(@forum)+ '.js?tag_name='%>"+tag_name,
{},
function(data){
alert(data == true)
if(data == true){
doc.parent().remove();
}else{
}
}
);
}
function addTag(){
if(<%=@forum.creator.id == User.current.id%>) {
if ($("input[name='addTag']").val().trim() != "" ) {
if($("input[name='addTag']").val().trim().length <= 120) {
$.get(
'<%= add_forum_tag_forum_path(@forum)%>' + "?tag_str=" + $("input[name='addTag']").val(),
{}
);
$("input[name='addTag']").val('');
}else{
alert("标签名字长度不能超过120个字符");
}
}
}
}
var tagNameHtml; //当前双击的链接的父节点的html
var tagName; //标签的值
var parentCssBorder; //当前双击的链接的父节点
var ele; //当前双击的链接
var taggableId; //标签的id
var taggableType; //被标签的类型
//这里renameTag有两种情况一种是改变某个资源的tag名称。如果其他资源也有这个tag。则新增一个改变后的tag名
//第二种是改变某个tag名称。其他所有的资源如果拥有这个tag。那么对应的tag名也要改掉。
//目前这两种依据 的来源就是 是否 传了参数 id。如果有id。就指定了资源id就是第一种情况。如果没有id。就是第二种情况
function rename_tag(domEle,name,id,type){
if(domEle.children().get(0) != undefined ){ //已经是编辑框的情况下不要动
return;
}
tagNameHtml = domEle.parent().html();
tagName = name;
parentCssBorder = domEle.parent().css("border");
ele = domEle;
taggableId = id;
taggableType = type;
width = parseInt(domEle.css('width').replace('px','')) >=100 ? parseInt(domEle.css('width').replace('px','')) : 100;
domEle.html('<input name="" id="renameTagName" maxlength="<%=Setting.tags_max_length%>" minlength="<%= Setting.tags_min_length%>" style="width:'+width+'px;" value="'+name+'"/>');
domEle.parent().css("border","1px solid #ffffff");
$("#renameTagName").focus();
}
$("#renameTagName").live('blur',function(){
if($("#renameTagName")[0] != undefined ){//存在renameTagName,则处于编辑状态
if($("#renameTagName").val().trim() == tagName){ //如果值一样,则恢复原来的状态
ele.parent().css("border","");
ele.parent().html(tagNameHtml);
}else{ //否则就要更新tag名称了
if(confirm("是否将标签改为 "+ $("#renameTagName").val().trim())){
$.post(
'<%= update_tag_name_path %>',
{"taggableId": taggableId, "taggableType": taggableType, "tagName": tagName, "renameName": $("#renameTagName").val().trim()}
)
}else{
ele.parent().css("border","");
ele.parent().html(tagNameHtml);
}
}
}
});
function del_forum_confirm(){
if(confirm('您确定要删除么?')){
$("#del_link").click();
}
}
</script>

View File

@ -0,0 +1,142 @@
<div class="homepageLeft-new">
<div class="postDetailContainer">
<div class="fl mr10 pr"> <%= link_to image_tag(url_to_avatar(@forum.creator),:width => 60,:height => 60,:alt => '贴吧图像' ), user_path( @forum.creator) %>
<!--<div class="homepageEditProfile"><a href="javascript:void(0);" class="homepageEditProfileIcon"></a></div>-->
</div>
<div class="fl" style="width: 135px;">
<% user_name = @forum.creator.show_real_name.empty? ? @forum.creator.name : @forum.creator.show_real_name %>
<div class="fl mb8 mt10">吧主:</div>
<a href="<%= user_path(@forum.creator)%>" target="_blank" class="linkBlue w80 fl mb8 mt10" style="overflow: hidden;white-space: nowrap;text-overflow:ellipsis; "><%= user_name %></a>
<div class="fontGrey3 fl">回答:<a href="javascript:void(0);" class="linkOrange mr5" style="cursor: default"><%= @my_replies_count %></a>
<% unless @my_topic_count == 0 %>
帖子:<a href="javascript:void(0);" class="linkOrange" style="cursor: default"><%= @my_topic_count %></a>
<% end %>
</div>
</div>
<div class="cl"></div>
<div class="fl">
<%= link_to @forum.name, forum_path(@forum), :class => "f16 fontBlue", :style => "word-break: break-all; word-wrap:break-word;white-space:pre-wrap;" %>
</div>
<div class="cl"></div>
<div class="fontGrey2 mt10">
<span id="forum_desc_span" style="word-break:normal; width:auto; display:block; white-space:pre-wrap;word-wrap : break-word ;overflow: hidden ;"><%= h @forum.description.html_safe%></span>
<% if @forum.creator.id == User.current.id %>
<a href="javascript:void(0);" onclick="edit_desc();">
<%= image_tag('signature_edit.png',{:width => 12,:height => 12}) %>
</a>
<% end %>
</div>
</div>
<% unless params[:controller] == "forums" %>
<div class="f1">
<%= link_to "<span class='btn-big-blue mt10'>我要提问</span>".html_safe, new_forum_memo_path(:forum_id => @forum) %>
</div>
<% end %>
</div>
<script>
var desc;
function edit_desc(){
desc = $("#forum_desc_span").html();
$("#forum_desc_span").html("<textarea id='forum_desc_input' onblur='change_forum_desc();' style='width: 200px;height: 80px; max-width: 207px; max-height: 80px; border: 1px solid #d9d9d9;outline: none;margin: 0px 0px 12px 0px;'>" + desc + "</textarea>");
$("#forum_desc_input").focus();
}
function change_forum_desc(){
$.ajax({
url: '<%= update_memo_description_forum_path(@forum) %>',
type: 'post',
data:{"forum[description]":$("#forum_desc_input").val().trim()},
success:function(data){
if(data.result == true){
$("#forum_desc_input").hide();
$("#forum_desc_span").html($("#forum_desc_input").val().trim());
}else{
alert("保存失败");
$("#forum_desc_input").hide();
$("#forum_desc_span").html(desc);
}
}
});
}
function delete_forum_tag(doc){
tag_name = doc.parent().children().eq(0).html().trim();
$.ajax(
"<%= delete_forum_tag_forum_path(@forum)+ '.js?tag_name='%>"+tag_name,
{},
function(data){
alert(data == true)
if(data == true){
doc.parent().remove();
}else{
}
}
);
}
function addTag(){
if(<%=@forum.creator.id == User.current.id%>) {
if ($("input[name='addTag']").val().trim() != "" ) {
if($("input[name='addTag']").val().trim().length <= 120) {
$.get(
'<%= add_forum_tag_forum_path(@forum)%>' + "?tag_str=" + $("input[name='addTag']").val(),
{}
);
$("input[name='addTag']").val('');
}else{
alert("标签名字长度不能超过120个字符");
}
}
}
}
var tagNameHtml; //当前双击的链接的父节点的html
var tagName; //标签的值
var parentCssBorder; //当前双击的链接的父节点
var ele; //当前双击的链接
var taggableId; //标签的id
var taggableType; //被标签的类型
//这里renameTag有两种情况一种是改变某个资源的tag名称。如果其他资源也有这个tag。则新增一个改变后的tag名
//第二种是改变某个tag名称。其他所有的资源如果拥有这个tag。那么对应的tag名也要改掉。
//目前这两种依据 的来源就是 是否 传了参数 id。如果有id。就指定了资源id就是第一种情况。如果没有id。就是第二种情况
function rename_tag(domEle,name,id,type){
if(domEle.children().get(0) != undefined ){ //已经是编辑框的情况下不要动
return;
}
tagNameHtml = domEle.parent().html();
tagName = name;
parentCssBorder = domEle.parent().css("border");
ele = domEle;
taggableId = id;
taggableType = type;
width = parseInt(domEle.css('width').replace('px','')) >=100 ? parseInt(domEle.css('width').replace('px','')) : 100;
domEle.html('<input name="" id="renameTagName" maxlength="<%=Setting.tags_max_length%>" minlength="<%= Setting.tags_min_length%>" style="width:'+width+'px;" value="'+name+'"/>');
domEle.parent().css("border","1px solid #ffffff");
$("#renameTagName").focus();
}
$("#renameTagName").live('blur',function(){
if($("#renameTagName")[0] != undefined ){//存在renameTagName,则处于编辑状态
if($("#renameTagName").val().trim() == tagName){ //如果值一样,则恢复原来的状态
ele.parent().css("border","");
ele.parent().html(tagNameHtml);
}else{ //否则就要更新tag名称了
if(confirm("是否将标签改为 "+ $("#renameTagName").val().trim())){
$.post(
'<%= update_tag_name_path %>',
{"taggableId": taggableId, "taggableType": taggableType, "tagName": tagName, "renameName": $("#renameTagName").val().trim()}
)
}else{
ele.parent().css("border","");
ele.parent().html(tagNameHtml);
}
}
}
});
function del_forum_confirm(){
if(confirm('您确定要删除么?')){
$("#del_link").click();
}
}
</script>

View File

@ -0,0 +1,33 @@
<div class="wenba-tiwenbox">
<div class="wenba-tiwen-con" >
<ul>
<li class="mb10 ">
<input type="text" placeholder="请输入标题" class="wenba-tiwen-input ">
</li>
<li class="mb10">
<textarea placeholder=" 请输入描述详情" class="wenba-tiwen-textarea"></textarea>
</li>
<li class="clear mb10">
<button class="sub_btn fl " name="button" type="button">上传附件</button>
<p class="fl ml5 mt3 c_grey">(未选择文件) 您可以上传小于<span class="c_red">50MB</span>的文件</p>
</li>
</ul>
<ul class="wenba-tagbox clearfix">
<h3 class="mb5">请选择分类(<span class="c_red">1</span>个)</h3>
<li><a href="javascript:void(0);" class="wenba-tiwen-tag wenba-tiwen-tag-active">新手讨论吧</a></li>
<li><a href="javascript:void(0);" class="wenba-tiwen-tag">网站建议吧</a></li>
<li><a href="javascript:void(0);" class="wenba-tiwen-tag">技术动态吧</a></li>
<li><a href="javascript:void(0);" class="wenba-tiwen-tag">教程共享吧</a></li>
<li><a href="javascript:void(0);" class="wenba-tiwen-tag">创业吧</a></li>
<li><a href="javascript:void(0);" class="wenba-tiwen-tag">互联网新闻</a></li>
<li><a href="javascript:void(0);" class="wenba-tiwen-tag">开源创新吧</a></li>
<li><a href="javascript:void(0);" class="wenba-tiwen-tag">网站新闻吧</a></li>
<li><a href="javascript:void(0);" class="wenba-tiwen-tag">技术知识交流</a></li>
<li><a href="javascript:void(0);" class="wenba-tiwen-tag">假日问候吧</a></li>
</ul>
<div class="clear ">
<button class=" btn btn-blue fr ">确定</button >
<button class=" btn fr mr5">取消</button >
</div>
</div>
</div>

View File

@ -0,0 +1,36 @@
<!-- get_praise_num(obj,1)函数中 1代表返回顶得次数 0返回踩的次数 -->
<% if User.current.logged? %>
<% if horizontal %>
<!-- 横排 -->
<div id="praise_tread_<%= obj.id %>" style="float:right; " >
<% @is_valuate = is_praise_or_tread(obj,user_id)%>
<% if @is_valuate.size > 0 %> <!-- 评价过 1代表赞 0代表踩 -->
<% @flag = @is_valuate.first.praise_or_tread %>
<% if @flag == 1 %> <!-- 顶过 --><!-- modified by bai -->
<a href="javascript:void(0);" class="<%= (obj.author.id == User.current.id || obj.forum.creator == User.current || User.current.admin?) ? 'linkGrey2 postLikeIcon mr30':'linkGrey2 postLikeIcon' %>" title="<%= l(:label_issue_praise_over)%>" > <%= get_praise_num(obj)%></a>
<% end %>
<% else %>
<% if user_id == obj.author_id %>
<!--<%#= image_tag "/images/praise_tread/praise_true.png" , weight:"22px", height:"22px",:title => l(:label_issue_not_praise_over) %>-->
<a href="javascript:void(0);" class="linkGrey2 postLikeIcon mr30" title="<%= l(:label_issue_not_praise_over)%>" > <%= get_praise_num(obj)%></a>
<% elsif user_id == obj.forum.creator_id || User.current.admin? %>
<a href="<%= praise_tread_praise_plus_path({:obj_id => obj.id,:obj_type => obj.class, :horizontal => horizontal })%>" data-remote="true" class="linkGrey2 postLikeIcon mr30" title="<%= l(:label_issue_praise)%>" > <%= get_praise_num(obj) %></a>
<% else %>
<!-- 积分少于2分不能踩帖 -->
<%# if OptionNumber.get_user_option_number(user_id).nil? || OptionNumber.get_user_option_number(user_id).total_score < 2 %>
<%#= link_to image_tag("/images/praise_tread/praise_true.png",weight:"22px", height:"22px",:title => l(:label_issue_praise)),
:controller=>"praise_tread",:action=>"praise_plus",:remote=>true,:obj_id => obj.id,:obj_type => obj.class,:horizontal => horizontal %>
<a href="<%= praise_tread_praise_plus_path({:obj_id=>obj.id,:obj_type=>obj.class,:horizontal => horizontal })%>" data-remote="true" class="<%= params[:controller] == 'memos' ? 'linkGrey2 postLikeIcon': 'linkGrey2 postLikeIcon mr30' %>" title="<%= l(:label_issue_praise)%>" > <%= get_praise_num(obj)%></a>
<!--<%# else %>-->
<!--<%#= link_to image_tag("/images/praise_tread/praise_true.png",weight:"22px", height:"22px",:title => l(:label_issue_praise)),-->
<!--:controller=>"praise_tread",:action=>"praise_plus",:remote=>true,:obj_id => obj.id,:obj_type => obj.class,:horizontal => horizontal %>-->
<!--<a href="javascript:void(0);" class="linkGrey2 postLikeIcon" title="<%#= l(:label_issue_praise)%>" target="_blank"> <%#= get_praise_num(obj)%></a>-->
<!--<%# end %>-->
<% end %>
<% end %>
</div>
<% end %>
<% end %>

View File

@ -0,0 +1,20 @@
<%= form_for(@memo_new, url: forum_memos_path, :html => {:multipart => true}) do |f| %>
<%= f.hidden_field :subject, :required => true, value: @memo.subject %>
<%= f.hidden_field :forum_id, :required => true, value: @memo.forum_id %>
<%= f.hidden_field :parent_id, :required => true, value: @memo.id %>
<div id="message_quote" class="wiki"></div>
<%= hidden_field_tag :asset_id,params[:asset_id],:required => false,:style => 'display:none' %>
<%= hidden_field_tag :quote,"",:required => false,:style => 'display:none' %>
<%= label_tag(l(:label_reply_plural)) %>:
<!-- <p> < %= f.text_area :content, :required => true, :size => "75%", :resize => "none", id: 'editor01' %> </p> -->
<%= f.kindeditor :content, :cols => 80, :rows => 15, :value => @content %>
<!--<script type="text/javascript">var ckeditor=CKEDITOR.replace('editor01');</script> -->
<div class="cl" style="padding-top: 10px;"></div>
<p style="float: left;margin-top: 6px;">
<%= l(:label_attachment_plural) %>
<br />
<%= render :partial => 'attachments/form' %>
</p>
<div class="cl"></div>
<%= f.submit value: l(:label_reply_plural), class: "replies" %>
<% end %>

View File

@ -0,0 +1,31 @@
<div class="ReplyToMessageContainer borderBottomNone" id="reply_to_message_<%= reply.id%>">
<div class="homepagePostReplyPortrait mr15 imageFuzzy" id="reply_image_<%= reply.id%>">
<%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), user_path(User.current), :alt => "用户头像" %>
</div>
<div class="ReplyToMessageInputContainer mb10">
<% if User.current.logged? %>
<div nhname='new_message_<%= reply.id%>'>
<%= form_for('memo',:url=>forum_memos_path,:method => "post") do |f|%>
<%= f.hidden_field :subject, :required => true, value: reply.subject %>
<%= f.hidden_field :forum_id, :required => true, value: reply.forum_id %>
<%= f.hidden_field :parent_id, :required => true, value: reply.id %>
<%= hidden_field_tag :quote,"",:required => false,:style => 'display:none' %>
<div nhname='toolbar_container_<%= reply.id%>' class="kindeditor"></div>
<textarea placeholder="有问题或有建议,请直接给我留言吧!" style="display: none" nhname='new_message_textarea_<%= reply.id%>' name="memo[content]"></textarea>
<a id="new_message_submit_btn_<%= reply.id%>" href="javascript:void(0)" onclick="this.style.display='none'" class="blue_n_btn fr" style="display:none;margin-top:6px;">发送</a>
<div class="cl"></div>
<p nhname='contentmsg_<%= reply.id%>'></p>
<% end%>
</div>
<% else %>
<%= render :partial => "users/show_unlogged" %>
<% end %>
<div class="cl"></div>
</div>
<div class="cl"></div>
</div>
<script>
$(function(){
sd_create_editor_from_data(<%= reply.id%>,null,"100%", "<%=reply.class.to_s%>");
});
</script>

View File

@ -0,0 +1,17 @@
<%= labelled_form_for(@memo, :url => forum_memos_path) do |f| %>
<div class="actions" style="max-width:680px;">
<%= hidden_field_tag :asset_id,params[:asset_id],:required => false,:style => 'display:none' %>
<p><%= f.text_field :subject, :required => true, :size => 95, :style => 'width:98%' %></p>
<p style="max-width:680px"><%= f.kindeditor :content,:width=>'99%', :required => true %></p>
<!--<script type="text/javascript">var ckeditor=CKEDITOR.replace('editor01');</script> -->
<div class="cl"></div>
<label class="fl" style="margin-left: -80px;margin-top: 5px;"><%= l(:label_attachment_plural) %></label>
<div style="margin-left: 10px;" class="fl">
<%= render :partial => 'attachments/form', :locals => {:container => @memo} %>
</div>
<div class="cl"></div>
<%= f.submit :value => l(:label_memo_create), :style => "margin-left: 100px;"%> <%= link_to l(:button_back), forum_path(@forum) %>
</div>
<% end %>

View File

@ -0,0 +1 @@
window.location.href='<%= forum_memo_path(:forum_id => @memo.forum_id, :id => @memo.id ) %>';

View File

@ -0,0 +1,6 @@
<% if params[:user_activity_id] %>
$("#message_replies_box").html("<%= escape_javascript(render :partial => 'memos/memo_all_replies') %>");
sd_create_editor_from_data(<%= @memo.id %>,"","100%", "<%= @memo.class.to_s %>");
<% else %>
$("#memo_detail_<%= params[:id] %>").remove();
<% end %>

View File

@ -0,0 +1,15 @@
<div class="edu-class-container edu-position">
<p class="mb10 font-14">
<i class="fa fa-map-marker mr5 color-grey"></i>
<a href="<%= user_path(@user) %>"><%= @user.show_real_name %></a> &gt; <a href="<%= forums_path %>">讨论 </a> &gt; 编辑
</p>
<div class="edu-con-top user_bg_shadow bor-grey-e">
<p class="ml15 color-grey3">编辑话题</p>
</div>
<div class="edu-con-bg01 mt15 user_bg_shadow bor-grey-e pt30 pb30">
<%#= labelled_form_for(@memo, :url => forum_memos_path(@forum)) do |f| %>
<%= form_for @memo, :url => forum_memo_path(@memo.forum_id, @memo), :html => {:multipart => true, :id => 'memo-form'} do |f| %>
<%= render :partial => "memos/form", :locals => {:f => f, :edit => true} %>
<% end %>
</div>
</div>

View File

@ -0,0 +1,9 @@
<%# if @user_activity_id != @memo.id %>
/* $("#activity_post_reply_<%#= @user_activity_id %>").html("<%#= escape_javascript(render :partial => 'users/course_message_post_reply',
:locals => { :activity => @memo,
:user_activity_id => @user_activity_id}) %>");
sd_create_editor_from_data(<%#= @user_activity_id%>,"","100%", "UserActivity");*/
<%# else %>
$("#message_replies_box").html("<%= escape_javascript(render :partial => 'memos/memo_all_replies') %>");
sd_create_editor_from_data(<%= @memo.id %>,"","100%", "<%= @memo.class.to_s %>");
<%# end %>

View File

@ -0,0 +1,15 @@
<div class="edu-class-container edu-position">
<p class="mb10 font-14">
<i class="fa fa-map-marker mr5 color-grey"></i>
<a href="<%= user_path(@user) %>"><%= @user.show_real_name %></a> &gt; <a href="<%= forums_path %>">讨论区 </a> &gt; 新建
</p>
<div class="edu-con-top user_bg_shadow bor-grey-e">
<p class="ml15 color-grey3">新建话题</p>
</div>
<div class="edu-con-bg01 mt15 user_bg_shadow bor-grey-e pt30 pb30">
<%#= labelled_form_for(@memo, :url => forum_memos_path(@forum)) do |f| %>
<%= form_for @memo, :url => forum_memos_path(@forum), :html => {:multipart => true, :id => 'memo-form'} do |f| %>
<%= render :partial => "memos/form", :locals => {:f => f, :edit => false} %>
<% end %>
</div>
</div>

View File

View File

@ -0,0 +1,6 @@
if($("#reply_message_<%= @memo.id%>").html() == "") {
$(".reply_to_message").html("");
$("#reply_message_<%= @memo.id%>").replaceWith("<%= escape_javascript(render :partial => 'memos/reply_message', :locals => {:reply => @memo}) %>");
}else {
$("#reply_message_<%= @memo.id%>").html("");
}

View File

@ -0,0 +1,233 @@
<%= content_for(:header_tags) do %>
<%= import_ke(enable_at: false, prettify: false, init_activity: true) %>
<% end %>
<div class="clearfix">
<div class="edu-class-container edu-position">
<p class="mb10 font-14">
<i class="fa fa-map-marker mr5 color-grey"></i>
<a href="<%= user_path(@user)%>"><%= @user.show_real_name %></a> &gt; <a href="<%= forums_path %>">讨论区 </a>
</p>
<div class="edu-con-top user_bg_shadow bor-grey-e clearfix mb20">
<p class="ml15 color-grey3 fl">
帖子详情
</p>
<%= link_to '返回', forums_path(:type => @type, :page => @forum_page), :class => 'fr font-12 mr15 mt3 color-grey' %>
<!-- <p class="color-grey fr font-12 mr15 mt5"><a href="javascript:void(0)">返回</a></p>-->
</div>
<div class="edu-tab clearfix mb20 user_bg_shadow bor-grey-e">
<div class="panel-inner-fourm nobg">
<div class="clearfix pr">
<a href="<%= user_path(@memo.author) %>" class="fl">
<%= image_tag(url_to_avatar(@memo.author), :width => 60, :height => 60, :alt=>'用户头像', :class=>"panel-list-img mr15" ) %>
</a>
<div class="panel-list-infobox fl" style="margin:0;margin-left: 6px">
<div class="clearfix mb5">
<p class="color-grey3 fl" style="font-size: 16px;">
<%= h @memo.subject %>
<% if @memo.sticky %>
<span class="btn-top btn-cir-orange mt5 ml5">置顶</span>
<% end %>
</p>
<!-- <p class="color-grey fr font-12 mr15 mt5"><a href="javascript:void(0)">返回</a></p>-->
</div>
<p class="mb10">
<a href="<%= user_path(@memo.author) %>" class="font-14 mr15 color-grey" target="_blank"><%= @memo.author.show_real_name %></a><span class="font-14 color-grey">更新于<%= time_from_now @memo.updated_at %></span>
<span id="reword_score_<%= @memo.id %>">
<% if @memo.try(:reward).present? %>
<span class="ml15 color-orange03" style="cursor: default;" data-tip-down="获得平台奖励金币:<%= @memo.try(:reward) %>"><i class="fa fa-gift mr5 font-16"></i><%= @memo.try(:reward) %></span>
<% end %>
</span>
</p>
<!--<p class="color-grey panel-lightgrey fl mt3">-->
<!--<span class="fl mr10 mt2">类别:分享</span>-->
<!-- </p>-->
</div>
<% if @user.admin? || @user == @memo.author %>
<div class="edu-position-hidebox" style="position: absolute;right: 10px;top:0px;">
<a href="javascript:void(0);"><i class="fa fa-bars font-16"></i></a>
<ul class="edu-position-hide undis">
<% if @user.admin? %>
<% if @memo.sticky %>
<li><a href="<%= change_sticky_forum_memo_path(@memo.forum,@memo) %>">取消置顶</a></li>
<% else %>
<li><a href="<%= change_sticky_forum_memo_path(@memo.forum,@memo) %>">置&nbsp;&nbsp;顶</a></li>
<% end %>
<% end %>
<li><a href="<%= edit_forum_memo_path(@memo.forum, @memo)%>">编&nbsp;&nbsp;辑</a></li>
<li><a href="javascript:void(0)" onclick="delete_confirm_box_3('<%= forum_memo_path(@memo.forum, @memo) %>', '您确定要删除吗?')">删&nbsp;&nbsp;除</a></li>
</ul>
</div>
<% end %>
</div>
<div class="panel-inner-info clearfix memos_con" style="line-height: 1.5">
<!--帖子内容-->
<%= @memo.content.html_safe %>
</div>
<ul class="panel-inner-info clearfix">
<!--上传的文件内容-->
<% if @memo.attachments.any?%>
<% options = {:author => true, :deletable => @memo.deleted_attach_able_by?(User.current) } %>
<%= render :partial => 'attachments_links', :locals => {:attachments => @memo.attachments, :options => options, :is_float => true} %>
<% end %>
</ul>
</div>
<div class="panel-mesbox" id="message_replies_box">
<%= render :partial => "memo_all_replies" %>
</div>
</div>
</div>
</div>
<script>
function ThumbUp(item){
$(item).toggleClass("orange-btn");
$(item).toggleClass("orange-bg-btn");
if($(item).attr("attr-thumb")=="0"){
$(item).find("span").html(parseInt($(item).find("span").html())+1);
$(item).attr("attr-thumb","1");
}else{
$(item).find("span").html(parseInt($(item).find("span").html())-1);
$(item).attr("attr-thumb","0");
}
}
$(function(){
sd_create_editor_from_data(<%= @memo.id %>, null, "100%", "<%= @memo.class.to_s %>");
});
</script>
<% if false %>
<%= content_for(:header_tags) do %>
<%= import_ke(enable_at: false, prettify: false, init_activity: true) %>
<%= javascript_include_tag 'forum' %>
<% end %>
<div class="banner-big f16 fontGrey3 mb10">
<%= link_to "问吧", forums_path, :class => "c_blue" %> > <%= link_to @forum.name, forum_path(@forum), :class => "c_blue" %> > <%=h @memo.subject %>
</div>
<script>
$(function() {
sd_create_editor_from_data(<%= @memo.id%>,null,"100%", "<%=@memo.class.to_s%>");
});
function del_confirm(){
if(confirm('确认删除么?')){
$("#del_memo_link").click();
}else{
}
}
</script>
<div class="postRightContainer mr10">
<div class="postThemeContainer">
<div class="postDetailPortrait">
<%= link_to image_tag(url_to_avatar(@memo.author),:width=>50,:height => 50,:alt=>'贴吧图像' ),user_path(@memo.author) %>
</div>
<div class="postThemeWrap">
<% if @memo.author.id == User.current.id || User.current.admin? || User.current == @forum.creator %>
<div class="homepagePostSetting">
<ul>
<li class="homepagePostSettingIcon">
<ul class="homepagePostSettiongText">
<% if @memo.author.id == User.current.id || User.current.admin? %>
<li><a href="<%= edit_forum_memo_path(@memo.forum,@memo)%>" class="postOptionLink">编辑</a></li>
<% end %>
<% if User.current.admin? || User.current == @forum.creator %>
<% if @memo.sticky %>
<li><a href="<%= change_sticky_forum_memo_path(@memo.forum,@memo) %>" class="postOptionLink">取消置顶</a></li>
<% else %>
<li><a href="<%= change_sticky_forum_memo_path(@memo.forum,@memo) %>" class="postOptionLink">置顶</a></li>
<% end %>
<% end %>
<li><a href="javascript:void(0);" class="postOptionLink" onclick="del_confirm();">删除</a></li>
<li style="display: none"><a href="<%= forum_memo_path(@memo.forum, @memo) %>" data-method="delete" id="del_memo_link" ></a></li>
</ul>
</li>
</ul>
</div>
<% end %>
<div class="postDetailTitle fl">
<a href="javascript:void(0);" class="f14 linkGrey4 fb" style="overflow:hidden;">主题: <%= @memo.subject%></a>
</div>
<%= render :partial => "memos/praise_tread",:locals => {:obj => @memo,:show_flag => true,:user_id =>User.current.id,:horizontal => true}%>
<div class="cl"></div>
<div class="postDetailCreater">
<%= link_to @memo.author.show_real_name, user_path(@memo.author), :class => "linkBlue2", :target=> "_blank"%></div>
<div class="postDetailDate mb5"><%= format_date( @memo.created_at)%></div>
<div class="cl"></div>
<div class="homepagePostIntro memo-content ke-block" id="activity_description_<%= @memo.id %>" style="word-break: break-all; word-wrap:break-word;margin-bottom: 0px !important;" >
<%= @memo.content.html_safe%>
</div>
<div class="cl"></div>
<div class=" fl" style="width: 600px">
<% if @memo.attachments.any?%>
<% options = {:author => true, :deletable => @memo.deleted_attach_able_by?(User.current) } %>
<%= render :partial => 'attachments_links', :locals => {:attachments => @memo.attachments, :options => options, :is_float => true} %>
<% end %>
</div>
<div class="cl"></div>
<span class=" fr" style="color: #888888; font-size: 12px;">更新时间:<%= format_date(@memo.updated_at)%></span>
</div>
<div class="cl"></div>
</div>
<div class="cl"></div>
<div class="homepagePostReply">
<div class="homepagePostReplyBanner">
<div class="homepagePostReplyBannerCount">回复(<%= @reply_count %></div>
<div class="homepagePostReplyBannerTime"></div>
</div>
<div class="" id="reply_div_<%= @memo.id %>">
<%= render :partial => 'memos/memo_all_replies' %>
</div>
<div class="cl"></div>
<div class="homepagePostReplyContainer borderBottomNone minHeight48">
<div class="homepagePostReplyPortrait mr15 imageFuzzy" id="reply_image_<%= @memo.id%>"><%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), user_path(User.current), :alt => "用户头像" %></div>
<div class="homepagePostReplyInputContainer mb10">
<% if User.current.logged? %>
<div nhname='new_message_<%= @memo.id%>' style="display:none;">
<%= form_for('memo',:url=>forum_memos_path,:method => "post") do |f|%>
<%= f.hidden_field :subject, :required => true, value: @memo.subject %>
<%= f.hidden_field :forum_id, :required => true, value: @memo.forum_id %>
<%= f.hidden_field :parent_id, :required => true, value: @memo.id %>
<%= hidden_field_tag :quote,"",:required => false,:style => 'display:none' %>
<div nhname='toolbar_container_<%= @memo.id%>' class="kindeditor"></div>
<textarea placeholder="有问题或有建议,请直接给我留言吧!" style="display: none" nhname='new_message_textarea_<%= @memo.id %>' name="memo[content]"></textarea>
<a id="new_message_submit_btn_<%= @memo.id%>" href="javascript:void(0)" onclick="this.style.display='none'" class="blue_n_btn fr" style="display:none;margin-top:6px;">发送</a>
<div class="cl"></div>
<p nhname='contentmsg_<%= @memo.id%>'></p>
<% end%>
</div>
<% else %>
<%= render :partial => "users/show_unlogged" %>
<% end %>
<div class="cl"></div>
</div>
<div class="cl"></div>
</div>
</div>
</div>
<div class="fl">
<%= render :partial => "memos/my_show_count_message" %>
</div>
<script type="text/javascript">
$(function(){
$("#activity_description_<%= @memo.id %> p,#activity_description__<%= @memo.id %> span,#activity_description_<%= @memo.id %> em").each(function(){
var postContent = $(this).html();
postContent = postContent.replace(/&nbsp;/g," ");
postContent= postContent.replace(/ {2}/g,"&nbsp; ");
postContent=postContent.replace(/&nbsp; &nbsp;/g,"&nbsp;&nbsp;&nbsp;");
postContent=postContent.replace(/&nbsp; /g,"&nbsp;&nbsp; ");
$(this).html(postContent);
});
autoUrl('activity_description_<%= @memo.id %>');
description_show_hide(<%= @memo.id %>);
});
</script>
<% end %>

View File

@ -0,0 +1 @@
$("#more_memo_replies").replaceWith("<%= escape_javascript(render :partial => 'memos/memo_all_replies')%>");

View File

@ -0,0 +1,5 @@
<% if @flag%>
window.location.href='<%= forum_memo_path(:forum_id=>@memo.forum_id,:id=>@memo.id ) %>'
<%else%>
$("#error").html('内容填写存在错误');
<% end %>

View File

@ -0,0 +1,577 @@
# encoding=utf-8
class ForumSectionsService
include ApplicationHelper
include ApiIndexHelper
LIMIT = 10
def index params
index_sections = all_sections(params[:is_detail] || nil)
{status: 0, forum_sections: index_sections}
end
def select_sections
forum_root_tags = ForumSection.roots.select([:id, :title, :ancestry])
get_all_sections(forum_root_tags)
end
def create params, current_user
set_forum_section(params[:id])
return {status: -1, message: "请登录"} unless check_user_permission(current_user, params[:id])
if params[:title].strip.length > 20
{status: -1, message: "不能超过最大限制20个字符"}
elsif ForumSection.exists?(title: params[:title].strip)
{status: -1, message: "不能重名"}
else
forum_section_params = {
user_id: current_user.id,
title: params[:title].strip,
parent_id: params[:id],
is_recommend: false
}
forum_section = ForumSection.new(forum_section_params)
if forum_section.save
{status: 0, message: "创建成功", title: params[:title], childre_section_id: forum_section.id }
else
{status: -1, message: "保存失败"}
end
end
end
def rename params, current_user
set_forum_section(params[:id])
return {status: -1, message: "请登录"} unless check_user_permission(current_user, params[:id])
if params[:title].strip.length > 20
{status: -1, message: "不能超过最大限制20个字符"}
elsif ForumSection.exists?(title: params[:title].strip)
{status: -1, message: "不能重名"}
else
forum_section = ForumSection.find(params[:children_section_id])
if forum_section.update_attribute(:title, params[:title].strip)
{status: 0, message: "重命名成功", title: params[:title].strip, childre_section_id: params[:children_section_id] }
else
{status: -1, message: "重命名失败"}
end
end
end
def destroy params, current_user
set_forum_section(params[:id])
return {status: -1, message: "请登录"} unless check_user_permission(current_user, params[:id])
forum_section = ForumSection.find(params[:children_section_id])
if forum_section.destroy
{status: 0, message: "删除成功"}
else
{status: -1, message: "删除失败"}
end
end
def order_forums params, current_user
set_forum_section(params[:id])
return {status: -1, message: "请登录"} unless check_user_permission(current_user, params[:id])
children_forums = @forum_section.children_forum.order("created_at #{params[:order_type]}")
children_forums_sections = get_children_sections(children_forums)
forum_tag = {
title: @forum_section.try(:title),
id: @forum_section.try(:id),
children_tags: children_forums_sections
}
{status:0, forum_tag: forum_tag }
end
def search_users params, current_user
set_forum_section(params[:id])
return {status: -1, message: "请登录"} unless check_user_permission(current_user, params[:id])
search_users = []
user_name = params[:user_name].to_s.strip
page = params[:page].to_i > 0 ? (params[:page].to_i - 1) : 0
offset = page * LIMIT
# if user_name.blank?
# users_count = 0
# else
#
# end
users = User.where("( LOWER(login) LIKE ? or LOWER(concat(lastname, firstname)) LIKE ? or LOWER(mail) LIKE ? )",
"%#{user_name}%","%#{user_name}%","%#{user_name}%")
users_count = users.size
users = users.order("created_on desc").limit(LIMIT).offset(offset)
users.each do |u|
user_item = {
id: u.id,
login: u.try(:login),
username: u.try(:show_real_name),
nickname: u.try(:nickname)
}
search_users.push(user_item)
end
{status:0, user_lists: search_users, users_count: users_count, limit: LIMIT}
end
def add_users params, current_user
set_forum_section(params[:id])
return {status: -1, message: "请登录"} unless check_user_permission(current_user, params[:id])
user_ids = params[:user_ids].reject(&:blank?)
children_forum_id = params[:children_section_id]
if user_ids.present?
forum_users = []
user_ids.each do |id|
unless ForumModerator.exists?(user_id: id, forum_section_id:children_forum_id)
moder_lists = {
user_id: id,
forum_section_id: children_forum_id,
is_children: true
}
new_forum_moder = ForumModerator.new(moder_lists)
if new_forum_moder.save
user = new_forum_moder.user
user_list = {
forum_moderator_id: new_forum_moder.id,
login: user.try(:login),
username: user.try(:show_real_name),
user_url: "/users/#{user.try(:login)}"
}
forum_users.push(user_list)
end
end
end
{status:0, message: "用户添加成功", user_lists: forum_users}
else
{status:-1, message: "请添加管理员"}
end
end
#一级版主的管理模块
def managements params, current_user
set_forum_section(params[:id])
return {status: -1, message: "请登录"} unless check_user_permission(current_user, params[:id])
bread_crumb = get_bread_crumb(@forum_section, current_user)
#当为一级分类时
# current_user_info = format_for_current_user current_user
if @forum_section.root?
children_forum_sections = @forum_section.children.select([:id,:title, :ancestry])
children_forum_users = get_children_sections(children_forum_sections)
forum_tag = {
title: @forum_section.try(:title),
id: @forum_section.try(:id),
children_tags: children_forum_users
}
else #当为二级分类时
forum_tag = {
title: @forum_section.try(:title),
id: @forum_section.try(:id)
}
end
# if @forum_section.parent_id.present?
# forum_tag = {
# title: @forum_section.try(:title),
# id: @forum_section.try(:id),
# }
# else #当为一级分类时
# children_forum_sections = ForumSection.where(parent_id: @forum_section.id).select([:id,:title])
# children_forum_users = get_children_sections(children_forum_sections)
# forum_tag = {
# title: @forum_section.try(:title),
# id: @forum_section.try(:id),
# children_tags: children_forum_users
# }
# end
user_management_sections = []
#当前用户具有的管理权限的版块
current_user_forum_ids = current_user.forum_moderators.pluck(:forum_section_id)
current_user_parent_forums = ForumSection.roots.where(id: current_user_forum_ids).select([:id,:title, :ancestry])
current_user_parent_forums.each do |section|
manage_children_forum_sections = section.children.select([:id,:title])
section_forum_tag = {
title: section.try(:title),
id: section.try(:id),
children_tags: object_to_hash(manage_children_forum_sections)
}
user_management_sections.push(section_forum_tag)
end
{status: 0, bread_crumb: bread_crumb, forum_tag: forum_tag, user_manage_sections: user_management_sections}
end
#处理申请的页面
def applied_forums params, current_user
set_forum_section(params[:id])
return {status: -1, message: "请登录"} unless check_user_permission(current_user, params[:id])
if @forum_section.parent_id.present?
applied_forum_moderators = {}
else
applied_forum_moderators = []
all_applied_forums = @forum_section.apply_forums.where(is_confirm: 0) #待审批的版主申请
if all_applied_forums.size > 0
all_applied_forums.each do |apply|
user = apply.user
forum_section = apply.forum_section
parent_forum_section_array = {}
if forum_section.parent_id.present?
parent_forum_section = forum_section.parent_forum
parent_forum_section_array = {
forum_title: parent_forum_section.try(:title),
forum_id: parent_forum_section.try(:id),
forum_url: "/memos/forum_memos/#{parent_forum_section.try(:id)}",
}
end
apply_user = {
apply_id: apply.id,
username: user.try(:show_real_name),
login: user.try(:login),
image_url: "#{url_to_avatar(user)}?#{Time.now.to_i}",
user_url: "/users/#{user.try(:login)}",
user_ip: apply.user_ip,
user_ip_address: get_user_ip(apply.user_ip),
time: time_from_now(apply.created_at),
forum_title: forum_section.try(:title),
forum_id: forum_section.try(:id),
forum_url: "/memos/forum_memos/#{forum_section.try(:id)}",
parent_forum: parent_forum_section_array
}
applied_forum_moderators.push(apply_user)
end
end
end
{status: 0, applied_moderators: applied_forum_moderators}
end
#处理版主的申请
def deal_applies params, current_user
set_forum_section(params[:id])
return {status: -1, message: "请登录"} unless check_user_permission(current_user, params[:id])
apply_forum = ApplyForum.find(params[:apply_id])
if apply_forum.present?
apply_forum.update_attributes(is_confirm: params[:deal_type].to_i, confirm_user_id: current_user.id, deal_time: Time.now)
forum_moder = ForumModerator.where(user_id: apply_forum.user_id,forum_section_id: params[:id])
if params[:deal_type].to_i == 2
forum_moder.delete_all if forum_moder.exists?
elsif params[:deal_type].to_i == 1
unless forum_moder.exists?
ForumModerator.create(user_id: apply_forum.user_id, forum_section_id: params[:id],is_children: @forum_section.try(:parent_id).present?)
end
end
review_params = {
review_status: params[:deal_type].to_i,
reason: nil,
user_id: current_user.id,
reviewable_type: "ApplyForum",
reviewable_id: params[:apply_id],
source: "apply_forum"
}
if Review.exists?(reviewable_type: "ApplyForum", reviewable_id: params[:apply_id], source: "apply_forum")
this_review = Review.where(reviewable_type: "ApplyForum", reviewable_id: params[:apply_id], source: "apply_forum").first
this_review.update_attributes(review_params)
else
Review.create(review_params)
end
status = 1
msg = "操作成功"
else
status = -1
msg = "操作失败"
end
{status: status, message: msg}
end
def destroy_moderator params, current_user
set_forum_section(params[:id])
return {status: -1, message: "请登录"} unless check_user_permission(current_user, params[:id])
forum_manager = ForumModerator.find(params[:moderator_id])
if forum_manager.present?
if forum_manager.destroy
status = 1
msg = "删除成功"
else
status = -1
msg = "删除失败"
end
else
status = -1
msg = "用户不存在"
end
{status: status, message: msg}
end
def user_apply params, current_user, user_ip
set_forum_section(params[:id])
if @forum_section.forum_moderators.exists?(user_id: current_user.id)
status = -1
msg = "您已经是该版块的版主"
elsif ApplyForum.exists?(user_id: current_user.id, is_confirm: [0,1])
status = -1
msg = "您已提交了版主申请"
else
apply_params = {
user_id: current_user.id,
user_ip: user_ip,
forum_section_id: params[:id],
is_confirm: 0
}
apply_forum = ApplyForum.new(apply_params)
if apply_forum.save
status = 0
msg = "申请成功"
if @forum_section.parent_id.present?
parent_section_id = @forum_section.parent_id
manager_ids = ForumModerator.where(forum_section_id: @forum_section.parent_id).pluck(:user_id)
extra = "2"
else
parent_section_id = ""
manager_ids = User.select(:admin, :id).admin_users.pluck(:id)
# admin_role_ids= AdminRole.includes(:admin_permissions).joins(:admin_permissions).where("admin_permissions.name = 'forum_post'").pluck(:id)
# manager_ids = UserAdminRole.where(admin_role_id: admin_role_ids).pluck(:user_id).uniq
extra = "1"
end
if manager_ids.size == 0
manager_ids = [1]
end
manager_ids.each do |id|
Tiding.create(:user_id => id, :trigger_user_id => current_user.id,
container_id: params[:id], container_type: 'ForumSection',
:parent_container_id => parent_section_id, :parent_container_type => "ForumSection",
:viewed => 0,status: 0, :tiding_type => "ForumSection",extra: extra)
end
else
status = -1
msg = "申请失败,请稍后重试"
end
end
{status: status, message: msg }
end
#待审核的帖子
def unchecked_memos params, current_user
set_forum_section(params[:id])
return {status: -1, message: "请登录"} unless check_user_permission(current_user, params[:id])
select_section_ids = [params[:id]]
# unless @forum_section.parent_id.present?
children_forums = @forum_section.child_ids
select_section_ids = select_section_ids + children_forums
#end
select_section_ids.uniq
# page = params[:page].to_i
page = params[:page].to_i > 0 ? (params[:page].to_i - 1) : 0
offset = page * LIMIT
# memo_forum_section_ids = MemoForum.where(forum_id: select_section_ids).pluck(:memo_id).uniq
memos_all = Memo.where(hidden:true, published_at: nil, parent_id: nil, forum_section_id: select_section_ids).order("created_at desc")
# memos_all = Memo.where(hidden: true, parent_id: nil, id: memo_forum_section_ids).joins(:memo_forums).where("memo_forums.forum_id in (#{select_section_ids.join(",")})").order("created_at desc")
memos_count = memos_all.size
memos = memos_all.limit(LIMIT).offset(offset)
memos_lists = []
memos.each do |memo|
user = memo.author
is_banned = user_is_banned?(user)
if memo.memo_forums.exists?(is_children: true)
memo_min_sections = memo.memo_forums.where(is_children: true).first
else
memo_min_sections = memo.memo_forums.first
end
memo_last_section = memo_min_sections&.forum_section
memo_list = {
memo_id: memo.id,
is_banned: is_banned,
memo_title: memo.subject,
username: user.try(:show_real_name),
login: user.try(:login),
image_url: "#{url_to_avatar(user)}?#{Time.now.to_i}",
user_url: "/users/#{user.try(:login)}",
user_id: user.try(:id),
time: time_from_now(memo.updated_at),
forum_title: memo_last_section.try(:title),
forum_id: memo_last_section.try(:id),
forum_url: "/memos/forum_memos/#{memo_last_section.try(:id)}",
}
memos_lists.push(memo_list)
end
{status:0, memos_count: memos_count, memos_lists: memos_lists, limit: LIMIT}
end
def unchecked_replies params, current_user
set_forum_section(params[:id])
return {status: -1, message: "请登录"} unless check_user_permission(current_user, params[:id])
select_section_ids = [params[:id]]
# unless @forum_section.parent_id.present?
children_forums = @forum_section.child_ids
select_section_ids = select_section_ids + children_forums
# end
select_section_ids.uniq
# page = params[:page].to_i
page = params[:page].to_i > 0 ? (params[:page].to_i - 1) : 0
offset = page * LIMIT
#全部的父帖子
parent_memos_ids = Memo.where(parent_id: nil).joins(:memo_forums).where("memo_forums.forum_id in (#{select_section_ids.join(",")})").pluck(:id).uniq
# memos_all = Memo.where(hidden:true,published_at: nil, parent_id: parent_memos_ids).order("created_at ASC")
memos_all = Memo.where(hidden:true, published_at: nil, parent_id: nil, forum_section_id: select_section_ids).order("created_at desc")
memos_count = memos_all.size
memos = memos_all.limit(LIMIT).offset(offset)
memos_lists = []
memos.each do |memo|
user = memo.author
is_banned = user_is_banned?(user)
parent_memo = Memo.find_by_id(memo.parent_id)
memo_list = {
is_banned: is_banned,
reply_id: memo.id,
reply_content: memo.content,
username: user.try(:show_real_name),
login: user.try(:login),
image_url: "#{url_to_avatar(user)}?#{Time.now.to_i}",
user_url: "/users/#{user.try(:login)}",
user_id: user.try(:id),
time: time_from_now(memo.updated_at),
source_title: parent_memo.try(:subject),
source_id: parent_memo.try(:id),
}
memos_lists.push(memo_list)
end
{status:0, replies_count: memos_count, replies_lists: memos_lists, limit: LIMIT}
end
def checked_memos params, current_user
set_forum_section(params[:id])
return {status: -1, message: "请登录"} unless check_user_permission(current_user, params[:id])
select_section_ids = [params[:id]]
# unless @forum_section.parent_id.present?
children_forums = @forum_section.child_ids
select_section_ids = select_section_ids + children_forums
# end
select_section_ids.uniq
# page = params[:page].to_i
page = params[:page].to_i > 0 ? (params[:page].to_i - 1) : 0
offset = page * LIMIT
#全部的父帖子
# memo_forum_section_ids = MemoForum.where(forum_id: select_section_ids).pluck(:memo_id).uniq
memos_all = Memo.where(hidden: false,parent_id: nil, forum_section_id: select_section_ids).order("created_at desc")
# memos_all = Memo.where(hidden: false, parent_id: nil).joins(:memo_forums).where("memo_forums.forum_id in (#{select_section_ids.join(",")})")
if params[:type].present?
if params[:type] == "sticky"
memos_all = memos_all.where(sticky: true)
end
if params[:type] == "is_fine"
memos_all = memos_all.where(is_fine: true)
end
end
memos_all = memos_all.order("sticky desc, is_fine desc,published_at desc")
memos_count = memos_all.size
memos = memos_all.limit(LIMIT).offset(offset)
memos_lists = []
memos.each do |memo|
user = memo.author
is_banned = user_is_banned?(user)
if memo.memo_forums.exists?(is_children: true)
memo_min_sections = memo.memo_forums.where(is_children: true).first
else
memo_min_sections = memo.memo_forums.first
end
memo_last_section = memo_min_sections&.forum_section
memo_list = {
memo_id: memo.id,
is_banned: is_banned,
memo_title: memo.subject,
username: user.try(:show_real_name),
login: user.try(:login),
image_url: "#{url_to_avatar(user)}?#{Time.now.to_i}",
user_url: "/users/#{user.try(:login)}",
time: time_from_now(memo.updated_at),
forum_title: memo_last_section.try(:title),
forum_id: memo_last_section.try(:id),
forum_url: "/memos/forum_memos/#{memo_last_section.try(:id)}",
is_fine: memo.is_fine,
sticky: memo.sticky
}
memos_lists.push(memo_list)
end
{status:0, memos_count: memos_count, memos_lists: memos_lists, limit: LIMIT}
end
def forum_section_header params, current_user
forum_section = ForumSection.find_by_id(params[:id])
bread_crumb = get_bread_crumb(forum_section, current_user)
{status: 0, bread_crumb: bread_crumb}
end
def edit_notice params
forum_section = ForumSection.find_by_id(params[:id])
return {status: -1, message: "版块不存在"} if forum_section.blank?
return {status: -1, message: "请输入公告内容"} if params[:content].blank?
notice = forum_section&.section_notice
if notice.present?
notice.update_attribute(:content, params[:content])
message = "公告修改成功"
else
SectionNotice.create!(forum_section_id: params[:id], content: params[:content], user_id: forum_section.user_id)
message = "公告添加成功"
end
return {status: 1, message: message}
end
protected
def set_forum_section(section_id)
@forum_section = ForumSection.find(section_id)
unless @forum_section.present?
{status: 404}
end
end
def check_user_permission(current_user, forum_id)
if current_user.blank?
check_user_permission = false
else
if @forum_section.parent_id.present?
parent_section_id = @forum_section.parent_id
else
parent_section_id = forum_id
end
check_user_permission = (current_user.admin? || ForumModerator.where(forum_section_id: parent_section_id, user_id: current_user.id))
end
check_user_permission
end
# 将数据库对象转换成哈希对象
def object_to_hash objects
objects.map{|o| o.attributes.dup}
end
end

View File

@ -0,0 +1,44 @@
class ListMemosService
def all_memos(memo_type, params, target_user_id, current_user_id)
hidden = params[:is_hidden].to_s == "hidden"
is_show = params[:is_hidden].to_s == "show"
start_time = params[:start_time]
end_time = params[:end_time]
all_memos = Memo.includes(:forum_section,author: :user_extension)
all_memos = all_memos.where(forum_section_id: params[:forum_section_id]) if params[:forum_section_id].present?
if target_user_id != current_user_id
all_memos = all_memos.visible
else
all_memos = all_memos.hidden_memos if hidden
all_memos = all_memos.visible if is_show
end
case memo_type
when "memos" #我的帖子
all_memos = all_memos.user_posts(target_user_id)
all_memos = all_memos.search_by_time("published_at", start_time, end_time) if start_time.present? || end_time.present?
when "histories" #我的足迹
user_watchers = VisitAction.where(visitable_type: "Memo",user_id: current_user_id)
user_watchers = user_watchers.search_by_time("updated_at", start_time, end_time) if start_time.present? || end_time.present?
watcher_memo_ids = user_watchers.pluck(:visitable_id)
all_memos = all_memos.visible.where(id: watcher_memo_ids).roots
when "stars" #我收藏的
watch_actions = Watcher.where(watchable_type: "Memo", user_id: current_user_id)
watch_actions = watch_actions.search_by_time("created_at", start_time, end_time) if start_time.present? || end_time.present?
watch_section_ids = watch_actions.pluck(:watchable_id).reject(&:blank?).uniq
all_memos = all_memos.where(id: watch_section_ids).roots
when "replies"
reply_root_ids = all_memos.user_replies(target_user_id).pluck(:root_id)
all_memos = all_memos.where(id: reply_root_ids)
all_memos = all_memos.search_by_time("published_at", start_time, end_time) if start_time.present? || end_time.present?
else
all_memos = []
end
return all_memos
end
end

View File

@ -0,0 +1,827 @@
# encoding=utf-8
class MemosService
include ApplicationHelper
include ApiIndexHelper
include ActionView::Helpers::NumberHelper
LIMIT = 10
def index params, current_user
page = params[:page].to_i > 0 ? (params[:page].to_i - 1) : 0
index_limit = params[:limit] || 5
offset = page * index_limit.to_i
search = params[:search].to_s.strip
sort_name = params[:sort] || "published_at"
all_memos = Memo&.visible&.roots
all_hottest_memos = all_memos.hottest_five_memos
hottest_memos = object_to_hash(all_hottest_memos)
all_recommend_memos = all_memos.recommend_five_memos
recommend_memos = object_to_hash(all_recommend_memos)
if search.present?
all_memos = all_memos.where("subject like ?", "%#{search}%")
end
memos_count = all_memos.size # 帖子的总数
all_memos = all_memos.order_index(sort_name)&.includes(:forum_section,author: :user_extension).limit(index_limit).offset(offset)
memo_lists = get_memo_lists(all_memos, false, current_user, false)
{status: 0,limit: index_limit, memos_count: memos_count,
hottest_memos: hottest_memos, recommend_memos: recommend_memos, memos: memo_lists}
end
def related_memos params, current_user
memo = Memo.find(params[:id])
return { status: 404 } if memo.hidden? && (!current_user || !(current_user.admin? || current_user.id == memo.author_id))
all_memos = Memo.visible.roots.where("id != ?", params[:id].to_i).includes(memo_forums: :forum_section,author: :user_extension).related_search_name(memo.try(:subject).to_s).order_index("published_at").limit(5).offset(0)
memo_lists = get_memo_lists(all_memos, false, current_user, false)
{status: 0, memos: memo_lists}
end
def new params, current_user, session
return {status: -1, message: "您的账户已被禁言,如有疑问请联系版主或论坛管理员"} if user_is_banned?(current_user)
csrf_token = session[:_csrf_token] ||= SecureRandom.base64(32)
params_section = {}
if params[:section_id].present?
current_forum_section = ForumSection.find_by_id(params[:section_id])
params_section = {
id: current_forum_section.id,
title: current_forum_section.title,
parent_section_id: current_forum_section.ancestry,
parent_section_title: current_forum_section&.parent&.try(:title)
}
end
{status:0,:csrf_token => csrf_token, params_section: params_section}
end
# params 直接传params[:memo][:subject]
# subject标题
# content内容
# forum_id 话题类型
# sticky 是否置顶(创建时没入口)
# repertoire_name + language 技术标签
# attachments 附件
# attachment_id 是帖子的头像
def create params, current_user
return {status: -1, message: "请填写必填的内容"} if params[:memo][:subject].blank? || params[:memo][:content].blank? || params[:forum_id].blank? || params[:memo][:tag_id].blank? || params[:memo][:is_original].blank?
# elsif params[:memo][:content].length > 2000
# {status: -1, message: "不能超过2000个字符"}
return {status: -1, message: "您的账户已被禁言,如有疑问请联系版主或论坛管理员"} if user_is_banned?(current_user)
begin
memo = Memo.new(params[:memo])
memo.author = current_user
memo.forum_section_id = params[:children_forum_id].present? ? params[:children_forum_id] : params[:forum_id]
# memo.published_at = Time.now if params[:memo][:published_at].blank?
memo.hidden = true
# memo.save!
if memo.save!
memo.update_attachments(params[:attachments]) if params[:attachments].present?
# 为了区分帖子头像改变其类型为MemoIcon
create_user_tidings(memo, "forum_post")
if params[:attachment_id]
attachment = Attachment.find(params[:attachment_id])
attachment.update_attributes(:container_id => memo.id, :container_type => "Memo", :memo_image => true)
end
{status: 1, message: "帖子创建成功,请等待管理员审核", memo_id: memo.id}
else
{status: -1, message: memo.errors.messages.values[0][0]}
end
rescue => e
{status: -1, message: e}
end
end
# params
# :id 帖子id
# return
# :memo 帖子
# :memo_replies 帖子的回复
# :recommend_shixun 推荐实训
# :admin 当前用户是否是管理员
# :author_info 表示当前帖子用户的信息
def show params, current_user
memo = Memo.find(params[:id])
return { status: 404 } if memo.hidden? && (!current_user || !(current_user.admin? || current_user.id == memo.author_id))
is_banned = user_is_banned?(current_user)
forum_section = memo&.forum_section
watcher_params = {
visitable_type: "Memo",
visitable_id: params[:id],
user_id: current_user.id
}
#帖子的二级分类
forum_tag = {
title: forum_section.try(:title),
id: forum_section.try(:id)
}
# 消息总数
attachments_list = acttachements_info memo.attachments.where(:memo_image => false)
memo_image = memo.attachments.where(:memo_image => true).first
memo_image_info = {:id => memo_image.id, :filename => memo_image.filename, :url => "/attachments/download/" + "#{memo_image.id}" + "/" + "#{memo_image.filename}",
:filesize => memo_image.filesize} if memo_image
user_praise = PraiseTread.is_user_praise(memo.id, "Memo", current_user.try(:id)).exists?
memo.update_column(:viewed_count, memo.viewed_count + 1) if params[:only_data].blank?
# 帖子的回复
memos = memo.reply_for_memo
unless current_user.try(:admin?) # 只有管理员和发布人能看到隐藏的回复
memos = memos.where("hidden = false or (hidden = true and author_id = ?)", current_user.try(:id))
end
memo_author = memo.author
memo_author_memos = memo_author.memos.visible.roots
memos = memos.includes(:praise_tread, :author).order_index("created_at").limit(LIMIT)
watched = memo_author.watched_by?(current_user)
banned_permission = user_banned_permission current_user, memo.forum_section_id #当前用户是否具有禁言的权限
memo_watched = memo.watched_by?(current_user)
# list = memo_list memos, current_user
is_md = memo.is_md
author_info = {username: memo_author.show_real_name,
watched: watched,
is_blocked: current_user&.blocked_for(memo_author.id),
is_blocked_by: memo_author&.blocked_for(current_user.id),
image_url: "/images/#{url_to_avatar(memo_author)}?#{Time.now.to_i}",
identity: memo_author.identity,
login: memo_author.login,
user_id: memo_author.id,
description: memo_author&.user_extension&.brief_introduction,
memos_count: memo_author_memos.posts.size,
replies_count: memo_author_memos.total_replies.size,
watchers_count: memo_author.fan_count,
current_login: current_user.try(:login),
current_image_url: current_user.try(:login).present? ? "/images/#{url_to_avatar(current_user)}?#{Time.now.to_i}" : "/images/avatars/User/b",
is_current_user: memo.author_id == current_user.try(:id)
}
recent_memos = memo_author_memos.posts.where("id != ?", params[:id].to_i).order_index("published_at").select([:id,:subject]).limit(3).as_json
memo_info = {id: memo.id,
subject: memo.subject,
is_md: is_md,
content: memo.content,
time: time_from_now(memo.published_at.present? ? memo.published_at : memo.created_at),
published_time: rename_time_minute(memo.published_at),
hidden: memo.hidden,
memo_watched: memo_watched,
forum_tag: forum_tag, #类型
sticky: memo.sticky, # 置顶 1
is_fine: memo.is_fine, #是否加精
viewed_count: memo.viewed_count, #浏览
replies_count: memo.can_see_reply_count(current_user), #回复
praises_count: memo.praises_count, #赞数
reward: memo.reward,
attachment_url: attachments_list,
user_praise: user_praise,
tag_name: memo.meno_tag_name,
is_original: memo.is_original,
reprint_link: memo.reprint_link,
apply_destroy: current_user&.id == memo.author_id && memo.apply_destroy?,
}
if current_user
#TODO 通知消息暂时隐藏
# unless memo.children.blank?
# memo.children.includes(:memo_messages).each do |child|
# child.memo_messages.each do |memo_message|
# memo_message.update_attributes(:viewed => true) if current_user.id == memo_message.user_id
# end
# end
# end
# query_memo_messages = memo.memo_messages
# unless query_memo_messages
# query_memo_messages.each do |query_memo_message|
# query_memo_message.update_attributes(:viewed => true) if current_user.id == query_memo_message.user_id
# end
# end
if memo.author_id != current_user.id
if memo.visit_actions.exists?(watcher_params)
memo.visit_actions.where(watcher_params).first.update_attribute(:updated_at,Time.now)
else
VisitAction.create!(watcher_params)
end
end
end
{status: 0, memo: memo_info, author_info: author_info, memo_image_info: memo_image_info,
recent_memos: recent_memos,banned_permission: banned_permission, is_banned: is_banned, is_current_admin: current_user&.admin?, current_login: current_user&.login}
end
def more_reply params, current_user
page = params[:page].to_i > 0 ? (params[:page].to_i - 1) : 0
limit = params[:limit] || 10
offset = page * limit.to_i
memo_id = params[:id]
memo = Memo.find(memo_id)
memos = memo.reply_for_memo
unless current_user.try(:admin?) # 只有管理员和发布人能看到隐藏的回复
memos = memos.where("hidden = false or (hidden = true and author_id = ?)", current_user.try(:id))
end
# 总数,分页使用
# memos_all = Memo.where(parent_id: memo_id, hidden: false)
memos_count = memos.count
memos = memos.includes(:praise_tread, :author).order_index("created_at").limit(limit).offset(offset)
list = memo_list memos, current_user
{:memo_replies => list, :memos_count => memos_count}
end
def confirm_delete params, current_user
memo = Memo.find(params[:id])
return {status: 404} unless memo.present?
return {status: -1, message: "您没有权限操作!"} unless current_user&.id == memo.author_id
if params[:is_apply].to_i == 1 #表示申请操作
memo.apply_destroy!
memo.save!
Tiding.create!(:user_id => 1, :trigger_user_id => current_user&.id,
container_id: memo.id, container_type: 'Memo',
:viewed => 0, :tiding_type => "apply_delete", :extra => "d_1")
{status: 1, message: "操作成功"}
else
memo.common!
memo.save!
Tiding.create!(:user_id => 1, :trigger_user_id => current_user&.id,
container_id: memo.id, container_type: 'Memo',
:viewed => 0, :tiding_type => "cancel_delete", :extra => "d_0")
{status: 1, message: "已取消申请删帖"}
end
end
def destroy params, current_user
user_permission = check_banned_permission current_user, params[:id]
memo = Memo.select(:id,:parent_id, :forum_section_id).find(params[:id])
return {status: -1, message: "帖子不存在!"} unless memo.present?
return {status: -1, message: "您没有权限操作!"} unless user_permission
if memo.destroy
{status: 0, message: "帖子删除成功!"}
else
{status: -1, message: "帖子删除失败!"}
end
end
# 隐藏评论功能
def hidden params, current_user
memo = Memo.select([:id, :hidden]).find(params[:id])
if current_user.admin?
if params[:hidden] == "1"
memo.update_attribute(:hidden, true)
elsif params[:hidden] == "0"
memo.update_column("hidden", false)
end
else
raise("你没有权限")
end
end
def edit params, current_user
# memo_type = object_to_hash Forum.select([:id, :name])
# memo_tag = object_to_hash Label.select([:id, :name])
memo = Memo.select([:id, :subject, :content,:author_id,:tag_id, :is_original, :reprint_link, :forum_section_id]).find params[:id]
return {status: -1, message: "帖子不存在"} if memo.blank?
return {status: -1, message: "您的账户已被禁言,如有疑问请联系版主或论坛管理员"} if user_is_banned?(current_user)
return { status: -1, message: "您没有权限编辑" } unless current_user.present? && (current_user.admin? || (current_user.id == memo.author_id) || user_banned_permission(current_user, params[:id]))
attachments_list = acttachements_info memo.attachments.where(:memo_image => false)
memo_image = memo.attachments.where(:memo_image => true).first
memo_image_info = {:id => memo_image.id,
:filename => memo_image.filename,
:url => "/attachments/download/" + "#{memo_image.id}" + "/" + "#{memo_image.filename}",
:filesize => number_to_human_size(memo_image.filesize,significant: false, precision: 2)} if memo_image
banned_permission = user_banned_permission current_user, params[:id]
memo_forum_section = memo&.forum_section
if memo_forum_section&.parent.present?
forum_first = {
forum_id: memo_forum_section&.parent.try(:id),
forum_name: memo_forum_section&.parent.try(:title)
}
children_forum_first = {
children_forum_id: memo_forum_section.try(:id),
children_forum_name: memo_forum_section.try(:title)
}
else
forum_first = {
forum_id: memo_forum_section.try(:id),
forum_name: memo_forum_section.try(:title)
}
children_forum_first = {}
end
memo.attributes.merge!({banned_permission: banned_permission,
attachments_url: attachments_list,
memo_image_info: memo_image_info,
forum_section: forum_first,
children_forum_section: children_forum_first
})
end
def memo_hidden params, current_user
memo = Memo.find params[:id]
if params[:checked].to_s == 'true'
publish_time = Time.now
action_type = "passed"
extra = "1"
else
publish_time = Time.now
action_type = "refuse"
extra = "2"
end
memo.update_attributes(hidden: !(params[:checked].to_s == 'true'), published_at: publish_time) # 勾选代表不隐藏,所以要取反
CheckedAction.create!(user_id: current_user.id,checkable_type: "Memo",checkable_id: params[:id], action_type: action_type, action_at: Time.now)
if !memo.hidden? && memo.parent_id.present? && !memo.tidings.exists?(user_id: memo.parent.author_id,trigger_user_id: memo.author_id, extra: "3")
Tiding.create(:user_id => memo.parent.author_id, :trigger_user_id => memo.author_id,
container_id: memo.id, container_type: 'Memo',
:parent_container_id => memo.root_id, :parent_container_type => "Memo",
:viewed => 0, :tiding_type => "Comment", :extra => "3")
elsif !memo.hidden? && memo.parent_id.blank?
Tiding.create(:user_id => memo.author_id, :trigger_user_id => current_user.id,
container_id: memo.id, container_type: 'Memo',
:viewed => 0, :tiding_type => "Comment",:extra => extra)
end
{status: 1, message: "设置成功", is_hidden: memo.hidden}
end
def update params, current_user
params.permit!
if params[:memo][:subject].blank? || params[:memo][:content].blank? || params[:forum_id].blank?
{status: -1, message: "帖子内容不能为空"}
elsif user_is_banned?(current_user)
{status: -1, message: "您的账户已被禁言,如有疑问请联系版主或论坛管理员"}
else
memo = Memo.find params[:id]
return { status: 404 } if memo.hidden? && (!current_user || !(current_user.admin? || current_user.id == memo.author_id))
memo.update_attributes(params[:memo])
memo.update_attachments(params[:attachments]) if params[:attachments].present?
memo.forum_section_id = params[:children_forum_id].present? ? params[:children_forum_id] : params[:forum_id]
if memo.save!
if params[:attachment_id]
attachment = Attachment.find(params[:attachment_id])
attachment.update_attributes(:container_id => memo.id, :container_type => "Memo", :memo_image => true)
end
{status: 1, message: "帖子更新成功!"}
else
{status: -1, message: memo.errors.messages.values[0][0]}
end
end
end
# params
# parent_id: 给谁的回复id
# content: 回复的内容
def reply params, current_user
memo = Memo.find params[:parent_id]
return {status: -1, message: "您的账户已被禁言,如有疑问请联系版主或论坛管理员"} if user_is_banned?(current_user)
return {status: -1, message: "根据对方设置,暂时不能评论"} if memo.author.blocked_for(current_user&.id)
return { status: 404 } if memo.hidden? && (!current_user || !(current_user.admin? || current_user.id == memo.author_id))
begin
memo_params = {
parent_id: params[:parent_id] || nil,
content: params[:content].to_s,
subject: memo.subject,
author_id: current_user.id,
root_id: memo.root_id || memo.id,
hidden: true
}
reply = Memo.new(memo_params)
if reply.save
memo.update_attribute(:last_reply_on, Time.now)
memo.children << reply
create_user_tidings(reply, "forum_comment")
replies = {:id => reply.id, :content => reply.content, :time => time_from_now(reply.created_at), :user_id => reply.author_id,
:image_url => "/images/#{url_to_avatar(reply.author)}?#{Time.now.to_i}", :username => reply.author.show_real_name, :reward => memo.reward, :hidden => reply.hidden,
:praise_count => reply.praises_count,:user_login => reply.author.try(:login), replies_count: reply.can_see_reply_count(current_user)}
{
status: 0,
reply: replies
}
else
{status: -1, message: reply.errors.messages.values[0][0]}
end
rescue => e
{status: -1, message: "出现错误"}
raise ActiveRecord::Rollback
end
end
def watch_memo params, current_user
memo = Memo.find params[:id]
if params[:is_watch] == 1
if Watcher.exists?(watchable_type: "Memo", watchable_id: params[:id], user_id: current_user.id)
w_status = -1
w_msg = "您已收藏"
else
memo_watch = Watcher.new(watchable: memo, user_id: current_user.id)
if memo_watch.save
w_status = 0
w_msg = "收藏成功"
else
w_status = -1
w_msg = "收藏失败,请稍后重试"
end
end
else
if Watcher.exists?(watchable_type: "Memo", watchable_id: params[:id], user_id: current_user.id)
Watcher.where(watchable_type: "Memo", watchable_id: params[:id], user_id: current_user.id).destroy_all
w_status = 0
w_msg = "取消收藏成功"
else
w_status = -1
w_msg = "您还未添加收藏"
end
end
{status: w_status, message: w_msg}
end
# params:
# order 排序
# sticky: 1 置顶,0 取消置顶
# id 帖子ID
def set_top_or_down params, current_user
user_permission = check_banned_permission current_user, params[:id]
s_order = params[:order] || "updated_at"
if user_permission
if Memo.find(params[:id]).update_attribute(:sticky, params[:sticky])
set_status = 0
set_msg = "操作成功"
else
set_status = -1
set_msg = "操作失败"
end
else
set_status = -1
set_msg = "您没有权限"
end
# memos = Memo.field_for_list.includes(:praise_tread, :author, :forums).where(:root_id => nil).order("sticky=1 desc, #{s_order} desc").limit(15)
# memo_list = memo_data memos
{status: set_status, message: set_msg}
end
def plus params, current_user
plus_type = params[:container_type].to_s
plus_id = params[:id]
pt = PraiseTread.where(:praise_tread_object_id => params[:id], :praise_tread_object_type => params[:container_type],
:user_id => current_user, :praise_or_tread => 1).first
# 如果当前用户已赞过,则不能重复赞
if params[:type] == 1 && pt.blank?
if pt.blank?
PraiseTread.create!(:praise_tread_object_id => plus_id, :praise_tread_object_type => plus_type,
:user_id => current_user.id, :praise_or_tread => 1) if pt.blank?
plus_name = plus_type.constantize.find(params[:id])
Tiding.create(:user_id => plus_name.try(:author_id), :trigger_user_id => current_user.id,
container_id: plus_id, container_type: plus_type,
:parent_container_id => plus_id, :parent_container_type => plus_type,
:viewed => 0, :tiding_type => "PraiseTread")
end
else
pt.destroy if pt.present? # 如果已赞过,则删掉这条赞(取消);如果没赞过,则为非法请求不处理
end
{:praise_count => PraiseTread.where(:praise_tread_object_id => params[:id], :praise_tread_object_type => params[:container_type],
:praise_or_tread => 1).count}
end
def banned_user params, current_user
user_permission = check_banned_permission current_user, params[:id]
if user_permission
last_banned_forum = BannedForum.where(user_id: params[:user_id])&.last
user_banned_count = last_banned_forum&.banned_count.to_i
if params[:banned].to_i == 1 #表示禁言
banned_params = {
user_id: params[:user_id],
author_id: current_user.id,
memo_id: params[:id],
is_banned: true,
banned_count: user_banned_count + 1
}
BannedForum.create!(banned_params)
{status: 0, message: "禁言成功"}
else
BannedForum.where(user_id: params[:user_id]).update_all(is_banned: false)
{status: 0, message: "取消禁言成功"}
end
else
{status: -1, message: "您没有权限操作"}
end
end
def is_fine params, current_user
user_permission = check_banned_permission current_user, params[:id]
if user_permission
if params[:is_fine] == 1
is_fine_b = true
else
is_fine_b = false
end
memo = Memo.find(params[:id]).update_attribute(:is_fine, is_fine_b)
if memo
{status: 0, message: "操作成功"}
else
{status: -1, message: "操作失败"}
end
else
{status: -1, message: "您没有权限操作"}
end
end
def forum_memos_head params, current_user
forum_section = ForumSection.find_by_id(params[:id])
return {status: -1, message: "版块不存在"} if forum_section.blank?
section_author = forum_section.user
forum_section_user = {username: section_author.try(:show_real_name), user_login: section_author.try(:login)}
forum_moders = []
if ForumModerator.exists?(forum_section_id: forum_section.id)
all_forum_moderators = forum_section.forum_moderators.includes(user: :user_extension).select([:id, :user_id])
all_forum_moderators.each do |moder|
moder_user = moder.user
forum_moder = {
username: moder_user.show_real_name,
user_login: moder_user.try(:login)
}
forum_moders << forum_moder
end
end
today_memos = forum_section.group_today
publish_today_count = today_memos.roots.size
replies_today_count = today_memos.size - publish_today_count
bread_crumb = get_bread_crumb(forum_section, current_user)
banned_permission = user_banned_permission current_user, params[:id]
watched = forum_section.watched_by?(current_user)
{
watched: watched,
bread_crumb: bread_crumb,
publish_today_count: publish_today_count,
replies_today_count: replies_today_count,
forum_section: single_section_info(forum_section),
forum_section_user: forum_section_user,
forum_moders: forum_moders,
banned_permission: banned_permission
}
end
def forum_memos params, current_user
forum_section = ForumSection.find_by_id(params[:id])
sort_name = params[:sort] || "published_at"
return {status: -1, message: "版块不存在"} if forum_section.blank?
page = params[:page].to_i > 0 ? (params[:page].to_i - 1) : 0
offset = page * LIMIT
all_memos =
if forum_section.is_root?
forum_section_ids = forum_section.child_ids << forum_section.id
Rails.logger.info "######### forum_section_ids: #{forum_section_ids}"
Memo.where(forum_section_id: forum_section_ids)
else
forum_section.memos.posts
end
select_type = params[:select_type]
case select_type.to_s
when "is_fine"
all_memos = all_memos.visible.where(is_fine: true)
when "my_memos"
all_memos = all_memos.where(author_id: current_user.id)
when "my_topics"
my_reply_memos = current_user.memos.visible.select([:id, :author_id, :hidden,:parent_id]).where("parent_id is not Null").pluck(:parent_id).uniq
all_memos = all_memos.where(id: my_reply_memos)
else
all_memos = all_memos.visible
end
if params[:search].present?
all_memos = all_memos.where("subject like '%#{params[:search].to_s.strip}%'")
end
# 总数,分页使用
all_memos = all_memos.order_index(sort_name)
memos_count = all_memos.size
all_memos = all_memos.limit(LIMIT).includes(:author, :praise_tread).offset(offset)
memo_lists = []
if all_memos.size > 0
memo_lists = get_memo_lists(all_memos, true, current_user, false)
end
{
memos_count: memos_count,
limit: LIMIT,
memos: memo_lists,
}
end
def forum_memos_right params, current_user
forum_section = ForumSection.find_by_id(params[:id])
notice = forum_section.section_notice
all_memos = forum_section.memos.posts.select(:author_id)
active_user_ids = all_memos.group("author_id").size.keys.uniq.first(6)
children_sections = ForumSection.where("ancestry is not null").order("watchers_count desc, memos_count desc").select([]).first(4)
new_childre_section = list_hot_sections(children_sections)
active_users = User.where(id: active_user_ids)
active_user_array = []
active_users.each do |user|
active_user_array.push({
username: user.show_real_name,
login: user.login,
image_url: "#{url_to_avatar(user)}?#{Time.now.to_i}"
})
end
{
username: forum_section.user.show_real_name,
user_login: forum_section.user.login,
notice: notice.try(:content),
recommend_forum_sections: new_childre_section,
active_users: active_user_array
}
end
def is_watch params, current_user
forum_section = ForumSection.find(params[:id])
children_sections = nil
children_sections = forum_section.descendants
if params[:is_watch] == 1
if Watcher.exists?(watchable_type: "ForumSection", watchable_id: params[:id], user_id: current_user.id)
w_status = -1
w_msg = "您已收藏"
else
Watcher.create(watchable: forum_section, user_id: current_user.id)
forum_section.increment!(:watchers_count)
if children_sections.present?
children_sections.each do |section|
Watcher.create!(watchable: section, user_id: current_user.id)
section.increment!(:watchers_count)
end
end
w_status = 0
w_msg = "收藏成功"
end
else
sections_ids = []
sections_ids = children_sections.pluck(:id) if children_sections.present?
forum_all_sections = [params[:id]] + sections_ids
forum_section.decrement!(:watchers_count)
if Watcher.exists?(watchable_type: "ForumSection", watchable_id: params[:id], user_id: current_user.id)
Watcher.where(watchable_type: "ForumSection", watchable_id: forum_all_sections, user_id: current_user.id).destroy_all
w_status = 0
w_msg = "取消收藏成功"
else
w_status = -1
w_msg = "您还未收藏"
end
end
{status: w_status, message: w_msg}
end
protected
def find_memo params
if params[:id].blank?
@memo = Memo.new
else
@memo = Memo.find params[:id]
end
end
# 将memos对象添加额外信息
def memo_data memos
memo_list = []
memos.each do |m|
forum_name = m.forums.map(&:name)
user_info = {username: m.author.show_real_name, login: m.author.login, image_url: "#{url_to_avatar(m.author)}?#{Time.now.to_i}", forum_name:forum_name, praise_count: m.praises_count}
memo_list << m.attributes.dup.merge(user_info)
end
memo_list
end
# 权限
def permission memo, current_user
if current_user.admin?
1
elsif memo.author_id == current_user.id
2
else
3
end
end
def check_banned_permission current_user, memo_id
return true if current_user&.admin?
forum_id = MemoForum&.where(is_children: false, memo_id: memo_id)&.first.try(:forum_id).to_s
user_banned_permission current_user, forum_id
end
def tag_list reps
rep_list = []
reps.each do |r|
sub_ids = SubRepertoire.where(:repertoire_id => r.id).pluck(:id)
tag = object_to_hash TagRepertoire.where(:sub_repertoire_id => sub_ids).field_for_list.order("name asc")
rep_list << {:rep => r, :tag => tag}
end
return rep_list
end
def memo_list memos, current_user
return nil if memos.blank?
# parent_reply_ids = memos.where()
list = [] # 贴子的回复
memos.includes(:praise_tread).each do |memo|
is_banned = user_is_banned?(memo.author) #帖子的用户是否被禁言
# 用户是否点赞
user_praise = memo.praise_tread.exists?(user_id: current_user.try(:id).to_i)
permission = current_user ? current_user.manager_of_memo?(memo) : false
# 实训TPM的管理员可以看到隐藏的评论
replies = {:id => memo.id, :content => memo.content, :time => time_from_now(memo.created_at), :user_id => memo.author_id,
:image_url => "/images/#{url_to_avatar(memo.author)}?#{Time.now.to_i}", :username => memo.author.show_real_name, :reward => memo.reward, :hidden => memo.hidden,
:permission => permission, :praise_count => memo.praises_count, :user_praise => user_praise,
:user_login => memo.author.try(:login), :admin => current_user&.admin, is_banned: is_banned, replies_count: memo.can_see_reply_count(current_user)}
childrens = Memo.where(:parent_id => memo.id).includes(:author).reorder("created_at desc").limit(5)
unless current_user.try(:admin?) # 只有管理员和发布人能看到隐藏的回复
childrens = childrens.where("hidden = false or (hidden = true and author_id = ?)", current_user.try(:id))
end
children_list = [] # 子回复
childrens.each do |child|
children_praise = child.praise_tread.exists?(user_id: current_user.try(:id).to_i)
children_is_banned = user_is_banned?(child.author) #帖子的用户是否被禁言
children_list << {:id => child.id, :content => child.content, :time => time_from_now(child.created_at),:praise_count => memo.praises_count, :user_praise => children_praise,
:image_url => "/images/#{url_to_avatar(child.author)}?#{Time.now.to_i}", :username => child.author.show_real_name, :hidden => child.hidden, replies_count: child.can_see_reply_count(current_user),
:permission => permission, :user_login => child.author.try(:login), :user_id => child.author.try(:id), :parent_id => child.parent_id, is_banned: children_is_banned}
end
list << replies.merge({children: children_list})
end
list
end
# 帖子附件信息
def acttachements_info attachments
attachments_list = []
if attachments.present?
attachments.each do |attach|
attachments_list << {:id => attach.id,
:title => attach.filename,
:url => "/attachments/download/" + "#{attach.id}" + "/" + "#{attach.filename}",
:filesize => number_to_human_size(attach.filesize,significant: false, precision: 2)}
end
end
return attachments_list
end
# 判断编辑器存储的内容是否是html类型的ke目的为了区分ke和markdown
def editor_html update_time
# str.include?("<p>" || "<div>" || "<span>" || "<img>" || "<strong>") && update_time < "2018-06-23"
update_time < "2018-06-23"
end
def list_hot_sections(forum_sections)
new_sections = []
forum_sections.each do |sec|
single_info = single_section_info(sec)
new_sections.push(single_info)
end
return new_sections
end
def single_section_info(section)
image = section.image_attachment
return {
id: section.id,
title: section.title,
description: section.description,
memos_count: section.visible_memos_count,
watchers_count: section.watchers_count,
picture: image.present? ? "/attachments/download/" + "#{image.id}" + "/" + "#{image.filename}" : ""
}
end
end

View File

@ -0,0 +1,134 @@
class MyMemosService
include ApplicationHelper
include ApiIndexHelper
LIMIT = 10
def index params, current_user
memo_user = User.find_by_login(params[:login])
memo_type = params[:memo_type] || "memos"
return {status: -1, message: "用户不存在"} unless memo_user
return {status: 403, message: "没有权限"} if !%w(memos replies).include?(memo_type) && current_user&.login != params[:login]
return {status: 403, message: "没有权限"} if params[:is_hidden] == "hidden" && current_user&.login != params[:login]
banned_permission = user_banned_permission current_user, nil
page = params[:page].to_i > 0 ? (params[:page].to_i - 1) : 0
index_limit = params[:limit] || 15
offset = page * index_limit.to_i
all_memos = ListMemosService.new.all_memos(memo_type, params, memo_user.id, current_user.id)
memos_count = all_memos.size # 帖子的总数
if memo_type == "replies"
all_memos = all_memos.order("last_reply_on desc")
else
all_memos = all_memos.order("sticky desc, is_fine desc, published_at desc, updated_at desc")
end
all_memos = all_memos.limit(index_limit.to_i).offset(offset)
show_last_reply = memo_type == "replies"
all_memo_lists = get_memo_lists(all_memos, show_last_reply, current_user, show_last_reply)
{
status: 0,
is_current_user: params[:login] == current_user&.login,
banned_permission: banned_permission,
limit: index_limit.to_i,
memos_count: memos_count,
memos: all_memo_lists
}
end
def my_interested params, current_user
return {status: -1, message: "请登录"} unless current_user
return {status: 403, message: "没有权限"} if current_user&.login != params[:login]
page = params[:page].to_i > 0 ? (params[:page].to_i - 1) : 0
index_limit = params[:limit] || 32
offset = page * index_limit.to_i
watch_section_ids = Watcher.where(watchable_type: "ForumSection",user_id: current_user.id).pluck(:watchable_id)
forum_sections = ForumSection.where(id: watch_section_ids).select([:id,:title, :memos_count])
if params[:search].present?
forum_sections = forum_sections.where("title like ? ", "%#{params[:search].to_s.strip}%")
end
forum_sections_count = forum_sections.size # 帖子的总数
forum_sections = forum_sections.limit(index_limit).offset(offset)
all_forum_sections = forum_sections.as_json
{
count: forum_sections_count,
forum_details: all_forum_sections,
}
end
def recommend_memos current_user
return {status: -1, message: "请登录"} unless current_user
all_memos = Memo.includes(memo_forums: :forum_section,author: :user_extension)
all_hottest_memos = all_memos.visible.hottest_five_memos
hottest_memos = object_to_hash(all_hottest_memos)
all_recommend_memos = all_memos.visible.recommend_five_memos
recommend_memos = object_to_hash(all_recommend_memos)
{
status: 0,
hottest_memos: hottest_memos,
recommend_memos: recommend_memos,
}
end
def replies_memos params, current_user
return {status: -1, message: "请登录"} unless current_user
reply_root_ids = Memo.visible.user_replies(current_user.id).pluck(:root_id)
reply_memos = Memo.where(id: reply_root_ids)
page = params[:page].to_i > 0 ? (params[:page].to_i - 1) : 0
# page = params[:page].to_i
offset = page * 15
is_hidden = params[:is_hidden].present? && params[:is_hidden] != "show"
reply_memos = reply_memos.where(forum_section_id: params[:forum_section_id]) if params[:forum_section_id].present?
reply_memos = reply_memos.where(hidden: is_hidden) if is_hidden
reply_memos_count = reply_memos.size # 帖子的总数
reply_memos = reply_memos.order("updated_at desc").limit(15).offset(offset)
reply_list_memos = reply_memo_lists(reply_memos)
{
status: 0,
memos_count: reply_memos_count,
memos: reply_list_memos
}
end
private
def my_page_crumb(tab,current_user)
{
user:{login: current_user.try(:login), url: "/users/#{current_user.try(:login)}"},
forum: {title: "论坛交流", url: ""},
forum_tag: tab
}
end
def reply_memo_lists(memos)
memos_array = []
memos.each do |memo|
last_reply = memo&.last_reply_memo(false)
memo_list = {
id: memo.id,
subject: memo.subject,
reply_time: rename_time_second(last_reply&.created_at),
reply_content: last_reply&.content
}
memos_array.push(memo_list)
end
return memos_array
end
def get_sections_lists parent, forum_second_ids,children_section_ids
forum_second_tags = ForumSection.where(id: (forum_second_ids & children_section_ids).uniq)&.select([:id,:title])
{id: parent.id,
name: parent.title,
position: parent.position,
children_tags: object_to_hash(forum_second_tags)
}
end
end

View File

@ -66,7 +66,7 @@ class Projects::ApplyJoinService < ApplicationService
return if owner.phone.blank?
Educoder::Sms.send(mobile: owner.phone, send_type:'applied_project_info',
user_name: owner.show_name, name: project.name)
user_name: owner.show_real_name, name: project.name)
rescue Exception => ex
Rails.logger.error("发送短信失败 => #{ex.message}")
end

View File

@ -0,0 +1,552 @@
#coding=utf-8
class UsersService
include ApplicationHelper
# include AccountHelper
# include AvatarHelper
include ApiHelper
# include WordsHelper
include ApiIndexHelper
#将用户注册的功能函数写这里
#参数约定
#成功返回注册后的User实例失败直接抛异常
# 生成邀请码
CODES = %W(0 1 2 3 4 5 6 7 8 9)
def generate_user_login type
code = CODES.sample(8).join
code = type + code.to_s
return generate_user_login(type) if User.where(login: code).present?
code
end
def edit_brief params, current_user
target_user = User.find_by(login: params[:login])
return {status: -1, message: "请输入内容"} if params[:content].blank?
return {status: -1, message: "请登录"} unless current_user.present?
return {status: -1, message: "您没有权限操作"} unless current_user.login == params[:login]
user_extent = target_user.user_extension
user_extent.brief_introduction = params[:content].first(20)
if user_extent.save
{status: 0, message: "更新成功"}
else
{status: -1, message: user_extent.errors.messages.values[0]}
end
end
def user_info params, current_user
target_user = User.find_by(login: params[:login])
return {status: 404, message: "用户不存在"} unless target_user.present?
format_common_user = format_common_user(target_user)
target_user_info = {
current_login: current_user&.login,
fans_count: target_user&.watcher_users.size,
stars_count: User.watched_by(target_user.id).size,
identify: target_user.identity,
authentication: target_user.authentication,
professional: target_user.professional_certification,
bind_phone: target_user.phone.present?,
bind_email: target_user.mail.present?,
brief: target_user&.user_extension&.brief_introduction,
is_current_user: current_user&.login == params[:login],
is_watched: target_user.watched_by?(current_user),
is_blocked: current_user&.blocked_for(target_user.id),
is_blocked_by: target_user&.blocked_for(current_user.id),
# identify_status: target_user&.get_auth_status("1"),
# profession_status: target_user&.get_auth_status("2"),
}.merge(format_common_user)
{status: 0, user: target_user_info}
end
def block_user_lists params, current_user
return {status: -1, message: "请登录"} unless current_user.present?
return {status: -1, message: "您没有权限操作"} unless current_user.login == params[:login]
user_block_ids = current_user.block_users.pluck(:block_user_id).uniq
block_users_size = user_block_ids.size
page = params[:page].to_i > 0 ? (params[:page].to_i - 1) : 0
limit = params[:limit] || 30
offset = page * limit.to_i
block_users =User.where(id: user_block_ids).limit(limit).offset(offset)
block_lists = []
block_users.each do |user|
if user.present?
block_lists.push({
username: user.show_name,
login: user.login,
image_url: "/images/#{url_to_avatar(user)}?#{Time.now.to_i}",
brief: user&.user_extension.try(:brief_introduction)
})
end
end
{status: 0, users_size: block_users_size, users: block_lists}
end
def block_user params, current_user
target_user = User.find_by(login:params[:login])
return {status: -1, message: "请选择屏蔽类型"} unless params[:block].present?
return {status: -1, message: "请登录"} unless current_user.present?
return {status: -1, message: "用户不存在"} unless target_user.present?
if params[:block].to_s == "block"
Watcher.is_watcher_user.between_user(target_user.id, current_user.id).destroy_all
if current_user&.block_users.block_user_present(target_user.id).exists?
return {status: 0, message: "已加入黑名单"}
else
BlockUser.create(user_id: current_user&.id, block_user_id: target_user.id)
return {status: 0, message: "已加入黑名单"}
end
else
current_user&.block_users.block_user_present(target_user.id).destroy_all
return {status: 0, message: "已移出黑名单"}
end
end
def watch_user params, current_user
target_user = User.find_by(login:params[:login])
return {status: -1, message: "请选择关注类型"} unless params[:watch].present?
return {status: -1, message: "请登录"} unless current_user.try(:login).present?
return {status: -1, message: "用户不存在"} unless target_user.present?
return {status: -1, message: "根据对方设置,不可关注"} if target_user&.blocked_for(current_user.id)
if params[:watch].to_s == "watch"
if target_user.watched_by?(current_user)
return {status: 0, message: "已关注"}
else
target_user.add_watcher(current_user)
# current_user.watch!(target_user)
return {status: 0, message: "已关注"}
end
else
target_user.remove_watcher(current_user)
# current_user.unwatch!(target_user)
return {status: 0, message: "已取消关注"}
end
end
def user_projects params, current_user
return {status: -1, message: "请登录"} unless current_user.present?
target_user = User.find_by(login:params[:login])
show_all = params[:login] == current_user&.login || current_user&.admin?
select_type = params[:type] || "p_project"
order = params[:order] || "desc"
p_type = params[:p] || "a"
status = p_type == "a" ? "(0,1)" : "("+p_type+")"
page = params[:page].to_i > 0 ? (params[:page].to_i - 1) : 0
limit = params[:limit] || 16
offset = page * limit.to_i
is_current_user = params[:login] == current_user&.login
case select_type
when "l_projects"
project_ids = Project.find_by_sql("SELECT p.id FROM projects p, members m, member_roles mr WHERE m.project_id = p.id AND m.id=mr.member_id AND mr.role_id in (4, 5) AND m.user_id=#{target_user.id} AND p.status != 9 AND p.is_public in #{status}").map(&:id)
projects = Project.where(:id => project_ids).includes(:project_score, owner: :user_extension).order("updated_on #{order}")
when "p_projects"
project_ids = Project.find_by_sql("SELECT p.id FROM projects p, members m, member_roles mr WHERE m.project_id = p.id AND m.id=mr.member_id AND mr.role_id = 3 AND m.user_id=#{target_user.id} AND p.status != 9 AND p.is_public in #{status}").map(&:id)
projects = Project.where(:id => project_ids).includes(:project_score, owner: :user_extension).order("updated_on #{order}")
end
projects_size = project_ids.size
projects = projects.limit(limit).offset(offset)
project_list_arrays = []
projects.each do |p|
project_user = format_common_user(p.owner)
owner_school = p.owner&.school_name
project_list_arrays.push({
id: p.id,
name: p.name,
is_public: p.is_public,
issues_count: p.issue_count,
members_count: p.member_count,
commits_count: p&.project_score.try(:changeset_num).to_i,
identifier: p.identifier,
school_name: owner_school
}.merge(project_user))
end
{status: 0,is_current_user: is_current_user, projects_size: projects_size, projects: project_list_arrays}
end
def get_user_info params, current_user
if current_user.present? && (current_user.id != 2)
status = 0
else
status = -1
end
current_user_info = format_for_current_user current_user
{status: status, current_user: current_user_info}
end
# 关注
def watch params, current_user
s = WatchesService.new
s.watch params.merge(:current_user_id => current_user.id)
return {:status => 1, :message => "success"}
end
# 取消关注
def unwatch params, current_user
s = WatchesService.new
s.unwatch params.merge(:current_user_id => current_user.id)
return {:status => 1, :message => "success"}
end
def register(params)
@user = User.new
@user.admin = false
@user.register
@user.login = generate_user_login params[:mail] ? 'm' : (params[:phone] ? 'p' : 'w')
@user.mail = params[:mail]
@user.phone = params[:phone]
password = params[:password] || params[:mail_password]
password_confirmation = params[:password] || params[:mail_password]
should_confirmation_password = params[:should_confirmation_password]
if !password.blank? && !password_confirmation.blank? && should_confirmation_password
@user.password, @user.password_confirmation = password, password_confirmation
elsif !password.blank? && !should_confirmation_password
@user.password = password
else
@user.password = ""
end
if params[:mail]
case Setting.self_registration
when '1'
@user = email_activation_register(@user)
when '3'
@user = automatically_register(@user)
else
@user = administrator_manually__register(@user)
end
else
@user = automatically_register(@user)
end
if @user.id != nil
ue = @user.user_extension ||= UserExtensions.new
ue.user_id = @user.id
ue.save
if params[:entity_type]
entity = Entity.new
entity.user_id = @user.id
entity.entity_type = params[:entity_type].to_i
entity.save!
end
end
@user
#img_url = url_to_avatar(@user)
#gender = @user.user_extension.gender.nil? ? 0 : @user.user_extension.gender
#work_unit = get_user_work_unit @user
#location = get_user_location @user
#{:id => @user.id, :img_url => img_url, :nickname => @user.login, :gender => gender, :work_unit => work_unit, :mail => @user.mail, :location => location, :brief_introduction => @user.user_extension.brief_introduction}
end
# 自动注册功能 FOR邮件邀请
def register_auto(login, mail, password, first_name, last_name, gender)
mail_notification = "day"
@user = User.new
@user.admin = false
@user.register
@user.login = login
@user.mail = mail
@user.firstname = first_name
@user.lastname = last_name
@user.mail_notification = mail_notification
password_confirmation = password
should_confirmation_password = true
if !password.blank? && !password_confirmation.blank? && should_confirmation_password
@user.password, @user.password_confirmation = password, password_confirmation
elsif !password.blank? && !should_confirmation_password
@user.password = password
else
@user.password = ""
end
@user = automatically_register_lock(@user)
if @user.id != nil
ue = @user.user_extension ||= UserExtensions.new
ue.gender = gender
ue.user_id = @user.id
ue.save
end
@user
end
#显示用户
#id用户id
def show_user(params)
@user = User.find(params[:id])
img_url = "/images/"+url_to_avatar(@user)
gender = @user.user_extension.gender.nil? ? 0 : @user.user_extension.gender
work_unit = get_user_work_unit @user
location = get_user_location @user
{:id => @user.id, :img_url => img_url,:realname => @user.realname, :nickname => @user.nickname, :gender => gender, :work_unit => work_unit, :mail => @user.mail, :location => location, :brief_introduction => @user.user_extension.brief_introduction}
end
#忘记密码
def lost_password params
user = ::User.find_by_mail(params[:mail].to_s)
# user not found or not active
unless user && user.active?
raise l(:notice_account_unknown_email,:locale => 'zh')
end
# user cannot change its password
unless user.change_password_allowed?
raise l(:notice_can_t_change_password,:locale => user.language)
return
end
# create a new token for password recovery
token = Token.new(:user => user, :action => "recovery")
if token.save
Mailer.run.lost_password(token)
return l(:notice_account_lost_email_sent,:locale => user.language)
end
end
#编辑用户
#gender 1female 0male 其他male
def edit_user params
@user = User.find(params[:id])
fileio = params[:file]
# @se = @user.extensions
# if @user.user_extension.identity == 0 || @user.user_extension.identity == 1
# @se.school_id = params[:occupation]
# elsif @user.user_extension.identity == 3
# @se.occupation = params[:occupation]
# elsif @user.user_extension.identity == 2
# @user.firstname = params[:occupation]
# end
# @se.brief_introduction = params[:brief_introduction]
# @se.gender = params[:gender]
# @se.location = params[:province] if params[:province]
# @se.location_city = params[:city] if params[:city]
# raise @se.errors.full_message unless @se.save
unless fileio.nil?
file = fileio[:tempfile]
diskfile=disk_filename(@user.class.to_s, @user.id)
@image_file = fileio[:name]
@urlfile='/' << File.join("images", "avatars", avatar_directory(@user.class.to_s), avatar_filename(@user.id, @image_file))
path = File.dirname(diskfile)
unless File.directory?(path)
FileUtils.mkdir_p(path)
end
File.rename(file.path, @urlfile)
begin
f = Magick::ImageList.new(diskfile)
# gif格式不再做大小处理
if f.format != 'GIF'
width = 300.0
proportion = (width/f[0].columns)
height = (f[0].rows*proportion)
f.resize_to_fill!(width, height)
f.write(diskfile)
end
rescue Exception => e
logger.error "[Error] avatar : users_service#edit_user ===> #{e}"
end
end
#img_url = url_to_avatar(@user)
#gender = @user.user_extension.gender.nil? ? 0 : @user.user_extension.gender
#work_unit = get_user_work_unit @user
#location = get_user_location @user
#{:id => @user.id, :img_url => img_url, :nickname => @user.login, :gender => gender, :work_unit => work_unit, :mail => @user.mail, :location => location, :brief_introduction => @user.user_extension.brief_introduction}
@user
end
# 获取某个用户的所有留言信息
def get_all_messages params
user = User.find(params[:user_id])
jours = user.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC').page(params[:page] || 1).per(10)
jours.update_all(:is_readed => true, :status => false)
jours.each do |journal|
fetch_user_leaveWord_reply(journal).update_all(:is_readed => true, :status => false)
end
jours
end
# 回复用户
def reply_user_messages params,current_user
user = User.find(params[:user_id])
m_parent_id = params[:parent_id]
author_id = current_user.id
reply_id = params[:ref_user_id]
ref_message_id = params[:ref_message_id]
content = params[:content]
options = {:user_id => author_id, # 作者id
:status => true,
:m_parent_id => m_parent_id,# 父留言id
:m_reply_id => ref_message_id, # 子留言 id
:reply_id => reply_id, # 被留言用户id
:notes => content,
:is_readed => false}
if(params[:type] == 1)
user.add_jour(nil, nil,nil,options)
elsif(params[:type] == 2)
Course.find(params[:course_id]).journals_for_messages.build(options).save! unless params[:course_id].nil?
else
end
end
# 给用户留言
def leave_message params,current_user
obj = User.find(params[:user_id]).add_jour(current_user, params[:content], 0)
obj
end
#关注列表
def user_watcher params
@user = User.find(params[:id])
User.watched_by(@user.id)
end
#用户课程列表
def user_courses_list params,current_user
@user = User.find(params[:id])
if !current_user.admin? && !@user.active?
raise '404'
return
end
if current_user == @user || current_user.admin?
membership = @user.coursememberships.all
else
membership = @user.coursememberships.all(:conditions => Course.visible_condition(current_user))
end
membership.sort! {|older, newer| newer.created_on <=> older.created_on }
course_list = []
membership.each do |mp|
course_list << {:course => mp.course,:img_url => "/images/"+url_to_avatar(mp.course),:current_user_is_member => current_user.member_of_course?(mp.course),:current_user_is_teacher => is_course_teacher(current_user,mp.course)}
end
course_list
end
#修改密码
def change_password params
ActiveRecord::Base.transaction do
@current_user = User.find(params[:current_user_id])
if @current_user.check_password?(params[:password])
@current_user.password, @current_user.password_confirmation = params[:new_password], params[:new_password_confirmation]
@current_user.save
# 修改密码同步gitlab密码修改
unless @current_user.gid.nil?
begin
g = Gitlab.client
g.edit_user(@current_user.gid, :password => params[:new_password])
rescue Exception => e
logger.error "change users password failed! ===> #{e}"
end
end
#raise @current_user.errors.full_message
#return @current_user
else
if params[:password].present?
raise l(:notice_account_wrong_password,:locale => 'zh')
else
if params[:new_password].strip != "" && params[:new_password_confirmation].strip != ""
@current_user.password, @current_user.password_confirmation = params[:new_password], params[:new_password_confirmation]
@current_user.save
unless @current_user.gid.nil?
begin
g = Gitlab.client
g.edit_user(@current_user.gid, :password => params[:new_password])
rescue Exception => e
logger.error "change users password failed! ===> #{e}"
end
end
end
end
end
@current_user
end
end
#搜索用户
def search_user params
status = params[:status] || 1
has = {
"show_changesets" => true
}
scope = User.logged.status(status)
search_by = params[:search_by] ? params[:search_by] : "0"
if params[:is_search_assitant].nil?
#modify by yutao 2015/5/18 没有params[:user_id]参数时去掉"id not in (?)"条件(bug:#2270) start
#say by yutao: params[:user_id]这个是指谁发起的搜索么? 如果是 这个值貌似应该从session获取 怪怪的赶脚-_-!
if params[:name].present?
if !params[:user_id].nil?
watcher = User.watched_by(params[:user_id])
watcher.push(params[:user_id])
scope = scope.where("id not in (?)",watcher)
end
#scope = scope.like(params[:name],search_by)
scope = scope.where("( LOWER(login) LIKE ? or LOWER(concat(lastname, firstname)) LIKE ? or LOWER(mail) LIKE ? )",
"%#{params[:name]}%","%#{params[:name]}%","%#{params[:name]}%")
end
#modify by yutao 2015/5/18 没有params[:user_id]参数时去掉"id not in (?)"条件 end
else
teachers = searchTeacherAndAssistant(Course.find(params[:course_id]))
scope = scope.where("id not in (?)",teachers.map{|t| t.user_id}).like(params[:name],search_by) if params[:name].present?
end
scope
end
# 课程留言中与我相关的回复
def my_course_messages params,current_user
#找到我所有的课程
@user = current_user
if !current_user.admin? && !@user.active?
raise '404'
return
end
if current_user == @user || current_user.admin?
membership = @user.coursememberships.all
end
# membership.sort! {|older, newer| newer.created_on <=> older.created_on }
message_list = []
membership.each do |mp|
#课程轮询找到与我相关的回复
message_list << mp.course.journals_for_messages.where("reply_id = ?",current_user.id)
end
message_list
end
# 获取与我相关的留言:我的留言,回复我的留言
def my_personal_messages params,current_user
jours = current_user.journals_for_messages.where('m_parent_id is null or reply_id = ?',current_user.id)
jours.update_all(:is_readed => true, :status => false)
jours
end
# 所有的与我相关
def reply_my_messages params,current_user
jours = my_personal_messages params,current_user
jours1 = my_course_messages params,current_user
my_jours = []
my_jours << jours << jours1
my_jours.flatten!.sort! {|older, newer| newer.created_on <=> older.created_on }
my_jours_arr = Kaminari.paginate_array(my_jours, total_count: my_jours.count).page(params[:page] || 1).per(10)
my_jours_arr
end
def wechat_unbind uw
user = uw.user
#发重新绑定的微信模版消息
type = "login"
title = "尊敬的用户,您已解除绑定。"
key1 = "个人原因"
remark = "点击进入重新绑定。"
ws = WechatService.new
ws.rebind_notice user.id, type, user.id, title, key1,format_time(Time.now), remark
uw.user_id = nil
uw.delete
end
end

View File

@ -0,0 +1,57 @@
require 'uri'
require 'net/http'
class SyncForumsRake
# 运行示例: bundle exec rails runner "SyncForumsRake.new.call()"
def call
SyncLog.sync_log("==========begin_to_sync_forums=============")
begin
# url = "https://www.trustie.net/sync_forges/get_forums" #trustie上的相关路由
main_url = "https://www.trustie.net"
url = "#{main_url}/sync_forges/get_forums"
uri = URI.parse(url)
http = Net::HTTP.new(uri.hostname, uri.port)
http.use_ssl = main_url.include?("https")
headers = { "Content-Type" => "application/json" }
response = http.get(uri.path, headers)
# response = http.send_request('GET', uri.path,{'Content-Type' => 'application/json'})
if response.code == '200'
target_jsons = eval(response.body)
create_target(target_jsons[:all_forums], main_url)
else
SyncLog.sync_log("==========sync_forums_to_forge_failed============")
end
rescue => e
SyncLog.sync_log("==========sync_forums_to_forge_failed============errors:#{e}")
end
end
def create_target(targets, main_url)
curreunt_sections = ForumSection.all
positions = curreunt_sections.pluck(:position).select { |a| a.is_a? Integer }
positions = positions.max.to_i
targets.each_with_index do |t, index|
section_params = {
id: t[:id],
title: t[:name],
position: positions + index + 1,
description: t[:description],
user_id: t[:creator_id]
}
if curreunt_sections.exists?(t[:id])
current_section = curreunt_sections.where(id: t[:id]).first
if current_section.update_attributes(section_params)
SyncMemosJob.perform_later(t[:id], main_url)
end
else
section = ForumSection.new(section_params)
if section.save!
SyncMemosJob.perform_later(section.id, main_url)
end
end
end
end
end

View File

@ -0,0 +1,71 @@
<div class="box admin-list-container users-list-container">
<table class="table table-hover users-list-table">
<thead class="thead-light">
<tr>
<th width="9%">序号</th>
<th width="15%">作者</th>
<th width="32%" class="edu-txt-left" style="white-space:nowrap; overflow:hidden; text-overflow:ellipsis;">标题</th>
<th width="18%">发布时间<i class="fa fa-long-arrow-down %> color-light-green ml5"></i></th>
<th>回复数</th>
<th width="18%">操作</th>
</tr>
</thead>
<tbody>
<% @memos.each_with_index do |memo,index| %>
<tr id="apply_destroy_memo_<%= memo.id %>">
<td><%= list_index_no((params[:page] || 1).to_i, index) %></td>
<td>
<%= link_to(memo.try(:author).try(:show_real_name), "/users/#{memo.author.login}", target: "_blank") %>
</td>
<td class="edu-txt-left" style="white-space:nowrap; overflow:hidden; text-overflow:ellipsis;">
<%= link_to(memo.subject, "/forums/#{memo.id}/detail", target: "_blank") %>
</td>
<td><%= format_time(memo.created_at) %></td>
<td>
<%= link_to(memo.replies_count, "/forums/#{memo.id}/detail", target: "_blank") %>
</td>
<td>
<%= link_to '拒绝', confirm_apply_destroy_admins_apply_destroy_index_path(id: memo.id, confirm: "reject"), method: :post, remote: true, data: {confirm: "拒绝删除该帖子吗?"} %>
<%= link_to '同意', confirm_apply_destroy_admins_apply_destroy_index_path(id: memo.id, confirm: "delete"), method: :post, remote: true, data: {confirm: "确认删除该帖子吗?"} %>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>
<%= render partial: 'admins/shared/paginate', locals: { objects: @memos } %>
<script>
$(".magic-checkbox").on("click", function() {
var $link = $(this);
var id = $link.data('id');
var url = $link.data('url');
var checked = $link.is(':checked');
$.ajax({
url: url,
type: 'post',
data: {
id: id,
checked: checked
},
dataType: 'json',
success: function(data) {
if ($link.data('type') === 'hidden') {
console.log('#home_show_' + id, !checked);
$('#home_show_' + id).attr('disabled', !checked);
if (checked) {
$('.delete-link-' + id).hide();
} else {
$('.delete-link-' + id).show();
}
}
},
error: function() {
notice_box('操作失败');
$link.attr('checked', !checked);
}
})
});
</script>

View File

@ -0,0 +1 @@
$("#apply_destroy_memo_<%= params[:id] %>").remove()

View File

@ -0,0 +1,9 @@
<% define_admin_breadcrumbs do %>
<% add_admin_breadcrumb('申请删帖', admins_apply_destroy_index_path) %>
<% end %>
<div class="edu-class-container">
<div class="ex_container" id="apply_destory_memos">
<%= render :partial => "admins/apply_destroy/apply_destroy_memos_list" %>
</div>
</div>

View File

@ -0,0 +1 @@
$("#apply_destory_memos").html('<%= escape_javascript( render :partial => 'admins/apply_destroy/apply_destroy_memos_list') %>');

View File

@ -0,0 +1,38 @@
<div class="edu-back-white pl30 pr30 mb30">
<% if @banned_users_count > 0 %>
<% @banned_users.each do |ban| %>
<% user = ban.user %>
<% author = ban.author %>
<% memo = ban.memo %>
<% author_type = author.admin? ? "管理员" : "版主" %>
<div class="plan_infos_item" id="banned-users-item-<%= user.try(:id) %>">
<%= image_tag(url_to_avatar(user),width:"50px",height:"50px",class:"radius mr15") %>
<div class="flex1">
<li class="clearfix mb20">
<%= link_to user.try(:show_real_name),user,class: "fl mr15 color-grey-3 font-16" %>
<span class="fl color-grey-9 mt3 mr15"><%= time_from_now(ban.updated_at) %></span>
<span class="fl color-grey-9 mt3">第<span class="color-orange"><%= ban.banned_count %></span>次 被禁言</span>
<span class="fr">
<% if @banned_type == "banned" %>
<% remove_ban_message = "是否确认解除"+"\"#{user.try(:show_real_name)}\""+"的禁言?" %>
<%= link_to "取消禁言", "javascript:void(0)", class: "color-blue_4C", onclick: "custom_confirm_remote_box('#{confirm_banned_admin_banned_users_path(user_id: user.id, id: memo.id)}','#{remove_ban_message}','post');"%>
<% else %>
<%= link_to author.try(:show_real_name), user_path(author), class: "" %>
<span class="color-grey-9 ml20">
<%= time_from_now(ban.updated_at) %>
</span>
<% end %>
</span>
</li>
<div class="color-grey-9">
在【<span class="max-width-300"><%= link_to memo.subject.truncate(50), "forums/#{memo.id}", class: "color-blue_4C" %></span>】被<%= author_type %><%= link_to author.try(:show_real_name), user_path(author), class: "" %> 禁言
</div>
</div>
</div>
<% end %>
<% end %>
<%= render partial: 'admins/shared/paginate', locals: { objects: @banned_users } %>
</div>

View File

@ -0,0 +1,32 @@
<div class="box admin-list-container users-list-container">
<ul class="fl mt2 nav_blueline_status">
<li class="<%= @banned_type == "banned" ? "active" : "" %>" >
<%= link_to "禁言用户 #{@banned_users_size > 0 ? "(#{@banned_users_size})" : ""}", admins_banned_users_path(banned_type: "banned"),remote: true %>
</li>
<li class="<%= @banned_type == "unbanned" ? "active" : "" %>">
<%= link_to "解除禁言记录", admins_banned_users_path(banned_type: "unbanned"),remote: true %>
</li>
</ul>
<ul class="fr">
<input type="text" name="search_banned_user" value="<%= @search_params %>" class="form-control mr15 fl width240" placeholder="请输入用户名称进行搜索">
<a href="javascript:void(0)" class="btn btn-primary fl mr15 btn-sm" id="searchBanned">搜索</a>
<%= link_to "清除", admins_banned_users_path(search: nil, banned_type: @banned_type),remote: true, class: "btn btn-secondary fl btn-sm" %>
</ul>
</div>
<div id="banned-user-item">
<%= render partial: "admins/banned_users/banned_user_item" %>
</div>
<script>
$("#searchBanned").on("click",function () {
let task_status = "<%= @banned_type %>";
let search_name =$("input[name='search_banned_user']").val();
$.ajax({
url: "<%= admins_banned_users_path %>",
type: "get",
dataType: "script",
data: {banned_type:task_status,search: search_name }
});
});
</script>

View File

@ -0,0 +1,4 @@
<% if @status > 0 %>
$("#banned-users-item-<%= params[:user_id] %>").remove()
<% end %>
op_know('<%= @message %>')

View File

@ -0,0 +1,6 @@
<% define_admin_breadcrumbs do %>
<% add_admin_breadcrumb('禁言列表', admins_banned_users_path) %>
<% end %>
<div class="edu-class-container" id="banned-users-container">
<%= render partial: "admins/banned_users/banned_users_items" %>
</div>

View File

@ -0,0 +1 @@
$("#banned-users-container").html("<%= j render partial: "admins/banned_users/banned_users_items" %>")

View File

@ -0,0 +1,33 @@
<div class="box admin-list-container users-list-container">
<ul class="fl mt2 nav_blueline_status">
<li class="<%= @select_type == "unconfirm" ? "active" : "" %>" >
<%= link_to "待审批", admins_forum_applies_path(select_type: "unconfirm"),remote: true %>
</li>
<li class="<%= @select_type == "confirm" ? "active" : "" %>">
<%= link_to "已审批", admins_forum_applies_path(select_type: "confirm"),remote: true %>
</li>
</ul>
<ul class="fr">
<input type="text" name="search_section_name" value="<%= @section_name %>" class="form-control mr15 fl width240 " placeholder="请输入板块名称进行检索">
<input type="text" name="search_user_name" value="<%= @search_name %>" class="form-control mr15 fl width240 " placeholder="请输入用户名称进行检索">
<a href="javascript:void(0)" class="btn btn-primary fl mr15 mt2 btn-sm" id="searchApplies">搜索</a>
<%= link_to "清除", admins_forum_applies_path(user_name: nil,section_name: nil, select_type: @select_type),remote: true, class: "btn btn-secondary fl btn-sm" %>
</ul>
</div>
<div id="forum-apply-item">
<%= render partial: "admins/forum_applies/forum_apply_item" %>
</div>
<script>
$("#searchApplies").on("click",function () {
let select_status = "<%= @select_type %>";
let search_name =$("input[name='search_user_name']").val();
let section_name = $("input[name='search_section_name']").val();
$.ajax({
url: "<%= admins_forum_applies_path %>",
type: "get",
dataType: "script",
data: {select_type:select_status,user_name: search_name, section_name: section_name }
});
});
</script>

View File

@ -0,0 +1,25 @@
<div class="edu-back-white pl30 pr30 mb30">
<!-- 签订协议托管-待审批 -->
<% if @forum_applies_count > 0 %>
<% @forum_applies.each do |apply| %>
<% user = apply&.user %>
<% if user.present? %>
<div class="plan_infos_item" id="forum-apply-action-<%= apply.id %>">
<%= render partial: "admin/forum_applies/item_list", locals: {user: user, apply: apply} %>
</div>
<% end %>
<% end %>
<% end %>
<%= render partial: 'admins/shared/paginate', locals: { objects: @forum_applies } %>
</div>
<script type="text/javascript">
function refuseClick(id) {
$("#refuseContent_"+id).removeClass("none")
}
function cancelRefuse(id) {
$("#refuseContent_"+id).addClass("none")
}
</script>

View File

@ -0,0 +1,52 @@
<%= image_tag(url_to_avatar(user),width:"50px",height:"50px",class:"radius mr15") %>
<div class="flex1">
<li class="clearfix mb20">
<%= link_to user.try(:show_real_name),user_path(user),class: "fl mr15 color-grey-3 font-16" %>
<span class="fl color-grey-9 mt3"><%= time_from_now(apply.updated_at) %></span>
<span class="fl color-grey-9 mt3 ml50">IP<%= user_ip_addr apply.user_ip %></span>
<span class="fr">
<% if apply.is_confirm != 0 %>
<% apply_user = apply&.reviews&.acted_forum&.last&.user %>
<% if apply_user.present? %>
<span class="fl mr20">
<%= link_to apply_user.try(:show_real_name), user_path(apply_user) %>
</span>
<% end %>
<% if apply.is_confirm == 2 %>
<span class="color-red fl ml20">已拒绝</span>
<% else %>
<span class="color-green fl ml20">已同意</span>
<a href="javascript:void(0)" class="color-blue ml20" onclick="refuseClick(<%= apply.id %>)">撤销审核</a>
<% end %>
<% else %>
<%= link_to "私信", message_detail_user_path(current_user, :user_id => apply.user_id), :class => "edu-default-btn edu-orangeline-btn ml20 fl",target:"_blank" %>
<%= link_to "同意", confirm_apply_admins_forum_apply_path(id:apply.id,review_result:"0"),remote: true, method: :post, class: "edu-default-btn edu-blueline-btn ml20 fl", data:{confirm: "是否同意申请版主?"} %>
<%# <%= link_to "拒绝", confirm_apply_admins_forum_apply_path(id:apply.id,review_result:"0"),remote: true, method: :post, class: "edu-default-btn edu-blueline-btn ml20 fl", data:{confirm: "是否同意申请版主?"} %> %>
<a href="javascript:void(0)" class="edu-default-btn edu-greyline-btn ml20 fl" onclick="refuseClick(<%= apply.id %>)">拒绝</a>
<% end %>
</span>
</li>
<div class="width100">
<span class="color-grey-9">申请成为"<%= link_to apply.forum_section.try(:title), "/memos/forum_memos/#{apply.id}", class: "color-blue" %>"的版主</span>
</div>
<% if apply.is_confirm == 2 %>
<p class="color-orange lineh-35 mt10"><span class="fl color-orange mr5">拒绝原因:</span><%= apply&.reviews&.apply_forum&.first&.reason.to_s %></p>
<% end %>
<% if apply.is_confirm != 2 %>
<%= labelled_form_for apply, :url => confirm_apply_admins_forum_apply_path(apply, is_confirm: apply.is_confirm), :html => {id:"refuseContent_#{apply.id}",class:"none",method: :post, remote: true} do |f| %>
<div class="df mt10">
<input type="hidden" id="review_result_type" name="review_result" value="1" />
<span class="refuse_reason color-orange mr5"><%= apply.is_confirm == 0 ? "拒绝原因" : "撤销审核原因" %>:</span>
<div class="flex1">
<textarea name="reason" maxlength="200" placeholder="我想说点什么呢,200字以内" class="winput-100-70 mt8 mb10"></textarea>
<li class="clearfix">
<a href="javascript:void(0)" class="edu-default-btn edu-greyback-btn fl mr20" onclick="cancelRefuse(<%= apply.id %>)">取消</a>
<%= f.submit "确定",class:"edu-default-btn edu-blueback-btn fl mr20" %>
</li>
</div>
</div>
<% end %>
<% end %>
<!-- 点击拒绝显示的部分 -->
</div>

View File

@ -0,0 +1,9 @@
<% if @status > 0%>
<% if @is_confirm == 0 %>
$("#forum-apply-action-<%= @forum_apply.id %>").remove()
<% else %>
$("#forum-apply-action-<%= @forum_apply.id %>").html("<%= j render partial: "admins/forum_applies/item_list", locals: {user: @forum_apply.user, apply: @forum_apply} %>")
<% end %>
<% end %>
op_know("<%= @message %>")

View File

@ -0,0 +1,7 @@
<% define_admin_breadcrumbs do %>
<% add_admin_breadcrumb('版主审批', admins_forum_applies_path) %>
<% end %>
<div class="edu-class-container" id="forum-applies-container">
<%= render partial: "admins/forum_applies/forum_applies_items" %>
</div>

View File

@ -0,0 +1 @@
$("#forum-applies-container").html("<%= j render partial: "admins/forum_applies/forum_applies_items" %>")

View File

@ -0,0 +1,12 @@
<% if users.present? && users.size > 0 %>
<% users.each do |u| %>
<% user = u.user %>
<span class="moderator-list-content">
<span class="blue-user-btn" id="forum_section_moderator_user_<%= u.id %>">
<span class="mr5"><%= link_to user.try(:show_real_name), user_path(user) %></span>
<span><%= link_to "<i class='fa fa-close font16'></i>".html_safe,admins_forum_section_forum_moderator_path(forum, u), method: :delete, data:{confirm: "确认删除吗?"}, remote: true, class: "color-grey-9" %></span>
</span>
</span>
<% end %>
<% end %>

View File

@ -0,0 +1,28 @@
<div class="task-popup" style="width:500px;">
<div class="task-popup-title clearfix f14">
<span>添加版主</span>
</div>
<%= form_tag(admin_forum_section_forum_moderators_path(@forum_section), method: :post, class: "", remote: true) do %>
<div class="task-popup-content mt10">
<div class="df">
<div class="flex1 text-center">
<%= text_field_tag :user_name,nil,class: "winput-300-35" ,id: "search-forum-moderators",placeholder: "请输入用户的名称搜索" %>
<%= link_to "搜索", "javascript:void(0)", class: "task-btn task-btn-orange ml15", onclick: "search_forum_users('search-forum-moderators')" %>
</div>
</div>
<div id="has-none-moderators" class="none forum-moderators-items">
</div>
<div id="forum-moderators-show" class="none forum-moderators-items">
</div>
</div>
<div class="cl"></div>
<div class="edu-txt-center mbt10">
<li class="inline">
<a href="javascript:void(0)" class="task-btn fl mr50" onclick="hideModal();">取消</a>
<%= submit_tag "确定", class: "edu-default-btn edu-blueback-btn" %>
</li>
</div>
<% end %>
</div>

View File

@ -0,0 +1,4 @@
<% if @forum_status > 0 %>
$("#forum_sections_moderators_<%= @forum_section.id %>").html("<%= j render partial: "admins/forum_moderators/forum_moderator_item", locals: {users: @forum_moderators, forum: @forum_section} %>")
$('#admin-managers-modal').modal("hide")
<% end %>

Some files were not shown because too many files have changed in this diff Show More