admin video applies

dev_aliyun
p31729568 6 years ago
parent 66239316c8
commit c71e5ea1ea

@ -0,0 +1,47 @@
class Managements::VideoAppliesController < Managements::BaseController
before_filter :set_menu_type
def index
applies = VideoApply.order('video_applies.updated_at desc')
search = params[:search].to_s.strip
if search.present?
applies = applies.joins(:video)
.where('videos.title like :search', search: "%#{search}%")
end
applies = applies.where(status: params[:status].presence || :pending)
@video_applies = paginateHelper applies.includes(video: { user: :user_extensions })
respond_to do |format|
format.js
format.html
end
end
def agree
Videos::AgreeApplyService.new(current_video_apply, current_user).call
render json: { status: 0 }
rescue Videos::AgreeApplyService::Error => e
render json: { status: -1, message: e.message }
end
def refuse
Videos::RefuseApplyService.new(current_video_apply, current_user, reason: params[:reason]).call
render json: { status: 0 }
rescue Videos::RefuseApplyService::Error => e
render json: { status: -1, message: e.message }
end
private
def current_video_apply
@_current_video_apply ||= VideoApply.find(params[:id])
end
def set_menu_type
@menu_type = 10
@sub_type = 10
end
end

@ -756,6 +756,7 @@ module ApplicationHelper
when 7 then '职业认证'
when 8 then '教学案例发布'
when 9 then '众包需求发布'
when 10 then '视频发布'
else '职业认证'
end
when 11

@ -0,0 +1,36 @@
class Video < ActiveRecord::Base
include AASM
belongs_to :user
has_many :video_applies, dependent: :destroy
has_one :processing_video_apply, conditions: { status: :pending }, class_name: 'VideoApply'
aasm(:status) do
state :pending, initial: true
state :processing
state :refused
state :published
event :apply_publish do
transitions from: :pending, to: :processing
end
event :refuse do
transitions from: :processing, to: :refused
end
event :publish do
transitions from: :processing, to: :published, guard: :vod_uploaded?
end
end
aasm(:vod_status, namespace: :vod) do
state :uploading, initial: true
state :uploaded
event :upload_success do
transitions from: :uploading, to: :uploaded
end
end
end

@ -0,0 +1,19 @@
class VideoApply < ActiveRecord::Base
include AASM
belongs_to :video
aasm(:status) do
state :pending, initial: true
state :refused
state :agreed
event :refuse do
transitions from: :pending, to: :refused
end
event :agree do
transitions from: :pending, to: :agreed
end
end
end

@ -0,0 +1,35 @@
class Videos::AgreeApplyService
Error = Class.new(StandardError)
attr_reader :video_apply, :video, :user
def initialize(video_apply, user)
@video_apply = video_apply
@video = video_apply.video
@user = user
end
def call
raise Error, '该状态下不能进行此操作' unless video_apply.may_agree? && video.may_publish?
ActiveRecord::Base.transaction do
video_apply.agree!
video.published_at = Time.now
video.publish
video.save!
# 将消息改为已处理
Tiding.where(container_id: video.id, container_type: 'Video', tiding_type: 'Apply', status: 0).update_all(status: 1)
notify_video_author!
end
end
private
def notify_video_author!
Tiding.create!(user_id: video.user_id, trigger_user_id: 1,
container_id: video.id, container_type: 'Video',
tiding_type: 'System', status: 1)
end
end

@ -0,0 +1,38 @@
class Videos::RefuseApplyService
Error = Class.new(StandardError)
attr_reader :video_apply, :video, :user, :params
def initialize(video_apply, user, params)
@video_apply = video_apply
@video = video_apply.video
@user = user
@params = params
end
def call
reason = params[:reason].to_s.strip
raise Error, '原因不能为空' if reason.blank?
raise Error, '该状态下不能进行此操作' unless video_apply.may_refuse?
ActiveRecord::Base.transaction do
video_apply.reason = reason
video_apply.refuse
video_apply.save!
video.refuse!
# 将消息改为已处理
Tiding.where(container_id: video.id, container_type: 'Video', tiding_type: 'Apply', status: 0).update_all(status: 1)
notify_video_author!
end
end
private
def notify_video_author!
Tiding.create!(user_id: video.user_id, trigger_user_id: 1,
container_id: video.id, container_type: 'Video',
tiding_type: 'System', status: 2, extra: video_apply.reason)
end
end

@ -123,6 +123,7 @@
<li><%= link_to '实践课程发布', subject_authorization_managements_path %></li>
<li><%= link_to '教学案例发布', library_applies_path(status: :pending) %></li>
<li><%= link_to '众包需求发布', project_package_applies_path(status: :pending) %></li>
<li><%= link_to '视频发布', video_applies_path(status: :pending) %></li>
</ul>
</li>
<li class="fl edu-admin-nav-li edu-position"><a href="javascript:void(0);" class="edu-admin-nav-a">认证+</a>

@ -0,0 +1,77 @@
<% if @video_applies.present? %>
<% @video_applies.each do |apply| %>
<% user = apply.video.user %>
<% video = apply.video %>
<div class="admin-con-box apply-<%= apply.id %> clearfix">
<a href="<%= user_path(user) %>" target="_blank" class="fl with10 edu-ad-user">
<%= image_tag(url_to_avatar(user), :class => "fl with10 edu-ad-user", :alt => "头像", :width => "50", :height => "50" ) %>
</a>
<div class="fl with90">
<ul>
<li class="clearfix mb5">
<a href="<%= user_path(user) %>" class="fl"><%= user.try(:show_real_name) %></a>
<span class="fl ml30 font-12 mt3 color-grey"><%= time_from_now(apply.created_at) %></span>
<% if apply.pending? %>
<a href="javascript:void(0);" class="fr color-orange" onclick="reject_video_authentication_reason(this);" >拒绝</a>
<a href="javascript:void(0);" class="fr mr15 color-orange" data-remote="true" onclick="video_authorization_gree('<%= apply.id %>');">同意</a>
<%= link_to('播放视频', video.file_url, class: 'fr mr15 color-orange', target: '_blank') %>
<% else %>
<a href="javascript:void(0);" class="<%= apply.agreed? ? 'task-btn-green' : '' %> task-btn fr"><%= apply.agreed? ? "已同意" : "已拒绝" %></a>
<% end %>
</li>
<li class="clearfix mb10">
<span><%= video.title %></span>
</li>
<% if apply.pending? %>
<div class="undis">
<li class="clearfix edu-form-border mb10">
<label class="edu-form-label fl">原因:</label>
<input type="text" class="task-form-90 task-height-40 panel-box-sizing fl edu-form-noborder" placeholder="我得说点儿什么最多200个字符">
</li>
<li class="clearfix">
<a href="javascript:void(0);" class="task-btn task-btn-orange fr" onclick="video_submit_reject_reason('<%= apply.id %>', this);" >确定</a>
<a href="javascript:void(0);" class="task-btn fr mr10" onclick="video_hide_reject_reason(this);" >取消</a>
</li>
</div>
<% else %>
<% if apply.refused? %>
<li>原因:<span class="color-orange"><%= apply.reason %></span></li>
<% end %>
<% end %>
</ul>
</div>
</div>
<% end %>
<div class="mt20 mb20" style="text-align:center;">
<div class="pages_user_show" style="width:auto; display:inline-block;">
<ul id="homework_pository_ref_pages">
<%= pagination_links_full @obj_pages, @obj_count, :per_page_links => false, :remote => true, :flag => true, :is_new => true %>
</ul>
<div class="cl"></div>
</div>
</div>
<% else %>
<%= render :partial => "welcome/no_data" %>
<% end %>
<script type="text/javascript">
function video_authorization_gree(id){
$.ajax({
url: '/managements/video_applies/' + id + '/agree',
type: 'post',
success: function(data){
if (data && data.status != -1) {
$('#authentication_list .admin-con-box.apply-' + id).remove();
if($('#authentication_list .admin-con-box').length == 0){
location.reload();
}
} else {
alert(data.message);
}
}
})
}
</script>

@ -0,0 +1,120 @@
<div class="edu-class-container mb15">
<div class="edu-con-top clearfix">
<p class="ml15 fl color-grey">视频发布</p>
</div>
<div class="edu-con-bg01 mt15">
<div class="edu-tab clearfix mb20">
<ul id="edu-tab-nav" class="border-bottom-orange">
<li id="edu-tab-nav-1" class="new-tab-nav background-orange" onclick="HoverLi(1);">
<%= link_to "待审批", video_applies_path(status: :pending), class: 'tab_type', remote: true %>
</li>
<li id="edu-tab-nav-2" class="new-tab-nav" onclick="HoverLi(2);">
<%= link_to "已审批", video_applies_path(status: [:refused, :agreed]), class: 'tab_type', remote: true %>
</li>
</ul>
<div class="cl"></div>
<div id="edu-tab-con-1">
<div class="mt10">
<div class="edu-position fr task-form-30 mb10 mr15">
<input class="task-form-100 panel-box-sizing" placeholder="输入视频标题进行检索" type="text" id="search_name">
<a href="javascript:void(0);" class="edu-btn-search font-16 color-grey mt10" id="search"><i class="fa fa-search"></i></a>
</div>
<div class="cl"></div>
<div id="authentication_list" class="auth_table">
<%= render :partial => "managements/video_applies/video_apply_list"%>
</div>
</div>
</div>
<div id="edu-tab-con-2" class="undis">
<div class="mt10">
<p class="fl task-form-60 mt8 ml15 clearfix">
<%= link_to "全部", video_applies_path(status: [:refused, :agreed]), :class => "edu-filter-cir-grey mr5 fl font-12 active", :id => "video_all_authentication", :remote => true %>
<%= link_to "同意", video_applies_path(status: :agreed), :class => "edu-filter-cir-grey mr5 fl font-12", :id => "video_agree_authentication", :remote => true %>
<%= link_to "拒绝", video_applies_path(status: :refused), :class => "edu-filter-cir-grey mr5 fl font-12", :id => "video_reject_authentication", :remote => true %>
</p>
<div class="edu-position fr task-form-30 mb10 fr mr15">
<input class="task-form-100 panel-box-sizing" placeholder="输入视频标题进行检索" type="text" id="video_search_name">
<a href="javascript:void(0);" class="edu-btn-search font-16 color-grey mt10" id="video_search"><i class="fa fa-search"></i></a>
</div>
<div class="cl"></div>
<div id="video_authentication_list" class="auth_table">
</div>
</div>
</div>
<div class="cl"></div>
</div>
</div>
</div>
<script>
/* -------------------------- 拒绝 ------------------------------------ */
function reject_video_authentication_reason(nThis){
var reason = $(nThis).parent().parent().find('div');
reason.find("input").val("");
reason.toggle();
}
/* -------------------------- 取消 ------------------------------------ */
function video_hide_reject_reason(nThis){
var reason = $(nThis).parent().parent();
reason.find("input").val("");
reason.hide();
}
/* ------------------------- 提交拒绝原因 --------------------------------- */
function video_submit_reject_reason(id, nThis){
var nReason = $(nThis).parent().parent();
var reason = nReason.find("input").val();
if (reason == '') {
alert('请输入原因');
return;
}
$.ajax({
url: '/managements/video_applies/' + id + '/refuse',
type: 'post',
data: {reason: reason},
success: function(data){
if (data && data.status != -1) {
$('#authentication_list .admin-con-box.apply-' + id).remove();
if($('#authentication_list .admin-con-box').length == 0){
location.reload();
}
} else {
alert(data.message);
}
}
});
}
/* -------------------------- 按名字进行搜索(未审批) ----------------------------- */
$("#search").live("click", function(){
var iName = $("#search_name").val();
$.ajax({
url: "/managements/video_applies",
dataType: 'script',
data: { search: iName, status: 'pending' }
});
});
/* ------------------- 按名字进行搜索(已审批)-------------------- */
$("#video_search").live("click", function(){
var iName = $("#video_search_name").val();
var id = $("#video_all_authentication").parent().find(".active").attr("id");
var status = '';
if(id == "video_all_authentication"){
status = ['refused', 'agreed'];
}else if(id=="video_agree_authentication"){
status = 'agreed';
}else{
status = 'refused';
}
$.ajax({
url: "/managements/video_applies",
dataType: 'script',
data: { search: iName, status: status}
});
});
</script>

@ -0,0 +1,30 @@
var nTabIcon_1 = $("#edu-tab-con-1");
var nTabIcon_2 = $("#edu-tab-con-2");
var nTabNav_1 = $("#edu-tab-nav-1");
var nTabNav_2 = $("#edu-tab-nav-2");
var nAudit = $("#video_all_authentication").parent();
<% if params[:status].to_s == 'pending' %>
$("#authentication_list").html("<%= j( render :partial => "managements/video_applies/video_apply_list" ) %>");
nTabNav_1.addClass("background-orange");
nTabNav_2.removeClass("background-orange");
nTabIcon_1.show();
nTabIcon_2.hide();
<% else %>
$("#video_authentication_list").html("<%= j( render :partial => "managements/video_applies/video_apply_list" ) %>");
nTabNav_1.removeClass("background-orange");
nTabNav_2.addClass("background-orange");
nTabIcon_1.hide();
nTabIcon_2.show();
/* -------------------------- 未审批(全部、同意、拒绝点击时动态样式) ------------------------------ */
if(<%= params[:status].to_s == 'agreed' %>){
nAudit.find(".active").removeClass("active");
$("#video_agree_authentication").addClass("active");
}else if(<%= params[:status].to_s == 'refused' %>){
nAudit.find(".active").removeClass("active");
$("#video_reject_authentication").addClass("active");
}else{
nAudit.find(".active").removeClass("active");
$("#video_all_authentication").addClass("active");
}
<% end %>

@ -765,6 +765,13 @@ RedmineApp::Application.routes.draw do ## oauth相关
post :refuse
end
end
resources :video_applies, only: [:index] do
member do
post :agree
post :refuse
end
end
end
end
end

Loading…
Cancel
Save